diff --git a/crates/archivr-server/static/assets/index-fBW6UZq7.js b/crates/archivr-server/static/assets/index-DZAStbJ2.js similarity index 61% rename from crates/archivr-server/static/assets/index-fBW6UZq7.js rename to crates/archivr-server/static/assets/index-DZAStbJ2.js index f9fe128..fba4f7e 100644 --- a/crates/archivr-server/static/assets/index-fBW6UZq7.js +++ b/crates/archivr-server/static/assets/index-DZAStbJ2.js @@ -6,7 +6,7 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var Xr=Symbol.for("react.element"),Vd=Symbol.for("react.portal"),Qd=Symbol.for("react.fragment"),Kd=Symbol.for("react.strict_mode"),qd=Symbol.for("react.profiler"),Xd=Symbol.for("react.provider"),Jd=Symbol.for("react.context"),Yd=Symbol.for("react.forward_ref"),Gd=Symbol.for("react.suspense"),Zd=Symbol.for("react.memo"),ef=Symbol.for("react.lazy"),Xa=Symbol.iterator;function tf(e){return e===null||typeof e!="object"?null:(e=Xa&&e[Xa]||e["@@iterator"],typeof e=="function"?e:null)}var xu={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},wu=Object.assign,ku={};function tr(e,t,n){this.props=e,this.context=t,this.refs=ku,this.updater=n||xu}tr.prototype.isReactComponent={};tr.prototype.setState=function(e,t){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")};tr.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function ju(){}ju.prototype=tr.prototype;function Gi(e,t,n){this.props=e,this.context=t,this.refs=ku,this.updater=n||xu}var Zi=Gi.prototype=new ju;Zi.constructor=Gi;wu(Zi,tr.prototype);Zi.isPureReactComponent=!0;var Ja=Array.isArray,Su=Object.prototype.hasOwnProperty,ea={current:null},Nu={key:!0,ref:!0,__self:!0,__source:!0};function _u(e,t,n){var r,l={},i=null,a=null;if(t!=null)for(r in t.ref!==void 0&&(a=t.ref),t.key!==void 0&&(i=""+t.key),t)Su.call(t,r)&&!Nu.hasOwnProperty(r)&&(l[r]=t[r]);var o=arguments.length-2;if(o===1)l.children=n;else if(1"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),li=Object.prototype.hasOwnProperty,mf=/^[: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]*$/,Ga={},Za={};function gf(e){return li.call(Za,e)?!0:li.call(Ga,e)?!1:mf.test(e)?Za[e]=!0:(Ga[e]=!0,!1)}function yf(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 vf(e,t,n,r){if(t===null||typeof t>"u"||yf(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 Qe(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 ze={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){ze[e]=new Qe(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];ze[t]=new Qe(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){ze[e]=new Qe(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){ze[e]=new Qe(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){ze[e]=new Qe(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){ze[e]=new Qe(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){ze[e]=new Qe(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){ze[e]=new Qe(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){ze[e]=new Qe(e,5,!1,e.toLowerCase(),null,!1,!1)});var na=/[\-:]([a-z])/g;function ra(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(na,ra);ze[t]=new Qe(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(na,ra);ze[t]=new Qe(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(na,ra);ze[t]=new Qe(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){ze[e]=new Qe(e,1,!1,e.toLowerCase(),null,!1,!1)});ze.xlinkHref=new Qe("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){ze[e]=new Qe(e,1,!1,e.toLowerCase(),null,!0,!0)});function la(e,t,n,r){var l=ze.hasOwnProperty(t)?ze[t]:null;(l!==null?l.type!==0:r||!(2"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),li=Object.prototype.hasOwnProperty,mf=/^[: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]*$/,Ga={},Za={};function gf(e){return li.call(Za,e)?!0:li.call(Ga,e)?!1:mf.test(e)?Za[e]=!0:(Ga[e]=!0,!1)}function yf(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 vf(e,t,n,r){if(t===null||typeof t>"u"||yf(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 Qe(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 ze={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){ze[e]=new Qe(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];ze[t]=new Qe(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){ze[e]=new Qe(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){ze[e]=new Qe(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){ze[e]=new Qe(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){ze[e]=new Qe(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){ze[e]=new Qe(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){ze[e]=new Qe(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){ze[e]=new Qe(e,5,!1,e.toLowerCase(),null,!1,!1)});var na=/[\-:]([a-z])/g;function ra(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(na,ra);ze[t]=new Qe(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(na,ra);ze[t]=new Qe(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(na,ra);ze[t]=new Qe(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){ze[e]=new Qe(e,1,!1,e.toLowerCase(),null,!1,!1)});ze.xlinkHref=new Qe("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){ze[e]=new Qe(e,1,!1,e.toLowerCase(),null,!0,!0)});function la(e,t,n,r){var l=ze.hasOwnProperty(t)?ze[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{Ps=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?yr(e):""}function xf(e){switch(e.tag){case 5:return yr(e.type);case 16:return yr("Lazy");case 13:return yr("Suspense");case 19:return yr("SuspenseList");case 0:case 2:case 15:return e=Ls(e.type,!1),e;case 11:return e=Ls(e.type.render,!1),e;case 1:return e=Ls(e.type,!0),e;default:return""}}function oi(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 Pn:return"Fragment";case bn:return"Portal";case si:return"Profiler";case sa:return"StrictMode";case ii:return"Suspense";case ai:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Ru:return(e.displayName||"Context")+".Consumer";case zu:return(e._context.displayName||"Context")+".Provider";case ia:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case aa:return t=e.displayName||null,t!==null?t:oi(e.type)||"Memo";case Ht:t=e._payload,e=e._init;try{return oi(e(t))}catch{}}return null}function wf(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 oi(t);case 8:return t===sa?"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 nn(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function Iu(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function kf(e){var t=Iu(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 il(e){e._valueTracker||(e._valueTracker=kf(e))}function Du(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=Iu(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function Ol(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 ui(e,t){var n=t.checked;return he({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function to(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=nn(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 Ou(e,t){t=t.checked,t!=null&&la(e,"checked",t,!1)}function ci(e,t){Ou(e,t);var n=nn(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")?di(e,t.type,n):t.hasOwnProperty("defaultValue")&&di(e,t.type,nn(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function no(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 di(e,t,n){(t!=="number"||Ol(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var vr=Array.isArray;function Bn(e,t,n,r){if(e=e.options,t){t={};for(var l=0;l"+t.valueOf().toString()+"",t=al.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function zr(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var jr={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},jf=["Webkit","ms","Moz","O"];Object.keys(jr).forEach(function(e){jf.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),jr[t]=jr[e]})});function Bu(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||jr.hasOwnProperty(e)&&jr[e]?(""+t).trim():t+"px"}function Hu(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,l=Bu(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,l):e[n]=l}}var Sf=he({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 hi(e,t){if(t){if(Sf[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(L(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(L(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(L(61))}if(t.style!=null&&typeof t.style!="object")throw Error(L(62))}}function mi(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 gi=null;function oa(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var yi=null,Hn=null,Un=null;function so(e){if(e=Gr(e)){if(typeof yi!="function")throw Error(L(280));var t=e.stateNode;t&&(t=ps(t),yi(e.stateNode,e.type,t))}}function Uu(e){Hn?Un?Un.push(e):Un=[e]:Hn=e}function Wu(){if(Hn){var e=Hn,t=Un;if(Un=Hn=null,so(e),t)for(e=0;e>>=0,e===0?32:31-($f(e)/If|0)|0}var ol=64,ul=4194304;function xr(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 Bl(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=xr(o):(i&=a,i!==0&&(r=xr(i)))}else a=n&~l,a!==0?r=xr(a):i!==0&&(r=xr(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 Jr(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-jt(t),e[t]=n}function Ff(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=Nr),mo=" ",go=!1;function cc(e,t){switch(e){case"keyup":return pp.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function dc(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Ln=!1;function mp(e,t){switch(e){case"compositionend":return dc(t);case"keypress":return t.which!==32?null:(go=!0,mo);case"textInput":return e=t.data,e===mo&&go?null:e;default:return null}}function gp(e,t){if(Ln)return e==="compositionend"||!ga&&cc(e,t)?(e=oc(),Cl=pa=Qt=null,Ln=!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=wo(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 gc(){for(var e=window,t=Ol();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=Ol(e.document)}return t}function ya(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 _p(e){var t=gc(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&mc(n.ownerDocument.documentElement,n)){if(r!==null&&ya(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=ko(n,i);var a=ko(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,zn=null,Si=null,Cr=null,Ni=!1;function jo(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Ni||zn==null||zn!==Ol(r)||(r=zn,"selectionStart"in r&&ya(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}),Cr&&Mr(Cr,r)||(Cr=r,r=Wl(Si,"onSelect"),0In||(e.current=Pi[In],Pi[In]=null,In--)}function se(e,t){In++,Pi[In]=e.current,e.current=t}var rn={},Fe=sn(rn),Je=sn(!1),gn=rn;function Xn(e,t){var n=e.type.contextTypes;if(!n)return rn;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 Ye(e){return e=e.childContextTypes,e!=null}function Ql(){ae(Je),ae(Fe)}function bo(e,t,n){if(Fe.current!==rn)throw Error(L(168));se(Fe,t),se(Je,n)}function _c(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(L(108,wf(e)||"Unknown",l));return he({},n,r)}function Kl(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||rn,gn=Fe.current,se(Fe,e),se(Je,Je.current),!0}function Po(e,t,n){var r=e.stateNode;if(!r)throw Error(L(169));n?(e=_c(e,t,gn),r.__reactInternalMemoizedMergedChildContext=e,ae(Je),ae(Fe),se(Fe,e)):ae(Je),se(Je,n)}var zt=null,hs=!1,Vs=!1;function Cc(e){zt===null?zt=[e]:zt.push(e)}function Op(e){hs=!0,Cc(e)}function an(){if(!Vs&&zt!==null){Vs=!0;var e=0,t=re;try{var n=zt;for(re=1;e>=a,l-=a,Rt=1<<32-jt(t)+l|n<N?($=E,E=null):$=E.sibling;var P=h(p,E,y[N],j);if(P===null){E===null&&(E=$);break}e&&E&&P.alternate===null&&t(p,E),d=i(P,d,N),b===null?_=P:b.sibling=P,b=P,E=$}if(N===y.length)return n(p,E),de&&un(p,N),_;if(E===null){for(;NN?($=E,E=null):$=E.sibling;var V=h(p,E,P.value,j);if(V===null){E===null&&(E=$);break}e&&E&&V.alternate===null&&t(p,E),d=i(V,d,N),b===null?_=V:b.sibling=V,b=V,E=$}if(P.done)return n(p,E),de&&un(p,N),_;if(E===null){for(;!P.done;N++,P=y.next())P=m(p,P.value,j),P!==null&&(d=i(P,d,N),b===null?_=P:b.sibling=P,b=P);return de&&un(p,N),_}for(E=r(p,E);!P.done;N++,P=y.next())P=g(E,p,N,P.value,j),P!==null&&(e&&P.alternate!==null&&E.delete(P.key===null?N:P.key),d=i(P,d,N),b===null?_=P:b.sibling=P,b=P);return e&&E.forEach(function(H){return t(p,H)}),de&&un(p,N),_}function k(p,d,y,j){if(typeof y=="object"&&y!==null&&y.type===Pn&&y.key===null&&(y=y.props.children),typeof y=="object"&&y!==null){switch(y.$$typeof){case sl:e:{for(var _=y.key,b=d;b!==null;){if(b.key===_){if(_=y.type,_===Pn){if(b.tag===7){n(p,b.sibling),d=l(b,y.props.children),d.return=p,p=d;break e}}else if(b.elementType===_||typeof _=="object"&&_!==null&&_.$$typeof===Ht&&Ro(_)===b.type){n(p,b.sibling),d=l(b,y.props),d.ref=fr(p,b,y),d.return=p,p=d;break e}n(p,b);break}else t(p,b);b=b.sibling}y.type===Pn?(d=mn(y.props.children,p.mode,j,y.key),d.return=p,p=d):(j=$l(y.type,y.key,y.props,null,p.mode,j),j.ref=fr(p,d,y),j.return=p,p=j)}return a(p);case bn:e:{for(b=y.key;d!==null;){if(d.key===b)if(d.tag===4&&d.stateNode.containerInfo===y.containerInfo&&d.stateNode.implementation===y.implementation){n(p,d.sibling),d=l(d,y.children||[]),d.return=p,p=d;break e}else{n(p,d);break}else t(p,d);d=d.sibling}d=Zs(y,p.mode,j),d.return=p,p=d}return a(p);case Ht:return b=y._init,k(p,d,b(y._payload),j)}if(vr(y))return x(p,d,y,j);if(ar(y))return w(p,d,y,j);gl(p,y)}return typeof y=="string"&&y!==""||typeof y=="number"?(y=""+y,d!==null&&d.tag===6?(n(p,d.sibling),d=l(d,y),d.return=p,p=d):(n(p,d),d=Gs(y,p.mode,j),d.return=p,p=d),a(p)):n(p,d)}return k}var Yn=Pc(!0),Lc=Pc(!1),Jl=sn(null),Yl=null,Mn=null,ka=null;function ja(){ka=Mn=Yl=null}function Sa(e){var t=Jl.current;ae(Jl),e._currentValue=t}function Ri(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 Vn(e,t){Yl=e,ka=Mn=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Xe=!0),e.firstContext=null)}function ht(e){var t=e._currentValue;if(ka!==e)if(e={context:e,memoizedValue:t,next:null},Mn===null){if(Yl===null)throw Error(L(308));Mn=e,Yl.dependencies={lanes:0,firstContext:e}}else Mn=Mn.next=e;return t}var fn=null;function Na(e){fn===null?fn=[e]:fn.push(e)}function zc(e,t,n,r){var l=t.interleaved;return l===null?(n.next=n,Na(t)):(n.next=l.next,l.next=n),t.interleaved=n,Mt(e,r)}function Mt(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 Ut=!1;function _a(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Rc(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 It(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function Gt(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Z&2){var l=r.pending;return l===null?t.next=t:(t.next=l.next,l.next=t),r.pending=t,Mt(e,n)}return l=r.interleaved,l===null?(t.next=t,Na(r)):(t.next=l.next,l.next=t),r.interleaved=t,Mt(e,n)}function Tl(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,ca(e,n)}}function $o(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 Gl(e,t,n,r){var l=e.updateQueue;Ut=!1;var i=l.firstBaseUpdate,a=l.lastBaseUpdate,o=l.shared.pending;if(o!==null){l.shared.pending=null;var u=o,c=u.next;u.next=null,a===null?i=c:a.next=c,a=u;var v=e.alternate;v!==null&&(v=v.updateQueue,o=v.lastBaseUpdate,o!==a&&(o===null?v.firstBaseUpdate=c:o.next=c,v.lastBaseUpdate=u))}if(i!==null){var m=l.baseState;a=0,v=c=u=null,o=i;do{var h=o.lane,g=o.eventTime;if((r&h)===h){v!==null&&(v=v.next={eventTime:g,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var x=e,w=o;switch(h=t,g=n,w.tag){case 1:if(x=w.payload,typeof x=="function"){m=x.call(g,m,h);break e}m=x;break e;case 3:x.flags=x.flags&-65537|128;case 0:if(x=w.payload,h=typeof x=="function"?x.call(g,m,h):x,h==null)break e;m=he({},m,h);break e;case 2:Ut=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,h=l.effects,h===null?l.effects=[o]:h.push(o))}else g={eventTime:g,lane:h,tag:o.tag,payload:o.payload,callback:o.callback,next:null},v===null?(c=v=g,u=m):v=v.next=g,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(v===null&&(u=m),l.baseState=u,l.firstBaseUpdate=c,l.lastBaseUpdate=v,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);xn|=a,e.lanes=a,e.memoizedState=m}}function Io(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=Ks.transition;Ks.transition={};try{e(!1),t()}finally{re=n,Ks.transition=r}}function Jc(){return mt().memoizedState}function Bp(e,t,n){var r=en(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},Yc(e))Gc(t,n);else if(n=zc(e,t,n,r),n!==null){var l=We();St(n,e,r,l),Zc(n,t,r)}}function Hp(e,t,n){var r=en(e),l={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(Yc(e))Gc(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,Nt(o,a)){var u=t.interleaved;u===null?(l.next=l,Na(t)):(l.next=u.next,u.next=l),t.interleaved=l;return}}catch{}finally{}n=zc(e,t,l,r),n!==null&&(l=We(),St(n,e,r,l),Zc(n,t,r))}}function Yc(e){var t=e.alternate;return e===pe||t!==null&&t===pe}function Gc(e,t){Er=es=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function Zc(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,ca(e,n)}}var ts={readContext:ht,useCallback:De,useContext:De,useEffect:De,useImperativeHandle:De,useInsertionEffect:De,useLayoutEffect:De,useMemo:De,useReducer:De,useRef:De,useState:De,useDebugValue:De,useDeferredValue:De,useTransition:De,useMutableSource:De,useSyncExternalStore:De,useId:De,unstable_isNewReconciler:!1},Up={readContext:ht,useCallback:function(e,t){return Ct().memoizedState=[e,t===void 0?null:t],e},useContext:ht,useEffect:Oo,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,Pl(4194308,4,Vc.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Pl(4194308,4,e,t)},useInsertionEffect:function(e,t){return Pl(4,2,e,t)},useMemo:function(e,t){var n=Ct();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=Ct();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=Bp.bind(null,pe,e),[r.memoizedState,e]},useRef:function(e){var t=Ct();return e={current:e},t.memoizedState=e},useState:Do,useDebugValue:Ra,useDeferredValue:function(e){return Ct().memoizedState=e},useTransition:function(){var e=Do(!1),t=e[0];return e=Ap.bind(null,e[1]),Ct().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=pe,l=Ct();if(de){if(n===void 0)throw Error(L(407));n=n()}else{if(n=t(),Te===null)throw Error(L(349));vn&30||Oc(r,t,n)}l.memoizedState=n;var i={value:n,getSnapshot:t};return l.queue=i,Oo(Fc.bind(null,r,i,e),[e]),r.flags|=2048,Qr(9,Mc.bind(null,r,i,n,t),void 0,null),n},useId:function(){var e=Ct(),t=Te.identifierPrefix;if(de){var n=$t,r=Rt;n=(r&~(1<<32-jt(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=Wr++,0")&&(u=u.replace("",e.displayName)),u}while(1<=a&&0<=o);break}}}finally{Ps=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?vr(e):""}function xf(e){switch(e.tag){case 5:return vr(e.type);case 16:return vr("Lazy");case 13:return vr("Suspense");case 19:return vr("SuspenseList");case 0:case 2:case 15:return e=Ls(e.type,!1),e;case 11:return e=Ls(e.type.render,!1),e;case 1:return e=Ls(e.type,!0),e;default:return""}}function oi(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 Pn:return"Fragment";case bn:return"Portal";case si:return"Profiler";case sa:return"StrictMode";case ii:return"Suspense";case ai:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Ru:return(e.displayName||"Context")+".Consumer";case zu:return(e._context.displayName||"Context")+".Provider";case ia:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case aa:return t=e.displayName||null,t!==null?t:oi(e.type)||"Memo";case Ht:t=e._payload,e=e._init;try{return oi(e(t))}catch{}}return null}function wf(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 oi(t);case 8:return t===sa?"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 nn(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function Iu(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function kf(e){var t=Iu(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 al(e){e._valueTracker||(e._valueTracker=kf(e))}function Du(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=Iu(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function Ol(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 ui(e,t){var n=t.checked;return he({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function to(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=nn(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 Ou(e,t){t=t.checked,t!=null&&la(e,"checked",t,!1)}function ci(e,t){Ou(e,t);var n=nn(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")?di(e,t.type,n):t.hasOwnProperty("defaultValue")&&di(e,t.type,nn(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function no(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 di(e,t,n){(t!=="number"||Ol(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var xr=Array.isArray;function Bn(e,t,n,r){if(e=e.options,t){t={};for(var l=0;l"+t.valueOf().toString()+"",t=ol.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Rr(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Sr={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},jf=["Webkit","ms","Moz","O"];Object.keys(Sr).forEach(function(e){jf.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Sr[t]=Sr[e]})});function Bu(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Sr.hasOwnProperty(e)&&Sr[e]?(""+t).trim():t+"px"}function Hu(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,l=Bu(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,l):e[n]=l}}var Sf=he({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 hi(e,t){if(t){if(Sf[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(L(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(L(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(L(61))}if(t.style!=null&&typeof t.style!="object")throw Error(L(62))}}function mi(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 gi=null;function oa(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var yi=null,Hn=null,Un=null;function so(e){if(e=Zr(e)){if(typeof yi!="function")throw Error(L(280));var t=e.stateNode;t&&(t=ps(t),yi(e.stateNode,e.type,t))}}function Uu(e){Hn?Un?Un.push(e):Un=[e]:Hn=e}function Wu(){if(Hn){var e=Hn,t=Un;if(Un=Hn=null,so(e),t)for(e=0;e>>=0,e===0?32:31-($f(e)/If|0)|0}var ul=64,cl=4194304;function wr(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 Bl(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=wr(o):(i&=a,i!==0&&(r=wr(i)))}else a=n&~l,a!==0?r=wr(a):i!==0&&(r=wr(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 Yr(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-jt(t),e[t]=n}function Ff(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=_r),mo=" ",go=!1;function cc(e,t){switch(e){case"keyup":return pp.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function dc(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Ln=!1;function mp(e,t){switch(e){case"compositionend":return dc(t);case"keypress":return t.which!==32?null:(go=!0,mo);case"textInput":return e=t.data,e===mo&&go?null:e;default:return null}}function gp(e,t){if(Ln)return e==="compositionend"||!ga&&cc(e,t)?(e=oc(),El=pa=Qt=null,Ln=!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=wo(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 gc(){for(var e=window,t=Ol();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=Ol(e.document)}return t}function ya(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 _p(e){var t=gc(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&mc(n.ownerDocument.documentElement,n)){if(r!==null&&ya(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=ko(n,i);var a=ko(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,zn=null,Si=null,Er=null,Ni=!1;function jo(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Ni||zn==null||zn!==Ol(r)||(r=zn,"selectionStart"in r&&ya(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}),Er&&Fr(Er,r)||(Er=r,r=Wl(Si,"onSelect"),0In||(e.current=Pi[In],Pi[In]=null,In--)}function se(e,t){In++,Pi[In]=e.current,e.current=t}var rn={},Fe=sn(rn),Je=sn(!1),gn=rn;function Jn(e,t){var n=e.type.contextTypes;if(!n)return rn;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 Ye(e){return e=e.childContextTypes,e!=null}function Ql(){ae(Je),ae(Fe)}function bo(e,t,n){if(Fe.current!==rn)throw Error(L(168));se(Fe,t),se(Je,n)}function _c(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(L(108,wf(e)||"Unknown",l));return he({},n,r)}function Kl(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||rn,gn=Fe.current,se(Fe,e),se(Je,Je.current),!0}function Po(e,t,n){var r=e.stateNode;if(!r)throw Error(L(169));n?(e=_c(e,t,gn),r.__reactInternalMemoizedMergedChildContext=e,ae(Je),ae(Fe),se(Fe,e)):ae(Je),se(Je,n)}var zt=null,hs=!1,Vs=!1;function Cc(e){zt===null?zt=[e]:zt.push(e)}function Op(e){hs=!0,Cc(e)}function an(){if(!Vs&&zt!==null){Vs=!0;var e=0,t=re;try{var n=zt;for(re=1;e>=a,l-=a,Rt=1<<32-jt(t)+l|n<N?($=E,E=null):$=E.sibling;var P=h(p,E,y[N],j);if(P===null){E===null&&(E=$);break}e&&E&&P.alternate===null&&t(p,E),d=i(P,d,N),b===null?_=P:b.sibling=P,b=P,E=$}if(N===y.length)return n(p,E),de&&un(p,N),_;if(E===null){for(;NN?($=E,E=null):$=E.sibling;var V=h(p,E,P.value,j);if(V===null){E===null&&(E=$);break}e&&E&&V.alternate===null&&t(p,E),d=i(V,d,N),b===null?_=V:b.sibling=V,b=V,E=$}if(P.done)return n(p,E),de&&un(p,N),_;if(E===null){for(;!P.done;N++,P=y.next())P=m(p,P.value,j),P!==null&&(d=i(P,d,N),b===null?_=P:b.sibling=P,b=P);return de&&un(p,N),_}for(E=r(p,E);!P.done;N++,P=y.next())P=g(E,p,N,P.value,j),P!==null&&(e&&P.alternate!==null&&E.delete(P.key===null?N:P.key),d=i(P,d,N),b===null?_=P:b.sibling=P,b=P);return e&&E.forEach(function(H){return t(p,H)}),de&&un(p,N),_}function k(p,d,y,j){if(typeof y=="object"&&y!==null&&y.type===Pn&&y.key===null&&(y=y.props.children),typeof y=="object"&&y!==null){switch(y.$$typeof){case il:e:{for(var _=y.key,b=d;b!==null;){if(b.key===_){if(_=y.type,_===Pn){if(b.tag===7){n(p,b.sibling),d=l(b,y.props.children),d.return=p,p=d;break e}}else if(b.elementType===_||typeof _=="object"&&_!==null&&_.$$typeof===Ht&&Ro(_)===b.type){n(p,b.sibling),d=l(b,y.props),d.ref=pr(p,b,y),d.return=p,p=d;break e}n(p,b);break}else t(p,b);b=b.sibling}y.type===Pn?(d=mn(y.props.children,p.mode,j,y.key),d.return=p,p=d):(j=Il(y.type,y.key,y.props,null,p.mode,j),j.ref=pr(p,d,y),j.return=p,p=j)}return a(p);case bn:e:{for(b=y.key;d!==null;){if(d.key===b)if(d.tag===4&&d.stateNode.containerInfo===y.containerInfo&&d.stateNode.implementation===y.implementation){n(p,d.sibling),d=l(d,y.children||[]),d.return=p,p=d;break e}else{n(p,d);break}else t(p,d);d=d.sibling}d=Zs(y,p.mode,j),d.return=p,p=d}return a(p);case Ht:return b=y._init,k(p,d,b(y._payload),j)}if(xr(y))return x(p,d,y,j);if(or(y))return w(p,d,y,j);yl(p,y)}return typeof y=="string"&&y!==""||typeof y=="number"?(y=""+y,d!==null&&d.tag===6?(n(p,d.sibling),d=l(d,y),d.return=p,p=d):(n(p,d),d=Gs(y,p.mode,j),d.return=p,p=d),a(p)):n(p,d)}return k}var Gn=Pc(!0),Lc=Pc(!1),Jl=sn(null),Yl=null,Mn=null,ka=null;function ja(){ka=Mn=Yl=null}function Sa(e){var t=Jl.current;ae(Jl),e._currentValue=t}function Ri(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 Vn(e,t){Yl=e,ka=Mn=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Xe=!0),e.firstContext=null)}function ht(e){var t=e._currentValue;if(ka!==e)if(e={context:e,memoizedValue:t,next:null},Mn===null){if(Yl===null)throw Error(L(308));Mn=e,Yl.dependencies={lanes:0,firstContext:e}}else Mn=Mn.next=e;return t}var fn=null;function Na(e){fn===null?fn=[e]:fn.push(e)}function zc(e,t,n,r){var l=t.interleaved;return l===null?(n.next=n,Na(t)):(n.next=l.next,l.next=n),t.interleaved=n,Mt(e,r)}function Mt(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 Ut=!1;function _a(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Rc(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 It(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function Gt(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Z&2){var l=r.pending;return l===null?t.next=t:(t.next=l.next,l.next=t),r.pending=t,Mt(e,n)}return l=r.interleaved,l===null?(t.next=t,Na(r)):(t.next=l.next,l.next=t),r.interleaved=t,Mt(e,n)}function bl(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,ca(e,n)}}function $o(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 Gl(e,t,n,r){var l=e.updateQueue;Ut=!1;var i=l.firstBaseUpdate,a=l.lastBaseUpdate,o=l.shared.pending;if(o!==null){l.shared.pending=null;var u=o,c=u.next;u.next=null,a===null?i=c:a.next=c,a=u;var v=e.alternate;v!==null&&(v=v.updateQueue,o=v.lastBaseUpdate,o!==a&&(o===null?v.firstBaseUpdate=c:o.next=c,v.lastBaseUpdate=u))}if(i!==null){var m=l.baseState;a=0,v=c=u=null,o=i;do{var h=o.lane,g=o.eventTime;if((r&h)===h){v!==null&&(v=v.next={eventTime:g,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var x=e,w=o;switch(h=t,g=n,w.tag){case 1:if(x=w.payload,typeof x=="function"){m=x.call(g,m,h);break e}m=x;break e;case 3:x.flags=x.flags&-65537|128;case 0:if(x=w.payload,h=typeof x=="function"?x.call(g,m,h):x,h==null)break e;m=he({},m,h);break e;case 2:Ut=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,h=l.effects,h===null?l.effects=[o]:h.push(o))}else g={eventTime:g,lane:h,tag:o.tag,payload:o.payload,callback:o.callback,next:null},v===null?(c=v=g,u=m):v=v.next=g,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(v===null&&(u=m),l.baseState=u,l.firstBaseUpdate=c,l.lastBaseUpdate=v,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);xn|=a,e.lanes=a,e.memoizedState=m}}function Io(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=Ks.transition;Ks.transition={};try{e(!1),t()}finally{re=n,Ks.transition=r}}function Jc(){return mt().memoizedState}function Bp(e,t,n){var r=en(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},Yc(e))Gc(t,n);else if(n=zc(e,t,n,r),n!==null){var l=We();St(n,e,r,l),Zc(n,t,r)}}function Hp(e,t,n){var r=en(e),l={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(Yc(e))Gc(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,Nt(o,a)){var u=t.interleaved;u===null?(l.next=l,Na(t)):(l.next=u.next,u.next=l),t.interleaved=l;return}}catch{}finally{}n=zc(e,t,l,r),n!==null&&(l=We(),St(n,e,r,l),Zc(n,t,r))}}function Yc(e){var t=e.alternate;return e===pe||t!==null&&t===pe}function Gc(e,t){Tr=es=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function Zc(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,ca(e,n)}}var ts={readContext:ht,useCallback:De,useContext:De,useEffect:De,useImperativeHandle:De,useInsertionEffect:De,useLayoutEffect:De,useMemo:De,useReducer:De,useRef:De,useState:De,useDebugValue:De,useDeferredValue:De,useTransition:De,useMutableSource:De,useSyncExternalStore:De,useId:De,unstable_isNewReconciler:!1},Up={readContext:ht,useCallback:function(e,t){return Ct().memoizedState=[e,t===void 0?null:t],e},useContext:ht,useEffect:Oo,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,Ll(4194308,4,Vc.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Ll(4194308,4,e,t)},useInsertionEffect:function(e,t){return Ll(4,2,e,t)},useMemo:function(e,t){var n=Ct();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=Ct();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=Bp.bind(null,pe,e),[r.memoizedState,e]},useRef:function(e){var t=Ct();return e={current:e},t.memoizedState=e},useState:Do,useDebugValue:Ra,useDeferredValue:function(e){return Ct().memoizedState=e},useTransition:function(){var e=Do(!1),t=e[0];return e=Ap.bind(null,e[1]),Ct().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=pe,l=Ct();if(de){if(n===void 0)throw Error(L(407));n=n()}else{if(n=t(),Te===null)throw Error(L(349));vn&30||Oc(r,t,n)}l.memoizedState=n;var i={value:n,getSnapshot:t};return l.queue=i,Oo(Fc.bind(null,r,i,e),[e]),r.flags|=2048,Kr(9,Mc.bind(null,r,i,n,t),void 0,null),n},useId:function(){var e=Ct(),t=Te.identifierPrefix;if(de){var n=$t,r=Rt;n=(r&~(1<<32-jt(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=Vr++,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[Et]=t,e[Br]=r,ud(e,t,!1,!1),t.stateNode=e;e:{switch(a=mi(n,r),n){case"dialog":ie("cancel",e),ie("close",e),l=r;break;case"iframe":case"object":case"embed":ie("load",e),l=r;break;case"video":case"audio":for(l=0;ler&&(t.flags|=128,r=!0,pr(i,!1),t.lanes=4194304)}else{if(!r)if(e=Zl(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&&!de)return Oe(t),null}else 2*ve()-i.renderingStartTime>er&&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=ve(),t.sibling=null,n=fe.current,se(fe,r?n&1|2:n&1),t):(Oe(t),null);case 22:case 23:return Fa(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?tt&1073741824&&(Oe(t),t.subtreeFlags&6&&(t.flags|=8192)):Oe(t),null;case 24:return null;case 25:return null}throw Error(L(156,t.tag))}function Yp(e,t){switch(xa(t),t.tag){case 1:return Ye(t.type)&&Ql(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return Gn(),ae(Je),ae(Fe),Ta(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Ea(t),null;case 13:if(ae(fe),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(L(340));Jn()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return ae(fe),null;case 4:return Gn(),null;case 10:return Sa(t.type._context),null;case 22:case 23:return Fa(),null;case 24:return null;default:return null}}var vl=!1,Me=!1,Gp=typeof WeakSet=="function"?WeakSet:Set,F=null;function Fn(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){ye(e,t,r)}else n.current=null}function Hi(e,t,n){try{n()}catch(r){ye(e,t,r)}}var qo=!1;function Zp(e,t){if(_i=Hl,e=gc(),ya(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,c=0,v=0,m=e,h=null;t:for(;;){for(var g;m!==n||l!==0&&m.nodeType!==3||(o=a+l),m!==i||r!==0&&m.nodeType!==3||(u=a+r),m.nodeType===3&&(a+=m.nodeValue.length),(g=m.firstChild)!==null;)h=m,m=g;for(;;){if(m===e)break t;if(h===n&&++c===l&&(o=a),h===i&&++v===r&&(u=a),(g=m.nextSibling)!==null)break;m=h,h=m.parentNode}m=g}n=o===-1||u===-1?null:{start:o,end:u}}else n=null}n=n||{start:0,end:0}}else n=null;for(Ci={focusedElem:e,selectionRange:n},Hl=!1,F=t;F!==null;)if(t=F,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,F=e;else for(;F!==null;){t=F;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 w=x.memoizedProps,k=x.memoizedState,p=t.stateNode,d=p.getSnapshotBeforeUpdate(t.elementType===t.type?w:vt(t.type,w),k);p.__reactInternalSnapshotBeforeUpdate=d}break;case 3:var y=t.stateNode.containerInfo;y.nodeType===1?y.textContent="":y.nodeType===9&&y.documentElement&&y.removeChild(y.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(L(163))}}catch(j){ye(t,t.return,j)}if(e=t.sibling,e!==null){e.return=t.return,F=e;break}F=t.return}return x=qo,qo=!1,x}function Tr(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&&Hi(t,n,i)}l=l.next}while(l!==r)}}function ys(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 Ui(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 fd(e){var t=e.alternate;t!==null&&(e.alternate=null,fd(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Et],delete t[Br],delete t[bi],delete t[Ip],delete t[Dp])),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 pd(e){return e.tag===5||e.tag===3||e.tag===4}function Xo(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||pd(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 Wi(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=Vl));else if(r!==4&&(e=e.child,e!==null))for(Wi(e,t,n),e=e.sibling;e!==null;)Wi(e,t,n),e=e.sibling}function Vi(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(Vi(e,t,n),e=e.sibling;e!==null;)Vi(e,t,n),e=e.sibling}var Pe=null,xt=!1;function Bt(e,t,n){for(n=n.child;n!==null;)hd(e,t,n),n=n.sibling}function hd(e,t,n){if(Tt&&typeof Tt.onCommitFiberUnmount=="function")try{Tt.onCommitFiberUnmount(us,n)}catch{}switch(n.tag){case 5:Me||Fn(n,t);case 6:var r=Pe,l=xt;Pe=null,Bt(e,t,n),Pe=r,xt=l,Pe!==null&&(xt?(e=Pe,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):Pe.removeChild(n.stateNode));break;case 18:Pe!==null&&(xt?(e=Pe,n=n.stateNode,e.nodeType===8?Ws(e.parentNode,n):e.nodeType===1&&Ws(e,n),Dr(e)):Ws(Pe,n.stateNode));break;case 4:r=Pe,l=xt,Pe=n.stateNode.containerInfo,xt=!0,Bt(e,t,n),Pe=r,xt=l;break;case 0:case 11:case 14:case 15:if(!Me&&(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)&&Hi(n,t,a),l=l.next}while(l!==r)}Bt(e,t,n);break;case 1:if(!Me&&(Fn(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(o){ye(n,t,o)}Bt(e,t,n);break;case 21:Bt(e,t,n);break;case 22:n.mode&1?(Me=(r=Me)||n.memoizedState!==null,Bt(e,t,n),Me=r):Bt(e,t,n);break;default:Bt(e,t,n)}}function Jo(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new Gp),t.forEach(function(r){var l=oh.bind(null,e,r);n.has(r)||(n.add(r),r.then(l,l))})}}function yt(e,t){var n=t.deletions;if(n!==null)for(var r=0;rl&&(l=a),r&=~i}if(r=l,r=ve()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*th(r/1960))-r,10e?16:e,Kt===null)var r=!1;else{if(e=Kt,Kt=null,ls=0,Z&6)throw Error(L(331));var l=Z;for(Z|=4,F=e.current;F!==null;){var i=F,a=i.child;if(F.flags&16){var o=i.deletions;if(o!==null){for(var u=0;uve()-Oa?hn(e,0):Da|=n),Ge(e,t)}function jd(e,t){t===0&&(e.mode&1?(t=ul,ul<<=1,!(ul&130023424)&&(ul=4194304)):t=1);var n=We();e=Mt(e,t),e!==null&&(Jr(e,t,n),Ge(e,n))}function ah(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),jd(e,n)}function oh(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(L(314))}r!==null&&r.delete(t),jd(e,n)}var Sd;Sd=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Je.current)Xe=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return Xe=!1,Xp(e,t,n);Xe=!!(e.flags&131072)}else Xe=!1,de&&t.flags&1048576&&Ec(t,Xl,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Ll(e,t),e=t.pendingProps;var l=Xn(t,Fe.current);Vn(t,n),l=Pa(null,t,r,e,l,n);var i=La();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,Ye(r)?(i=!0,Kl(t)):i=!1,t.memoizedState=l.state!==null&&l.state!==void 0?l.state:null,_a(t),l.updater=gs,t.stateNode=l,l._reactInternals=t,Ii(t,r,e,n),t=Mi(null,t,r,!0,i,n)):(t.tag=0,de&&i&&va(t),Ue(null,t,l,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Ll(e,t),e=t.pendingProps,l=r._init,r=l(r._payload),t.type=r,l=t.tag=ch(r),e=vt(r,e),l){case 0:t=Oi(null,t,r,e,n);break e;case 1:t=Vo(null,t,r,e,n);break e;case 11:t=Uo(null,t,r,e,n);break e;case 14:t=Wo(null,t,r,vt(r.type,e),n);break e}throw Error(L(306,r,""))}return t;case 0:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:vt(r,l),Oi(e,t,r,l,n);case 1:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:vt(r,l),Vo(e,t,r,l,n);case 3:e:{if(id(t),e===null)throw Error(L(387));r=t.pendingProps,i=t.memoizedState,l=i.element,Rc(e,t),Gl(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=Zn(Error(L(423)),t),t=Qo(e,t,r,n,l);break e}else if(r!==l){l=Zn(Error(L(424)),t),t=Qo(e,t,r,n,l);break e}else for(nt=Yt(t.stateNode.containerInfo.firstChild),rt=t,de=!0,wt=null,n=Lc(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(Jn(),r===l){t=Ft(e,t,n);break e}Ue(e,t,r,n)}t=t.child}return t;case 5:return $c(t),e===null&&zi(t),r=t.type,l=t.pendingProps,i=e!==null?e.memoizedProps:null,a=l.children,Ei(r,l)?a=null:i!==null&&Ei(r,i)&&(t.flags|=32),sd(e,t),Ue(e,t,a,n),t.child;case 6:return e===null&&zi(t),null;case 13:return ad(e,t,n);case 4:return Ca(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=Yn(t,null,r,n):Ue(e,t,r,n),t.child;case 11:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:vt(r,l),Uo(e,t,r,l,n);case 7:return Ue(e,t,t.pendingProps,n),t.child;case 8:return Ue(e,t,t.pendingProps.children,n),t.child;case 12:return Ue(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,se(Jl,r._currentValue),r._currentValue=a,i!==null)if(Nt(i.value,a)){if(i.children===l.children&&!Je.current){t=Ft(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=It(-1,n&-n),u.tag=2;var c=i.updateQueue;if(c!==null){c=c.shared;var v=c.pending;v===null?u.next=u:(u.next=v.next,v.next=u),c.pending=u}}i.lanes|=n,u=i.alternate,u!==null&&(u.lanes|=n),Ri(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(L(341));a.lanes|=n,o=a.alternate,o!==null&&(o.lanes|=n),Ri(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}Ue(e,t,l.children,n),t=t.child}return t;case 9:return l=t.type,r=t.pendingProps.children,Vn(t,n),l=ht(l),r=r(l),t.flags|=1,Ue(e,t,r,n),t.child;case 14:return r=t.type,l=vt(r,t.pendingProps),l=vt(r.type,l),Wo(e,t,r,l,n);case 15:return rd(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:vt(r,l),Ll(e,t),t.tag=1,Ye(r)?(e=!0,Kl(t)):e=!1,Vn(t,n),ed(t,r,l),Ii(t,r,l,n),Mi(null,t,r,!0,e,n);case 19:return od(e,t,n);case 22:return ld(e,t,n)}throw Error(L(156,t.tag))};function Nd(e,t){return Yu(e,t)}function uh(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 ft(e,t,n,r){return new uh(e,t,n,r)}function Ba(e){return e=e.prototype,!(!e||!e.isReactComponent)}function ch(e){if(typeof e=="function")return Ba(e)?1:0;if(e!=null){if(e=e.$$typeof,e===ia)return 11;if(e===aa)return 14}return 2}function tn(e,t){var n=e.alternate;return n===null?(n=ft(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 $l(e,t,n,r,l,i){var a=2;if(r=e,typeof e=="function")Ba(e)&&(a=1);else if(typeof e=="string")a=5;else e:switch(e){case Pn:return mn(n.children,l,i,t);case sa:a=8,l|=8;break;case si:return e=ft(12,n,t,l|2),e.elementType=si,e.lanes=i,e;case ii:return e=ft(13,n,t,l),e.elementType=ii,e.lanes=i,e;case ai:return e=ft(19,n,t,l),e.elementType=ai,e.lanes=i,e;case $u:return xs(n,l,i,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case zu:a=10;break e;case Ru:a=9;break e;case ia:a=11;break e;case aa:a=14;break e;case Ht:a=16,r=null;break e}throw Error(L(130,e==null?e:typeof e,""))}return t=ft(a,n,t,l),t.elementType=e,t.type=r,t.lanes=i,t}function mn(e,t,n,r){return e=ft(7,e,r,t),e.lanes=n,e}function xs(e,t,n,r){return e=ft(22,e,r,t),e.elementType=$u,e.lanes=n,e.stateNode={isHidden:!1},e}function Gs(e,t,n){return e=ft(6,e,null,t),e.lanes=n,e}function Zs(e,t,n){return t=ft(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function dh(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=Rs(0),this.expirationTimes=Rs(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Rs(0),this.identifierPrefix=r,this.onRecoverableError=l,this.mutableSourceEagerHydrationData=null}function Ha(e,t,n,r,l,i,a,o,u){return e=new dh(e,t,n,o,u),t===1?(t=1,i===!0&&(t|=8)):t=0,i=ft(3,null,null,t),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},_a(i),e}function fh(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Td)}catch(e){console.error(e)}}Td(),Tu.exports=st;var yh=Tu.exports,bd,lu=yh;bd=lu.createRoot,lu.hydrateRoot;async function ke(e){const t=await fetch(e);if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()}async function vh(){return ke("/api/archives")}async function xh(e){return ke(`/api/archives/${e}/entries`)}async function wh(e,t,n){const r=new URLSearchParams;return t&&r.set("q",t),n&&r.set("tag",n),ke(`/api/archives/${e}/entries/search?${r}`)}async function Ji(e,t){return ke(`/api/archives/${e}/entries/${t}`)}async function kh(e,t){return ke(`/api/archives/${e}/entries/${t}/children`)}function jh(e,t,n){return Promise.all(n.map(r=>ke(`/api/archives/${e}/entries/${t}/artifacts/${r}`)))}async function Sh(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 Nh(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 kl(e,t){return ke(`/api/archives/${e}/entries/${t}/tags`)}async function su(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 _h(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 iu(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 Ch(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 Eh(e,t){const n=await fetch(`/api/archives/${e}/tags/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(await n.text())}async function Th(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 bh(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 ei(e){return ke(`/api/archives/${e}/runs`)}async function jl(e){return ke(`/api/archives/${e}/tags`)}async function Ph(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(()=>({}));throw new Error(a.error||`HTTP ${i.status}`)}return i.json()}async function Lh(e,t){return ke(`/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 Pd(e,t){return ke(`/api/archives/${e}/capture_jobs/${t}`)}async function Rh(){return(await(await fetch("/api/auth/setup")).json()).setup_required===!0}async function $h(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 Ih(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 Dh(){await fetch("/api/auth/logout",{method:"POST"})}async function Oh(){const e=await fetch("/api/auth/me");return e.status===401?null:e.json()}async function Mh(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 Fh(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 Ah(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 Bh(){return ke("/api/auth/tokens")}async function Hh(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 Uh(e){const t=await fetch(`/api/auth/tokens/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(await t.text())}async function Qa(){return ke("/api/admin/instance-settings")}async function Il(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 Wh(){return ke("/api/admin/users")}async function Vh(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 Qh(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 Kh(){return ke("/api/admin/roles")}async function qh(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 Ld(e){return ke(`/api/archives/${e}/collections`)}async function Xh(e,t,n,r=2){const l=await fetch(`/api/archives/${e}/collections`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:t,slug:n,default_visibility_bits:r})});if(!l.ok){const i=await l.json().catch(()=>({error:l.statusText}));throw new Error(i.error||l.statusText)}return l.json()}async function Jh(e,t){return ke(`/api/archives/${e}/collections/${t}`)}async function zd(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 Yh(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 Gh(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 Zh(e,t){return ke(`/api/archives/${e}/entries/${t}/collections`)}async function au(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 em(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 tm(e){return ke(`/api/archives/${e}/blob-cleanup`)}async function nm(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 rm(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 lm(){return ke("/api/admin/cookie-rules")}async function sm(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 im(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 am(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}`)}}const om=window.fetch;window.fetch=async(...e)=>{var n;const t=await om(...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 um({onLogin:e}){const[t,n]=f.useState(""),[r,l]=f.useState(""),[i,a]=f.useState(null),[o,u]=f.useState(!1);async function c(v){v.preventDefault(),a(null),u(!0);try{const m=await Ih(t,r);e(m)}catch(m){a(m.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:c,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:v=>n(v.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:v=>l(v.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 cm({onComplete:e}){const[t,n]=f.useState(""),[r,l]=f.useState(""),[i,a]=f.useState(""),[o,u]=f.useState(null),[c,v]=f.useState(!1);async function m(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),v(!0);try{await $h(t,r),e()}catch(g){u(g.message)}finally{v(!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:m,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:c,children:c?"Creating account…":"Create account"})]})]})})}function dm({archives:e,archiveId:t,onArchiveChange:n,view:r,onViewChange:l,onCaptureClick:i}){const{currentUser:a,setCurrentUser:o}=f.useContext(_s)??{},[u,c]=f.useState(!1);async function v(){c(!0),await Dh(),o(null),window.location.reload()}return s.jsxs("header",{className:"topbar",children:[s.jsx("div",{className:"brand",children:"Archivr"}),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))})}),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"}),a&&s.jsxs("div",{className:"user-menu",children:[s.jsx("span",{className:"user-name",children:a.display_name||a.username}),s.jsx("button",{className:"logout-btn",onClick:v,disabled:u,children:u?"Logging out…":"Log out"})]})]})}let Yi=1;function Rd(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/")}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 Dl(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("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"))return!0}catch{}return!1}function mr(e=""){return{id:Yi++,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 fm(e,t){if(e==="best")return t.map(r=>({...r,quality:"best"}));if(e==="audio")return t.map(r=>r.has_audio?{...r,quality:"audio"}:r.quality!==null?r:{...r,quality:null});const n=parseInt(e);return t.map(r=>r.qualities.length===0?r:Math.max(...r.qualities.map(i=>parseInt(i)))>=n?{...r,quality:e}:r.quality!==null?r:{...r,quality:null})}function ou(e){return e.playlistItems!==null&&e.playlistItems.some(t=>t.quality===null)}function pm({open:e,archiveId:t,onClose:n,onCaptured:r,onToast:l,onJobStarted:i,onJobSettled:a,activeJobs:o=[]}){const u=f.useRef(null),c=f.useRef(!0),v=f.useRef(new Map),m=f.useRef(new Map),h=f.useRef(new Map),g=f.useRef(t);f.useEffect(()=>{g.current=t},[t]);const x=f.useRef(r),w=f.useRef(l);f.useEffect(()=>{x.current=r},[r]),f.useEffect(()=>{w.current=l},[l]);const k=f.useRef(i),p=f.useRef(a);f.useEffect(()=>{k.current=i},[i]),f.useEffect(()=>{p.current=a},[a]);const[d,y]=f.useState(()=>{try{const S=JSON.parse(sessionStorage.getItem("captureItems")||"null");if(Array.isArray(S)&&S.length>0){const O=S.filter(I=>!I.status||I.status==="idle");if(O.length>0)return O.forEach(I=>{I.id>=Yi&&(Yi=I.id+1)}),O}}catch{}return[mr()]});f.useEffect(()=>{sessionStorage.setItem("captureItems",JSON.stringify(d))},[d]);const[j,_]=f.useState(!1),[b,E]=f.useState(null),[N,$]=f.useState(null),[P,V]=f.useState(!0),[H,Q]=f.useState(!0),[Y,oe]=f.useState(!0);f.useEffect(()=>{Qa().then(S=>{$(S),V(S.cookie_ext_enabled??!0),Q(S.modal_closer_enabled??!0)}).catch(()=>$({}))},[]);const le=b!==null?b:(N==null?void 0:N.ublock_enabled)??!0,[ee,R]=f.useState(!1);f.useEffect(()=>{["captureDialogLocator","captureDialogError","captureDialogBusy","captureDialogJobStatus","captureDialogJobUid"].forEach(S=>sessionStorage.removeItem(S)),o.forEach(S=>{S.jobUid&&!v.current.has(S.jobUid)&&T(S.id,S.jobUid,S.locator,S.archiveId,null)})},[]),f.useEffect(()=>{const S=u.current;if(!S)return;const O=()=>{m.current.forEach(I=>clearTimeout(I)),m.current.clear(),n()};return S.addEventListener("close",O),()=>S.removeEventListener("close",O)},[n]),f.useEffect(()=>{const S=u.current;S&&(e?(c.current||y([mr()]),c.current=!1,S.open||S.showModal()):(m.current.forEach(O=>clearTimeout(O)),m.current.clear(),S.open&&S.close()))},[e]),f.useEffect(()=>()=>{v.current.forEach(S=>clearInterval(S)),m.current.forEach(S=>clearTimeout(S))},[]);function T(S,O,I,B,W=null){if(v.current.has(O))return;const q=setInterval(async()=>{var ce,Ce,Ke,Ae;try{const Be=await Pd(B,O);if(Be.status==="completed"){clearInterval(v.current.get(O)),v.current.delete(O),await Promise.resolve((ce=x.current)==null?void 0:ce.call(x)),(Ce=p.current)==null||Ce.call(p,S);try{const ge=Be.notes_json?JSON.parse(Be.notes_json):null;if(ge!=null&&ge.ublock_skipped||ge!=null&&ge.cookie_ext_skipped){const ot=ge.ublock_skipped&&ge.cookie_ext_skipped?"Captured without ad-blocking or cookie-consent extension. Check ARCHIVR_UBLOCK_EXT and ARCHIVR_COOKIE_EXT in your server config.":ge.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.";w.current(ot,I,"warning"),A(W,"warning",I)}else W||w.current(null,I,"success"),A(W,"archived")}catch{W||w.current(null,I,"success"),A(W,"archived")}}else if(Be.status==="failed"){clearInterval(v.current.get(O)),v.current.delete(O),(Ke=p.current)==null||Ke.call(p,S);const ge=Be.error_text||"Capture failed.";w.current(ge,I),A(W,"failed",I)}}catch(Be){clearInterval(v.current.get(O)),v.current.delete(O),(Ae=p.current)==null||Ae.call(p,S);const ge=Be.message||"Network error";w.current(ge,I),A(W,"failed",I)}},500);v.current.set(O,q)}function A(S,O,I=null){if(!S)return;const B=h.current.get(S);if(!B||(O==="archived"||O==="warning"?(B.archived++,O==="warning"&&(B.warnings++,I&&B.warningLocators.push(I))):(B.failed++,I&&B.failedLocators.push(I)),B.archived+B.failed0?`${W} archived (${q} with warnings)`:`${W} archived`;Ae=ce>0?`${ot}, ${ce} failed`:ot}const Be=W===0?"error":ce>0||q>0?"warning":"success",ge=[];Ce.length>0&&ge.push(`Failed: +`+i.stack}return{value:e,source:t,stack:l,digest:null}}function Js(e,t,n){return{value:e,source:null,stack:n??null,digest:t??null}}function Di(e,t){try{console.error(t.value)}catch(n){setTimeout(function(){throw n})}}var Qp=typeof WeakMap=="function"?WeakMap:Map;function td(e,t,n){n=It(-1,n),n.tag=3,n.payload={element:null};var r=t.value;return n.callback=function(){rs||(rs=!0,Qi=r),Di(e,t)},n}function nd(e,t,n){n=It(-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(){Di(e,t)}}var i=e.stateNode;return i!==null&&typeof i.componentDidCatch=="function"&&(n.callback=function(){Di(e,t),typeof r!="function"&&(Zt===null?Zt=new Set([this]):Zt.add(this));var a=t.stack;this.componentDidCatch(t.value,{componentStack:a!==null?a:""})}),n}function Ao(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new Qp;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=ih.bind(null,e,t,n),t.then(e,e))}function Bo(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 Ho(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=It(-1,1),t.tag=2,Gt(n,t,1))),n.lanes|=1),e)}var Kp=At.ReactCurrentOwner,Xe=!1;function Ue(e,t,n,r){t.child=e===null?Lc(t,null,n,r):Gn(t,e.child,n,r)}function Uo(e,t,n,r,l){n=n.render;var i=t.ref;return Vn(t,l),r=Pa(e,t,n,r,i,l),n=La(),e!==null&&!Xe?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~l,Ft(e,t,l)):(de&&n&&va(t),t.flags|=1,Ue(e,t,r,l),t.child)}function Wo(e,t,n,r,l){if(e===null){var i=n.type;return typeof i=="function"&&!Ba(i)&&i.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(t.tag=15,t.type=i,rd(e,t,i,r,l)):(e=Il(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:Fr,n(a,r)&&e.ref===t.ref)return Ft(e,t,l)}return t.flags|=1,e=tn(i,r),e.ref=t.ref,e.return=t,t.child=e}function rd(e,t,n,r,l){if(e!==null){var i=e.memoizedProps;if(Fr(i,r)&&e.ref===t.ref)if(Xe=!1,t.pendingProps=r=i,(e.lanes&l)!==0)e.flags&131072&&(Xe=!0);else return t.lanes=e.lanes,Ft(e,t,l)}return Oi(e,t,n,r,l)}function ld(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},se(An,tt),tt|=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,se(An,tt),tt|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=i!==null?i.baseLanes:n,se(An,tt),tt|=r}else i!==null?(r=i.baseLanes|n,t.memoizedState=null):r=n,se(An,tt),tt|=r;return Ue(e,t,l,n),t.child}function sd(e,t){var n=t.ref;(e===null&&n!==null||e!==null&&e.ref!==n)&&(t.flags|=512,t.flags|=2097152)}function Oi(e,t,n,r,l){var i=Ye(n)?gn:Fe.current;return i=Jn(t,i),Vn(t,l),n=Pa(e,t,n,r,i,l),r=La(),e!==null&&!Xe?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~l,Ft(e,t,l)):(de&&r&&va(t),t.flags|=1,Ue(e,t,n,l),t.child)}function Vo(e,t,n,r,l){if(Ye(n)){var i=!0;Kl(t)}else i=!1;if(Vn(t,l),t.stateNode===null)zl(e,t),ed(t,n,r),Ii(t,n,r,l),r=!0;else if(e===null){var a=t.stateNode,o=t.memoizedProps;a.props=o;var u=a.context,c=n.contextType;typeof c=="object"&&c!==null?c=ht(c):(c=Ye(n)?gn:Fe.current,c=Jn(t,c));var v=n.getDerivedStateFromProps,m=typeof v=="function"||typeof a.getSnapshotBeforeUpdate=="function";m||typeof a.UNSAFE_componentWillReceiveProps!="function"&&typeof a.componentWillReceiveProps!="function"||(o!==r||u!==c)&&Fo(t,a,r,c),Ut=!1;var h=t.memoizedState;a.state=h,Gl(t,r,a,l),u=t.memoizedState,o!==r||h!==u||Je.current||Ut?(typeof v=="function"&&($i(t,n,v,r),u=t.memoizedState),(o=Ut||Mo(t,n,o,r,h,u,c))?(m||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=c,r=o):(typeof a.componentDidMount=="function"&&(t.flags|=4194308),r=!1)}else{a=t.stateNode,Rc(e,t),o=t.memoizedProps,c=t.type===t.elementType?o:vt(t.type,o),a.props=c,m=t.pendingProps,h=a.context,u=n.contextType,typeof u=="object"&&u!==null?u=ht(u):(u=Ye(n)?gn:Fe.current,u=Jn(t,u));var g=n.getDerivedStateFromProps;(v=typeof g=="function"||typeof a.getSnapshotBeforeUpdate=="function")||typeof a.UNSAFE_componentWillReceiveProps!="function"&&typeof a.componentWillReceiveProps!="function"||(o!==m||h!==u)&&Fo(t,a,r,u),Ut=!1,h=t.memoizedState,a.state=h,Gl(t,r,a,l);var x=t.memoizedState;o!==m||h!==x||Je.current||Ut?(typeof g=="function"&&($i(t,n,g,r),x=t.memoizedState),(c=Ut||Mo(t,n,c,r,h,x,u)||!1)?(v||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=c):(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 Mi(e,t,n,r,i,l)}function Mi(e,t,n,r,l,i){sd(e,t);var a=(t.flags&128)!==0;if(!r&&!a)return l&&Po(t,n,!1),Ft(e,t,i);r=t.stateNode,Kp.current=t;var o=a&&typeof n.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&a?(t.child=Gn(t,e.child,null,i),t.child=Gn(t,null,o,i)):Ue(e,t,o,i),t.memoizedState=r.state,l&&Po(t,n,!0),t.child}function id(e){var t=e.stateNode;t.pendingContext?bo(e,t.pendingContext,t.pendingContext!==t.context):t.context&&bo(e,t.context,!1),Ca(e,t.containerInfo)}function Qo(e,t,n,r,l){return Yn(),wa(l),t.flags|=256,Ue(e,t,n,r),t.child}var Fi={dehydrated:null,treeContext:null,retryLane:0};function Ai(e){return{baseLanes:e,cachePool:null,transitions:null}}function ad(e,t,n){var r=t.pendingProps,l=fe.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),se(fe,l&1),e===null)return zi(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=xs(a,r,0,null),e=mn(e,r,n,null),i.return=t,e.return=t,i.sibling=e,t.child=i,t.child.memoizedState=Ai(n),t.memoizedState=Fi,e):$a(t,a));if(l=e.memoizedState,l!==null&&(o=l.dehydrated,o!==null))return qp(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=tn(l,u),r.subtreeFlags=l.subtreeFlags&14680064),o!==null?i=tn(o,i):(i=mn(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?Ai(n):{baseLanes:a.baseLanes|n,cachePool:null,transitions:a.transitions},i.memoizedState=a,i.childLanes=e.childLanes&~n,t.memoizedState=Fi,r}return i=e.child,e=i.sibling,r=tn(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 $a(e,t){return t=xs({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function vl(e,t,n,r){return r!==null&&wa(r),Gn(t,e.child,null,n),e=$a(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function qp(e,t,n,r,l,i,a){if(n)return t.flags&256?(t.flags&=-257,r=Js(Error(L(422))),vl(e,t,a,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(i=r.fallback,l=t.mode,r=xs({mode:"visible",children:r.children},l,0,null),i=mn(i,l,a,null),i.flags|=2,r.return=t,i.return=t,r.sibling=i,t.child=r,t.mode&1&&Gn(t,e.child,null,a),t.child.memoizedState=Ai(a),t.memoizedState=Fi,i);if(!(t.mode&1))return vl(e,t,a,null);if(l.data==="$!"){if(r=l.nextSibling&&l.nextSibling.dataset,r)var o=r.dgst;return r=o,i=Error(L(419)),r=Js(i,r,void 0),vl(e,t,a,r)}if(o=(a&e.childLanes)!==0,Xe||o){if(r=Te,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,Mt(e,l),St(r,e,l,-1))}return Aa(),r=Js(Error(L(421))),vl(e,t,a,r)}return l.data==="$?"?(t.flags|=128,t.child=e.child,t=ah.bind(null,e),l._reactRetry=t,null):(e=i.treeContext,nt=Yt(l.nextSibling),rt=t,de=!0,wt=null,e!==null&&(ct[dt++]=Rt,ct[dt++]=$t,ct[dt++]=yn,Rt=e.id,$t=e.overflow,yn=t),t=$a(t,r.children),t.flags|=4096,t)}function Ko(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),Ri(e.return,t,n)}function Ys(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 od(e,t,n){var r=t.pendingProps,l=r.revealOrder,i=r.tail;if(Ue(e,t,r.children,n),r=fe.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&&Ko(e,n,t);else if(e.tag===19)Ko(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(se(fe,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&&Zl(e)===null&&(l=n),n=n.sibling;n=l,n===null?(l=t.child,t.child=null):(l=n.sibling,n.sibling=null),Ys(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&&Zl(e)===null){t.child=l;break}e=l.sibling,l.sibling=n,n=l,l=e}Ys(t,!0,n,null,i);break;case"together":Ys(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function zl(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function Ft(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),xn|=t.lanes,!(n&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error(L(153));if(t.child!==null){for(e=t.child,n=tn(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=tn(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function Xp(e,t,n){switch(t.tag){case 3:id(t),Yn();break;case 5:$c(t);break;case 1:Ye(t.type)&&Kl(t);break;case 4:Ca(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,l=t.memoizedProps.value;se(Jl,r._currentValue),r._currentValue=l;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(se(fe,fe.current&1),t.flags|=128,null):n&t.child.childLanes?ad(e,t,n):(se(fe,fe.current&1),e=Ft(e,t,n),e!==null?e.sibling:null);se(fe,fe.current&1);break;case 19:if(r=(n&t.childLanes)!==0,e.flags&128){if(r)return od(e,t,n);t.flags|=128}if(l=t.memoizedState,l!==null&&(l.rendering=null,l.tail=null,l.lastEffect=null),se(fe,fe.current),r)break;return null;case 22:case 23:return t.lanes=0,ld(e,t,n)}return Ft(e,t,n)}var ud,Bi,cd,dd;ud=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}};Bi=function(){};cd=function(e,t,n,r){var l=e.memoizedProps;if(l!==r){e=t.stateNode,pn(bt.current);var i=null;switch(n){case"input":l=ui(e,l),r=ui(e,r),i=[];break;case"select":l=he({},l,{value:void 0}),r=he({},r,{value:void 0}),i=[];break;case"textarea":l=fi(e,l),r=fi(e,r),i=[];break;default:typeof l.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Vl)}hi(n,r);var a;n=null;for(c in l)if(!r.hasOwnProperty(c)&&l.hasOwnProperty(c)&&l[c]!=null)if(c==="style"){var o=l[c];for(a in o)o.hasOwnProperty(a)&&(n||(n={}),n[a]="")}else c!=="dangerouslySetInnerHTML"&&c!=="children"&&c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&c!=="autoFocus"&&(zr.hasOwnProperty(c)?i||(i=[]):(i=i||[]).push(c,null));for(c in r){var u=r[c];if(o=l!=null?l[c]:void 0,r.hasOwnProperty(c)&&u!==o&&(u!=null||o!=null))if(c==="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(c,n)),n=u;else c==="dangerouslySetInnerHTML"?(u=u?u.__html:void 0,o=o?o.__html:void 0,u!=null&&o!==u&&(i=i||[]).push(c,u)):c==="children"?typeof u!="string"&&typeof u!="number"||(i=i||[]).push(c,""+u):c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&(zr.hasOwnProperty(c)?(u!=null&&c==="onScroll"&&ie("scroll",e),i||o===u||(i=[])):(i=i||[]).push(c,u))}n&&(i=i||[]).push("style",n);var c=i;(t.updateQueue=c)&&(t.flags|=4)}};dd=function(e,t,n,r){n!==r&&(t.flags|=4)};function hr(e,t){if(!de)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 Oe(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 Jp(e,t,n){var r=t.pendingProps;switch(xa(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Oe(t),null;case 1:return Ye(t.type)&&Ql(),Oe(t),null;case 3:return r=t.stateNode,Zn(),ae(Je),ae(Fe),Ta(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(gl(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,wt!==null&&(Xi(wt),wt=null))),Bi(e,t),Oe(t),null;case 5:Ea(t);var l=pn(Wr.current);if(n=t.type,e!==null&&t.stateNode!=null)cd(e,t,n,r,l),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error(L(166));return Oe(t),null}if(e=pn(bt.current),gl(t)){r=t.stateNode,n=t.type;var i=t.memoizedProps;switch(r[Et]=t,r[Hr]=i,e=(t.mode&1)!==0,n){case"dialog":ie("cancel",r),ie("close",r);break;case"iframe":case"object":case"embed":ie("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[Et]=t,e[Hr]=r,ud(e,t,!1,!1),t.stateNode=e;e:{switch(a=mi(n,r),n){case"dialog":ie("cancel",e),ie("close",e),l=r;break;case"iframe":case"object":case"embed":ie("load",e),l=r;break;case"video":case"audio":for(l=0;ltr&&(t.flags|=128,r=!0,hr(i,!1),t.lanes=4194304)}else{if(!r)if(e=Zl(a),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),hr(i,!0),i.tail===null&&i.tailMode==="hidden"&&!a.alternate&&!de)return Oe(t),null}else 2*ve()-i.renderingStartTime>tr&&n!==1073741824&&(t.flags|=128,r=!0,hr(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=ve(),t.sibling=null,n=fe.current,se(fe,r?n&1|2:n&1),t):(Oe(t),null);case 22:case 23:return Fa(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?tt&1073741824&&(Oe(t),t.subtreeFlags&6&&(t.flags|=8192)):Oe(t),null;case 24:return null;case 25:return null}throw Error(L(156,t.tag))}function Yp(e,t){switch(xa(t),t.tag){case 1:return Ye(t.type)&&Ql(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return Zn(),ae(Je),ae(Fe),Ta(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Ea(t),null;case 13:if(ae(fe),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(L(340));Yn()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return ae(fe),null;case 4:return Zn(),null;case 10:return Sa(t.type._context),null;case 22:case 23:return Fa(),null;case 24:return null;default:return null}}var xl=!1,Me=!1,Gp=typeof WeakSet=="function"?WeakSet:Set,F=null;function Fn(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){ye(e,t,r)}else n.current=null}function Hi(e,t,n){try{n()}catch(r){ye(e,t,r)}}var qo=!1;function Zp(e,t){if(_i=Hl,e=gc(),ya(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,c=0,v=0,m=e,h=null;t:for(;;){for(var g;m!==n||l!==0&&m.nodeType!==3||(o=a+l),m!==i||r!==0&&m.nodeType!==3||(u=a+r),m.nodeType===3&&(a+=m.nodeValue.length),(g=m.firstChild)!==null;)h=m,m=g;for(;;){if(m===e)break t;if(h===n&&++c===l&&(o=a),h===i&&++v===r&&(u=a),(g=m.nextSibling)!==null)break;m=h,h=m.parentNode}m=g}n=o===-1||u===-1?null:{start:o,end:u}}else n=null}n=n||{start:0,end:0}}else n=null;for(Ci={focusedElem:e,selectionRange:n},Hl=!1,F=t;F!==null;)if(t=F,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,F=e;else for(;F!==null;){t=F;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 w=x.memoizedProps,k=x.memoizedState,p=t.stateNode,d=p.getSnapshotBeforeUpdate(t.elementType===t.type?w:vt(t.type,w),k);p.__reactInternalSnapshotBeforeUpdate=d}break;case 3:var y=t.stateNode.containerInfo;y.nodeType===1?y.textContent="":y.nodeType===9&&y.documentElement&&y.removeChild(y.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(L(163))}}catch(j){ye(t,t.return,j)}if(e=t.sibling,e!==null){e.return=t.return,F=e;break}F=t.return}return x=qo,qo=!1,x}function br(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&&Hi(t,n,i)}l=l.next}while(l!==r)}}function ys(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 Ui(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 fd(e){var t=e.alternate;t!==null&&(e.alternate=null,fd(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Et],delete t[Hr],delete t[bi],delete t[Ip],delete t[Dp])),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 pd(e){return e.tag===5||e.tag===3||e.tag===4}function Xo(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||pd(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 Wi(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=Vl));else if(r!==4&&(e=e.child,e!==null))for(Wi(e,t,n),e=e.sibling;e!==null;)Wi(e,t,n),e=e.sibling}function Vi(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(Vi(e,t,n),e=e.sibling;e!==null;)Vi(e,t,n),e=e.sibling}var Pe=null,xt=!1;function Bt(e,t,n){for(n=n.child;n!==null;)hd(e,t,n),n=n.sibling}function hd(e,t,n){if(Tt&&typeof Tt.onCommitFiberUnmount=="function")try{Tt.onCommitFiberUnmount(us,n)}catch{}switch(n.tag){case 5:Me||Fn(n,t);case 6:var r=Pe,l=xt;Pe=null,Bt(e,t,n),Pe=r,xt=l,Pe!==null&&(xt?(e=Pe,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):Pe.removeChild(n.stateNode));break;case 18:Pe!==null&&(xt?(e=Pe,n=n.stateNode,e.nodeType===8?Ws(e.parentNode,n):e.nodeType===1&&Ws(e,n),Or(e)):Ws(Pe,n.stateNode));break;case 4:r=Pe,l=xt,Pe=n.stateNode.containerInfo,xt=!0,Bt(e,t,n),Pe=r,xt=l;break;case 0:case 11:case 14:case 15:if(!Me&&(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)&&Hi(n,t,a),l=l.next}while(l!==r)}Bt(e,t,n);break;case 1:if(!Me&&(Fn(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(o){ye(n,t,o)}Bt(e,t,n);break;case 21:Bt(e,t,n);break;case 22:n.mode&1?(Me=(r=Me)||n.memoizedState!==null,Bt(e,t,n),Me=r):Bt(e,t,n);break;default:Bt(e,t,n)}}function Jo(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new Gp),t.forEach(function(r){var l=oh.bind(null,e,r);n.has(r)||(n.add(r),r.then(l,l))})}}function yt(e,t){var n=t.deletions;if(n!==null)for(var r=0;rl&&(l=a),r&=~i}if(r=l,r=ve()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*th(r/1960))-r,10e?16:e,Kt===null)var r=!1;else{if(e=Kt,Kt=null,ls=0,Z&6)throw Error(L(331));var l=Z;for(Z|=4,F=e.current;F!==null;){var i=F,a=i.child;if(F.flags&16){var o=i.deletions;if(o!==null){for(var u=0;uve()-Oa?hn(e,0):Da|=n),Ge(e,t)}function jd(e,t){t===0&&(e.mode&1?(t=cl,cl<<=1,!(cl&130023424)&&(cl=4194304)):t=1);var n=We();e=Mt(e,t),e!==null&&(Yr(e,t,n),Ge(e,n))}function ah(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),jd(e,n)}function oh(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(L(314))}r!==null&&r.delete(t),jd(e,n)}var Sd;Sd=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Je.current)Xe=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return Xe=!1,Xp(e,t,n);Xe=!!(e.flags&131072)}else Xe=!1,de&&t.flags&1048576&&Ec(t,Xl,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;zl(e,t),e=t.pendingProps;var l=Jn(t,Fe.current);Vn(t,n),l=Pa(null,t,r,e,l,n);var i=La();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,Ye(r)?(i=!0,Kl(t)):i=!1,t.memoizedState=l.state!==null&&l.state!==void 0?l.state:null,_a(t),l.updater=gs,t.stateNode=l,l._reactInternals=t,Ii(t,r,e,n),t=Mi(null,t,r,!0,i,n)):(t.tag=0,de&&i&&va(t),Ue(null,t,l,n),t=t.child),t;case 16:r=t.elementType;e:{switch(zl(e,t),e=t.pendingProps,l=r._init,r=l(r._payload),t.type=r,l=t.tag=ch(r),e=vt(r,e),l){case 0:t=Oi(null,t,r,e,n);break e;case 1:t=Vo(null,t,r,e,n);break e;case 11:t=Uo(null,t,r,e,n);break e;case 14:t=Wo(null,t,r,vt(r.type,e),n);break e}throw Error(L(306,r,""))}return t;case 0:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:vt(r,l),Oi(e,t,r,l,n);case 1:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:vt(r,l),Vo(e,t,r,l,n);case 3:e:{if(id(t),e===null)throw Error(L(387));r=t.pendingProps,i=t.memoizedState,l=i.element,Rc(e,t),Gl(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=er(Error(L(423)),t),t=Qo(e,t,r,n,l);break e}else if(r!==l){l=er(Error(L(424)),t),t=Qo(e,t,r,n,l);break e}else for(nt=Yt(t.stateNode.containerInfo.firstChild),rt=t,de=!0,wt=null,n=Lc(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(Yn(),r===l){t=Ft(e,t,n);break e}Ue(e,t,r,n)}t=t.child}return t;case 5:return $c(t),e===null&&zi(t),r=t.type,l=t.pendingProps,i=e!==null?e.memoizedProps:null,a=l.children,Ei(r,l)?a=null:i!==null&&Ei(r,i)&&(t.flags|=32),sd(e,t),Ue(e,t,a,n),t.child;case 6:return e===null&&zi(t),null;case 13:return ad(e,t,n);case 4:return Ca(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=Gn(t,null,r,n):Ue(e,t,r,n),t.child;case 11:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:vt(r,l),Uo(e,t,r,l,n);case 7:return Ue(e,t,t.pendingProps,n),t.child;case 8:return Ue(e,t,t.pendingProps.children,n),t.child;case 12:return Ue(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,se(Jl,r._currentValue),r._currentValue=a,i!==null)if(Nt(i.value,a)){if(i.children===l.children&&!Je.current){t=Ft(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=It(-1,n&-n),u.tag=2;var c=i.updateQueue;if(c!==null){c=c.shared;var v=c.pending;v===null?u.next=u:(u.next=v.next,v.next=u),c.pending=u}}i.lanes|=n,u=i.alternate,u!==null&&(u.lanes|=n),Ri(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(L(341));a.lanes|=n,o=a.alternate,o!==null&&(o.lanes|=n),Ri(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}Ue(e,t,l.children,n),t=t.child}return t;case 9:return l=t.type,r=t.pendingProps.children,Vn(t,n),l=ht(l),r=r(l),t.flags|=1,Ue(e,t,r,n),t.child;case 14:return r=t.type,l=vt(r,t.pendingProps),l=vt(r.type,l),Wo(e,t,r,l,n);case 15:return rd(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:vt(r,l),zl(e,t),t.tag=1,Ye(r)?(e=!0,Kl(t)):e=!1,Vn(t,n),ed(t,r,l),Ii(t,r,l,n),Mi(null,t,r,!0,e,n);case 19:return od(e,t,n);case 22:return ld(e,t,n)}throw Error(L(156,t.tag))};function Nd(e,t){return Yu(e,t)}function uh(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 ft(e,t,n,r){return new uh(e,t,n,r)}function Ba(e){return e=e.prototype,!(!e||!e.isReactComponent)}function ch(e){if(typeof e=="function")return Ba(e)?1:0;if(e!=null){if(e=e.$$typeof,e===ia)return 11;if(e===aa)return 14}return 2}function tn(e,t){var n=e.alternate;return n===null?(n=ft(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 Il(e,t,n,r,l,i){var a=2;if(r=e,typeof e=="function")Ba(e)&&(a=1);else if(typeof e=="string")a=5;else e:switch(e){case Pn:return mn(n.children,l,i,t);case sa:a=8,l|=8;break;case si:return e=ft(12,n,t,l|2),e.elementType=si,e.lanes=i,e;case ii:return e=ft(13,n,t,l),e.elementType=ii,e.lanes=i,e;case ai:return e=ft(19,n,t,l),e.elementType=ai,e.lanes=i,e;case $u:return xs(n,l,i,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case zu:a=10;break e;case Ru:a=9;break e;case ia:a=11;break e;case aa:a=14;break e;case Ht:a=16,r=null;break e}throw Error(L(130,e==null?e:typeof e,""))}return t=ft(a,n,t,l),t.elementType=e,t.type=r,t.lanes=i,t}function mn(e,t,n,r){return e=ft(7,e,r,t),e.lanes=n,e}function xs(e,t,n,r){return e=ft(22,e,r,t),e.elementType=$u,e.lanes=n,e.stateNode={isHidden:!1},e}function Gs(e,t,n){return e=ft(6,e,null,t),e.lanes=n,e}function Zs(e,t,n){return t=ft(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function dh(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=Rs(0),this.expirationTimes=Rs(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Rs(0),this.identifierPrefix=r,this.onRecoverableError=l,this.mutableSourceEagerHydrationData=null}function Ha(e,t,n,r,l,i,a,o,u){return e=new dh(e,t,n,o,u),t===1?(t=1,i===!0&&(t|=8)):t=0,i=ft(3,null,null,t),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},_a(i),e}function fh(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Td)}catch(e){console.error(e)}}Td(),Tu.exports=st;var yh=Tu.exports,bd,lu=yh;bd=lu.createRoot,lu.hydrateRoot;async function ke(e){const t=await fetch(e);if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()}async function vh(){return ke("/api/archives")}async function xh(e){return ke(`/api/archives/${e}/entries`)}async function wh(e,t,n){const r=new URLSearchParams;return t&&r.set("q",t),n&&r.set("tag",n),ke(`/api/archives/${e}/entries/search?${r}`)}async function Ji(e,t){return ke(`/api/archives/${e}/entries/${t}`)}async function kh(e,t){return ke(`/api/archives/${e}/entries/${t}/children`)}function jh(e,t,n){return Promise.all(n.map(r=>ke(`/api/archives/${e}/entries/${t}/artifacts/${r}`)))}async function Sh(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 Nh(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 jl(e,t){return ke(`/api/archives/${e}/entries/${t}/tags`)}async function su(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 _h(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 iu(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 Ch(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 Eh(e,t){const n=await fetch(`/api/archives/${e}/tags/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(await n.text())}async function Th(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 bh(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 ei(e){return ke(`/api/archives/${e}/runs`)}async function Sl(e){return ke(`/api/archives/${e}/tags`)}async function Ph(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(()=>({}));throw new Error(a.error||`HTTP ${i.status}`)}return i.json()}async function Lh(e,t){return ke(`/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 Pd(e,t){return ke(`/api/archives/${e}/capture_jobs/${t}`)}async function Rh(){return(await(await fetch("/api/auth/setup")).json()).setup_required===!0}async function $h(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 Ih(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 Dh(){await fetch("/api/auth/logout",{method:"POST"})}async function Oh(){const e=await fetch("/api/auth/me");return e.status===401?null:e.json()}async function Mh(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 Fh(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 Ah(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 Bh(){return ke("/api/auth/tokens")}async function Hh(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 Uh(e){const t=await fetch(`/api/auth/tokens/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(await t.text())}async function Qa(){return ke("/api/admin/instance-settings")}async function Dl(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 Wh(){return ke("/api/admin/users")}async function Vh(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 Qh(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 Kh(){return ke("/api/admin/roles")}async function qh(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 Ld(e){return ke(`/api/archives/${e}/collections`)}async function Xh(e,t,n,r=2){const l=await fetch(`/api/archives/${e}/collections`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:t,slug:n,default_visibility_bits:r})});if(!l.ok){const i=await l.json().catch(()=>({error:l.statusText}));throw new Error(i.error||l.statusText)}return l.json()}async function Jh(e,t){return ke(`/api/archives/${e}/collections/${t}`)}async function zd(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 Yh(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 Gh(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 Zh(e,t){return ke(`/api/archives/${e}/entries/${t}/collections`)}async function au(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 em(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 tm(e){return ke(`/api/archives/${e}/blob-cleanup`)}async function nm(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 rm(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 lm(){return ke("/api/admin/cookie-rules")}async function sm(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 im(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 am(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}`)}}const om=window.fetch;window.fetch=async(...e)=>{var n;const t=await om(...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 um({onLogin:e}){const[t,n]=f.useState(""),[r,l]=f.useState(""),[i,a]=f.useState(null),[o,u]=f.useState(!1);async function c(v){v.preventDefault(),a(null),u(!0);try{const m=await Ih(t,r);e(m)}catch(m){a(m.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:c,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:v=>n(v.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:v=>l(v.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 cm({onComplete:e}){const[t,n]=f.useState(""),[r,l]=f.useState(""),[i,a]=f.useState(""),[o,u]=f.useState(null),[c,v]=f.useState(!1);async function m(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),v(!0);try{await $h(t,r),e()}catch(g){u(g.message)}finally{v(!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:m,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:c,children:c?"Creating account…":"Create account"})]})]})})}function dm({archives:e,archiveId:t,onArchiveChange:n,view:r,onViewChange:l,onCaptureClick:i}){const{currentUser:a,setCurrentUser:o}=f.useContext(_s)??{},[u,c]=f.useState(!1);async function v(){c(!0),await Dh(),o(null),window.location.reload()}return s.jsxs("header",{className:"topbar",children:[s.jsx("div",{className:"brand",children:"Archivr"}),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))})}),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"}),a&&s.jsxs("div",{className:"user-menu",children:[s.jsx("span",{className:"user-name",children:a.display_name||a.username}),s.jsx("button",{className:"logout-btn",onClick:v,disabled:u,children:u?"Logging out…":"Log out"})]})]})}let Yi=1;function Rd(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/")}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 Kn(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("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"))return!0}catch{}return!1}function gr(e=""){return{id:Yi++,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 fm(e,t){if(e==="best")return t.map(r=>({...r,quality:"best"}));if(e==="audio")return t.map(r=>r.has_audio?{...r,quality:"audio"}:r.quality!==null?r:{...r,quality:null});const n=parseInt(e);return t.map(r=>r.qualities.length===0?r:Math.max(...r.qualities.map(i=>parseInt(i)))>=n?{...r,quality:e}:r.quality!==null?r:{...r,quality:null})}function ou(e){return e.playlistItems!==null&&e.playlistItems.some(t=>t.quality===null)}function pm({open:e,archiveId:t,onClose:n,onCaptured:r,onToast:l,onJobStarted:i,onJobSettled:a,activeJobs:o=[]}){const u=f.useRef(null),c=f.useRef(!0),v=f.useRef(new Map),m=f.useRef(new Map),h=f.useRef(new Map),g=f.useRef(t);f.useEffect(()=>{g.current=t},[t]);const x=f.useRef(r),w=f.useRef(l);f.useEffect(()=>{x.current=r},[r]),f.useEffect(()=>{w.current=l},[l]);const k=f.useRef(i),p=f.useRef(a);f.useEffect(()=>{k.current=i},[i]),f.useEffect(()=>{p.current=a},[a]);const[d,y]=f.useState(()=>{try{const S=JSON.parse(sessionStorage.getItem("captureItems")||"null");if(Array.isArray(S)&&S.length>0){const O=S.filter(I=>!I.status||I.status==="idle");if(O.length>0)return O.forEach(I=>{I.id>=Yi&&(Yi=I.id+1)}),O}}catch{}return[gr()]});f.useEffect(()=>{sessionStorage.setItem("captureItems",JSON.stringify(d))},[d]);const[j,_]=f.useState(!1),[b,E]=f.useState(null),[N,$]=f.useState(null),[P,V]=f.useState(!0),[H,Q]=f.useState(!0),[Y,oe]=f.useState(!0);f.useEffect(()=>{Qa().then(S=>{$(S),V(S.cookie_ext_enabled??!0),Q(S.modal_closer_enabled??!0)}).catch(()=>$({}))},[]);const le=b!==null?b:(N==null?void 0:N.ublock_enabled)??!0,[ee,R]=f.useState(!1);f.useEffect(()=>{["captureDialogLocator","captureDialogError","captureDialogBusy","captureDialogJobStatus","captureDialogJobUid"].forEach(S=>sessionStorage.removeItem(S)),o.forEach(S=>{S.jobUid&&!v.current.has(S.jobUid)&&T(S.id,S.jobUid,S.locator,S.archiveId,null)})},[]),f.useEffect(()=>{const S=u.current;if(!S)return;const O=()=>{m.current.forEach(I=>clearTimeout(I)),m.current.clear(),n()};return S.addEventListener("close",O),()=>S.removeEventListener("close",O)},[n]),f.useEffect(()=>{const S=u.current;S&&(e?(c.current||y([gr()]),c.current=!1,S.open||S.showModal()):(m.current.forEach(O=>clearTimeout(O)),m.current.clear(),S.open&&S.close()))},[e]),f.useEffect(()=>()=>{v.current.forEach(S=>clearInterval(S)),m.current.forEach(S=>clearTimeout(S))},[]);function T(S,O,I,B,W=null){if(v.current.has(O))return;const q=setInterval(async()=>{var ce,Ce,Ke,Ae;try{const Be=await Pd(B,O);if(Be.status==="completed"){clearInterval(v.current.get(O)),v.current.delete(O),await Promise.resolve((ce=x.current)==null?void 0:ce.call(x)),(Ce=p.current)==null||Ce.call(p,S);try{const ge=Be.notes_json?JSON.parse(Be.notes_json):null;if(ge!=null&&ge.ublock_skipped||ge!=null&&ge.cookie_ext_skipped){const ot=ge.ublock_skipped&&ge.cookie_ext_skipped?"Captured without ad-blocking or cookie-consent extension. Check ARCHIVR_UBLOCK_EXT and ARCHIVR_COOKIE_EXT in your server config.":ge.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.";w.current(ot,I,"warning"),A(W,"warning",I)}else W||w.current(null,I,"success"),A(W,"archived")}catch{W||w.current(null,I,"success"),A(W,"archived")}}else if(Be.status==="failed"){clearInterval(v.current.get(O)),v.current.delete(O),(Ke=p.current)==null||Ke.call(p,S);const ge=Be.error_text||"Capture failed.";w.current(ge,I),A(W,"failed",I)}}catch(Be){clearInterval(v.current.get(O)),v.current.delete(O),(Ae=p.current)==null||Ae.call(p,S);const ge=Be.message||"Network error";w.current(ge,I),A(W,"failed",I)}},500);v.current.set(O,q)}function A(S,O,I=null){if(!S)return;const B=h.current.get(S);if(!B||(O==="archived"||O==="warning"?(B.archived++,O==="warning"&&(B.warnings++,I&&B.warningLocators.push(I))):(B.failed++,I&&B.failedLocators.push(I)),B.archived+B.failed0?`${W} archived (${q} with warnings)`:`${W} archived`;Ae=ce>0?`${ot}, ${ce} failed`:ot}const Be=W===0?"error":ce>0||q>0?"warning":"success",ge=[];Ce.length>0&&ge.push(`Failed: ${Ce.map(ot=>` ${ot}`).join(` `)}`),Ke.length>0&&ge.push(`With warnings: ${Ke.map(ot=>` ${ot}`).join(` `)}`);const Sn=ge.length>0?ge.join(` -`):null;w.current(Sn,null,Be,Ae)}async function J(S,O,I,B={}){var Ce,Ke;const W=g.current,q=((Ce=crypto.randomUUID)==null?void 0:Ce.call(crypto))??`job-${Date.now()}-${Math.random()}`,ce={ublock_enabled:le,reader_mode:ee,cookie_ext_enabled:P,modal_closer_enabled:H,via_freedium:Y,...B};try{const Ae=await Ph(W,S,O,ce);(Ke=k.current)==null||Ke.call(k,{id:q,jobUid:Ae.job_uid,locator:S,archiveId:W}),T(q,Ae.job_uid,S,W,I)}catch(Ae){const Be=Ae.message||"Submission failed.";w.current(Be,S),A(I,"failed",S)}}function U(){var B,W;const S=d.filter(q=>q.locator.trim());if(S.length===0||S.some(q=>ou(q))||S.some(q=>q.playlistProbeState==="probing"||q.probeState==="probing"))return;const O=S.length>1?((B=crypto.randomUUID)==null?void 0:B.call(crypto))??`batch-${Date.now()}`:null;O&&h.current.set(O,{total:S.length,archived:0,warnings:0,failed:0,failedLocators:[],warningLocators:[]});const I=S.map(q=>({locator:q.locator.trim(),quality:q.playlistItems!==null?null:q.quality||"best",extraExtensions:q.playlistItems!==null?{per_item_quality:Object.fromEntries(q.playlistItems.map(ce=>[ce.id,ce.quality])),sync:q.syncEnabled}:{}}));y([mr()]),(W=u.current)==null||W.close(),I.forEach(({locator:q,quality:ce,extraExtensions:Ce})=>J(q,ce,O,Ce))}function me(){y(S=>[...S,mr()])}function ue(S){clearTimeout(m.current.get(S)),m.current.delete(S),y(O=>{const I=O.filter(B=>B.id!==S);return I.length===0?[mr()]:I})}function Re(S,O){if(clearTimeout(m.current.get(S)),y(I=>I.map(B=>B.id===S?{...B,locator:O,probeState:"idle",probeQualities:null,probeHasAudio:!1,quality:"best",playlistProbeState:"idle",playlistInfo:null,playlistItems:null,playlistQuality:null,playlistExpanded:!1}:B)),Rd(O)){const I=setTimeout(async()=>{m.current.delete(S),y(B=>B.map(W=>W.id===S?{...W,probeState:"probing"}:W));try{const B=await Lh(g.current,O.trim());y(W=>W.map(q=>{if(q.id!==S||q.locator!==O)return q;const ce=B.qualities??[],Ce=B.has_audio??!1,Ke=ce.length===0&&Ce?"audio":"best";return{...q,probeState:"done",probeQualities:ce,probeHasAudio:Ce,quality:Ke}}))}catch{y(B=>B.map(W=>W.id===S?{...W,probeState:"idle",probeQualities:null}:W))}},600);m.current.set(S,I)}else if(Dl(O)){const I=setTimeout(async()=>{m.current.delete(S),y(B=>B.map(W=>W.id===S?{...W,playlistProbeState:"probing"}:W));try{const B=await zh(g.current,O.trim());y(W=>W.map(q=>q.id!==S||q.locator!==O?q:{...q,playlistProbeState:"done",playlistInfo:B,playlistItems:B.items.map(ce=>({...ce,quality:null})),playlistQuality:null}))}catch{y(B=>B.map(W=>W.id===S?{...W,playlistProbeState:"error"}:W))}},800);m.current.set(S,I)}}function xe(S,O){y(I=>I.map(B=>B.id===S?{...B,quality:O}:B))}function be(S,O){y(I=>I.map(B=>{if(B.id!==S)return B;const W=fm(O,B.playlistItems);return{...B,playlistQuality:O,playlistItems:W}}))}function Ze(S,O,I){y(B=>B.map(W=>W.id!==S?W:{...W,playlistItems:W.playlistItems.map(q=>q.id===O?{...q,quality:I}:q)}))}function at(S){y(O=>O.map(I=>I.id===S?{...I,playlistExpanded:!I.playlistExpanded}:I))}function Pt(S,O){y(I=>I.map(B=>B.id===S?{...B,syncEnabled:O}:B))}const $e=d.filter(S=>S.locator.trim()).length,et=d.some(S=>ou(S)),z=d.some(S=>S.playlistProbeState==="probing"||S.probeState==="probing");return s.jsx("dialog",{ref:u,className:"capture-dialog",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 S;return(S=u.current)==null?void 0:S.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:d.map((S,O)=>s.jsx(hm,{item:S,autoFocus:O===d.length-1,onLocatorChange:I=>Re(S.id,I),onQualityChange:I=>xe(S.id,I),onRemove:()=>ue(S.id),onSubmit:U,onPlaylistQualityChange:I=>be(S.id,I),onPlaylistItemQualityChange:(I,B)=>Ze(S.id,I,B),onPlaylistToggle:()=>at(S.id),onSyncChange:I=>Pt(S.id,I)},S.id))}),s.jsxs("button",{type:"button",className:"capture-add-row",onClick:me,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 another"]}),s.jsxs("div",{className:"capture-advanced",children:[s.jsxs("button",{type:"button",className:"capture-advanced-toggle",onClick:()=>_(S=>!S),"aria-expanded":j,children:[s.jsx("svg",{className:`capture-chevron${j?" 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"]}),j&&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":le,className:`ext-toggle ext-toggle--sm${le?" ext-toggle--on":""}`,onClick:()=>E(S=>S===null?!le:!S),"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"}),!(N!=null&&N.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":P,className:`ext-toggle ext-toggle--sm${P?" ext-toggle--on":""}`,onClick:()=>V(S=>!S),"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":ee,className:`ext-toggle ext-toggle--sm${ee?" ext-toggle--on":""}`,onClick:()=>R(S=>!S),"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":H,className:`ext-toggle ext-toggle--sm${H?" ext-toggle--on":""}`,onClick:()=>Q(S=>!S),"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":Y,className:`ext-toggle ext-toggle--sm${Y?" ext-toggle--on":""}`,onClick:()=>oe(S=>!S),"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:U,disabled:$e===0||et||z,children:$e>1?`Archive ${$e}`:"Archive"}),s.jsx("button",{type:"button",className:"capture-cancel",onClick:()=>{var S;return(S=u.current)==null?void 0:S.close()},children:"Cancel"})]})]})})}function hm({item:e,autoFocus:t,onLocatorChange:n,onQualityChange:r,onRemove:l,onSubmit:i,onPlaylistQualityChange:a,onPlaylistItemQualityChange:o,onPlaylistToggle:u,onSyncChange:c}){const v=f.useRef(null);f.useEffect(()=>{var g;t&&((g=v.current)==null||g.focus())},[t]);const m=(()=>{if(Dl(e.locator)){if(e.playlistProbeState==="probing")return s.jsx("span",{className:"capture-quality-probing","aria-label":"Probing playlist…",children:"…"});if(e.playlistProbeState==="done"){const g=[...new Set(e.playlistItems.flatMap(k=>k.qualities.map(p=>parseInt(p))))].sort((k,p)=>p-k),x=e.playlistItems.every(k=>k.has_audio),w=e.playlistItems.filter(k=>k.quality===null).length;return s.jsxs(s.Fragment,{children:[s.jsxs("select",{className:"capture-quality",value:e.playlistQuality??"",onChange:k=>a(k.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"}),g.map(k=>s.jsxs("option",{value:`${k}p`,children:[k,"p"]},k)),x&&s.jsx("option",{value:"audio",children:"Audio only"})]}),w>0&&s.jsxs("span",{className:"capture-conflict-badge",children:[w," need selection"]}),s.jsx("button",{type:"button",className:"capture-playlist-toggle",onClick:u,"aria-label":e.playlistExpanded?"Collapse video list":"Expand video list","aria-expanded":e.playlistExpanded,children:e.playlistExpanded?"▲":"▼"})]})}return e.playlistProbeState==="error"?s.jsx("span",{className:"capture-quality-hint",children:"Probe failed — using best quality"}):null}if(!Rd(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 g=e.probeQualities??[],x=e.probeHasAudio??!1;return g.length===0&&!x?s.jsx("span",{className:"capture-quality-hint",children:"No media detected"}):g.length===0&&x?s.jsx("select",{className:"capture-quality",value:"audio",onChange:w=>r(w.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:w=>r(w.target.value),"aria-label":"Video quality",children:[s.jsx("option",{value:"best",children:"Best quality"}),g.map(w=>s.jsx("option",{value:w,children:w},w)),x&&s.jsx("option",{value:"audio",children:"Audio only"})]})}return null})(),h=Dl(e.locator)&&e.playlistProbeState==="done"?s.jsxs("label",{className:"capture-sync-row",children:[s.jsx("input",{type:"checkbox",checked:e.syncEnabled,onChange:g=>c(g.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:[s.jsx("input",{ref:v,className:"capture-input",type:"text",placeholder:"https://… · yt:ID · ytm:ID · tweet:ID · x:ID",value:e.locator,onChange:g=>n(g.target.value),onKeyDown:g=>{g.key==="Enter"&&i()},autoComplete:"off",spellCheck:!1}),m,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}),Dl(e.locator)&&e.playlistProbeState==="done"&&e.playlistExpanded?s.jsxs("div",{className:"capture-playlist-items",children:[e.playlistItems.map(g=>s.jsxs("div",{className:`capture-playlist-item${g.quality===null?" capture-playlist-item--conflict":""}`,children:[s.jsx("span",{className:"capture-playlist-item-title",children:g.title||g.url}),s.jsxs("select",{className:"capture-item-quality",value:g.quality??"",onChange:x=>o(g.id,x.target.value),"aria-label":`Quality for ${g.title||g.url}`,children:[g.quality===null&&s.jsx("option",{value:"",disabled:!0,children:"Choose…"}),s.jsx("option",{value:"best",children:"Best quality"}),g.qualities.map(x=>s.jsx("option",{value:x,children:x},x)),g.has_audio&&s.jsx("option",{value:"audio",children:"Audio only"})]}),g.quality===null&&s.jsx("span",{className:"capture-playlist-conflict-badge",children:"Choose quality"})]},g.id)),h]}):h]})}function mm(){return s.jsxs("div",{className:"skeleton-row",children:[s.jsx("div",{className:"col-check","aria-hidden":"true"}),s.jsx("div",{className:"col-added",children:s.jsx("span",{className:"skeleton-cell",style:{width:108,height:13}})}),s.jsxs("div",{className:"col-title",style:{gap:"0.42em",display:"flex",alignItems:"center"},children:[s.jsx("span",{className:"skeleton-cell",style:{width:14,height:14,borderRadius:"50%",flexShrink:0}}),s.jsx("span",{className:"skeleton-cell",style:{width:"58%",height:13}})]}),s.jsx("div",{className:"col-type",children:s.jsx("span",{className:"skeleton-cell",style:{width:58,height:20,borderRadius:99}})}),s.jsx("div",{className:"col-size",children:s.jsx("span",{className:"skeleton-cell",style:{width:44,height:12}})}),s.jsx("div",{className:"col-url",children:s.jsx("span",{className:"skeleton-cell",style:{width:"65%",height:12}})})]})}function qr(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 kt(e){return gm(e)??""}function Ka(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 uu={youtube:'',youtube_music:'',spotify:'',x:'',instagram:'',facebook:'',tiktok:'',reddit:'',snapchat:'',local:'',web:'',other:'?'};function Ns(e){return uu[e]??uu.other}function $d(e){return e.split("/").map(t=>t?t.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"").join("/")}function ym({entry:e,onRowClick:t,selectedUids:n}){const r=(n==null?void 0:n.size)===1&&n.has(e.entry_uid),l=(n==null?void 0:n.size)>=2&&n.has(e.entry_uid),i=["child-entry-row",r&&"is-selected",l&&"is-multi-selected"].filter(Boolean).join(" ");return s.jsxs("div",{className:i,tabIndex:0,"data-entry-uid":e.entry_uid,onMouseDown:a=>{a.shiftKey&&a.preventDefault()},onClick:a=>t(e,a),onKeyDown:a=>{a.key==="Enter"&&t(e,a)},children:[s.jsx("div",{className:"col-check","aria-hidden":"true"}),s.jsx("div",{className:"col-added",children:Ka(e.archived_at)}),s.jsxs("div",{className:"col-title",children:[s.jsx("span",{className:"source-icon",children:s.jsx("span",{dangerouslySetInnerHTML:{__html:Ns(e.source_kind)}})}),s.jsx("span",{className:"entry-title",children:kt(e.title)||kt(e.entry_uid)})]}),s.jsx("div",{className:"col-type",children:s.jsx("span",{className:"type-pill",children:kt(e.entity_kind)})}),s.jsx("div",{className:"col-size",children:s.jsx("span",{className:"size-total",children:qr(e.total_artifact_bytes)})}),s.jsx("div",{className:"url-cell col-url",children:kt(e.original_url)})]})}function vm({entry:e,archiveId:t,isSelected:n,isMultiSelected:r,onRowClick:l,selectedUids:i}){const[a,o]=f.useState(!1),[u,c]=f.useState(!1),[v,m]=f.useState(null),[h,g]=f.useState(!1),w=e.source_kind==="web"&&e.entity_kind==="page"&&e.has_favicon&&t&&!a?s.jsx("img",{src:`/api/archives/${t}/entries/${e.entry_uid}/favicon`,width:"16",height:"16",alt:"",onError:()=>o(!0),style:{objectFit:"contain"}}):s.jsx("span",{dangerouslySetInnerHTML:{__html:Ns(e.source_kind)}}),k=n||r,p=e.child_count>0;function d(_){_.stopPropagation(),l(e,{ctrlKey:!0,metaKey:!1,shiftKey:!1,preventDefault(){}})}async function y(_){if(_.stopPropagation(),u){c(!1);return}if(c(!0),v===null&&!h){g(!0);try{const b=await kh(t,e.entry_uid);m(b)}catch{m([])}finally{g(!1)}}}const j=["entry-row-outer",n&&"is-selected",r&&"is-multi-selected"].filter(Boolean).join(" ");return s.jsxs("div",{className:j,"data-entry-uid":e.entry_uid,children:[s.jsxs("div",{className:"entry-row-main",tabIndex:0,onMouseDown:_=>{_.shiftKey&&_.preventDefault()},onClick:_=>l(e,_),onKeyDown:_=>{_.key==="Enter"&&l(e,_)},children:[s.jsx("div",{className:"col-check",children:s.jsx("button",{type:"button",className:`row-checkbox${k?" is-checked":""}`,"aria-pressed":k,"aria-label":k?"Deselect entry":"Select entry",onClick:d,onKeyDown:_=>_.stopPropagation()})}),s.jsx("div",{className:"col-added",children:Ka(e.archived_at)}),s.jsxs("div",{className:"col-title",children:[p&&s.jsx("button",{type:"button",className:`entry-expand-btn${u?" is-expanded":""}`,"aria-label":u?"Collapse children":`Expand ${e.child_count} items`,"aria-expanded":u,onClick:y,onKeyDown:_=>_.stopPropagation()}),s.jsx("span",{className:"source-icon",children:w}),s.jsx("span",{className:"entry-title",children:kt(e.title)||kt(e.entry_uid)}),p&&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:kt(e.entity_kind)})}),s.jsxs("div",{className:"col-size",children:[s.jsx("span",{className:"size-total",children:qr(e.total_artifact_bytes)}),e.cached_bytes>0&&e.total_artifact_bytes>0&&s.jsxs("span",{className:"size-cached-pct",title:`${qr(e.cached_bytes)} already on disk from an earlier entry`,children:[Math.round(e.cached_bytes/e.total_artifact_bytes*100),"% cached"]})]}),s.jsx("div",{className:"url-cell col-url",children:kt(e.original_url)})]}),u&&s.jsxs("div",{className:"child-entries","aria-label":`${e.child_count} child entries`,children:[h&&s.jsx("div",{className:"child-entries-loading",children:"Loading…"}),v&&v.map(_=>s.jsx(ym,{entry:_,onRowClick:l,selectedUids:i},_.entry_uid))]})]})}function xm({entries:e,selectedUids:t,onRowClick:n,archiveId:r,pendingCaptures:l=[]}){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(i=>i.archiveId===r).reverse().map(i=>s.jsx(mm,{},i.id)),e.map(i=>s.jsx(vm,{entry:i,archiveId:r,isSelected:t.size===1&&t.has(i.entry_uid),isMultiSelected:t.size>=2&&t.has(i.entry_uid),onRowClick:n,selectedUids:t},i.entry_uid))]})]})})}function wm(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 km({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 jm({runs:e}){const[t,n]=f.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:wm(l.started_at)}),s.jsxs("td",{children:[s.jsx(km,{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 Sm=4;function Nm({archives:e}){const{currentUser:t}=f.useContext(_s)??{},n=t&&(t.role_bits&Sm)!==0,[r,l]=f.useState("users"),[i,a]=f.useState([]),[o,u]=f.useState([]),[c,v]=f.useState(!1),[m,h]=f.useState(null),[g,x]=f.useState(""),[w,k]=f.useState(""),[p,d]=f.useState(""),[y,j]=f.useState(null),[_,b]=f.useState(!1),[E,N]=f.useState(""),[$,P]=f.useState(""),[V,H]=f.useState(null),[Q,Y]=f.useState(!1),oe=f.useCallback(async()=>{if(n){v(!0),h(null);try{const[T,A]=await Promise.all([Wh(),Kh()]);a(T),u(A)}catch(T){h(T.message)}finally{v(!1)}}},[n]);f.useEffect(()=>{oe()},[oe]);async function le(T){const A=T.status==="active"?"disabled":"active";try{await Qh(T.user_uid,A),a(J=>J.map(U=>U.user_uid===T.user_uid?{...U,status:A}:U))}catch(J){h(J.message)}}async function ee(T){if(T.preventDefault(),!g.trim()||!w){j("Username and password required");return}b(!0),j(null);try{await Vh(g.trim(),w,p.trim()||void 0),x(""),k(""),d(""),await oe()}catch(A){j(A.message)}finally{b(!1)}}async function R(T){if(T.preventDefault(),!E.trim()||!$.trim()){H("Slug and name required");return}Y(!0),H(null);try{await qh(E.trim(),$.trim()),N(""),P(""),await oe()}catch(A){H(A.message)}finally{Y(!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"})]}),m&&s.jsx("div",{className:"form-msg form-msg--err",children:m}),r==="users"&&s.jsxs("div",{className:"admin-section",children:[s.jsx("h2",{children:"Users"}),c?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(T=>s.jsxs("tr",{className:T.status==="disabled"?"admin-row-disabled":"",children:[s.jsx("td",{children:T.username}),s.jsx("td",{className:"muted",children:T.email||"—"}),s.jsx("td",{children:T.role_slugs.join(", ")||"—"}),s.jsx("td",{children:s.jsx("span",{className:`status-badge status-${T.status}`,children:T.status})}),s.jsx("td",{children:s.jsx("button",{className:"admin-action-btn",onClick:()=>le(T),children:T.status==="active"?"Ban":"Unban"})})]},T.user_uid))})]}),s.jsx("h3",{children:"Create User"}),s.jsxs("form",{className:"admin-form",onSubmit:ee,children:[s.jsx("input",{className:"admin-input",placeholder:"Username",value:g,onChange:T=>x(T.target.value),required:!0}),s.jsx("input",{className:"admin-input",type:"password",placeholder:"Password (min 8 chars)",value:w,onChange:T=>k(T.target.value),required:!0}),s.jsx("input",{className:"admin-input",type:"email",placeholder:"Email (optional)",value:p,onChange:T=>d(T.target.value)}),y&&s.jsx("div",{className:"form-msg form-msg--err",children:y}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:_,children:_?"Creating…":"Create User"})]})]}),r==="roles"&&s.jsxs("div",{className:"admin-section",children:[s.jsx("h2",{children:"Roles"}),c?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(T=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx("code",{children:T.slug})}),s.jsx("td",{children:T.name}),s.jsx("td",{children:T.level}),s.jsx("td",{children:T.bit_position}),s.jsx("td",{children:T.is_builtin?"✓":""})]},T.role_uid))})]}),s.jsx("h3",{children:"Create Custom Role"}),s.jsxs("form",{className:"admin-form",onSubmit:R,children:[s.jsx("input",{className:"admin-input",placeholder:"Slug (e.g. moderator)",value:E,onChange:T=>N(T.target.value),required:!0}),s.jsx("input",{className:"admin-input",placeholder:"Display Name (e.g. Moderator)",value:$,onChange:T=>P(T.target.value),required:!0}),V&&s.jsx("div",{className:"form-msg form-msg--err",children:V}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:Q,children:Q?"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(T=>s.jsxs("div",{className:"admin-archive",children:[s.jsx("strong",{children:T.label}),s.jsx("div",{className:"muted",children:T.archive_path})]},T.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(T=>s.jsxs("div",{className:"admin-archive",children:[s.jsx("strong",{children:T.label}),s.jsx("div",{className:"muted",children:T.archive_path})]},T.id))})]})}function Id({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(Id,{node:r,onPick:t},r.tag.tag_uid))})})]})}function cu({title:e,tagNodes:t,excludeUid:n,onPick:r,onCancel:l}){f.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(Id,{node:o,onPick:r},o.tag.tag_uid))}):s.jsx("p",{className:"tag-picker-empty",children:"No other tags available."})]})]})})}function Dd({parentPath:e,archiveId:t,onDone:n,onCancel:r}){const[l,i]=f.useState(""),a=f.useRef(!1);async function o(){const u=l.trim();if(!u){r();return}const c=e?`${e}/${u}`:`/${u}`;try{await Th(t,c),n()}catch(v){alert(v.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 Od({node:e,archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:c,onMoveSourceSelect:v,pendingCreateParentUid:m,onCreateDone:h,onCreateCancel:g}){var V;const x=n===e.tag.full_path,[w,k]=f.useState(!1),[p,d]=f.useState(""),y=f.useRef(!1);function j(){if(w)return;if(c){v(e);return}const H=x?null:e.tag.full_path;r(H),l("archive")}function _(H){H.stopPropagation(),!c&&(d(e.tag.slug),k(!0))}async function b(){const H=p.trim();if(!H||H===e.tag.slug){k(!1);return}try{const Q=await Ch(t,e.tag.tag_uid,H);i(e.tag.full_path,Q.full_path),o()}catch{}finally{k(!1)}}async function E(H){var Y;H.stopPropagation();const Q=((Y=e.children)==null?void 0:Y.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(Q))try{await Eh(t,e.tag.tag_uid),a(e.tag.full_path),o()}catch{}}const N={archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:c,onMoveSourceSelect:v,pendingCreateParentUid:m,onCreateDone:h,onCreateCancel:g},$=m===e.tag.tag_uid,P=((V=e.children)==null?void 0:V.length)>0;return s.jsxs("li",{children:[s.jsxs("div",{className:`tag-node-row${c?" tag-node-row--move-select":""}`,children:[w?s.jsx("input",{className:"tag-rename-input",autoFocus:!0,value:p,onChange:H=>d(H.target.value),onKeyDown:H=>{H.key==="Enter"&&H.currentTarget.blur(),H.key==="Escape"&&(y.current=!0,H.currentTarget.blur())},onBlur:()=>{y.current?(y.current=!1,k(!1)):b()}}):s.jsxs("button",{className:`tag-node-btn${x?" is-active":""}${c?" tag-node-btn--move-select":""}`,title:c?`Select "${e.tag.full_path}" to move`:e.tag.full_path,onClick:j,onDoubleClick:c?void 0:_,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)`}),!c&&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(),_(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"})})]}),!w&&!c&&s.jsx("button",{className:"remove tag-node-delete",title:`Delete "${e.tag.full_path}"`,onClick:E,"aria-label":`Delete "${e.tag.full_path}"`,children:"×"})]}),(P||$)&&s.jsx("div",{className:"tag-children",children:s.jsxs("ul",{className:"tag-tree-list",children:[e.children.map(H=>s.jsx(Od,{node:H,...N},H.tag.tag_uid)),$&&s.jsx("li",{children:s.jsx(Dd,{parentPath:e.tag.full_path,archiveId:t,onDone:h,onCancel:g})})]})})]})}function _m({archiveId:e,tagNodes:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u}){const[c,v]=f.useState(null),[m,h]=f.useState(null);function g(){v("select-source"),h(null)}function x(){v(null),h(null)}f.useEffect(()=>{if(c!=="select-source")return;function Q(Y){Y.key==="Escape"&&(Y.preventDefault(),Y.stopPropagation(),x())}return document.addEventListener("keydown",Q),()=>document.removeEventListener("keydown",Q)},[c]);function w(Q){h(Q),v("select-dest")}async function k(Q){const Y=m.tag.full_path,oe=m.tag.tag_uid,le=(Q==null?void 0:Q.tag_uid)??null;x();try{const ee=await bh(e,oe,le);i(Y,ee.full_path),o()}catch(ee){alert(ee.message||"Move failed")}}const[p,d]=f.useState(null),[y,j]=f.useState(void 0);function _(){d("select-parent"),j(void 0)}function b(){d(null),j(void 0)}function E(Q){j(Q??null),d("input")}function N(){d(null),j(void 0),o()}const $=c==="select-source",P=p==="input"?y?y.tag_uid:"__root__":void 0,V={archiveId:e,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:$,onMoveSourceSelect:w,pendingCreateParentUid:P,onCreateDone:N,onCreateCancel:b},H=P==="__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:$?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:_,title:"Create a new tag",disabled:!!p||!!c,children:"+ New"}),s.jsx("button",{className:"tag-tree-action-btn",onClick:g,title:"Move a tag to a different parent",disabled:!!p||!!c||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(Q=>s.jsx(Od,{node:Q,...V},Q.tag.tag_uid)),H&&s.jsx("li",{children:s.jsx(Dd,{parentPath:null,archiveId:e,onDone:N,onCancel:b})})]})]}),p==="select-parent"&&s.jsx(cu,{title:"Create tag under…",tagNodes:t,excludeUid:null,onPick:E,onCancel:b}),c==="select-dest"&&m&&s.jsx(cu,{title:`Move "${m.tag.slug}" under…`,tagNodes:t,excludeUid:m.tag.tag_uid,onPick:k,onCancel:x})]})}const kr=[{value:0,label:"Private"},{value:2,label:"Users only"},{value:3,label:"Public"}],Cm=e=>{var t;return((t=kr.find(n=>n.value===e))==null?void 0:t.label)??String(e)};function Em({archiveId:e}){const[t,n]=f.useState([]),[r,l]=f.useState(!1),[i,a]=f.useState(null),[o,u]=f.useState(null),[c,v]=f.useState(null),[m,h]=f.useState(!1),[g,x]=f.useState(null),[w,k]=f.useState(""),[p,d]=f.useState(""),[y,j]=f.useState(2),[_,b]=f.useState(!1),[E,N]=f.useState(null),[$,P]=f.useState(""),[V,H]=f.useState(2),[Q,Y]=f.useState(!1),[oe,le]=f.useState(null),[ee,R]=f.useState(!1),[T,A]=f.useState(""),J=f.useRef(null),U=t.find(z=>z.collection_uid===o)??null,me=(U==null?void 0:U.slug)==="_default_",ue=f.useCallback(async()=>{if(e){l(!0),a(null);try{const z=await Ld(e);n(z)}catch(z){a(z.message)}finally{l(!1)}}},[e]),Re=f.useCallback(async z=>{if(!z){v(null);return}h(!0),x(null);try{const S=await Jh(e,z);v(S)}catch(S){x(S.message)}finally{h(!1)}},[e]);f.useEffect(()=>{ue()},[ue]),f.useEffect(()=>{Re(o)},[o,Re]),f.useEffect(()=>{ee&&J.current&&J.current.focus()},[ee]);async function xe(z){z.preventDefault();const S=w.trim(),O=p.trim();if(!(!S||!O)){b(!0),N(null);try{const I=await Xh(e,S,O,y);k(""),d(""),j(2),await ue(),u(I.collection_uid)}catch(I){N(I.message)}finally{b(!1)}}}async function be(){const z=T.trim();if(!z||!U){R(!1);return}try{await au(e,U.collection_uid,{name:z}),await ue(),v(S=>S&&{...S,name:z})}catch(S){a(S.message)}finally{R(!1)}}async function Ze(z){if(U)try{await au(e,U.collection_uid,{default_visibility_bits:z}),await ue(),v(S=>S&&{...S,default_visibility_bits:z})}catch(S){a(S.message)}}async function at(){if(U&&window.confirm(`Delete collection "${U.name}"? Entries will not be deleted.`))try{await em(e,U.collection_uid),u(null),v(null),await ue()}catch(z){a(z.message)}}async function Pt(z){z.preventDefault();const S=$.trim();if(!(!S||!U)){Y(!0),le(null);try{await zd(e,U.collection_uid,S,V),P(""),await Re(U.collection_uid)}catch(O){le(O.message)}finally{Y(!1)}}}async function $e(z){if(U)try{await Yh(e,U.collection_uid,z),await Re(U.collection_uid)}catch(S){x(S.message)}}async function et(z,S){if(U)try{await Gh(e,U.collection_uid,z,S),v(O=>O&&{...O,entries:O.entries.map(I=>I.entry_uid===z?{...I,collection_visibility_bits:S}:I)})}catch(O){x(O.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(z=>s.jsxs("button",{className:`coll-sidebar-row${o===z.collection_uid?" is-active":""}`,onClick:()=>u(z.collection_uid),children:[s.jsx("span",{className:"coll-row-name",children:z.name}),s.jsx("span",{className:"coll-row-meta",children:Cm(z.default_visibility_bits)})]},z.collection_uid)),t.length===0&&!r&&s.jsx("div",{className:"muted",style:{padding:"8px 12px"},children:"No collections yet."})]}),U?s.jsxs("div",{className:"coll-detail",children:[s.jsxs("div",{className:"coll-detail-header",children:[ee?s.jsx("input",{ref:J,className:"coll-rename-input",value:T,onChange:z=>A(z.target.value),onBlur:be,onKeyDown:z=>{z.key==="Enter"&&be(),z.key==="Escape"&&R(!1)}}):s.jsxs("h3",{className:`coll-detail-name${me?"":" coll-detail-name--editable"}`,title:me?void 0:"Click to rename",onClick:()=>{me||(A(U.name),R(!0))},children:[(c==null?void 0:c.name)??U.name,!me&&s.jsx("span",{className:"coll-edit-hint",children:" ✎"})]}),!me&&s.jsx("button",{className:"coll-delete-btn",onClick:at,title:"Delete collection",children:"Delete"})]}),s.jsxs("div",{className:"coll-detail-vis",children:[s.jsx("span",{className:"coll-vis-label",children:"Default visibility"}),s.jsx("select",{className:"coll-vis-select",value:(c==null?void 0:c.default_visibility_bits)??U.default_visibility_bits,onChange:z=>Ze(Number(z.target.value)),disabled:me,children:kr.map(z=>s.jsx("option",{value:z.value,children:z.label},z.value))})]}),s.jsxs("div",{className:"coll-entries-section",children:[s.jsx("div",{className:"coll-section-heading",children:"Entries"}),m&&s.jsx("div",{className:"muted",children:"Loading…"}),g&&s.jsx("div",{className:"collections-error",children:g}),!m&&c&&(c.entries.length===0?s.jsx("div",{className:"muted",children:"No entries in this collection."}):s.jsx("ul",{className:"coll-entries-list",children:c.entries.map(z=>s.jsxs("li",{className:"coll-entry-row",children:[s.jsxs("div",{className:"coll-entry-info",children:[s.jsx("span",{className:"coll-entry-title",children:z.title||z.entry_uid}),s.jsx("span",{className:"coll-entry-kind muted",children:z.source_kind})]}),s.jsxs("div",{className:"coll-entry-actions",children:[s.jsx("select",{className:"coll-entry-vis-select",value:z.collection_visibility_bits,onChange:S=>et(z.entry_uid,Number(S.target.value)),children:kr.map(S=>s.jsx("option",{value:S.value,children:S.label},S.value))}),!me&&s.jsx("button",{className:"coll-entry-remove",onClick:()=>$e(z.entry_uid),title:"Remove from collection",children:"×"})]})]},z.entry_uid))}))]}),!me&&s.jsxs("form",{className:"coll-add-entry-form",onSubmit:Pt,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:$,onChange:z=>P(z.target.value),placeholder:"entry_uid",required:!0}),s.jsx("select",{className:"coll-vis-select",value:V,onChange:z=>H(Number(z.target.value)),children:kr.map(z=>s.jsx("option",{value:z.value,children:z.label},z.value))}),s.jsx("button",{className:"coll-add-btn",type:"submit",disabled:Q,children:Q?"…":"Add"})]}),oe&&s.jsx("div",{className:"collections-error",style:{marginTop:4},children:oe})]})]}):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:xe,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:w,onChange:z=>{k(z.target.value),p||d(z.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:z=>d(z.target.value),placeholder:"my-collection",required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"coll-vis",children:"Default visibility"}),s.jsx("select",{className:"capture-input",id:"coll-vis",style:{height:42},value:y,onChange:z=>j(Number(z.target.value)),children:kr.map(z=>s.jsx("option",{value:z.value,children:z.label},z.value))})]}),E&&s.jsx("div",{className:"collections-error",children:E}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:_,children:_?"Creating…":"Create collection"})]})]})]}):s.jsx("div",{className:"view-placeholder",children:"Select an archive."})}const Tm=4;function bm({tab:e,onTabChange:t,archiveId:n}){const{currentUser:r,setCurrentUser:l}=f.useContext(_s)??{},i=r&&(r.role_bits&Tm)!==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(Pm,{currentUser:r,setCurrentUser:l}),e==="tokens"&&s.jsx(Lm,{}),e==="instance"&&i&&s.jsx(zm,{}),e==="cookies"&&i&&s.jsx($m,{}),e==="extensions"&&i&&s.jsx(Im,{}),e==="storage"&&i&&s.jsx(Rm,{archiveId:n})]})}function Pm({currentUser:e,setCurrentUser:t}){const[n,r]=f.useState((e==null?void 0:e.display_name)??""),[l,i]=f.useState(!1),[a,o]=f.useState(null),[u,c]=f.useState(""),[v,m]=f.useState(""),[h,g]=f.useState(""),[x,w]=f.useState(!1),[k,p]=f.useState(null);async function d(j){j.preventDefault(),i(!0),o(null);try{await Mh(n),t(_=>({..._,display_name:n||null})),o({ok:!0,text:"Saved."})}catch(_){o({ok:!1,text:_.message})}finally{i(!1)}}async function y(j){if(j.preventDefault(),v!==h){p({ok:!1,text:"Passwords do not match."});return}w(!0),p(null);try{await Ah(u,v),c(""),m(""),g(""),p({ok:!0,text:"Password changed."})}catch(_){p({ok:!1,text:_.message})}finally{w(!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:d,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:j=>r(j.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 j=>{const _=j.target.checked;try{await Fh({humanize_slugs:_}),t(b=>({...b,humanize_slugs:_}))}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:y,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:j=>c(j.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:v,onChange:j=>m(j.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:j=>g(j.target.value),required:!0})]}),k&&s.jsx("div",{className:`form-msg form-msg--${k.ok?"ok":"err"}`,children:k.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:x,children:x?"Changing…":"Change Password"})]})]})]})}function Lm(){const[e,t]=f.useState([]),[n,r]=f.useState(!0),[l,i]=f.useState(null),[a,o]=f.useState(""),[u,c]=f.useState(!1),[v,m]=f.useState(null),h=f.useCallback(async()=>{r(!0),i(null);try{t(await Bh())}catch(w){i(w.message)}finally{r(!1)}},[]);f.useEffect(()=>{h()},[h]);async function g(w){if(w.preventDefault(),!!a.trim()){c(!0);try{const k=await Hh(a.trim());m(k),o(""),h()}catch(k){i(k.message)}finally{c(!1)}}}async function x(w){try{await Uh(w),t(k=>k.filter(p=>p.token_uid!==w))}catch(k){i(k.message)}}return s.jsx("div",{style:{maxWidth:600},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"API Tokens"}),v&&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:v.raw_token}),s.jsx("button",{className:"token-dismiss",onClick:()=>m(null),children:"Dismiss"})]}),s.jsxs("form",{className:"token-create-row",onSubmit:g,children:[s.jsx("input",{className:"field-input field-input--flex",placeholder:"Token name",value:a,onChange:w=>o(w.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(w=>s.jsxs("div",{className:"token-row",children:[s.jsxs("div",{className:"token-row-info",children:[s.jsx("strong",{children:w.name}),s.jsxs("div",{className:"muted",children:["Created ",w.created_at.slice(0,10),w.last_used_at&&` · Last used ${w.last_used_at.slice(0,10)}`]})]}),s.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"4px 10px"},onClick:()=>x(w.token_uid),children:"Revoke"})]},w.token_uid))]})]})})}function zm(){const[e,t]=f.useState(null),[n,r]=f.useState(!0),[l,i]=f.useState(null),[a,o]=f.useState(!1),[u,c]=f.useState(null);f.useEffect(()=>{(async()=>{try{t(await Qa())}catch(m){i(m.message)}finally{r(!1)}})()},[]);async function v(m){m.preventDefault(),o(!0),c(null);try{await Il(e),c({ok:!0,text:"Saved."})}catch(h){c({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:v,children:[[["public_index_enabled","Public index (unauthenticated browsing)"],["public_entry_content_enabled","Public entry content"],["open_registration_enabled","Open registration"]].map(([m,h])=>s.jsxs("label",{className:"checkbox-row",children:[s.jsx("input",{type:"checkbox",checked:!!e[m],onChange:g=>t(x=>({...x,[m]:g.target.checked}))}),h]},m)),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:m=>t(h=>({...h,default_entry_visibility:Number(m.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 ti(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 Rm({archiveId:e}){const[t,n]=f.useState("idle"),[r,l]=f.useState(null),[i,a]=f.useState(null),[o,u]=f.useState(null);function c(){n("idle"),l(null),a(null),u(null)}async function v(){n("scanning"),u(null),l(null);try{const g=await tm(e);l(g),n("scanned")}catch(g){u(g.message),n("error")}}async function m(){n("deleting"),u(null);try{const g=await nm(e);a(g),n("done")}catch(g){u(g.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:v,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:c,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:ti(r.total_bytes)})," recoverable."]}),s.jsxs("div",{style:{display:"flex",gap:8},children:[s.jsxs("button",{className:"btn-danger",onClick:m,children:["Delete (",ti(r.total_bytes),")"]}),s.jsx("button",{className:"btn-ghost",onClick:c,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:ti(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:c,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:c,children:"Try again"})]})]})})}function $m(){const[e,t]=f.useState(null),[n,r]=f.useState(!0),[l,i]=f.useState(null),[a,o]=f.useState("global"),[u,c]=f.useState(""),[v,m]=f.useState("{}"),[h,g]=f.useState(null),[x,w]=f.useState(!1),[k,p]=f.useState({});f.useEffect(()=>{d()},[]);async function d(){r(!0),i(null);try{t(await lm())}catch(N){i(N.message)}finally{r(!1)}}async function y(N){N.preventDefault();try{JSON.parse(v)}catch{g({ok:!1,text:'cookies must be valid JSON, e.g. {"session": "abc"}'});return}w(!0),g(null);try{await sm(a==="global"?null:u.trim(),a,v),c(""),m("{}"),o("global"),g({ok:!0,text:"Rule added."}),await d()}catch($){g({ok:!1,text:$.message})}finally{w(!1)}}async function j(N){try{await am(N),await d()}catch($){i($.message)}}function _(N){p($=>({...$,[N.rule_uid]:{cookiesInput:N.cookies_json,saving:!1,msg:null}}))}function b(N){p($=>{const P={...$};return delete P[N],P})}async function E(N){const $=k[N.rule_uid];try{JSON.parse($.cookiesInput)}catch{p(P=>({...P,[N.rule_uid]:{...P[N.rule_uid],msg:{ok:!1,text:"Invalid JSON"}}}));return}p(P=>({...P,[N.rule_uid]:{...P[N.rule_uid],saving:!0,msg:null}}));try{await im(N.rule_uid,{cookies_json:$.cookiesInput}),b(N.rule_uid),await d()}catch(P){p(V=>({...V,[N.rule_uid]:{...V[N.rule_uid],saving:!1,msg:{ok:!1,text:P.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(N=>{const $=k[N.rule_uid],P=N.url_pattern?s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"muted",children:[N.pattern_kind,":"]})," ",s.jsx("code",{children:N.url_pattern})]}):s.jsx("span",{className:"muted",children:"global (all URLs)"});return s.jsxs("tr",{children:[s.jsx("td",{children:P}),s.jsx("td",{children:$?s.jsxs(s.Fragment,{children:[s.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:12,width:"100%",minHeight:60},value:$.cookiesInput,onChange:V=>p(H=>({...H,[N.rule_uid]:{...H[N.rule_uid],cookiesInput:V.target.value}}))}),$.msg&&s.jsx("div",{className:`form-msg form-msg--${$.msg.ok?"ok":"err"}`,children:$.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:$.saving,onClick:()=>E(N),children:$.saving?"Saving…":"Save"}),s.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>b(N.rule_uid),children:"Cancel"})]})]}):s.jsx("code",{style:{fontSize:12,wordBreak:"break-all"},children:N.cookies_json})}),s.jsx("td",{children:!$&&s.jsxs("div",{style:{display:"flex",gap:6},children:[s.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>_(N),children:"Edit"}),s.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"2px 8px"},onClick:()=>j(N.rule_uid),children:"Del"})]})})]},N.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:y,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:N=>o(N.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:N=>c(N.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:v,onChange:N=>m(N.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 Im(){const[e,t]=f.useState(null),[n,r]=f.useState(!0),[l,i]=f.useState(!1),[a,o]=f.useState(null);f.useEffect(()=>{(async()=>{try{t(await Qa())}catch(k){o({ok:!1,text:k.message})}finally{r(!1)}})()},[]);async function u(k){i(!0),o(null);try{await Il({ublock_enabled:k}),t(p=>({...p,ublock_enabled:k})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}async function c(k){i(!0),o(null);try{await Il({cookie_ext_enabled:k}),t(p=>({...p,cookie_ext_enabled:k})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}async function v(k){i(!0),o(null);try{await Il({modal_closer_enabled:k}),t(p=>({...p,modal_closer_enabled:k})),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 m=(e==null?void 0:e.ublock_ext_available)??!1,h=(e==null?void 0:e.ublock_enabled)??!0,g=(e==null?void 0:e.cookie_ext_available)??!1,x=(e==null?void 0:e.cookie_ext_enabled)??!0,w=(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)."}),!m&&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."}),!g&&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:()=>c(!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":w,className:`ext-toggle${w?" ext-toggle--on":""}`,onClick:()=>v(!w),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 du={0:"Private",1:"Public",2:"Users only",3:"Public"},Dm=()=>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 Om({archiveId:e,selectedEntry:t,selectedUids:n,selectedEntries:r,detail:l,onTagFilterSet:i,tagNodes:a,onTagsRefresh:o,onEntryTitleChange:u,onEntryDeleted:c,onBulkDeleted:v,humanizeTags:m,onDetailRefresh:h,onOpenPreview:g,onPlay:x}){var nl;const[w,k]=f.useState([]),[p,d]=f.useState(""),[y,j]=f.useState([]),[_,b]=f.useState(""),E=f.useRef(0),N=f.useRef(!1),[$,P]=f.useState(!1),[V,H]=f.useState(""),[Q,Y]=f.useState("idle"),[oe,le]=f.useState(""),ee=f.useRef(null),[R,T]=f.useState(!1);f.useEffect(()=>{T(!1)},[(nl=l==null?void 0:l.summary)==null?void 0:nl.entry_uid]);const A=(n==null?void 0:n.size)>=2,[J,U]=f.useState(""),[me,ue]=f.useState("idle"),[Re,xe]=f.useState(""),[be,Ze]=f.useState([]),[at,Pt]=f.useState(""),[$e,et]=f.useState("idle"),[z,S]=f.useState(""),[O,I]=f.useState("idle");f.useEffect(()=>{const D=++E.current;if(ee.current&&(clearInterval(ee.current),ee.current=null),Y("idle"),le(""),!t||!e){k([]),j([]);return}P(!1),H(""),N.current=!1,k([]),Promise.all([kl(e,t.entry_uid),Zh(e,t.entry_uid)]).then(([te,He])=>{D===E.current&&(k(te),j(He))}).catch(()=>{})},[t,e]),f.useEffect(()=>()=>{clearInterval(ee.current)},[]),f.useEffect(()=>{if(!A||!e){Ze([]);return}Ld(e).then(Ze).catch(()=>Ze([]))},[A,e]),f.useEffect(()=>{U(""),ue("idle"),xe(""),Pt(""),et("idle"),S(""),I("idle")},[n]);async function B(){const D=n.size;if(!window.confirm(`Delete ${D} entr${D===1?"y":"ies"}? This cannot be undone.`))return;I("running");const te=new Set;for(const He of n)try{await iu(e,He),te.add(He)}catch{}I("idle"),v==null||v(te)}async function W(){const D=J.trim();if(D){ue("running"),xe("");try{for(const te of n)await su(e,te,D);U(""),ue("done"),o==null||o(),setTimeout(()=>ue("idle"),1800)}catch(te){xe(te.message),ue("error")}}}async function q(){if(!at)return;et("running"),S("");const D=[];for(const te of n)try{await zd(e,at,te)}catch{D.push(te)}D.length>0?(S(`Failed for ${D.length} entr${D.length===1?"y":"ies"}.`),et("error")):(et("done"),setTimeout(()=>et("idle"),1800))}async function ce(){const D=V.trim()||null;try{await Nh(e,t.entry_uid,D),u==null||u(t.entry_uid,D)}catch{}finally{P(!1)}}async function Ce(){const D=p.trim();if(!(!D||!t))try{await su(e,t.entry_uid,D),d(""),b("");const te=await kl(e,t.entry_uid);k(te),o()}catch(te){b(te.message)}}async function Ke(D){try{await _h(e,t.entry_uid,D);const te=await kl(e,t.entry_uid);k(te),o()}catch{}}async function Ae(){if(!(!t||!e)&&window.confirm("Delete this entry? This cannot be undone."))try{await iu(e,t.entry_uid),c==null||c(t.entry_uid)}catch{}}async function Be(){if(!t||!e||Q==="running")return;const D=E.current,te=t.entry_uid;Y("running"),le("");try{const{job_uid:He}=await rm(e,te);if(E.current!==D)return;ee.current=setInterval(async()=>{try{const gt=await Pd(e,He);if(gt.status==="completed"){if(clearInterval(ee.current),ee.current=null,E.current!==D)return;Y("done");const Cn=await kl(e,te);if(E.current!==D)return;k(Cn),h==null||h()}else if(gt.status==="failed"){if(clearInterval(ee.current),ee.current=null,E.current!==D)return;Y("error"),le(gt.error_text||"Re-archive failed.")}}catch{if(clearInterval(ee.current),ee.current=null,E.current!==D)return;Y("error"),le("Network error while polling.")}},500)}catch(He){if(E.current!==D)return;Y("error"),le(He.message||"Failed to start re-archive.")}}const ge=l?[["Added",Ka(l.summary.archived_at)],["Source",l.summary.source_kind],["Type",l.summary.entity_kind],["Visibility",du[l.summary.visibility]??l.summary.visibility],["Root",l.structured_root_relpath]]:[],Sn=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),ot=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv","pdf","html","htm","jpg","jpeg","png","gif","webp","avif","svg","bmp"]),Nn=l?l.artifacts.findIndex(D=>D.artifact_role==="primary_media"):-1,_n=Nn>=0?l.artifacts[Nn]:null,el=_n?_n.relpath.split(".").pop().toLowerCase():"",tl=_n&&Sn.has(el),Cs=Nn>=0&&t?`/api/archives/${e}/entries/${t.entry_uid}/artifacts/${Nn}`:null,Es=l&&!tl&&(l.summary.entity_kind==="tweet"||l.summary.entity_kind==="tweet_thread"||_n&&ot.has(el));return s.jsxs("aside",{className:"context-rail",children:[s.jsx("div",{className:"rail-eyebrow",children:"Context"}),A?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"}),Re&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:Re}),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:J,onChange:D=>U(D.target.value),onKeyDown:D=>{D.key==="Enter"&&W()}}),s.jsx("button",{className:"tag-add-btn",onClick:W,disabled:me==="running"||!J.trim(),children:me==="running"?"…":me==="done"?"✓":"Add"})]})]}),be.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:at,onChange:D=>Pt(D.target.value),children:[s.jsx("option",{value:"",children:"Pick a collection…"}),be.map(D=>s.jsx("option",{value:D.collection_uid,children:D.name},D.collection_uid))]}),s.jsx("button",{className:"tag-add-btn",onClick:q,disabled:!at||$e==="running",children:$e==="running"?"…":$e==="done"?"✓":$e==="error"?"!":"Add"})]}),z&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"6px 0 0"},children:z})]}),s.jsx("div",{className:"rail-delete-zone",children:s.jsx("button",{className:"rail-delete-btn",onClick:B,disabled:O==="running",children:O==="running"?"Deleting…":`Delete ${n.size} entr${n.size===1?"y":"ies"}`})})]}):t?l?s.jsxs(s.Fragment,{children:[$?s.jsx("input",{className:"rail-title-input",autoFocus:!0,value:V,onChange:D=>H(D.target.value),onKeyDown:D=>{D.key==="Enter"&&D.currentTarget.blur(),D.key==="Escape"&&(N.current=!0,D.currentTarget.blur())},onBlur:()=>{N.current?P(!1):ce(),N.current=!1}}):s.jsxs("h2",{className:"rail-title rail-title--editable",title:"Click to rename",onClick:()=>{H(l.summary.title??""),P(!0)},children:[kt(l.summary.title)||kt(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:Ns(l.summary.source_kind)}}),s.jsx("span",{className:"u-text",children:l.summary.original_url}),s.jsx("span",{className:"ext",children:s.jsx(Dm,{})})]}),tl&&x&&s.jsx("button",{className:"rail-preview-btn",onClick:()=>x(Cs,t),children:"▶ Play"}),Es&&g&&s.jsx("button",{className:"rail-preview-btn",onClick:g,children:"Preview"}),s.jsx("div",{className:"meta-list",children:ge.filter(([,D])=>D!=null&&D!=="").map(([D,te])=>s.jsxs("div",{className:"meta-item",children:[s.jsx("span",{className:"meta-k",children:D}),s.jsx("span",{className:`meta-v${D==="Root"?" mono":""}`,children:kt(te)})]},D))}),l.artifacts.length>0&&(()=>{const D=l.artifacts.map((je,lr)=>({...je,_idx:lr})),te=D.filter(je=>je.artifact_role==="font"),He=D.filter(je=>je.artifact_role!=="font"),gt=te.reduce((je,lr)=>je+(lr.byte_size||0),0),Cn=l.summary.entry_uid,rl=je=>s.jsx("li",{children:s.jsxs("a",{href:`/api/archives/${e}/entries/${Cn}/artifacts/${je._idx}`,target:"_blank",rel:"noopener noreferrer",className:"artifact-link",children:[s.jsx("span",{className:"artifact-name",children:je.artifact_role==="font"?je.relpath.split("/").pop():je.artifact_role.replace(/_/g," ")}),s.jsx("span",{className:"artifact-size",children:je.byte_size!=null?qr(je.byte_size):"—"})]})},je._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:[He.map(rl),te.length>0&&s.jsxs("li",{className:"artifact-group",children:[s.jsxs("button",{type:"button",className:"artifact-group-header artifact-link","aria-expanded":R,onClick:()=>T(je=>!je),children:[s.jsxs("span",{className:"artifact-name",children:[s.jsx("span",{"aria-hidden":"true",className:`artifact-group-chevron${R?" open":""}`,children:"›"}),` fonts (${te.length})`]}),s.jsx("span",{className:"artifact-size",children:qr(gt)})]}),R&&s.jsx("ul",{className:"artifact-list artifact-group-body",children:te.map(rl)})]})]})]})})()]}):s.jsx("p",{className:"tags-empty",children:"Loading\\u2026"}):s.jsx("p",{className:"tags-empty",children:"Select an entry."}),t&&!A&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Tags"}),w.length===0?s.jsx("p",{className:"tags-empty",children:"No tags yet."}):s.jsx("div",{className:"tags-wrap",children:w.map(D=>s.jsxs("span",{className:"tag-pill",title:D.full_path,children:[m?$d(D.full_path):D.full_path,s.jsx("button",{className:"remove",title:`Remove tag ${D.full_path}`,onClick:()=>Ke(D.tag_uid),children:"×"})]},D.tag_uid))}),_&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:_}),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:p,onChange:D=>d(D.target.value),onKeyDown:D=>{D.key==="Enter"&&Ce()}}),s.jsx("button",{className:"tag-add-btn",onClick:Ce,children:"Add"})]})]}),y.length>0&&s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Collections"}),y.map(D=>s.jsxs("div",{className:"coll-row",children:[s.jsx("span",{className:"coll-name",children:D.collection_uid}),s.jsx("span",{className:"vis-badge",children:du[D.visibility_bits]??`bits:${D.visibility_bits}`})]},D.collection_uid))]}),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:Be,disabled:Q==="running",children:Q==="running"?"Re-archiving…":"Re-archive"}),Q==="done"&&s.jsx("p",{className:"form-msg form-msg--ok",style:{marginTop:"6px"},children:"Re-archived successfully."}),Q==="error"&&s.jsx("p",{className:"form-msg form-msg--err",style:{marginTop:"6px"},children:oe})]}),s.jsx("div",{className:"rail-delete-zone",children:s.jsx("button",{className:"rail-delete-btn",onClick:Ae,children:"Delete entry"})})]})]})}function Mm({src:e}){const t=f.useRef(null);return f.useEffect(()=>{t.current&&t.current.load()},[e]),s.jsx("div",{className:"preview-video-wrap",style:{background:"#111",display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",minHeight:"240px"},children:e?s.jsxs("video",{ref:t,controls:!0,autoPlay:!1,style:{width:"100%",maxHeight:"100%",display:"block"},children:[s.jsx("source",{src:e}),"Your browser does not support the video element."]}):s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No video available"})})}function fu({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 Fm({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 Md(e){return e?new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(new Date(e*1e3)):""}function pu(e){return!e||!e.includes("&")?e:e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/'/g,"'")}const X={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"}},Se={bg:"#000000",border:"#2f3336",text:"#e7e9ea",dim:"#71767b",accent:"#1d9bf0",codeBg:"#16181c"},ni={article:{background:Se.bg,color:Se.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:Se.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:Se.border,flexShrink:0},aAuthorName:{fontSize:"15px",fontWeight:"700",color:Se.text,lineHeight:"1.3"},aAuthorSub:{fontSize:"15px",color:Se.dim,lineHeight:"1.3"},aDivider:{border:"none",borderTop:`1px solid ${Se.border}`,margin:"0"},aBody:{padding:"4px 16px 0"},bH1:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:Se.text,lineHeight:"36px",margin:"24px 0 10px"},bH2:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:Se.text,lineHeight:"36px",margin:"24px 0 10px"},bP:{fontSize:"17px",color:Se.text,lineHeight:"1.5",marginBottom:"16px",marginTop:"0"},bSpacer:{height:"6px",display:"block"},bQuote:{borderLeft:`3px solid ${Se.border}`,padding:"2px 14px",margin:"14px 0",color:Se.dim,fontSize:"17px",lineHeight:"1.5"},bHr:{border:"none",borderTop:`1px solid ${Se.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:Se.text,lineHeight:"1.5",marginBottom:"6px"},bTweet:{display:"flex",alignItems:"center",gap:"12px",border:`1px solid ${Se.border}`,borderRadius:"12px",padding:"14px 16px",margin:"14px 0",color:Se.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:Se.text,background:"transparent"},iCode:{fontFamily:"ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace",fontSize:"0.875em",background:Se.codeBg,padding:"2px 6px",borderRadius:"4px",color:"#e6edf3"},link:{color:Se.accent,textDecoration:"none"}};function Am(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 Kn(e,t,n){return e&&n[e]?n[e]:t||null}function Fd(){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 qa(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 Ad(e,t){const n=e.expanded_url||e.url||e.text||"",r=e.display_url||e.expanded_url||e.url||e.text||"",l=qa(e,t,e.url,e.text,e.display_url,e.expanded_url);return!l||!n?null:{...l,kind:"url",href:n,display:r}}function Bd(e,t){const n=e.screen_name||e.name||e.text||"",r=n?`@${n}`:null,l=qa(e,t,r);return!l||!n?null:{...l,kind:"mention",screen_name:n}}const hu=/https?:\/\/[^\s<>"'\])]+/g,Bm=/[.,;:!?)()]+$/;function as(e,t){const n=[];let r=0,l;for(hu.lastIndex=0;(l=hu.exec(e))!==null;){l.index>r&&n.push(e.slice(r,l.index));let i=l[0].replace(Bm,"");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:(rAd(o,e)).filter(Boolean),...(t.user_mentions||[]).map(o=>Bd(o,e)).filter(Boolean)];if(r.length===0&&n.length===0)return as(pu(e),X.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(([c,v])=>c<=o&&v>=u),a=[...l].sort((o,u)=>o-u);return a.slice(0,-1).map((o,u)=>{const c=a[u+1];if(i(o,c))return null;const v=e.slice(o,c),m=r.filter(x=>x.s<=o&&x.e>=c),h=m.find(x=>x.kind==="url");if(h)return s.jsx("a",{href:h.href,target:"_blank",rel:"noopener noreferrer",style:X.link,children:h.display||v},u);const g=m.find(x=>x.kind==="mention");return g?s.jsx("a",{href:`https://x.com/${g.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:X.link,children:v},u):s.jsx("span",{children:as(pu(v),X.link)},u)}).filter(o=>o!==null)}function Um(e,t,n,r,l=X){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 c=Ad(u,e);c&&i.push(c)}for(const u of r){const c=Bd(u,e);c&&i.push(c)}if(i.length===0)return as(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,c)=>u-c);return o.slice(0,-1).map((u,c)=>{const v=o[c+1],m=i.filter(k=>k.s<=u&&k.e>=v),h=e.slice(u,v);let g;if(h.includes(` +`):null;w.current(Sn,null,Be,Ae)}async function J(S,O,I,B={}){var Ce,Ke;const W=g.current,q=((Ce=crypto.randomUUID)==null?void 0:Ce.call(crypto))??`job-${Date.now()}-${Math.random()}`,ce={ublock_enabled:le,reader_mode:ee,cookie_ext_enabled:P,modal_closer_enabled:H,via_freedium:Y,...B};try{const Ae=await Ph(W,S,O,ce);(Ke=k.current)==null||Ke.call(k,{id:q,jobUid:Ae.job_uid,locator:S,archiveId:W}),T(q,Ae.job_uid,S,W,I)}catch(Ae){const Be=Ae.message||"Submission failed.";w.current(Be,S),A(I,"failed",S)}}function U(){var B,W;const S=d.filter(q=>q.locator.trim());if(S.length===0||S.some(q=>ou(q))||S.some(q=>q.probeState==="probing"||Kn(q.locator)&&q.playlistProbeState!=="done"))return;const O=S.length>1?((B=crypto.randomUUID)==null?void 0:B.call(crypto))??`batch-${Date.now()}`:null;O&&h.current.set(O,{total:S.length,archived:0,warnings:0,failed:0,failedLocators:[],warningLocators:[]});const I=S.map(q=>({locator:q.locator.trim(),quality:q.playlistItems!==null?null:q.quality||"best",extraExtensions:q.playlistItems!==null?{per_item_quality:Object.fromEntries(q.playlistItems.map(ce=>[ce.id,ce.quality])),sync:q.syncEnabled}:{}}));y([gr()]),(W=u.current)==null||W.close(),I.forEach(({locator:q,quality:ce,extraExtensions:Ce})=>J(q,ce,O,Ce))}function me(){y(S=>[...S,gr()])}function ue(S){clearTimeout(m.current.get(S)),m.current.delete(S),y(O=>{const I=O.filter(B=>B.id!==S);return I.length===0?[gr()]:I})}function Re(S,O){if(clearTimeout(m.current.get(S)),y(I=>I.map(B=>B.id===S?{...B,locator:O,probeState:"idle",probeQualities:null,probeHasAudio:!1,quality:"best",playlistProbeState:"idle",playlistInfo:null,playlistItems:null,playlistQuality:null,playlistExpanded:!1}:B)),Rd(O)){const I=setTimeout(async()=>{m.current.delete(S),y(B=>B.map(W=>W.id===S?{...W,probeState:"probing"}:W));try{const B=await Lh(g.current,O.trim());y(W=>W.map(q=>{if(q.id!==S||q.locator!==O)return q;const ce=B.qualities??[],Ce=B.has_audio??!1,Ke=ce.length===0&&Ce?"audio":"best";return{...q,probeState:"done",probeQualities:ce,probeHasAudio:Ce,quality:Ke}}))}catch{y(B=>B.map(W=>W.id===S?{...W,probeState:"idle",probeQualities:null}:W))}},600);m.current.set(S,I)}else if(Kn(O)){const I=setTimeout(async()=>{m.current.delete(S),y(B=>B.map(W=>W.id===S?{...W,playlistProbeState:"probing"}:W));try{const B=await zh(g.current,O.trim());y(W=>W.map(q=>q.id!==S||q.locator!==O?q:{...q,playlistProbeState:"done",playlistInfo:B,playlistItems:B.items.map(ce=>({...ce,quality:null})),playlistQuality:null}))}catch{y(B=>B.map(W=>W.id===S?{...W,playlistProbeState:"error"}:W))}},800);m.current.set(S,I)}}function xe(S,O){y(I=>I.map(B=>B.id===S?{...B,quality:O}:B))}function be(S,O){y(I=>I.map(B=>{if(B.id!==S)return B;const W=fm(O,B.playlistItems);return{...B,playlistQuality:O,playlistItems:W}}))}function Ze(S,O,I){y(B=>B.map(W=>W.id!==S?W:{...W,playlistItems:W.playlistItems.map(q=>q.id===O?{...q,quality:I}:q)}))}function at(S){y(O=>O.map(I=>I.id===S?{...I,playlistExpanded:!I.playlistExpanded}:I))}function Pt(S,O){y(I=>I.map(B=>B.id===S?{...B,syncEnabled:O}:B))}const $e=d.filter(S=>S.locator.trim()).length,et=d.some(S=>ou(S)),z=d.some(S=>S.probeState==="probing"||Kn(S.locator)&&S.playlistProbeState!=="done");return s.jsx("dialog",{ref:u,className:"capture-dialog",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 S;return(S=u.current)==null?void 0:S.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:d.map((S,O)=>s.jsx(hm,{item:S,autoFocus:O===d.length-1,onLocatorChange:I=>Re(S.id,I),onQualityChange:I=>xe(S.id,I),onRemove:()=>ue(S.id),onSubmit:U,onPlaylistQualityChange:I=>be(S.id,I),onPlaylistItemQualityChange:(I,B)=>Ze(S.id,I,B),onPlaylistToggle:()=>at(S.id),onSyncChange:I=>Pt(S.id,I)},S.id))}),s.jsxs("button",{type:"button",className:"capture-add-row",onClick:me,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 another"]}),s.jsxs("div",{className:"capture-advanced",children:[s.jsxs("button",{type:"button",className:"capture-advanced-toggle",onClick:()=>_(S=>!S),"aria-expanded":j,children:[s.jsx("svg",{className:`capture-chevron${j?" 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"]}),j&&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":le,className:`ext-toggle ext-toggle--sm${le?" ext-toggle--on":""}`,onClick:()=>E(S=>S===null?!le:!S),"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"}),!(N!=null&&N.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":P,className:`ext-toggle ext-toggle--sm${P?" ext-toggle--on":""}`,onClick:()=>V(S=>!S),"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":ee,className:`ext-toggle ext-toggle--sm${ee?" ext-toggle--on":""}`,onClick:()=>R(S=>!S),"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":H,className:`ext-toggle ext-toggle--sm${H?" ext-toggle--on":""}`,onClick:()=>Q(S=>!S),"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":Y,className:`ext-toggle ext-toggle--sm${Y?" ext-toggle--on":""}`,onClick:()=>oe(S=>!S),"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:U,disabled:$e===0||et||z,children:$e>1?`Archive ${$e}`:"Archive"}),s.jsx("button",{type:"button",className:"capture-cancel",onClick:()=>{var S;return(S=u.current)==null?void 0:S.close()},children:"Cancel"})]})]})})}function hm({item:e,autoFocus:t,onLocatorChange:n,onQualityChange:r,onRemove:l,onSubmit:i,onPlaylistQualityChange:a,onPlaylistItemQualityChange:o,onPlaylistToggle:u,onSyncChange:c}){const v=f.useRef(null);f.useEffect(()=>{var g;t&&((g=v.current)==null||g.focus())},[t]);const m=(()=>{if(Kn(e.locator)){if(e.playlistProbeState==="probing")return s.jsx("span",{className:"capture-quality-probing","aria-label":"Probing playlist…",children:"…"});if(e.playlistProbeState==="done"){const g=[...new Set(e.playlistItems.flatMap(k=>k.qualities.map(p=>parseInt(p))))].sort((k,p)=>p-k),x=e.playlistItems.every(k=>k.has_audio),w=e.playlistItems.filter(k=>k.quality===null).length;return s.jsxs(s.Fragment,{children:[s.jsxs("select",{className:"capture-quality",value:e.playlistQuality??"",onChange:k=>a(k.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"}),g.map(k=>s.jsxs("option",{value:`${k}p`,children:[k,"p"]},k)),x&&s.jsx("option",{value:"audio",children:"Audio only"})]}),w>0&&s.jsxs("span",{className:"capture-conflict-badge",children:[w," need selection"]}),s.jsx("button",{type:"button",className:"capture-playlist-toggle",onClick:u,"aria-label":e.playlistExpanded?"Collapse video list":"Expand video list","aria-expanded":e.playlistExpanded,children:e.playlistExpanded?"▲":"▼"})]})}return e.playlistProbeState==="error"?s.jsx("span",{className:"capture-quality-hint",children:"Probe failed — using best quality"}):null}if(!Rd(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 g=e.probeQualities??[],x=e.probeHasAudio??!1;return g.length===0&&!x?s.jsx("span",{className:"capture-quality-hint",children:"No media detected"}):g.length===0&&x?s.jsx("select",{className:"capture-quality",value:"audio",onChange:w=>r(w.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:w=>r(w.target.value),"aria-label":"Video quality",children:[s.jsx("option",{value:"best",children:"Best quality"}),g.map(w=>s.jsx("option",{value:w,children:w},w)),x&&s.jsx("option",{value:"audio",children:"Audio only"})]})}return null})(),h=Kn(e.locator)&&e.playlistProbeState==="done"?s.jsxs("label",{className:"capture-sync-row",children:[s.jsx("input",{type:"checkbox",checked:e.syncEnabled,onChange:g=>c(g.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:[s.jsx("input",{ref:v,className:"capture-input",type:"text",placeholder:"https://… · yt:ID · ytm:ID · tweet:ID · x:ID",value:e.locator,onChange:g=>n(g.target.value),onKeyDown:g=>{g.key==="Enter"&&i()},autoComplete:"off",spellCheck:!1}),m,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}),Kn(e.locator)&&e.playlistProbeState==="done"&&e.playlistExpanded?s.jsxs("div",{className:"capture-playlist-items",children:[e.playlistItems.map(g=>s.jsxs("div",{className:`capture-playlist-item${g.quality===null?" capture-playlist-item--conflict":""}`,children:[s.jsx("span",{className:"capture-playlist-item-title",children:g.title||g.url}),s.jsxs("select",{className:"capture-item-quality",value:g.quality??"",onChange:x=>o(g.id,x.target.value),"aria-label":`Quality for ${g.title||g.url}`,children:[g.quality===null&&s.jsx("option",{value:"",disabled:!0,children:"Choose…"}),s.jsx("option",{value:"best",children:"Best quality"}),g.qualities.map(x=>s.jsx("option",{value:x,children:x},x)),g.has_audio&&s.jsx("option",{value:"audio",children:"Audio only"})]}),g.quality===null&&s.jsx("span",{className:"capture-playlist-conflict-badge",children:"Choose quality"})]},g.id)),h]}):h]})}function mm(){return s.jsxs("div",{className:"skeleton-row",children:[s.jsx("div",{className:"col-check","aria-hidden":"true"}),s.jsx("div",{className:"col-added",children:s.jsx("span",{className:"skeleton-cell",style:{width:108,height:13}})}),s.jsxs("div",{className:"col-title",style:{gap:"0.42em",display:"flex",alignItems:"center"},children:[s.jsx("span",{className:"skeleton-cell",style:{width:14,height:14,borderRadius:"50%",flexShrink:0}}),s.jsx("span",{className:"skeleton-cell",style:{width:"58%",height:13}})]}),s.jsx("div",{className:"col-type",children:s.jsx("span",{className:"skeleton-cell",style:{width:58,height:20,borderRadius:99}})}),s.jsx("div",{className:"col-size",children:s.jsx("span",{className:"skeleton-cell",style:{width:44,height:12}})}),s.jsx("div",{className:"col-url",children:s.jsx("span",{className:"skeleton-cell",style:{width:"65%",height:12}})})]})}function Xr(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 kt(e){return gm(e)??""}function Ka(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 uu={youtube:'',youtube_music:'',spotify:'',x:'',instagram:'',facebook:'',tiktok:'',reddit:'',snapchat:'',local:'',web:'',other:'?'};function Ns(e){return uu[e]??uu.other}function $d(e){return e.split("/").map(t=>t?t.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"").join("/")}function ym({entry:e,onRowClick:t,selectedUids:n}){const r=(n==null?void 0:n.size)===1&&n.has(e.entry_uid),l=(n==null?void 0:n.size)>=2&&n.has(e.entry_uid),i=["child-entry-row",r&&"is-selected",l&&"is-multi-selected"].filter(Boolean).join(" ");return s.jsxs("div",{className:i,tabIndex:0,"data-entry-uid":e.entry_uid,onMouseDown:a=>{a.shiftKey&&a.preventDefault()},onClick:a=>t(e,a),onKeyDown:a=>{a.key==="Enter"&&t(e,a)},children:[s.jsx("div",{className:"col-check","aria-hidden":"true"}),s.jsx("div",{className:"col-added",children:Ka(e.archived_at)}),s.jsxs("div",{className:"col-title",children:[s.jsx("span",{className:"source-icon",children:s.jsx("span",{dangerouslySetInnerHTML:{__html:Ns(e.source_kind)}})}),s.jsx("span",{className:"entry-title",children:kt(e.title)||kt(e.entry_uid)})]}),s.jsx("div",{className:"col-type",children:s.jsx("span",{className:"type-pill",children:kt(e.entity_kind)})}),s.jsx("div",{className:"col-size",children:s.jsx("span",{className:"size-total",children:Xr(e.total_artifact_bytes)})}),s.jsx("div",{className:"url-cell col-url",children:kt(e.original_url)})]})}function vm({entry:e,archiveId:t,isSelected:n,isMultiSelected:r,onRowClick:l,selectedUids:i}){const[a,o]=f.useState(!1),[u,c]=f.useState(!1),[v,m]=f.useState(null),[h,g]=f.useState(!1),w=e.source_kind==="web"&&e.entity_kind==="page"&&e.has_favicon&&t&&!a?s.jsx("img",{src:`/api/archives/${t}/entries/${e.entry_uid}/favicon`,width:"16",height:"16",alt:"",onError:()=>o(!0),style:{objectFit:"contain"}}):s.jsx("span",{dangerouslySetInnerHTML:{__html:Ns(e.source_kind)}}),k=n||r,p=e.child_count>0;function d(_){_.stopPropagation(),l(e,{ctrlKey:!0,metaKey:!1,shiftKey:!1,preventDefault(){}})}async function y(_){if(_.stopPropagation(),u){c(!1);return}if(c(!0),v===null&&!h){g(!0);try{const b=await kh(t,e.entry_uid);m(b)}catch{m([])}finally{g(!1)}}}const j=["entry-row-outer",n&&"is-selected",r&&"is-multi-selected"].filter(Boolean).join(" ");return s.jsxs("div",{className:j,"data-entry-uid":e.entry_uid,children:[s.jsxs("div",{className:"entry-row-main",tabIndex:0,onMouseDown:_=>{_.shiftKey&&_.preventDefault()},onClick:_=>l(e,_),onKeyDown:_=>{_.key==="Enter"&&l(e,_)},children:[s.jsx("div",{className:"col-check",children:s.jsx("button",{type:"button",className:`row-checkbox${k?" is-checked":""}`,"aria-pressed":k,"aria-label":k?"Deselect entry":"Select entry",onClick:d,onKeyDown:_=>_.stopPropagation()})}),s.jsx("div",{className:"col-added",children:Ka(e.archived_at)}),s.jsxs("div",{className:"col-title",children:[p&&s.jsx("button",{type:"button",className:`entry-expand-btn${u?" is-expanded":""}`,"aria-label":u?"Collapse children":`Expand ${e.child_count} items`,"aria-expanded":u,onClick:y,onKeyDown:_=>_.stopPropagation()}),s.jsx("span",{className:"source-icon",children:w}),s.jsx("span",{className:"entry-title",children:kt(e.title)||kt(e.entry_uid)}),p&&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:kt(e.entity_kind)})}),s.jsxs("div",{className:"col-size",children:[s.jsx("span",{className:"size-total",children:Xr(e.total_artifact_bytes)}),e.cached_bytes>0&&e.total_artifact_bytes>0&&s.jsxs("span",{className:"size-cached-pct",title:`${Xr(e.cached_bytes)} already on disk from an earlier entry`,children:[Math.round(e.cached_bytes/e.total_artifact_bytes*100),"% cached"]})]}),s.jsx("div",{className:"url-cell col-url",children:kt(e.original_url)})]}),u&&s.jsxs("div",{className:"child-entries","aria-label":`${e.child_count} child entries`,children:[h&&s.jsx("div",{className:"child-entries-loading",children:"Loading…"}),v&&v.map(_=>s.jsx(ym,{entry:_,onRowClick:l,selectedUids:i},_.entry_uid))]})]})}function xm({entries:e,selectedUids:t,onRowClick:n,archiveId:r,pendingCaptures:l=[]}){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(i=>i.archiveId===r).reverse().map(i=>s.jsx(mm,{},i.id)),e.map(i=>s.jsx(vm,{entry:i,archiveId:r,isSelected:t.size===1&&t.has(i.entry_uid),isMultiSelected:t.size>=2&&t.has(i.entry_uid),onRowClick:n,selectedUids:t},i.entry_uid))]})]})})}function wm(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 km({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 jm({runs:e}){const[t,n]=f.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:wm(l.started_at)}),s.jsxs("td",{children:[s.jsx(km,{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 Sm=4;function Nm({archives:e}){const{currentUser:t}=f.useContext(_s)??{},n=t&&(t.role_bits&Sm)!==0,[r,l]=f.useState("users"),[i,a]=f.useState([]),[o,u]=f.useState([]),[c,v]=f.useState(!1),[m,h]=f.useState(null),[g,x]=f.useState(""),[w,k]=f.useState(""),[p,d]=f.useState(""),[y,j]=f.useState(null),[_,b]=f.useState(!1),[E,N]=f.useState(""),[$,P]=f.useState(""),[V,H]=f.useState(null),[Q,Y]=f.useState(!1),oe=f.useCallback(async()=>{if(n){v(!0),h(null);try{const[T,A]=await Promise.all([Wh(),Kh()]);a(T),u(A)}catch(T){h(T.message)}finally{v(!1)}}},[n]);f.useEffect(()=>{oe()},[oe]);async function le(T){const A=T.status==="active"?"disabled":"active";try{await Qh(T.user_uid,A),a(J=>J.map(U=>U.user_uid===T.user_uid?{...U,status:A}:U))}catch(J){h(J.message)}}async function ee(T){if(T.preventDefault(),!g.trim()||!w){j("Username and password required");return}b(!0),j(null);try{await Vh(g.trim(),w,p.trim()||void 0),x(""),k(""),d(""),await oe()}catch(A){j(A.message)}finally{b(!1)}}async function R(T){if(T.preventDefault(),!E.trim()||!$.trim()){H("Slug and name required");return}Y(!0),H(null);try{await qh(E.trim(),$.trim()),N(""),P(""),await oe()}catch(A){H(A.message)}finally{Y(!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"})]}),m&&s.jsx("div",{className:"form-msg form-msg--err",children:m}),r==="users"&&s.jsxs("div",{className:"admin-section",children:[s.jsx("h2",{children:"Users"}),c?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(T=>s.jsxs("tr",{className:T.status==="disabled"?"admin-row-disabled":"",children:[s.jsx("td",{children:T.username}),s.jsx("td",{className:"muted",children:T.email||"—"}),s.jsx("td",{children:T.role_slugs.join(", ")||"—"}),s.jsx("td",{children:s.jsx("span",{className:`status-badge status-${T.status}`,children:T.status})}),s.jsx("td",{children:s.jsx("button",{className:"admin-action-btn",onClick:()=>le(T),children:T.status==="active"?"Ban":"Unban"})})]},T.user_uid))})]}),s.jsx("h3",{children:"Create User"}),s.jsxs("form",{className:"admin-form",onSubmit:ee,children:[s.jsx("input",{className:"admin-input",placeholder:"Username",value:g,onChange:T=>x(T.target.value),required:!0}),s.jsx("input",{className:"admin-input",type:"password",placeholder:"Password (min 8 chars)",value:w,onChange:T=>k(T.target.value),required:!0}),s.jsx("input",{className:"admin-input",type:"email",placeholder:"Email (optional)",value:p,onChange:T=>d(T.target.value)}),y&&s.jsx("div",{className:"form-msg form-msg--err",children:y}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:_,children:_?"Creating…":"Create User"})]})]}),r==="roles"&&s.jsxs("div",{className:"admin-section",children:[s.jsx("h2",{children:"Roles"}),c?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(T=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx("code",{children:T.slug})}),s.jsx("td",{children:T.name}),s.jsx("td",{children:T.level}),s.jsx("td",{children:T.bit_position}),s.jsx("td",{children:T.is_builtin?"✓":""})]},T.role_uid))})]}),s.jsx("h3",{children:"Create Custom Role"}),s.jsxs("form",{className:"admin-form",onSubmit:R,children:[s.jsx("input",{className:"admin-input",placeholder:"Slug (e.g. moderator)",value:E,onChange:T=>N(T.target.value),required:!0}),s.jsx("input",{className:"admin-input",placeholder:"Display Name (e.g. Moderator)",value:$,onChange:T=>P(T.target.value),required:!0}),V&&s.jsx("div",{className:"form-msg form-msg--err",children:V}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:Q,children:Q?"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(T=>s.jsxs("div",{className:"admin-archive",children:[s.jsx("strong",{children:T.label}),s.jsx("div",{className:"muted",children:T.archive_path})]},T.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(T=>s.jsxs("div",{className:"admin-archive",children:[s.jsx("strong",{children:T.label}),s.jsx("div",{className:"muted",children:T.archive_path})]},T.id))})]})}function Id({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(Id,{node:r,onPick:t},r.tag.tag_uid))})})]})}function cu({title:e,tagNodes:t,excludeUid:n,onPick:r,onCancel:l}){f.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(Id,{node:o,onPick:r},o.tag.tag_uid))}):s.jsx("p",{className:"tag-picker-empty",children:"No other tags available."})]})]})})}function Dd({parentPath:e,archiveId:t,onDone:n,onCancel:r}){const[l,i]=f.useState(""),a=f.useRef(!1);async function o(){const u=l.trim();if(!u){r();return}const c=e?`${e}/${u}`:`/${u}`;try{await Th(t,c),n()}catch(v){alert(v.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 Od({node:e,archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:c,onMoveSourceSelect:v,pendingCreateParentUid:m,onCreateDone:h,onCreateCancel:g}){var V;const x=n===e.tag.full_path,[w,k]=f.useState(!1),[p,d]=f.useState(""),y=f.useRef(!1);function j(){if(w)return;if(c){v(e);return}const H=x?null:e.tag.full_path;r(H),l("archive")}function _(H){H.stopPropagation(),!c&&(d(e.tag.slug),k(!0))}async function b(){const H=p.trim();if(!H||H===e.tag.slug){k(!1);return}try{const Q=await Ch(t,e.tag.tag_uid,H);i(e.tag.full_path,Q.full_path),o()}catch{}finally{k(!1)}}async function E(H){var Y;H.stopPropagation();const Q=((Y=e.children)==null?void 0:Y.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(Q))try{await Eh(t,e.tag.tag_uid),a(e.tag.full_path),o()}catch{}}const N={archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:c,onMoveSourceSelect:v,pendingCreateParentUid:m,onCreateDone:h,onCreateCancel:g},$=m===e.tag.tag_uid,P=((V=e.children)==null?void 0:V.length)>0;return s.jsxs("li",{children:[s.jsxs("div",{className:`tag-node-row${c?" tag-node-row--move-select":""}`,children:[w?s.jsx("input",{className:"tag-rename-input",autoFocus:!0,value:p,onChange:H=>d(H.target.value),onKeyDown:H=>{H.key==="Enter"&&H.currentTarget.blur(),H.key==="Escape"&&(y.current=!0,H.currentTarget.blur())},onBlur:()=>{y.current?(y.current=!1,k(!1)):b()}}):s.jsxs("button",{className:`tag-node-btn${x?" is-active":""}${c?" tag-node-btn--move-select":""}`,title:c?`Select "${e.tag.full_path}" to move`:e.tag.full_path,onClick:j,onDoubleClick:c?void 0:_,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)`}),!c&&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(),_(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"})})]}),!w&&!c&&s.jsx("button",{className:"remove tag-node-delete",title:`Delete "${e.tag.full_path}"`,onClick:E,"aria-label":`Delete "${e.tag.full_path}"`,children:"×"})]}),(P||$)&&s.jsx("div",{className:"tag-children",children:s.jsxs("ul",{className:"tag-tree-list",children:[e.children.map(H=>s.jsx(Od,{node:H,...N},H.tag.tag_uid)),$&&s.jsx("li",{children:s.jsx(Dd,{parentPath:e.tag.full_path,archiveId:t,onDone:h,onCancel:g})})]})})]})}function _m({archiveId:e,tagNodes:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u}){const[c,v]=f.useState(null),[m,h]=f.useState(null);function g(){v("select-source"),h(null)}function x(){v(null),h(null)}f.useEffect(()=>{if(c!=="select-source")return;function Q(Y){Y.key==="Escape"&&(Y.preventDefault(),Y.stopPropagation(),x())}return document.addEventListener("keydown",Q),()=>document.removeEventListener("keydown",Q)},[c]);function w(Q){h(Q),v("select-dest")}async function k(Q){const Y=m.tag.full_path,oe=m.tag.tag_uid,le=(Q==null?void 0:Q.tag_uid)??null;x();try{const ee=await bh(e,oe,le);i(Y,ee.full_path),o()}catch(ee){alert(ee.message||"Move failed")}}const[p,d]=f.useState(null),[y,j]=f.useState(void 0);function _(){d("select-parent"),j(void 0)}function b(){d(null),j(void 0)}function E(Q){j(Q??null),d("input")}function N(){d(null),j(void 0),o()}const $=c==="select-source",P=p==="input"?y?y.tag_uid:"__root__":void 0,V={archiveId:e,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:$,onMoveSourceSelect:w,pendingCreateParentUid:P,onCreateDone:N,onCreateCancel:b},H=P==="__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:$?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:_,title:"Create a new tag",disabled:!!p||!!c,children:"+ New"}),s.jsx("button",{className:"tag-tree-action-btn",onClick:g,title:"Move a tag to a different parent",disabled:!!p||!!c||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(Q=>s.jsx(Od,{node:Q,...V},Q.tag.tag_uid)),H&&s.jsx("li",{children:s.jsx(Dd,{parentPath:null,archiveId:e,onDone:N,onCancel:b})})]})]}),p==="select-parent"&&s.jsx(cu,{title:"Create tag under…",tagNodes:t,excludeUid:null,onPick:E,onCancel:b}),c==="select-dest"&&m&&s.jsx(cu,{title:`Move "${m.tag.slug}" under…`,tagNodes:t,excludeUid:m.tag.tag_uid,onPick:k,onCancel:x})]})}const jr=[{value:0,label:"Private"},{value:2,label:"Users only"},{value:3,label:"Public"}],Cm=e=>{var t;return((t=jr.find(n=>n.value===e))==null?void 0:t.label)??String(e)};function Em({archiveId:e}){const[t,n]=f.useState([]),[r,l]=f.useState(!1),[i,a]=f.useState(null),[o,u]=f.useState(null),[c,v]=f.useState(null),[m,h]=f.useState(!1),[g,x]=f.useState(null),[w,k]=f.useState(""),[p,d]=f.useState(""),[y,j]=f.useState(2),[_,b]=f.useState(!1),[E,N]=f.useState(null),[$,P]=f.useState(""),[V,H]=f.useState(2),[Q,Y]=f.useState(!1),[oe,le]=f.useState(null),[ee,R]=f.useState(!1),[T,A]=f.useState(""),J=f.useRef(null),U=t.find(z=>z.collection_uid===o)??null,me=(U==null?void 0:U.slug)==="_default_",ue=f.useCallback(async()=>{if(e){l(!0),a(null);try{const z=await Ld(e);n(z)}catch(z){a(z.message)}finally{l(!1)}}},[e]),Re=f.useCallback(async z=>{if(!z){v(null);return}h(!0),x(null);try{const S=await Jh(e,z);v(S)}catch(S){x(S.message)}finally{h(!1)}},[e]);f.useEffect(()=>{ue()},[ue]),f.useEffect(()=>{Re(o)},[o,Re]),f.useEffect(()=>{ee&&J.current&&J.current.focus()},[ee]);async function xe(z){z.preventDefault();const S=w.trim(),O=p.trim();if(!(!S||!O)){b(!0),N(null);try{const I=await Xh(e,S,O,y);k(""),d(""),j(2),await ue(),u(I.collection_uid)}catch(I){N(I.message)}finally{b(!1)}}}async function be(){const z=T.trim();if(!z||!U){R(!1);return}try{await au(e,U.collection_uid,{name:z}),await ue(),v(S=>S&&{...S,name:z})}catch(S){a(S.message)}finally{R(!1)}}async function Ze(z){if(U)try{await au(e,U.collection_uid,{default_visibility_bits:z}),await ue(),v(S=>S&&{...S,default_visibility_bits:z})}catch(S){a(S.message)}}async function at(){if(U&&window.confirm(`Delete collection "${U.name}"? Entries will not be deleted.`))try{await em(e,U.collection_uid),u(null),v(null),await ue()}catch(z){a(z.message)}}async function Pt(z){z.preventDefault();const S=$.trim();if(!(!S||!U)){Y(!0),le(null);try{await zd(e,U.collection_uid,S,V),P(""),await Re(U.collection_uid)}catch(O){le(O.message)}finally{Y(!1)}}}async function $e(z){if(U)try{await Yh(e,U.collection_uid,z),await Re(U.collection_uid)}catch(S){x(S.message)}}async function et(z,S){if(U)try{await Gh(e,U.collection_uid,z,S),v(O=>O&&{...O,entries:O.entries.map(I=>I.entry_uid===z?{...I,collection_visibility_bits:S}:I)})}catch(O){x(O.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(z=>s.jsxs("button",{className:`coll-sidebar-row${o===z.collection_uid?" is-active":""}`,onClick:()=>u(z.collection_uid),children:[s.jsx("span",{className:"coll-row-name",children:z.name}),s.jsx("span",{className:"coll-row-meta",children:Cm(z.default_visibility_bits)})]},z.collection_uid)),t.length===0&&!r&&s.jsx("div",{className:"muted",style:{padding:"8px 12px"},children:"No collections yet."})]}),U?s.jsxs("div",{className:"coll-detail",children:[s.jsxs("div",{className:"coll-detail-header",children:[ee?s.jsx("input",{ref:J,className:"coll-rename-input",value:T,onChange:z=>A(z.target.value),onBlur:be,onKeyDown:z=>{z.key==="Enter"&&be(),z.key==="Escape"&&R(!1)}}):s.jsxs("h3",{className:`coll-detail-name${me?"":" coll-detail-name--editable"}`,title:me?void 0:"Click to rename",onClick:()=>{me||(A(U.name),R(!0))},children:[(c==null?void 0:c.name)??U.name,!me&&s.jsx("span",{className:"coll-edit-hint",children:" ✎"})]}),!me&&s.jsx("button",{className:"coll-delete-btn",onClick:at,title:"Delete collection",children:"Delete"})]}),s.jsxs("div",{className:"coll-detail-vis",children:[s.jsx("span",{className:"coll-vis-label",children:"Default visibility"}),s.jsx("select",{className:"coll-vis-select",value:(c==null?void 0:c.default_visibility_bits)??U.default_visibility_bits,onChange:z=>Ze(Number(z.target.value)),disabled:me,children:jr.map(z=>s.jsx("option",{value:z.value,children:z.label},z.value))})]}),s.jsxs("div",{className:"coll-entries-section",children:[s.jsx("div",{className:"coll-section-heading",children:"Entries"}),m&&s.jsx("div",{className:"muted",children:"Loading…"}),g&&s.jsx("div",{className:"collections-error",children:g}),!m&&c&&(c.entries.length===0?s.jsx("div",{className:"muted",children:"No entries in this collection."}):s.jsx("ul",{className:"coll-entries-list",children:c.entries.map(z=>s.jsxs("li",{className:"coll-entry-row",children:[s.jsxs("div",{className:"coll-entry-info",children:[s.jsx("span",{className:"coll-entry-title",children:z.title||z.entry_uid}),s.jsx("span",{className:"coll-entry-kind muted",children:z.source_kind})]}),s.jsxs("div",{className:"coll-entry-actions",children:[s.jsx("select",{className:"coll-entry-vis-select",value:z.collection_visibility_bits,onChange:S=>et(z.entry_uid,Number(S.target.value)),children:jr.map(S=>s.jsx("option",{value:S.value,children:S.label},S.value))}),!me&&s.jsx("button",{className:"coll-entry-remove",onClick:()=>$e(z.entry_uid),title:"Remove from collection",children:"×"})]})]},z.entry_uid))}))]}),!me&&s.jsxs("form",{className:"coll-add-entry-form",onSubmit:Pt,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:$,onChange:z=>P(z.target.value),placeholder:"entry_uid",required:!0}),s.jsx("select",{className:"coll-vis-select",value:V,onChange:z=>H(Number(z.target.value)),children:jr.map(z=>s.jsx("option",{value:z.value,children:z.label},z.value))}),s.jsx("button",{className:"coll-add-btn",type:"submit",disabled:Q,children:Q?"…":"Add"})]}),oe&&s.jsx("div",{className:"collections-error",style:{marginTop:4},children:oe})]})]}):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:xe,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:w,onChange:z=>{k(z.target.value),p||d(z.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:z=>d(z.target.value),placeholder:"my-collection",required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"coll-vis",children:"Default visibility"}),s.jsx("select",{className:"capture-input",id:"coll-vis",style:{height:42},value:y,onChange:z=>j(Number(z.target.value)),children:jr.map(z=>s.jsx("option",{value:z.value,children:z.label},z.value))})]}),E&&s.jsx("div",{className:"collections-error",children:E}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:_,children:_?"Creating…":"Create collection"})]})]})]}):s.jsx("div",{className:"view-placeholder",children:"Select an archive."})}const Tm=4;function bm({tab:e,onTabChange:t,archiveId:n}){const{currentUser:r,setCurrentUser:l}=f.useContext(_s)??{},i=r&&(r.role_bits&Tm)!==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(Pm,{currentUser:r,setCurrentUser:l}),e==="tokens"&&s.jsx(Lm,{}),e==="instance"&&i&&s.jsx(zm,{}),e==="cookies"&&i&&s.jsx($m,{}),e==="extensions"&&i&&s.jsx(Im,{}),e==="storage"&&i&&s.jsx(Rm,{archiveId:n})]})}function Pm({currentUser:e,setCurrentUser:t}){const[n,r]=f.useState((e==null?void 0:e.display_name)??""),[l,i]=f.useState(!1),[a,o]=f.useState(null),[u,c]=f.useState(""),[v,m]=f.useState(""),[h,g]=f.useState(""),[x,w]=f.useState(!1),[k,p]=f.useState(null);async function d(j){j.preventDefault(),i(!0),o(null);try{await Mh(n),t(_=>({..._,display_name:n||null})),o({ok:!0,text:"Saved."})}catch(_){o({ok:!1,text:_.message})}finally{i(!1)}}async function y(j){if(j.preventDefault(),v!==h){p({ok:!1,text:"Passwords do not match."});return}w(!0),p(null);try{await Ah(u,v),c(""),m(""),g(""),p({ok:!0,text:"Password changed."})}catch(_){p({ok:!1,text:_.message})}finally{w(!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:d,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:j=>r(j.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 j=>{const _=j.target.checked;try{await Fh({humanize_slugs:_}),t(b=>({...b,humanize_slugs:_}))}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:y,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:j=>c(j.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:v,onChange:j=>m(j.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:j=>g(j.target.value),required:!0})]}),k&&s.jsx("div",{className:`form-msg form-msg--${k.ok?"ok":"err"}`,children:k.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:x,children:x?"Changing…":"Change Password"})]})]})]})}function Lm(){const[e,t]=f.useState([]),[n,r]=f.useState(!0),[l,i]=f.useState(null),[a,o]=f.useState(""),[u,c]=f.useState(!1),[v,m]=f.useState(null),h=f.useCallback(async()=>{r(!0),i(null);try{t(await Bh())}catch(w){i(w.message)}finally{r(!1)}},[]);f.useEffect(()=>{h()},[h]);async function g(w){if(w.preventDefault(),!!a.trim()){c(!0);try{const k=await Hh(a.trim());m(k),o(""),h()}catch(k){i(k.message)}finally{c(!1)}}}async function x(w){try{await Uh(w),t(k=>k.filter(p=>p.token_uid!==w))}catch(k){i(k.message)}}return s.jsx("div",{style:{maxWidth:600},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"API Tokens"}),v&&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:v.raw_token}),s.jsx("button",{className:"token-dismiss",onClick:()=>m(null),children:"Dismiss"})]}),s.jsxs("form",{className:"token-create-row",onSubmit:g,children:[s.jsx("input",{className:"field-input field-input--flex",placeholder:"Token name",value:a,onChange:w=>o(w.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(w=>s.jsxs("div",{className:"token-row",children:[s.jsxs("div",{className:"token-row-info",children:[s.jsx("strong",{children:w.name}),s.jsxs("div",{className:"muted",children:["Created ",w.created_at.slice(0,10),w.last_used_at&&` · Last used ${w.last_used_at.slice(0,10)}`]})]}),s.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"4px 10px"},onClick:()=>x(w.token_uid),children:"Revoke"})]},w.token_uid))]})]})})}function zm(){const[e,t]=f.useState(null),[n,r]=f.useState(!0),[l,i]=f.useState(null),[a,o]=f.useState(!1),[u,c]=f.useState(null);f.useEffect(()=>{(async()=>{try{t(await Qa())}catch(m){i(m.message)}finally{r(!1)}})()},[]);async function v(m){m.preventDefault(),o(!0),c(null);try{await Dl(e),c({ok:!0,text:"Saved."})}catch(h){c({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:v,children:[[["public_index_enabled","Public index (unauthenticated browsing)"],["public_entry_content_enabled","Public entry content"],["open_registration_enabled","Open registration"]].map(([m,h])=>s.jsxs("label",{className:"checkbox-row",children:[s.jsx("input",{type:"checkbox",checked:!!e[m],onChange:g=>t(x=>({...x,[m]:g.target.checked}))}),h]},m)),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:m=>t(h=>({...h,default_entry_visibility:Number(m.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 ti(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 Rm({archiveId:e}){const[t,n]=f.useState("idle"),[r,l]=f.useState(null),[i,a]=f.useState(null),[o,u]=f.useState(null);function c(){n("idle"),l(null),a(null),u(null)}async function v(){n("scanning"),u(null),l(null);try{const g=await tm(e);l(g),n("scanned")}catch(g){u(g.message),n("error")}}async function m(){n("deleting"),u(null);try{const g=await nm(e);a(g),n("done")}catch(g){u(g.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:v,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:c,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:ti(r.total_bytes)})," recoverable."]}),s.jsxs("div",{style:{display:"flex",gap:8},children:[s.jsxs("button",{className:"btn-danger",onClick:m,children:["Delete (",ti(r.total_bytes),")"]}),s.jsx("button",{className:"btn-ghost",onClick:c,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:ti(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:c,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:c,children:"Try again"})]})]})})}function $m(){const[e,t]=f.useState(null),[n,r]=f.useState(!0),[l,i]=f.useState(null),[a,o]=f.useState("global"),[u,c]=f.useState(""),[v,m]=f.useState("{}"),[h,g]=f.useState(null),[x,w]=f.useState(!1),[k,p]=f.useState({});f.useEffect(()=>{d()},[]);async function d(){r(!0),i(null);try{t(await lm())}catch(N){i(N.message)}finally{r(!1)}}async function y(N){N.preventDefault();try{JSON.parse(v)}catch{g({ok:!1,text:'cookies must be valid JSON, e.g. {"session": "abc"}'});return}w(!0),g(null);try{await sm(a==="global"?null:u.trim(),a,v),c(""),m("{}"),o("global"),g({ok:!0,text:"Rule added."}),await d()}catch($){g({ok:!1,text:$.message})}finally{w(!1)}}async function j(N){try{await am(N),await d()}catch($){i($.message)}}function _(N){p($=>({...$,[N.rule_uid]:{cookiesInput:N.cookies_json,saving:!1,msg:null}}))}function b(N){p($=>{const P={...$};return delete P[N],P})}async function E(N){const $=k[N.rule_uid];try{JSON.parse($.cookiesInput)}catch{p(P=>({...P,[N.rule_uid]:{...P[N.rule_uid],msg:{ok:!1,text:"Invalid JSON"}}}));return}p(P=>({...P,[N.rule_uid]:{...P[N.rule_uid],saving:!0,msg:null}}));try{await im(N.rule_uid,{cookies_json:$.cookiesInput}),b(N.rule_uid),await d()}catch(P){p(V=>({...V,[N.rule_uid]:{...V[N.rule_uid],saving:!1,msg:{ok:!1,text:P.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(N=>{const $=k[N.rule_uid],P=N.url_pattern?s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"muted",children:[N.pattern_kind,":"]})," ",s.jsx("code",{children:N.url_pattern})]}):s.jsx("span",{className:"muted",children:"global (all URLs)"});return s.jsxs("tr",{children:[s.jsx("td",{children:P}),s.jsx("td",{children:$?s.jsxs(s.Fragment,{children:[s.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:12,width:"100%",minHeight:60},value:$.cookiesInput,onChange:V=>p(H=>({...H,[N.rule_uid]:{...H[N.rule_uid],cookiesInput:V.target.value}}))}),$.msg&&s.jsx("div",{className:`form-msg form-msg--${$.msg.ok?"ok":"err"}`,children:$.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:$.saving,onClick:()=>E(N),children:$.saving?"Saving…":"Save"}),s.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>b(N.rule_uid),children:"Cancel"})]})]}):s.jsx("code",{style:{fontSize:12,wordBreak:"break-all"},children:N.cookies_json})}),s.jsx("td",{children:!$&&s.jsxs("div",{style:{display:"flex",gap:6},children:[s.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>_(N),children:"Edit"}),s.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"2px 8px"},onClick:()=>j(N.rule_uid),children:"Del"})]})})]},N.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:y,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:N=>o(N.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:N=>c(N.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:v,onChange:N=>m(N.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 Im(){const[e,t]=f.useState(null),[n,r]=f.useState(!0),[l,i]=f.useState(!1),[a,o]=f.useState(null);f.useEffect(()=>{(async()=>{try{t(await Qa())}catch(k){o({ok:!1,text:k.message})}finally{r(!1)}})()},[]);async function u(k){i(!0),o(null);try{await Dl({ublock_enabled:k}),t(p=>({...p,ublock_enabled:k})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}async function c(k){i(!0),o(null);try{await Dl({cookie_ext_enabled:k}),t(p=>({...p,cookie_ext_enabled:k})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}async function v(k){i(!0),o(null);try{await Dl({modal_closer_enabled:k}),t(p=>({...p,modal_closer_enabled:k})),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 m=(e==null?void 0:e.ublock_ext_available)??!1,h=(e==null?void 0:e.ublock_enabled)??!0,g=(e==null?void 0:e.cookie_ext_available)??!1,x=(e==null?void 0:e.cookie_ext_enabled)??!0,w=(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)."}),!m&&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."}),!g&&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:()=>c(!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":w,className:`ext-toggle${w?" ext-toggle--on":""}`,onClick:()=>v(!w),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 du={0:"Private",1:"Public",2:"Users only",3:"Public"},Dm=()=>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 Om({archiveId:e,selectedEntry:t,selectedUids:n,selectedEntries:r,detail:l,onTagFilterSet:i,tagNodes:a,onTagsRefresh:o,onEntryTitleChange:u,onEntryDeleted:c,onBulkDeleted:v,humanizeTags:m,onDetailRefresh:h,onOpenPreview:g,onPlay:x}){var rl;const[w,k]=f.useState([]),[p,d]=f.useState(""),[y,j]=f.useState([]),[_,b]=f.useState(""),E=f.useRef(0),N=f.useRef(!1),[$,P]=f.useState(!1),[V,H]=f.useState(""),[Q,Y]=f.useState("idle"),[oe,le]=f.useState(""),ee=f.useRef(null),[R,T]=f.useState(!1);f.useEffect(()=>{T(!1)},[(rl=l==null?void 0:l.summary)==null?void 0:rl.entry_uid]);const A=(n==null?void 0:n.size)>=2,[J,U]=f.useState(""),[me,ue]=f.useState("idle"),[Re,xe]=f.useState(""),[be,Ze]=f.useState([]),[at,Pt]=f.useState(""),[$e,et]=f.useState("idle"),[z,S]=f.useState(""),[O,I]=f.useState("idle");f.useEffect(()=>{const D=++E.current;if(ee.current&&(clearInterval(ee.current),ee.current=null),Y("idle"),le(""),!t||!e){k([]),j([]);return}P(!1),H(""),N.current=!1,k([]),Promise.all([jl(e,t.entry_uid),Zh(e,t.entry_uid)]).then(([te,He])=>{D===E.current&&(k(te),j(He))}).catch(()=>{})},[t,e]),f.useEffect(()=>()=>{clearInterval(ee.current)},[]),f.useEffect(()=>{if(!A||!e){Ze([]);return}Ld(e).then(Ze).catch(()=>Ze([]))},[A,e]),f.useEffect(()=>{U(""),ue("idle"),xe(""),Pt(""),et("idle"),S(""),I("idle")},[n]);async function B(){const D=n.size;if(!window.confirm(`Delete ${D} entr${D===1?"y":"ies"}? This cannot be undone.`))return;I("running");const te=new Set;for(const He of n)try{await iu(e,He),te.add(He)}catch{}I("idle"),v==null||v(te)}async function W(){const D=J.trim();if(D){ue("running"),xe("");try{for(const te of n)await su(e,te,D);U(""),ue("done"),o==null||o(),setTimeout(()=>ue("idle"),1800)}catch(te){xe(te.message),ue("error")}}}async function q(){if(!at)return;et("running"),S("");const D=[];for(const te of n)try{await zd(e,at,te)}catch{D.push(te)}D.length>0?(S(`Failed for ${D.length} entr${D.length===1?"y":"ies"}.`),et("error")):(et("done"),setTimeout(()=>et("idle"),1800))}async function ce(){const D=V.trim()||null;try{await Nh(e,t.entry_uid,D),u==null||u(t.entry_uid,D)}catch{}finally{P(!1)}}async function Ce(){const D=p.trim();if(!(!D||!t))try{await su(e,t.entry_uid,D),d(""),b("");const te=await jl(e,t.entry_uid);k(te),o()}catch(te){b(te.message)}}async function Ke(D){try{await _h(e,t.entry_uid,D);const te=await jl(e,t.entry_uid);k(te),o()}catch{}}async function Ae(){if(!(!t||!e)&&window.confirm("Delete this entry? This cannot be undone."))try{await iu(e,t.entry_uid),c==null||c(t.entry_uid)}catch{}}async function Be(){if(!t||!e||Q==="running")return;const D=E.current,te=t.entry_uid;Y("running"),le("");try{const{job_uid:He}=await rm(e,te);if(E.current!==D)return;ee.current=setInterval(async()=>{try{const gt=await Pd(e,He);if(gt.status==="completed"){if(clearInterval(ee.current),ee.current=null,E.current!==D)return;Y("done");const Cn=await jl(e,te);if(E.current!==D)return;k(Cn),h==null||h()}else if(gt.status==="failed"){if(clearInterval(ee.current),ee.current=null,E.current!==D)return;Y("error"),le(gt.error_text||"Re-archive failed.")}}catch{if(clearInterval(ee.current),ee.current=null,E.current!==D)return;Y("error"),le("Network error while polling.")}},500)}catch(He){if(E.current!==D)return;Y("error"),le(He.message||"Failed to start re-archive.")}}const ge=l?[["Added",Ka(l.summary.archived_at)],["Source",l.summary.source_kind],["Type",l.summary.entity_kind],["Visibility",du[l.summary.visibility]??l.summary.visibility],["Root",l.structured_root_relpath]]:[],Sn=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),ot=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv","pdf","html","htm","jpg","jpeg","png","gif","webp","avif","svg","bmp"]),Nn=l?l.artifacts.findIndex(D=>D.artifact_role==="primary_media"):-1,_n=Nn>=0?l.artifacts[Nn]:null,tl=_n?_n.relpath.split(".").pop().toLowerCase():"",nl=_n&&Sn.has(tl),Cs=Nn>=0&&t?`/api/archives/${e}/entries/${t.entry_uid}/artifacts/${Nn}`:null,Es=l&&!nl&&(l.summary.entity_kind==="tweet"||l.summary.entity_kind==="tweet_thread"||_n&&ot.has(tl));return s.jsxs("aside",{className:"context-rail",children:[s.jsx("div",{className:"rail-eyebrow",children:"Context"}),A?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"}),Re&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:Re}),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:J,onChange:D=>U(D.target.value),onKeyDown:D=>{D.key==="Enter"&&W()}}),s.jsx("button",{className:"tag-add-btn",onClick:W,disabled:me==="running"||!J.trim(),children:me==="running"?"…":me==="done"?"✓":"Add"})]})]}),be.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:at,onChange:D=>Pt(D.target.value),children:[s.jsx("option",{value:"",children:"Pick a collection…"}),be.map(D=>s.jsx("option",{value:D.collection_uid,children:D.name},D.collection_uid))]}),s.jsx("button",{className:"tag-add-btn",onClick:q,disabled:!at||$e==="running",children:$e==="running"?"…":$e==="done"?"✓":$e==="error"?"!":"Add"})]}),z&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"6px 0 0"},children:z})]}),s.jsx("div",{className:"rail-delete-zone",children:s.jsx("button",{className:"rail-delete-btn",onClick:B,disabled:O==="running",children:O==="running"?"Deleting…":`Delete ${n.size} entr${n.size===1?"y":"ies"}`})})]}):t?l?s.jsxs(s.Fragment,{children:[$?s.jsx("input",{className:"rail-title-input",autoFocus:!0,value:V,onChange:D=>H(D.target.value),onKeyDown:D=>{D.key==="Enter"&&D.currentTarget.blur(),D.key==="Escape"&&(N.current=!0,D.currentTarget.blur())},onBlur:()=>{N.current?P(!1):ce(),N.current=!1}}):s.jsxs("h2",{className:"rail-title rail-title--editable",title:"Click to rename",onClick:()=>{H(l.summary.title??""),P(!0)},children:[kt(l.summary.title)||kt(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:Ns(l.summary.source_kind)}}),s.jsx("span",{className:"u-text",children:l.summary.original_url}),s.jsx("span",{className:"ext",children:s.jsx(Dm,{})})]}),nl&&x&&s.jsx("button",{className:"rail-preview-btn",onClick:()=>x(Cs,t),children:"▶ Play"}),Es&&g&&s.jsx("button",{className:"rail-preview-btn",onClick:g,children:"Preview"}),s.jsx("div",{className:"meta-list",children:ge.filter(([,D])=>D!=null&&D!=="").map(([D,te])=>s.jsxs("div",{className:"meta-item",children:[s.jsx("span",{className:"meta-k",children:D}),s.jsx("span",{className:`meta-v${D==="Root"?" mono":""}`,children:kt(te)})]},D))}),l.artifacts.length>0&&(()=>{const D=l.artifacts.map((je,sr)=>({...je,_idx:sr})),te=D.filter(je=>je.artifact_role==="font"),He=D.filter(je=>je.artifact_role!=="font"),gt=te.reduce((je,sr)=>je+(sr.byte_size||0),0),Cn=l.summary.entry_uid,ll=je=>s.jsx("li",{children:s.jsxs("a",{href:`/api/archives/${e}/entries/${Cn}/artifacts/${je._idx}`,target:"_blank",rel:"noopener noreferrer",className:"artifact-link",children:[s.jsx("span",{className:"artifact-name",children:je.artifact_role==="font"?je.relpath.split("/").pop():je.artifact_role.replace(/_/g," ")}),s.jsx("span",{className:"artifact-size",children:je.byte_size!=null?Xr(je.byte_size):"—"})]})},je._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:[He.map(ll),te.length>0&&s.jsxs("li",{className:"artifact-group",children:[s.jsxs("button",{type:"button",className:"artifact-group-header artifact-link","aria-expanded":R,onClick:()=>T(je=>!je),children:[s.jsxs("span",{className:"artifact-name",children:[s.jsx("span",{"aria-hidden":"true",className:`artifact-group-chevron${R?" open":""}`,children:"›"}),` fonts (${te.length})`]}),s.jsx("span",{className:"artifact-size",children:Xr(gt)})]}),R&&s.jsx("ul",{className:"artifact-list artifact-group-body",children:te.map(ll)})]})]})]})})()]}):s.jsx("p",{className:"tags-empty",children:"Loading\\u2026"}):s.jsx("p",{className:"tags-empty",children:"Select an entry."}),t&&!A&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Tags"}),w.length===0?s.jsx("p",{className:"tags-empty",children:"No tags yet."}):s.jsx("div",{className:"tags-wrap",children:w.map(D=>s.jsxs("span",{className:"tag-pill",title:D.full_path,children:[m?$d(D.full_path):D.full_path,s.jsx("button",{className:"remove",title:`Remove tag ${D.full_path}`,onClick:()=>Ke(D.tag_uid),children:"×"})]},D.tag_uid))}),_&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:_}),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:p,onChange:D=>d(D.target.value),onKeyDown:D=>{D.key==="Enter"&&Ce()}}),s.jsx("button",{className:"tag-add-btn",onClick:Ce,children:"Add"})]})]}),y.length>0&&s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Collections"}),y.map(D=>s.jsxs("div",{className:"coll-row",children:[s.jsx("span",{className:"coll-name",children:D.collection_uid}),s.jsx("span",{className:"vis-badge",children:du[D.visibility_bits]??`bits:${D.visibility_bits}`})]},D.collection_uid))]}),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:Be,disabled:Q==="running",children:Q==="running"?"Re-archiving…":"Re-archive"}),Q==="done"&&s.jsx("p",{className:"form-msg form-msg--ok",style:{marginTop:"6px"},children:"Re-archived successfully."}),Q==="error"&&s.jsx("p",{className:"form-msg form-msg--err",style:{marginTop:"6px"},children:oe})]}),s.jsx("div",{className:"rail-delete-zone",children:s.jsx("button",{className:"rail-delete-btn",onClick:Ae,children:"Delete entry"})})]})]})}function Mm({src:e}){const t=f.useRef(null);return f.useEffect(()=>{t.current&&t.current.load()},[e]),s.jsx("div",{className:"preview-video-wrap",style:{background:"#111",display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",minHeight:"240px"},children:e?s.jsxs("video",{ref:t,controls:!0,autoPlay:!1,style:{width:"100%",maxHeight:"100%",display:"block"},children:[s.jsx("source",{src:e}),"Your browser does not support the video element."]}):s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No video available"})})}function fu({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 Fm({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 Md(e){return e?new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(new Date(e*1e3)):""}function pu(e){return!e||!e.includes("&")?e:e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/'/g,"'")}const X={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"}},Se={bg:"#000000",border:"#2f3336",text:"#e7e9ea",dim:"#71767b",accent:"#1d9bf0",codeBg:"#16181c"},ni={article:{background:Se.bg,color:Se.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:Se.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:Se.border,flexShrink:0},aAuthorName:{fontSize:"15px",fontWeight:"700",color:Se.text,lineHeight:"1.3"},aAuthorSub:{fontSize:"15px",color:Se.dim,lineHeight:"1.3"},aDivider:{border:"none",borderTop:`1px solid ${Se.border}`,margin:"0"},aBody:{padding:"4px 16px 0"},bH1:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:Se.text,lineHeight:"36px",margin:"24px 0 10px"},bH2:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:Se.text,lineHeight:"36px",margin:"24px 0 10px"},bP:{fontSize:"17px",color:Se.text,lineHeight:"1.5",marginBottom:"16px",marginTop:"0"},bSpacer:{height:"6px",display:"block"},bQuote:{borderLeft:`3px solid ${Se.border}`,padding:"2px 14px",margin:"14px 0",color:Se.dim,fontSize:"17px",lineHeight:"1.5"},bHr:{border:"none",borderTop:`1px solid ${Se.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:Se.text,lineHeight:"1.5",marginBottom:"6px"},bTweet:{display:"flex",alignItems:"center",gap:"12px",border:`1px solid ${Se.border}`,borderRadius:"12px",padding:"14px 16px",margin:"14px 0",color:Se.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:Se.text,background:"transparent"},iCode:{fontFamily:"ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace",fontSize:"0.875em",background:Se.codeBg,padding:"2px 6px",borderRadius:"4px",color:"#e6edf3"},link:{color:Se.accent,textDecoration:"none"}};function Am(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 qn(e,t,n){return e&&n[e]?n[e]:t||null}function Fd(){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 qa(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 Ad(e,t){const n=e.expanded_url||e.url||e.text||"",r=e.display_url||e.expanded_url||e.url||e.text||"",l=qa(e,t,e.url,e.text,e.display_url,e.expanded_url);return!l||!n?null:{...l,kind:"url",href:n,display:r}}function Bd(e,t){const n=e.screen_name||e.name||e.text||"",r=n?`@${n}`:null,l=qa(e,t,r);return!l||!n?null:{...l,kind:"mention",screen_name:n}}const hu=/https?:\/\/[^\s<>"'\])]+/g,Bm=/[.,;:!?)()]+$/;function as(e,t){const n=[];let r=0,l;for(hu.lastIndex=0;(l=hu.exec(e))!==null;){l.index>r&&n.push(e.slice(r,l.index));let i=l[0].replace(Bm,"");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:(rAd(o,e)).filter(Boolean),...(t.user_mentions||[]).map(o=>Bd(o,e)).filter(Boolean)];if(r.length===0&&n.length===0)return as(pu(e),X.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(([c,v])=>c<=o&&v>=u),a=[...l].sort((o,u)=>o-u);return a.slice(0,-1).map((o,u)=>{const c=a[u+1];if(i(o,c))return null;const v=e.slice(o,c),m=r.filter(x=>x.s<=o&&x.e>=c),h=m.find(x=>x.kind==="url");if(h)return s.jsx("a",{href:h.href,target:"_blank",rel:"noopener noreferrer",style:X.link,children:h.display||v},u);const g=m.find(x=>x.kind==="mention");return g?s.jsx("a",{href:`https://x.com/${g.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:X.link,children:v},u):s.jsx("span",{children:as(pu(v),X.link)},u)}).filter(o=>o!==null)}function Um(e,t,n,r,l=X){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 c=Ad(u,e);c&&i.push(c)}for(const u of r){const c=Bd(u,e);c&&i.push(c)}if(i.length===0)return as(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,c)=>u-c);return o.slice(0,-1).map((u,c)=>{const v=o[c+1],m=i.filter(k=>k.s<=u&&k.e>=v),h=e.slice(u,v);let g;if(h.includes(` `)){const k=h.split(` -`);g=k.flatMap((p,d)=>dk.kind==="style"&&k.style==="Code")&&(g=s.jsx("code",{style:l.iCode,children:g})),m.some(k=>k.kind==="style"&&k.style==="Bold")&&(g=s.jsx("strong",{children:g})),m.some(k=>k.kind==="style"&&k.style==="Italic")&&(g=s.jsx("em",{children:g})),m.some(k=>k.kind==="style"&&k.style==="Underline")&&(g=s.jsx("u",{children:g})),m.some(k=>k.kind==="style"&&k.style==="Strikethrough")&&(g=s.jsx("s",{children:g}));const x=m.find(k=>k.kind==="url");if(x){const k=/^https?:\/\/t\.co\//i.test(g);g=s.jsx("a",{href:x.href,target:"_blank",rel:"noopener noreferrer",style:l.link,children:k?x.display:g})}const w=m.find(k=>k.kind==="mention");return w&&(g=s.jsx("a",{href:`https://x.com/${w.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:l.link,children:g})),s.jsx("span",{children:typeof g=="string"?as(g,l.link):g},c)})}function Wm(e,t,n){const r=(n==null?void 0:n.st)||X,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=Kn(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:c=>{var v;!c.metaKey&&!c.ctrlKey&&(c.preventDefault(),(v=n==null?void 0:n.onImgClick)==null||v.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(Fd,{}),"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 ri(e,t,n,r){const l=(r==null?void 0:r.st)||X,i=e.type||"",a=e.text||"",o=e.inline_style_ranges||[],u=e.data||{},c=Um(a,o,u.urls||[],u.mentions||[],l);switch(i){case"header-one":return s.jsx("h1",{style:l.bH1,children:c},t);case"header-two":{const v=a.match(/(?:x\.com|twitter\.com)\/i\/status\/(\d+)/);return v?s.jsxs("a",{href:`https://x.com/i/status/${v[1]}`,target:"_blank",rel:"noopener noreferrer",style:l.bTweet,children:[s.jsx(Fd,{}),"View post on X"]},t):s.jsx("h2",{style:l.bH2,children:c},t)}case"unstyled":return a.trim()?s.jsx("p",{style:l.bP,children:c},t):s.jsx("span",{style:l.bSpacer},t);case"blockquote":return s.jsx("blockquote",{style:l.bQuote,children:c},t);case"unordered-list-item":case"ordered-list-item":return s.jsx("li",{style:l.bLi,children:c},t);case"atomic":return s.jsx("span",{children:Wm(e,n,r)},t);default:return a?s.jsx("p",{style:l.bP,children:c},t):null}}function Vm(e,t,n){const r=(n==null?void 0:n.st)||X,l=[];let i=0;for(;i{r&&(l==null||l(!0))},[r,l]);const o=r?ni:X,u=e.cover_media||{},c=e.author||t||{},v=e.first_published_at_secs?Md(e.first_published_at_secs):"",h=[c.screen_name?`@${c.screen_name}`:"",v].filter(Boolean).join(" · "),g=Kn(u.local_path,u.url,n),x=Kn(c.avatar_local_path,c.avatar_url,n),w=s.jsxs(s.Fragment,{children:[i&&s.jsx(Hd,{items:[{src:i,alt:""}],startIndex:0,onClose:()=>a(null)}),g&&s.jsx("a",{href:g,target:"_blank",rel:"noopener noreferrer",style:{display:"block",cursor:"zoom-in"},onClick:k=>{!k.metaKey&&!k.ctrlKey&&(k.preventDefault(),a(g))},children:s.jsx("img",{src:g,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:c.name||""}):s.jsx("div",{style:o.aAvatarPh}),s.jsxs("div",{children:[s.jsx("div",{style:o.aAuthorName,children:c.name||c.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:Vm(e.blocks||[],n,{onImgClick:a,st:o})})]});return r?s.jsx("div",{style:ni.article,children:s.jsx("div",{style:ni.articleInner,children:w})}):s.jsx("div",{style:X.article,children:w})}function Km({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:X.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 Hd({items:e,startIndex:t,onClose:n}){const[r,l]=f.useState(t);f.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:X.lightboxBackdrop,onClick:n,children:s.jsxs("div",{style:X.lightboxContent,onClick:a=>a.stopPropagation(),children:[s.jsxs("div",{style:X.lightboxToolbar,children:[e.length>1&&s.jsxs("span",{style:X.lightboxCounter,children:[r+1," / ",e.length]}),s.jsx("a",{href:i.src,target:"_blank",rel:"noopener noreferrer",style:X.lightboxLink,title:"Open in new tab",children:"↗"}),s.jsx("button",{style:X.lightboxBtn,onClick:n,"aria-label":"Close",children:"×"})]}),s.jsx("img",{src:i.src,alt:i.alt||"",style:X.lightboxImg}),e.length>1&&s.jsxs("div",{style:X.lightboxNav,children:[s.jsx("button",{style:X.lightboxNavBtn,onClick:()=>l(a=>Math.max(a-1,0)),disabled:r===0,children:"‹"}),s.jsx("button",{style:X.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 d,y;const[l,i]=f.useState(null),a=e.author||{},o=e.created_at_secs?Md(e.created_at_secs):"",u=e.entities||{},c=Kn(a.avatar_local_path,a.avatar_url,r),v=t&&!n,m=e.is_quote_status===!0,h=t?X.tweetRowThread:X.tweetRow,g=e.full_text||"",x=((y=(d=e.extended_entities)==null?void 0:d.media)!=null&&y.length?e.extended_entities.media:u.media)||[],w=[],k=[];for(const j of x)if(j.type==="photo"){const _=Kn(j.local_path,j.media_url_https,r);_&&w.push({kind:"photo",src:_,alt:j.alt_text||""})}else if(j.type==="video"||j.type==="animated_gif"){const _=j.local_path&&r[j.local_path]||(()=>{var E,N;return(N=(((E=j.video_info)==null?void 0:E.variants)||[]).filter($=>$.content_type==="video/mp4").sort(($,P)=>(P.bitrate||0)-($.bitrate||0))[0])==null?void 0:N.url})();_&&k.push({kind:j.type==="animated_gif"?"gif":"video",src:_})}const p=[];for(const j of x){if(!j.url||!(j.type==="photo"?w.some(E=>E.src===Kn(j.local_path,j.media_url_https,r)):k.length>0))continue;const b=qa(j,g,j.url);b&&p.push([b.s,b.e])}return s.jsxs(s.Fragment,{children:[l!==null&&s.jsx(Hd,{items:w,startIndex:l,onClose:()=>i(null)}),s.jsxs("div",{style:h,children:[s.jsxs("div",{style:X.leftCol,children:[c?s.jsx("img",{src:c,style:X.avatar,alt:a.name||""}):s.jsx("div",{style:X.avatarPh}),v&&s.jsx("div",{style:X.threadLine})]}),s.jsxs("div",{style:X.rightCol,children:[s.jsxs("div",{style:X.authorRow,children:[s.jsx("span",{style:X.authorName,children:a.name||a.screen_name||"Unknown"}),a.screen_name&&s.jsxs("span",{style:X.authorHandle,children:["@",a.screen_name]}),o&&s.jsxs("span",{style:X.datePart,children:["· ",o]}),m&&s.jsx("span",{style:X.qtBadge,title:"Quote tweet",children:"↻ QT"})]}),s.jsx("div",{style:X.tweetText,children:Hm(g,u,p)}),w.length>0&&s.jsx("div",{style:X.mediaGrid,children:s.jsx(Km,{photos:w,onOpen:j=>i(j)})}),k.map((j,_)=>s.jsx("div",{style:X.mediaGrid,children:s.jsx("video",{src:j.src,style:X.mediaVideo,controls:!0,loop:j.kind==="gif",muted:j.kind==="gif",autoPlay:j.kind==="gif"})},_)),(e.retweet_count>0||e.favorite_count>0)&&s.jsxs("div",{style:X.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 qm({archiveId:e,entryUid:t,artifacts:n,entityKind:r,fullPage:l,onXArticle:i}){const[a,o]=f.useState(!0),[u,c]=f.useState(null),[v,m]=f.useState([]);if(f.useEffect(()=>{if(o(!0),c(null),m([]),!n||!e||!t){o(!1);return}const x=n.map((k,p)=>({...k,index:p})).filter(k=>k.artifact_role==="raw_tweet_json");if(x.length===0){c("No tweet data found."),o(!1);return}let w=!1;return jh(e,t,x.map(k=>k.index)).then(async k=>{if(w)return;const p=/https?:\/\/t\.co\/[A-Za-z0-9]+/g,d=E=>{var $;const N=E.full_text||"";return((($=E.entities)==null?void 0:$.urls)||[]).map(P=>{var V;if(P.fromIndex!=null&&P.toIndex!=null)return[P.fromIndex,P.toIndex];if(((V=P.indices)==null?void 0:V.length)===2)return[P.indices[0],P.indices[1]];if(P.url){const H=N.indexOf(P.url);if(H!==-1)return[H,H+P.url.length]}return null}).filter(Boolean)},y=(E,N,$)=>E.some(([P,V])=>P<=N&&V>=$),j=new Set;for(const E of k){const N=E.full_text||"",$=d(E);let P;for(p.lastIndex=0;(P=p.exec(N))!==null;)y($,P.index,P.index+P[0].length)||j.add(P[0])}const _=j.size>0?await Sh([...j]).catch(()=>({})):{},b=k.map(E=>{var H;const N=E.full_text||"",$=d(E),P=[];let V;for(p.lastIndex=0;(V=p.exec(N))!==null;){const Q=V[0],Y=_[Q];Y&&Y!==Q&&!y($,V.index,V.index+Q.length)&&P.push({url:Q,expanded_url:Y,display_url:(()=>{try{const oe=new URL(Y);return oe.hostname+(oe.pathname.length>1?"/…":"")}catch{return Y}})(),fromIndex:V.index,toIndex:V.index+Q.length})}return P.length===0?E:{...E,entities:{...E.entities||{},urls:[...((H=E.entities)==null?void 0:H.urls)||[],...P]}}});w||m(b)}).catch(k=>{w||c(k.message||"Failed to load tweet.")}).finally(()=>{w||o(!1)}),()=>{w=!0}},[e,t,n]),a)return s.jsx("div",{style:X.loading,children:"Loading…"});if(u)return s.jsxs("div",{style:X.error,children:["Error: ",u]});if(v.length===0)return null;const h=Am(e,t,n);if(r==="tweet_thread")return s.jsx("div",{style:X.threadOuter,children:v.map((x,w)=>s.jsx(mu,{tweet:x,isInThread:!0,isLast:w===v.length-1,artifactMap:h},x.id||w))});const g=v[0];return g.is_article&&g.article?s.jsx(Qm,{article:g.article,tweetAuthor:g.author,artifactMap:h,fullPage:l,onXArticle:i}):s.jsx("div",{style:X.card,children:s.jsx(mu,{tweet:g,isInThread:!1,isLast:!0,artifactMap:h})})}const Xm=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv"]),Jm=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),Ym=new Set(["jpg","jpeg","png","gif","webp","avif","svg","bmp"]);function Ud({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 g=s.jsx(qm,{archiveId:e,entryUid:o,artifacts:a,entityKind:u,fullPage:r,onXArticle:l});return r?g:s.jsx("div",{className:"preview-tweet-wrap",children:g})}const c=a.findIndex(g=>g.artifact_role==="primary_media");if(c===-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((g,x)=>s.jsxs("li",{children:[g.artifact_role,": ",g.relpath]},x))})]});const v=a[c],m=`/api/archives/${e}/entries/${o}/artifacts/${c}`,h=v.relpath.split(".").pop().toLowerCase();return Xm.has(h)?s.jsx("div",{className:"preview-panel",children:s.jsx(Mm,{src:m})}):Jm.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:m,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(fu,{src:m,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(fu,{src:m,type:"page",title:i.title,originalUrl:i.original_url})}):Ym.has(h)?s.jsx("div",{className:"preview-panel",style:{height:"100%"},children:s.jsx(Fm,{src:m,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((g,x)=>s.jsxs("li",{children:[g.artifact_role,": ",g.relpath]},x))})]})}function Gm({archiveId:e,entry:t,detail:n,onClose:r}){var l,i;return f.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(Ud,{archiveId:e,entry:t,detail:n})})]})})}function gu(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 Zm({entry:e,src:t,archiveId:n,onClose:r}){const l=f.useRef(null),[i,a]=f.useState(!1),[o,u]=f.useState(0),[c,v]=f.useState(NaN),[m,h]=f.useState(1);f.useEffect(()=>{!l.current||!t||(l.current.load(),u(0),v(NaN),a(!1))},[t]),f.useEffect(()=>{l.current&&(l.current.volume=m)},[m]);function g(){const d=l.current;d&&(i?d.pause():d.play().catch(()=>{}))}function x(d){const y=l.current;if(!y||!isFinite(c))return;const j=Number(d.target.value);y.currentTime=j,u(j)}function w(d){h(Number(d.target.value))}const k=(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 d;return u(((d=l.current)==null?void 0:d.currentTime)??0)},onLoadedMetadata:()=>{var d;return v(((d=l.current)==null?void 0:d.duration)??NaN)},onDurationChange:()=>{var d;return v(((d=l.current)==null?void 0:d.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:Ns(p)}}),s.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.85rem",color:"var(--ink)"},title:k,children:k})]}),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:g,"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:gu(o)}),s.jsx("input",{type:"range",min:0,max:isFinite(c)?c: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:gu(c)})]}),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:m,onChange:w,"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 eg({archiveId:e,entryUid:t}){var h,g;const[n,r]=f.useState(null),[l,i]=f.useState(!0),[a,o]=f.useState(null),[u,c]=f.useState(!1);f.useEffect(()=>{if(!u)return;const x=document.documentElement,w=document.body,k=x.style.colorScheme,p=w.style.background;return x.style.colorScheme="dark",w.style.background="#000",()=>{x.style.colorScheme=k,w.style.background=p}},[u]),f.useEffect(()=>{c(!1),Ji(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 v=((h=n==null?void 0:n.summary)==null?void 0:h.title)||t,m=(g=n==null?void 0:n.summary)==null?void 0:g.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:v}),m&&s.jsx("a",{href:m,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(Ud,{archiveId:e,entry:n.summary,detail:n,fullPage:!0,onXArticle:c})]})]})}const tg=7e3;function ng({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(lg,{toast:r,onDismiss:t,onIgnoreUblock:n},r.id))}):null}function rg(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 lg({toast:e,onDismiss:t,onIgnoreUblock:n}){const[r,l]=f.useState(!1),i=e.type==="warning",a=e.type==="success";f.useEffect(()=>{if(r)return;const u=setTimeout(()=>t(e.id),tg);return()=>clearTimeout(u)},[r,e.id,t]);const o=rg(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 _s=f.createContext(null),gr=(()=>{const e=window.location.pathname.match(/^\/preview\/([^/]+)\/([^/]+)/);return e?{archiveId:e[1],entryUid:e[2]}:null})(),sg=["archive","tags","collections","runs","admin","settings"],ig=["profile","tokens","instance","cookies","extensions","storage"];function on(){const e=window.location.pathname.split("/").filter(Boolean),t=sg.includes(e[0])?e[0]:"archive",n=t==="settings"&&ig.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;return{view:t,settingsTab:n,q:l,tag:i,entry:a}}function ag(e,t){return e==="archive"?"/":e==="settings"?`/settings/${t}`:`/${e}`}function og(){const[e,t]=f.useState("loading"),[n,r]=f.useState(null);f.useEffect(()=>{(async()=>{if(await Rh()){t("setup");return}const M=await Oh();if(!M){t("login");return}r(M),t("authenticated")})()},[]),f.useEffect(()=>{const C=()=>{r(null),t("login")};return window.addEventListener("auth:expired",C),()=>window.removeEventListener("auth:expired",C)},[]),f.useEffect(()=>{const C=()=>{const{view:M,settingsTab:K,q:ne,tag:Ie,entry:ut}=on();y(M),_(K),E(ne),p(Ie),m(ut),g(null),w(ut?new Set([ut]):new Set)};return window.addEventListener("popstate",C),()=>window.removeEventListener("popstate",C)},[]);const[l,i]=f.useState([]),[a,o]=f.useState(null),[u,c]=f.useState([]),[v,m]=f.useState(()=>on().entry),[h,g]=f.useState(null),[x,w]=f.useState(()=>{const C=on().entry;return C?new Set([C]):new Set}),[k,p]=f.useState(()=>on().tag),[d,y]=f.useState(()=>on().view),[j,_]=f.useState(()=>on().settingsTab),[b,E]=f.useState(()=>on().q),[N,$]=f.useState(""),[P,V]=f.useState(!1),[H,Q]=f.useState([]),[Y,oe]=f.useState([]),[le,ee]=f.useState(()=>sessionStorage.getItem("captureDialogOpen")==="true"),[R,T]=f.useState([]),A=f.useRef(0),[J,U]=f.useState(()=>{try{const C=JSON.parse(sessionStorage.getItem("pendingCaptures")||"[]");if(Array.isArray(C))return C}catch{}return[]});f.useEffect(()=>{sessionStorage.setItem("pendingCaptures",JSON.stringify(J))},[J]);const[me,ue]=f.useState(()=>sessionStorage.getItem("ublockWarningIgnored")==="true"),[Re,xe]=f.useState(null),be=f.useRef(0),Ze=f.useRef(null),at=f.useRef(!1),Pt=f.useRef(!0),$e=f.useRef(null),et=(n==null?void 0:n.humanize_slugs)??!1;f.useEffect(()=>{const C=++be.current;xe(null),!(!h||!a)&&Ji(a,h.entry_uid).then(M=>{C===be.current&&xe(M)}).catch(()=>{})},[h,a]),f.useEffect(()=>{sessionStorage.setItem("captureDialogOpen",le)},[le]);const z=f.useCallback(async(C,M,K)=>{if(C){V(!0);try{let ne;M||K?ne=await wh(C,M,K):ne=await xh(C),c(ne),w(Ie=>{if(Ie.size<2)return Ie;const ut=new Set(ne.map(En=>En.entry_uid)),sr=new Set([...Ie].filter(En=>ut.has(En)));return sr.size===Ie.size?Ie:sr}),$(ne.length===0?"No results":`${ne.length} result${ne.length===1?"":"s"}`)}catch{c([]),$("Search failed. Try again.")}finally{V(!1)}}},[]);f.useEffect(()=>{e==="authenticated"&&vh().then(C=>{if(i(C),C.length>0){const M=C[0].id;o(M)}})},[e]),f.useEffect(()=>{if(a){if(Pt.current){Pt.current=!1,Promise.all([ei(a).then(Q),jl(a).then(oe)]);return}p(null),g(null),m(null),w(new Set),Promise.all([z(a,"",null),ei(a).then(Q),jl(a).then(oe)])}},[a]),f.useEffect(()=>{if(a===null)return;const C=setTimeout(()=>{z(a,b,k)},300);return()=>clearTimeout(C)},[b,a]),f.useEffect(()=>{a!==null&&(k!==null&&y("archive"),z(a,b,k))},[k,a]);const S=f.useCallback(C=>{o(C)},[]),O=f.useCallback(C=>{y(C),C==="tags"&&a&&jl(a).then(oe)},[a]);f.useEffect(()=>{if(gr)return;const C=ag(d,j);window.location.pathname!==C&&history.pushState(null,"",C+window.location.search)},[d,j]);const I=f.useCallback(C=>{m(C?C.entry_uid:null),g(C)},[]),B=f.useCallback((C,M)=>{if(M.shiftKey&&$e.current!==null){M.preventDefault();const K=u.findIndex(ir=>ir.entry_uid===$e.current),ne=u.findIndex(ir=>ir.entry_uid===C.entry_uid);if(K===-1||ne===-1){$e.current=C.entry_uid,w(new Set([C.entry_uid])),I(C);return}const Ie=Math.min(K,ne),ut=Math.max(K,ne),sr=u.slice(Ie,ut+1),En=new Set(sr.map(ir=>ir.entry_uid));w(En),En.size===1&&I(sr[0])}else M.ctrlKey||M.metaKey?($e.current=C.entry_uid,w(K=>{const ne=new Set(K);return ne.has(C.entry_uid)?ne.delete(C.entry_uid):ne.add(C.entry_uid),ne})):($e.current=C.entry_uid,w(new Set([C.entry_uid])),I(C))},[u,I]),W=f.useCallback(C=>{p(C)},[]),q=f.useCallback(()=>{p(null)},[]),ce=f.useCallback(()=>{a&&jl(a).then(oe)},[a]),Ce=f.useCallback((C,M)=>{k===C?p(M):k!=null&&k.startsWith(C+"/")&&p(M+k.slice(C.length))},[k]),Ke=f.useCallback(C=>{(k===C||k!=null&&k.startsWith(C+"/"))&&p(null)},[k]),Ae=f.useCallback((C,M)=>{c(K=>K.map(ne=>ne.entry_uid===C?{...ne,title:M}:ne)),g(K=>K&&K.entry_uid===C?{...K,title:M}:K),xe(K=>K&&K.summary.entry_uid===C?{...K,summary:{...K.summary,title:M}}:K)},[]),Be=f.useCallback(()=>{if(!a||!h)return;const C=++be.current;Ji(a,h.entry_uid).then(M=>{C===be.current&&xe(M)}).catch(()=>{})},[a,h]),ge=f.useCallback(C=>{c(M=>M.filter(K=>K.entry_uid!==C)),g(M=>(M==null?void 0:M.entry_uid)===C?null:M),m(M=>M===C?null:M),w(M=>{const K=new Set(M);return K.delete(C),K})},[]),Sn=f.useCallback(C=>{c(M=>M.filter(K=>!C.has(K.entry_uid))),w(new Set),g(null),m(null)},[]);f.useEffect(()=>{if(x.size>=2)m(null),g(null);else if(x.size===1){const[C]=x;m(C)}else m(null),g(null)},[x]);const ot=f.useMemo(()=>u.filter(C=>x.has(C.entry_uid)),[u,x]);f.useEffect(()=>{if(!v||h)return;const C=u.find(M=>M.entry_uid===v);C&&g(C)},[u,v,h]),f.useEffect(()=>{if(gr)return;const C=new URLSearchParams;b&&C.set("q",b),d==="archive"&&k&&C.set("tag",k),d==="archive"&&v&&C.set("entry",v);const M=C.toString(),K=window.location.pathname+(M?"?"+M:"");window.location.pathname+window.location.search!==K&&history.replaceState(null,"",K)},[b,k,v,d]),f.useEffect(()=>{const C=M=>{var K,ne;(M.metaKey||M.ctrlKey)&&M.key==="k"&&(M.preventDefault(),d==="archive"?((K=Ze.current)==null||K.focus(),(ne=Ze.current)==null||ne.select()):(at.current=!0,y("archive")))};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[d]),f.useEffect(()=>{d==="archive"&&at.current&&(at.current=!1,requestAnimationFrame(()=>{var C,M;(C=Ze.current)==null||C.focus(),(M=Ze.current)==null||M.select()}))},[d]);const Nn=f.useCallback(()=>{ee(!0)},[]),_n=f.useCallback(()=>{ee(!1)},[]),el=f.useCallback(()=>{if(a)return Promise.allSettled([z(a,b,k),ei(a).then(Q)])},[a,b,k,z]),tl=f.useCallback((C,M,K="error",ne=null)=>{if(K==="warning"&&me&&M)return;const Ie=++A.current;T(ut=>[...ut,{id:Ie,text:C,locator:M,type:K,headline:ne}])},[me]),Cs=f.useCallback(C=>{T(M=>M.filter(K=>K.id!==C))},[]),Es=f.useCallback(()=>{sessionStorage.setItem("ublockWarningIgnored","true"),ue(!0),T(C=>C.filter(M=>!(M.type==="warning"&&M.locator)))},[]),nl=f.useCallback(C=>{U(M=>[...M,C])},[]),D=f.useCallback(C=>{U(M=>M.filter(K=>K.id!==C))},[]),[te,He]=f.useState(null),[gt,Cn]=f.useState(null),rl=f.useCallback(()=>{h&&He(h.entry_uid)},[h]),je=f.useCallback(()=>He(null),[]),lr=f.useCallback((C,M)=>{Cn({src:C,entry:M})},[]),Wd=f.useCallback(()=>Cn(null),[]);return f.useEffect(()=>{He(null)},[h]),f.useEffect(()=>{const C=M=>{var ne,Ie,ut;if(M.key!=="Escape"||le||te)return;const K=(ne=document.activeElement)==null?void 0:ne.tagName;K==="INPUT"||K==="TEXTAREA"||K==="SELECT"||x.size>0&&(M.preventDefault(),w(new Set),(ut=(Ie=document.activeElement)==null?void 0:Ie.blur)==null||ut.call(Ie))};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[le,te,x]),f.useEffect(()=>(document.body.classList.toggle("has-audio-bar",!!gt),()=>document.body.classList.remove("has-audio-bar")),[gt]),e==="loading"?s.jsx("div",{className:"auth-loading",children:"Loading\\u2026"}):e==="setup"?s.jsx(cm,{onComplete:()=>t("login")}):e==="login"?s.jsx(um,{onLogin:C=>{r(C),t("authenticated")}}):gr?s.jsx(eg,{archiveId:gr.archiveId,entryUid:gr.entryUid}):s.jsx(_s.Provider,{value:{currentUser:n,setCurrentUser:r},children:s.jsxs(s.Fragment,{children:[s.jsx(dm,{archives:l,archiveId:a,onArchiveChange:S,view:d,onViewChange:O,onCaptureClick:Nn}),s.jsxs("main",{className:"app-shell",children:[s.jsxs("div",{className:"workspace",children:[d==="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:Ze,className:"search-input",type:"search","aria-label":"Search archive","aria-busy":P,placeholder:"Search titles, URLs, types, tags…",value:b,onChange:C=>E(C.target.value)}),s.jsx("span",{className:"kbd",children:"⌘K"})]}),s.jsxs("span",{className:"result-count",children:[N&&s.jsxs(s.Fragment,{children:[s.jsx("b",{children:N.split(" ")[0]})," ",N.split(" ").slice(1).join(" ")]}),k&&s.jsxs("button",{className:"tag-filter-badge",onClick:q,children:["× ",et?$d(k):k]})]})]}),d==="archive"&&s.jsx(xm,{entries:u,selectedUids:x,onRowClick:B,archiveId:a,pendingCaptures:J}),d==="runs"&&s.jsx(jm,{runs:H}),d==="admin"&&s.jsx(Nm,{archives:l}),d==="tags"&&s.jsx(_m,{archiveId:a,tagNodes:Y,tagFilter:k,onTagFilterSet:W,onViewChange:O,onTagRenamed:Ce,onTagDeleted:Ke,onTagsRefresh:ce,humanizeTags:et}),d==="collections"&&s.jsx(Em,{archiveId:a}),d==="settings"&&s.jsx(bm,{tab:j,onTabChange:_,archiveId:a})]}),s.jsx(Om,{archiveId:a,selectedEntry:h,selectedUids:x,selectedEntries:ot,detail:Re,onTagFilterSet:W,tagNodes:Y,onTagsRefresh:ce,onEntryTitleChange:Ae,onEntryDeleted:ge,onBulkDeleted:Sn,humanizeTags:et,onDetailRefresh:Be,onOpenPreview:rl,onPlay:lr})]}),te&&h&&h.entry_uid===te&&s.jsx(Gm,{archiveId:a,entry:h,detail:Re,onClose:je}),gt&&s.jsx(Zm,{entry:gt.entry,src:gt.src,archiveId:a,onClose:Wd}),s.jsx(pm,{open:le,archiveId:a,onClose:_n,onCaptured:el,onToast:tl,activeJobs:J,onJobStarted:nl,onJobSettled:D}),s.jsx(ng,{toasts:R,onDismiss:Cs,onIgnoreUblock:Es})]})})}bd(document.getElementById("root")).render(s.jsx(f.StrictMode,{children:s.jsx(og,{})})); +`);g=k.flatMap((p,d)=>dk.kind==="style"&&k.style==="Code")&&(g=s.jsx("code",{style:l.iCode,children:g})),m.some(k=>k.kind==="style"&&k.style==="Bold")&&(g=s.jsx("strong",{children:g})),m.some(k=>k.kind==="style"&&k.style==="Italic")&&(g=s.jsx("em",{children:g})),m.some(k=>k.kind==="style"&&k.style==="Underline")&&(g=s.jsx("u",{children:g})),m.some(k=>k.kind==="style"&&k.style==="Strikethrough")&&(g=s.jsx("s",{children:g}));const x=m.find(k=>k.kind==="url");if(x){const k=/^https?:\/\/t\.co\//i.test(g);g=s.jsx("a",{href:x.href,target:"_blank",rel:"noopener noreferrer",style:l.link,children:k?x.display:g})}const w=m.find(k=>k.kind==="mention");return w&&(g=s.jsx("a",{href:`https://x.com/${w.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:l.link,children:g})),s.jsx("span",{children:typeof g=="string"?as(g,l.link):g},c)})}function Wm(e,t,n){const r=(n==null?void 0:n.st)||X,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=qn(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:c=>{var v;!c.metaKey&&!c.ctrlKey&&(c.preventDefault(),(v=n==null?void 0:n.onImgClick)==null||v.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(Fd,{}),"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 ri(e,t,n,r){const l=(r==null?void 0:r.st)||X,i=e.type||"",a=e.text||"",o=e.inline_style_ranges||[],u=e.data||{},c=Um(a,o,u.urls||[],u.mentions||[],l);switch(i){case"header-one":return s.jsx("h1",{style:l.bH1,children:c},t);case"header-two":{const v=a.match(/(?:x\.com|twitter\.com)\/i\/status\/(\d+)/);return v?s.jsxs("a",{href:`https://x.com/i/status/${v[1]}`,target:"_blank",rel:"noopener noreferrer",style:l.bTweet,children:[s.jsx(Fd,{}),"View post on X"]},t):s.jsx("h2",{style:l.bH2,children:c},t)}case"unstyled":return a.trim()?s.jsx("p",{style:l.bP,children:c},t):s.jsx("span",{style:l.bSpacer},t);case"blockquote":return s.jsx("blockquote",{style:l.bQuote,children:c},t);case"unordered-list-item":case"ordered-list-item":return s.jsx("li",{style:l.bLi,children:c},t);case"atomic":return s.jsx("span",{children:Wm(e,n,r)},t);default:return a?s.jsx("p",{style:l.bP,children:c},t):null}}function Vm(e,t,n){const r=(n==null?void 0:n.st)||X,l=[];let i=0;for(;i{r&&(l==null||l(!0))},[r,l]);const o=r?ni:X,u=e.cover_media||{},c=e.author||t||{},v=e.first_published_at_secs?Md(e.first_published_at_secs):"",h=[c.screen_name?`@${c.screen_name}`:"",v].filter(Boolean).join(" · "),g=qn(u.local_path,u.url,n),x=qn(c.avatar_local_path,c.avatar_url,n),w=s.jsxs(s.Fragment,{children:[i&&s.jsx(Hd,{items:[{src:i,alt:""}],startIndex:0,onClose:()=>a(null)}),g&&s.jsx("a",{href:g,target:"_blank",rel:"noopener noreferrer",style:{display:"block",cursor:"zoom-in"},onClick:k=>{!k.metaKey&&!k.ctrlKey&&(k.preventDefault(),a(g))},children:s.jsx("img",{src:g,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:c.name||""}):s.jsx("div",{style:o.aAvatarPh}),s.jsxs("div",{children:[s.jsx("div",{style:o.aAuthorName,children:c.name||c.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:Vm(e.blocks||[],n,{onImgClick:a,st:o})})]});return r?s.jsx("div",{style:ni.article,children:s.jsx("div",{style:ni.articleInner,children:w})}):s.jsx("div",{style:X.article,children:w})}function Km({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:X.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 Hd({items:e,startIndex:t,onClose:n}){const[r,l]=f.useState(t);f.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:X.lightboxBackdrop,onClick:n,children:s.jsxs("div",{style:X.lightboxContent,onClick:a=>a.stopPropagation(),children:[s.jsxs("div",{style:X.lightboxToolbar,children:[e.length>1&&s.jsxs("span",{style:X.lightboxCounter,children:[r+1," / ",e.length]}),s.jsx("a",{href:i.src,target:"_blank",rel:"noopener noreferrer",style:X.lightboxLink,title:"Open in new tab",children:"↗"}),s.jsx("button",{style:X.lightboxBtn,onClick:n,"aria-label":"Close",children:"×"})]}),s.jsx("img",{src:i.src,alt:i.alt||"",style:X.lightboxImg}),e.length>1&&s.jsxs("div",{style:X.lightboxNav,children:[s.jsx("button",{style:X.lightboxNavBtn,onClick:()=>l(a=>Math.max(a-1,0)),disabled:r===0,children:"‹"}),s.jsx("button",{style:X.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 d,y;const[l,i]=f.useState(null),a=e.author||{},o=e.created_at_secs?Md(e.created_at_secs):"",u=e.entities||{},c=qn(a.avatar_local_path,a.avatar_url,r),v=t&&!n,m=e.is_quote_status===!0,h=t?X.tweetRowThread:X.tweetRow,g=e.full_text||"",x=((y=(d=e.extended_entities)==null?void 0:d.media)!=null&&y.length?e.extended_entities.media:u.media)||[],w=[],k=[];for(const j of x)if(j.type==="photo"){const _=qn(j.local_path,j.media_url_https,r);_&&w.push({kind:"photo",src:_,alt:j.alt_text||""})}else if(j.type==="video"||j.type==="animated_gif"){const _=j.local_path&&r[j.local_path]||(()=>{var E,N;return(N=(((E=j.video_info)==null?void 0:E.variants)||[]).filter($=>$.content_type==="video/mp4").sort(($,P)=>(P.bitrate||0)-($.bitrate||0))[0])==null?void 0:N.url})();_&&k.push({kind:j.type==="animated_gif"?"gif":"video",src:_})}const p=[];for(const j of x){if(!j.url||!(j.type==="photo"?w.some(E=>E.src===qn(j.local_path,j.media_url_https,r)):k.length>0))continue;const b=qa(j,g,j.url);b&&p.push([b.s,b.e])}return s.jsxs(s.Fragment,{children:[l!==null&&s.jsx(Hd,{items:w,startIndex:l,onClose:()=>i(null)}),s.jsxs("div",{style:h,children:[s.jsxs("div",{style:X.leftCol,children:[c?s.jsx("img",{src:c,style:X.avatar,alt:a.name||""}):s.jsx("div",{style:X.avatarPh}),v&&s.jsx("div",{style:X.threadLine})]}),s.jsxs("div",{style:X.rightCol,children:[s.jsxs("div",{style:X.authorRow,children:[s.jsx("span",{style:X.authorName,children:a.name||a.screen_name||"Unknown"}),a.screen_name&&s.jsxs("span",{style:X.authorHandle,children:["@",a.screen_name]}),o&&s.jsxs("span",{style:X.datePart,children:["· ",o]}),m&&s.jsx("span",{style:X.qtBadge,title:"Quote tweet",children:"↻ QT"})]}),s.jsx("div",{style:X.tweetText,children:Hm(g,u,p)}),w.length>0&&s.jsx("div",{style:X.mediaGrid,children:s.jsx(Km,{photos:w,onOpen:j=>i(j)})}),k.map((j,_)=>s.jsx("div",{style:X.mediaGrid,children:s.jsx("video",{src:j.src,style:X.mediaVideo,controls:!0,loop:j.kind==="gif",muted:j.kind==="gif",autoPlay:j.kind==="gif"})},_)),(e.retweet_count>0||e.favorite_count>0)&&s.jsxs("div",{style:X.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 qm({archiveId:e,entryUid:t,artifacts:n,entityKind:r,fullPage:l,onXArticle:i}){const[a,o]=f.useState(!0),[u,c]=f.useState(null),[v,m]=f.useState([]);if(f.useEffect(()=>{if(o(!0),c(null),m([]),!n||!e||!t){o(!1);return}const x=n.map((k,p)=>({...k,index:p})).filter(k=>k.artifact_role==="raw_tweet_json");if(x.length===0){c("No tweet data found."),o(!1);return}let w=!1;return jh(e,t,x.map(k=>k.index)).then(async k=>{if(w)return;const p=/https?:\/\/t\.co\/[A-Za-z0-9]+/g,d=E=>{var $;const N=E.full_text||"";return((($=E.entities)==null?void 0:$.urls)||[]).map(P=>{var V;if(P.fromIndex!=null&&P.toIndex!=null)return[P.fromIndex,P.toIndex];if(((V=P.indices)==null?void 0:V.length)===2)return[P.indices[0],P.indices[1]];if(P.url){const H=N.indexOf(P.url);if(H!==-1)return[H,H+P.url.length]}return null}).filter(Boolean)},y=(E,N,$)=>E.some(([P,V])=>P<=N&&V>=$),j=new Set;for(const E of k){const N=E.full_text||"",$=d(E);let P;for(p.lastIndex=0;(P=p.exec(N))!==null;)y($,P.index,P.index+P[0].length)||j.add(P[0])}const _=j.size>0?await Sh([...j]).catch(()=>({})):{},b=k.map(E=>{var H;const N=E.full_text||"",$=d(E),P=[];let V;for(p.lastIndex=0;(V=p.exec(N))!==null;){const Q=V[0],Y=_[Q];Y&&Y!==Q&&!y($,V.index,V.index+Q.length)&&P.push({url:Q,expanded_url:Y,display_url:(()=>{try{const oe=new URL(Y);return oe.hostname+(oe.pathname.length>1?"/…":"")}catch{return Y}})(),fromIndex:V.index,toIndex:V.index+Q.length})}return P.length===0?E:{...E,entities:{...E.entities||{},urls:[...((H=E.entities)==null?void 0:H.urls)||[],...P]}}});w||m(b)}).catch(k=>{w||c(k.message||"Failed to load tweet.")}).finally(()=>{w||o(!1)}),()=>{w=!0}},[e,t,n]),a)return s.jsx("div",{style:X.loading,children:"Loading…"});if(u)return s.jsxs("div",{style:X.error,children:["Error: ",u]});if(v.length===0)return null;const h=Am(e,t,n);if(r==="tweet_thread")return s.jsx("div",{style:X.threadOuter,children:v.map((x,w)=>s.jsx(mu,{tweet:x,isInThread:!0,isLast:w===v.length-1,artifactMap:h},x.id||w))});const g=v[0];return g.is_article&&g.article?s.jsx(Qm,{article:g.article,tweetAuthor:g.author,artifactMap:h,fullPage:l,onXArticle:i}):s.jsx("div",{style:X.card,children:s.jsx(mu,{tweet:g,isInThread:!1,isLast:!0,artifactMap:h})})}const Xm=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv"]),Jm=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),Ym=new Set(["jpg","jpeg","png","gif","webp","avif","svg","bmp"]);function Ud({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 g=s.jsx(qm,{archiveId:e,entryUid:o,artifacts:a,entityKind:u,fullPage:r,onXArticle:l});return r?g:s.jsx("div",{className:"preview-tweet-wrap",children:g})}const c=a.findIndex(g=>g.artifact_role==="primary_media");if(c===-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((g,x)=>s.jsxs("li",{children:[g.artifact_role,": ",g.relpath]},x))})]});const v=a[c],m=`/api/archives/${e}/entries/${o}/artifacts/${c}`,h=v.relpath.split(".").pop().toLowerCase();return Xm.has(h)?s.jsx("div",{className:"preview-panel",children:s.jsx(Mm,{src:m})}):Jm.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:m,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(fu,{src:m,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(fu,{src:m,type:"page",title:i.title,originalUrl:i.original_url})}):Ym.has(h)?s.jsx("div",{className:"preview-panel",style:{height:"100%"},children:s.jsx(Fm,{src:m,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((g,x)=>s.jsxs("li",{children:[g.artifact_role,": ",g.relpath]},x))})]})}function Gm({archiveId:e,entry:t,detail:n,onClose:r}){var l,i;return f.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(Ud,{archiveId:e,entry:t,detail:n})})]})})}function gu(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 Zm({entry:e,src:t,archiveId:n,onClose:r}){const l=f.useRef(null),[i,a]=f.useState(!1),[o,u]=f.useState(0),[c,v]=f.useState(NaN),[m,h]=f.useState(1);f.useEffect(()=>{!l.current||!t||(l.current.load(),u(0),v(NaN),a(!1))},[t]),f.useEffect(()=>{l.current&&(l.current.volume=m)},[m]);function g(){const d=l.current;d&&(i?d.pause():d.play().catch(()=>{}))}function x(d){const y=l.current;if(!y||!isFinite(c))return;const j=Number(d.target.value);y.currentTime=j,u(j)}function w(d){h(Number(d.target.value))}const k=(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 d;return u(((d=l.current)==null?void 0:d.currentTime)??0)},onLoadedMetadata:()=>{var d;return v(((d=l.current)==null?void 0:d.duration)??NaN)},onDurationChange:()=>{var d;return v(((d=l.current)==null?void 0:d.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:Ns(p)}}),s.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.85rem",color:"var(--ink)"},title:k,children:k})]}),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:g,"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:gu(o)}),s.jsx("input",{type:"range",min:0,max:isFinite(c)?c: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:gu(c)})]}),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:m,onChange:w,"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 eg({archiveId:e,entryUid:t}){var h,g;const[n,r]=f.useState(null),[l,i]=f.useState(!0),[a,o]=f.useState(null),[u,c]=f.useState(!1);f.useEffect(()=>{if(!u)return;const x=document.documentElement,w=document.body,k=x.style.colorScheme,p=w.style.background;return x.style.colorScheme="dark",w.style.background="#000",()=>{x.style.colorScheme=k,w.style.background=p}},[u]),f.useEffect(()=>{c(!1),Ji(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 v=((h=n==null?void 0:n.summary)==null?void 0:h.title)||t,m=(g=n==null?void 0:n.summary)==null?void 0:g.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:v}),m&&s.jsx("a",{href:m,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(Ud,{archiveId:e,entry:n.summary,detail:n,fullPage:!0,onXArticle:c})]})]})}const tg=7e3;function ng({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(lg,{toast:r,onDismiss:t,onIgnoreUblock:n},r.id))}):null}function rg(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 lg({toast:e,onDismiss:t,onIgnoreUblock:n}){const[r,l]=f.useState(!1),i=e.type==="warning",a=e.type==="success";f.useEffect(()=>{if(r)return;const u=setTimeout(()=>t(e.id),tg);return()=>clearTimeout(u)},[r,e.id,t]);const o=rg(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 _s=f.createContext(null),yr=(()=>{const e=window.location.pathname.match(/^\/preview\/([^/]+)\/([^/]+)/);return e?{archiveId:e[1],entryUid:e[2]}:null})(),sg=["archive","tags","collections","runs","admin","settings"],ig=["profile","tokens","instance","cookies","extensions","storage"];function on(){const e=window.location.pathname.split("/").filter(Boolean),t=sg.includes(e[0])?e[0]:"archive",n=t==="settings"&&ig.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;return{view:t,settingsTab:n,q:l,tag:i,entry:a}}function ag(e,t){return e==="archive"?"/":e==="settings"?`/settings/${t}`:`/${e}`}function og(){const[e,t]=f.useState("loading"),[n,r]=f.useState(null);f.useEffect(()=>{(async()=>{if(await Rh()){t("setup");return}const M=await Oh();if(!M){t("login");return}r(M),t("authenticated")})()},[]),f.useEffect(()=>{const C=()=>{r(null),t("login")};return window.addEventListener("auth:expired",C),()=>window.removeEventListener("auth:expired",C)},[]),f.useEffect(()=>{const C=()=>{const{view:M,settingsTab:K,q:ne,tag:Ie,entry:ut}=on();y(M),_(K),E(ne),p(Ie),m(ut),g(null),w(ut?new Set([ut]):new Set)};return window.addEventListener("popstate",C),()=>window.removeEventListener("popstate",C)},[]);const[l,i]=f.useState([]),[a,o]=f.useState(null),[u,c]=f.useState([]),[v,m]=f.useState(()=>on().entry),[h,g]=f.useState(null),[x,w]=f.useState(()=>{const C=on().entry;return C?new Set([C]):new Set}),[k,p]=f.useState(()=>on().tag),[d,y]=f.useState(()=>on().view),[j,_]=f.useState(()=>on().settingsTab),[b,E]=f.useState(()=>on().q),[N,$]=f.useState(""),[P,V]=f.useState(!1),[H,Q]=f.useState([]),[Y,oe]=f.useState([]),[le,ee]=f.useState(()=>sessionStorage.getItem("captureDialogOpen")==="true"),[R,T]=f.useState([]),A=f.useRef(0),[J,U]=f.useState(()=>{try{const C=JSON.parse(sessionStorage.getItem("pendingCaptures")||"[]");if(Array.isArray(C))return C}catch{}return[]});f.useEffect(()=>{sessionStorage.setItem("pendingCaptures",JSON.stringify(J))},[J]);const[me,ue]=f.useState(()=>sessionStorage.getItem("ublockWarningIgnored")==="true"),[Re,xe]=f.useState(null),be=f.useRef(0),Ze=f.useRef(null),at=f.useRef(!1),Pt=f.useRef(!0),$e=f.useRef(null),et=(n==null?void 0:n.humanize_slugs)??!1;f.useEffect(()=>{const C=++be.current;xe(null),!(!h||!a)&&Ji(a,h.entry_uid).then(M=>{C===be.current&&xe(M)}).catch(()=>{})},[h,a]),f.useEffect(()=>{sessionStorage.setItem("captureDialogOpen",le)},[le]);const z=f.useCallback(async(C,M,K)=>{if(C){V(!0);try{let ne;M||K?ne=await wh(C,M,K):ne=await xh(C),c(ne),w(Ie=>{if(Ie.size<2)return Ie;const ut=new Set(ne.map(En=>En.entry_uid)),ir=new Set([...Ie].filter(En=>ut.has(En)));return ir.size===Ie.size?Ie:ir}),$(ne.length===0?"No results":`${ne.length} result${ne.length===1?"":"s"}`)}catch{c([]),$("Search failed. Try again.")}finally{V(!1)}}},[]);f.useEffect(()=>{e==="authenticated"&&vh().then(C=>{if(i(C),C.length>0){const M=C[0].id;o(M)}})},[e]),f.useEffect(()=>{if(a){if(Pt.current){Pt.current=!1,Promise.all([ei(a).then(Q),Sl(a).then(oe)]);return}p(null),g(null),m(null),w(new Set),Promise.all([z(a,"",null),ei(a).then(Q),Sl(a).then(oe)])}},[a]),f.useEffect(()=>{if(a===null)return;const C=setTimeout(()=>{z(a,b,k)},300);return()=>clearTimeout(C)},[b,a]),f.useEffect(()=>{a!==null&&(k!==null&&y("archive"),z(a,b,k))},[k,a]);const S=f.useCallback(C=>{o(C)},[]),O=f.useCallback(C=>{y(C),C==="tags"&&a&&Sl(a).then(oe)},[a]);f.useEffect(()=>{if(yr)return;const C=ag(d,j);window.location.pathname!==C&&history.pushState(null,"",C+window.location.search)},[d,j]);const I=f.useCallback(C=>{m(C?C.entry_uid:null),g(C)},[]),B=f.useCallback((C,M)=>{if(M.shiftKey&&$e.current!==null){M.preventDefault();const K=u.findIndex(ar=>ar.entry_uid===$e.current),ne=u.findIndex(ar=>ar.entry_uid===C.entry_uid);if(K===-1||ne===-1){$e.current=C.entry_uid,w(new Set([C.entry_uid])),I(C);return}const Ie=Math.min(K,ne),ut=Math.max(K,ne),ir=u.slice(Ie,ut+1),En=new Set(ir.map(ar=>ar.entry_uid));w(En),En.size===1&&I(ir[0])}else M.ctrlKey||M.metaKey?($e.current=C.entry_uid,w(K=>{const ne=new Set(K);return ne.has(C.entry_uid)?ne.delete(C.entry_uid):ne.add(C.entry_uid),ne})):($e.current=C.entry_uid,w(new Set([C.entry_uid])),I(C))},[u,I]),W=f.useCallback(C=>{p(C)},[]),q=f.useCallback(()=>{p(null)},[]),ce=f.useCallback(()=>{a&&Sl(a).then(oe)},[a]),Ce=f.useCallback((C,M)=>{k===C?p(M):k!=null&&k.startsWith(C+"/")&&p(M+k.slice(C.length))},[k]),Ke=f.useCallback(C=>{(k===C||k!=null&&k.startsWith(C+"/"))&&p(null)},[k]),Ae=f.useCallback((C,M)=>{c(K=>K.map(ne=>ne.entry_uid===C?{...ne,title:M}:ne)),g(K=>K&&K.entry_uid===C?{...K,title:M}:K),xe(K=>K&&K.summary.entry_uid===C?{...K,summary:{...K.summary,title:M}}:K)},[]),Be=f.useCallback(()=>{if(!a||!h)return;const C=++be.current;Ji(a,h.entry_uid).then(M=>{C===be.current&&xe(M)}).catch(()=>{})},[a,h]),ge=f.useCallback(C=>{c(M=>M.filter(K=>K.entry_uid!==C)),g(M=>(M==null?void 0:M.entry_uid)===C?null:M),m(M=>M===C?null:M),w(M=>{const K=new Set(M);return K.delete(C),K})},[]),Sn=f.useCallback(C=>{c(M=>M.filter(K=>!C.has(K.entry_uid))),w(new Set),g(null),m(null)},[]);f.useEffect(()=>{if(x.size>=2)m(null),g(null);else if(x.size===1){const[C]=x;m(C)}else m(null),g(null)},[x]);const ot=f.useMemo(()=>u.filter(C=>x.has(C.entry_uid)),[u,x]);f.useEffect(()=>{if(!v||h)return;const C=u.find(M=>M.entry_uid===v);C&&g(C)},[u,v,h]),f.useEffect(()=>{if(yr)return;const C=new URLSearchParams;b&&C.set("q",b),d==="archive"&&k&&C.set("tag",k),d==="archive"&&v&&C.set("entry",v);const M=C.toString(),K=window.location.pathname+(M?"?"+M:"");window.location.pathname+window.location.search!==K&&history.replaceState(null,"",K)},[b,k,v,d]),f.useEffect(()=>{const C=M=>{var K,ne;(M.metaKey||M.ctrlKey)&&M.key==="k"&&(M.preventDefault(),d==="archive"?((K=Ze.current)==null||K.focus(),(ne=Ze.current)==null||ne.select()):(at.current=!0,y("archive")))};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[d]),f.useEffect(()=>{d==="archive"&&at.current&&(at.current=!1,requestAnimationFrame(()=>{var C,M;(C=Ze.current)==null||C.focus(),(M=Ze.current)==null||M.select()}))},[d]);const Nn=f.useCallback(()=>{ee(!0)},[]),_n=f.useCallback(()=>{ee(!1)},[]),tl=f.useCallback(()=>{if(a)return Promise.allSettled([z(a,b,k),ei(a).then(Q)])},[a,b,k,z]),nl=f.useCallback((C,M,K="error",ne=null)=>{if(K==="warning"&&me&&M)return;const Ie=++A.current;T(ut=>[...ut,{id:Ie,text:C,locator:M,type:K,headline:ne}])},[me]),Cs=f.useCallback(C=>{T(M=>M.filter(K=>K.id!==C))},[]),Es=f.useCallback(()=>{sessionStorage.setItem("ublockWarningIgnored","true"),ue(!0),T(C=>C.filter(M=>!(M.type==="warning"&&M.locator)))},[]),rl=f.useCallback(C=>{U(M=>[...M,C])},[]),D=f.useCallback(C=>{U(M=>M.filter(K=>K.id!==C))},[]),[te,He]=f.useState(null),[gt,Cn]=f.useState(null),ll=f.useCallback(()=>{h&&He(h.entry_uid)},[h]),je=f.useCallback(()=>He(null),[]),sr=f.useCallback((C,M)=>{Cn({src:C,entry:M})},[]),Wd=f.useCallback(()=>Cn(null),[]);return f.useEffect(()=>{He(null)},[h]),f.useEffect(()=>{const C=M=>{var ne,Ie,ut;if(M.key!=="Escape"||le||te)return;const K=(ne=document.activeElement)==null?void 0:ne.tagName;K==="INPUT"||K==="TEXTAREA"||K==="SELECT"||x.size>0&&(M.preventDefault(),w(new Set),(ut=(Ie=document.activeElement)==null?void 0:Ie.blur)==null||ut.call(Ie))};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[le,te,x]),f.useEffect(()=>(document.body.classList.toggle("has-audio-bar",!!gt),()=>document.body.classList.remove("has-audio-bar")),[gt]),e==="loading"?s.jsx("div",{className:"auth-loading",children:"Loading\\u2026"}):e==="setup"?s.jsx(cm,{onComplete:()=>t("login")}):e==="login"?s.jsx(um,{onLogin:C=>{r(C),t("authenticated")}}):yr?s.jsx(eg,{archiveId:yr.archiveId,entryUid:yr.entryUid}):s.jsx(_s.Provider,{value:{currentUser:n,setCurrentUser:r},children:s.jsxs(s.Fragment,{children:[s.jsx(dm,{archives:l,archiveId:a,onArchiveChange:S,view:d,onViewChange:O,onCaptureClick:Nn}),s.jsxs("main",{className:"app-shell",children:[s.jsxs("div",{className:"workspace",children:[d==="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:Ze,className:"search-input",type:"search","aria-label":"Search archive","aria-busy":P,placeholder:"Search titles, URLs, types, tags…",value:b,onChange:C=>E(C.target.value)}),s.jsx("span",{className:"kbd",children:"⌘K"})]}),s.jsxs("span",{className:"result-count",children:[N&&s.jsxs(s.Fragment,{children:[s.jsx("b",{children:N.split(" ")[0]})," ",N.split(" ").slice(1).join(" ")]}),k&&s.jsxs("button",{className:"tag-filter-badge",onClick:q,children:["× ",et?$d(k):k]})]})]}),d==="archive"&&s.jsx(xm,{entries:u,selectedUids:x,onRowClick:B,archiveId:a,pendingCaptures:J}),d==="runs"&&s.jsx(jm,{runs:H}),d==="admin"&&s.jsx(Nm,{archives:l}),d==="tags"&&s.jsx(_m,{archiveId:a,tagNodes:Y,tagFilter:k,onTagFilterSet:W,onViewChange:O,onTagRenamed:Ce,onTagDeleted:Ke,onTagsRefresh:ce,humanizeTags:et}),d==="collections"&&s.jsx(Em,{archiveId:a}),d==="settings"&&s.jsx(bm,{tab:j,onTabChange:_,archiveId:a})]}),s.jsx(Om,{archiveId:a,selectedEntry:h,selectedUids:x,selectedEntries:ot,detail:Re,onTagFilterSet:W,tagNodes:Y,onTagsRefresh:ce,onEntryTitleChange:Ae,onEntryDeleted:ge,onBulkDeleted:Sn,humanizeTags:et,onDetailRefresh:Be,onOpenPreview:ll,onPlay:sr})]}),te&&h&&h.entry_uid===te&&s.jsx(Gm,{archiveId:a,entry:h,detail:Re,onClose:je}),gt&&s.jsx(Zm,{entry:gt.entry,src:gt.src,archiveId:a,onClose:Wd}),s.jsx(pm,{open:le,archiveId:a,onClose:_n,onCaptured:tl,onToast:nl,activeJobs:J,onJobStarted:rl,onJobSettled:D}),s.jsx(ng,{toasts:R,onDismiss:Cs,onIgnoreUblock:Es})]})})}bd(document.getElementById("root")).render(s.jsx(f.StrictMode,{children:s.jsx(og,{})})); diff --git a/crates/archivr-server/static/index.html b/crates/archivr-server/static/index.html index c0a90ae..539ba6d 100644 --- a/crates/archivr-server/static/index.html +++ b/crates/archivr-server/static/index.html @@ -4,7 +4,7 @@ Archivr - + diff --git a/frontend/src/components/CaptureDialog.jsx b/frontend/src/components/CaptureDialog.jsx index efce61f..4b4f450 100644 --- a/frontend/src/components/CaptureDialog.jsx +++ b/frontend/src/components/CaptureDialog.jsx @@ -392,7 +392,8 @@ export default function CaptureDialog({ open, archiveId, onClose, onCaptured, on const toSubmit = items.filter(it => it.locator.trim()) if (toSubmit.length === 0) return if (toSubmit.some(it => hasConflict(it))) return - if (toSubmit.some(it => it.playlistProbeState === 'probing' || it.probeState === 'probing')) return + if (toSubmit.some(it => it.probeState === 'probing' || + (isPlaylistSource(it.locator) && it.playlistProbeState !== 'done'))) return const batchId = toSubmit.length > 1 ? (crypto.randomUUID?.() ?? `batch-${Date.now()}`) : null @@ -517,7 +518,12 @@ export default function CaptureDialog({ open, archiveId, onClose, onCaptured, on const pendingCount = items.filter(it => it.locator.trim()).length const anyConflict = items.some(it => hasConflict(it)) - const anyProbing = items.some(it => it.playlistProbeState === 'probing' || it.probeState === 'probing') + const anyProbing = items.some(it => + it.probeState === 'probing' || + // For playlist sources block unless probe completed successfully: + // idle = debounce not yet fired; probing = in flight; error = no quality data. + (isPlaylistSource(it.locator) && it.playlistProbeState !== 'done') + ) return (