(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))r(l);new MutationObserver(l=>{for(const i of l)if(i.type==="childList")for(const a of i.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&r(a)}).observe(document,{childList:!0,subtree:!0});function n(l){const i={};return l.integrity&&(i.integrity=l.integrity),l.referrerPolicy&&(i.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?i.credentials="include":l.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(l){if(l.ep)return;l.ep=!0;const i=n(l);fetch(l.href,i)}})();var ju={exports:{}},cs={},Su={exports:{}},Z={};/** * @license React * react.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Zr=Symbol.for("react.element"),ef=Symbol.for("react.portal"),tf=Symbol.for("react.fragment"),nf=Symbol.for("react.strict_mode"),rf=Symbol.for("react.profiler"),lf=Symbol.for("react.provider"),sf=Symbol.for("react.context"),af=Symbol.for("react.forward_ref"),of=Symbol.for("react.suspense"),uf=Symbol.for("react.memo"),cf=Symbol.for("react.lazy"),eo=Symbol.iterator;function df(e){return e===null||typeof e!="object"?null:(e=eo&&e[eo]||e["@@iterator"],typeof e=="function"?e:null)}var Nu={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},_u=Object.assign,Cu={};function ar(e,t,n){this.props=e,this.context=t,this.refs=Cu,this.updater=n||Nu}ar.prototype.isReactComponent={};ar.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")};ar.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function Eu(){}Eu.prototype=ar.prototype;function Zi(e,t,n){this.props=e,this.context=t,this.refs=Cu,this.updater=n||Nu}var ea=Zi.prototype=new Eu;ea.constructor=Zi;_u(ea,ar.prototype);ea.isPureReactComponent=!0;var to=Array.isArray,Tu=Object.prototype.hasOwnProperty,ta={current:null},bu={key:!0,ref:!0,__self:!0,__source:!0};function Pu(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)Tu.call(t,r)&&!bu.hasOwnProperty(r)&&(l[r]=t[r]);var o=arguments.length-2;if(o===1)l.children=n;else if(1>>1,V=z[G];if(0>>1;Gl($e,B))Lel(He,$e)?(z[G]=He,z[Le]=B,G=Le):(z[G]=$e,z[oe]=B,G=oe);else if(Lel(He,B))z[G]=He,z[Le]=B,G=Le;else break e}}return T}function l(z,T){var B=z.sortIndex-T.sortIndex;return B!==0?B:z.id-T.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var a=Date,o=a.now();e.unstable_now=function(){return a.now()-o}}var u=[],c=[],y=1,h=null,g=3,x=!1,v=!1,k=!1,j=typeof setTimeout=="function"?setTimeout:null,p=typeof clearTimeout=="function"?clearTimeout:null,d=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function m(z){for(var T=n(c);T!==null;){if(T.callback===null)r(c);else if(T.startTime<=z)r(c),T.sortIndex=T.expirationTime,t(u,T);else break;T=n(c)}}function w(z){if(k=!1,m(z),!v)if(n(u)!==null)v=!0,de(E);else{var T=n(c);T!==null&&te(w,T.startTime-z)}}function E(z,T){v=!1,k&&(k=!1,p(S),S=-1),x=!0;var B=g;try{for(m(T),h=n(u);h!==null&&(!(h.expirationTime>T)||z&&!K());){var G=h.callback;if(typeof G=="function"){h.callback=null,g=h.priorityLevel;var V=G(h.expirationTime<=T);T=e.unstable_now(),typeof V=="function"?h.callback=V:h===n(u)&&r(u),m(T)}else r(u);h=n(u)}if(h!==null)var fe=!0;else{var oe=n(c);oe!==null&&te(w,oe.startTime-T),fe=!1}return fe}finally{h=null,g=B,x=!1}}var P=!1,_=null,S=-1,I=5,b=-1;function K(){return!(e.unstable_now()-bz||125G?(z.sortIndex=B,t(c,z),n(u)===null&&z===n(c)&&(k?(p(S),S=-1):k=!0,te(w,B-G))):(z.sortIndex=V,t(u,z),v||x||(v=!0,de(E))),z},e.unstable_shouldYield=K,e.unstable_wrapCallback=function(z){var T=g;return function(){var B=g;g=T;try{return z.apply(this,arguments)}finally{g=B}}}})(Du);Iu.exports=Du;var jf=Iu.exports;/** * @license React * react-dom.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Sf=f,ut=jf;function L(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),ii=Object.prototype.hasOwnProperty,Nf=/^[: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]*$/,ro={},lo={};function _f(e){return ii.call(lo,e)?!0:ii.call(ro,e)?!1:Nf.test(e)?lo[e]=!0:(ro[e]=!0,!1)}function Cf(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 Ef(e,t,n,r){if(t===null||typeof t>"u"||Cf(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 Je(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 De={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){De[e]=new Je(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];De[t]=new Je(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){De[e]=new Je(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){De[e]=new Je(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){De[e]=new Je(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){De[e]=new Je(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){De[e]=new Je(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){De[e]=new Je(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){De[e]=new Je(e,5,!1,e.toLowerCase(),null,!1,!1)});var ra=/[\-:]([a-z])/g;function la(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(ra,la);De[t]=new Je(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(ra,la);De[t]=new Je(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(ra,la);De[t]=new Je(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){De[e]=new Je(e,1,!1,e.toLowerCase(),null,!1,!1)});De.xlinkHref=new Je("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){De[e]=new Je(e,1,!1,e.toLowerCase(),null,!0,!0)});function sa(e,t,n,r){var l=De.hasOwnProperty(t)?De[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{zs=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?wr(e):""}function Tf(e){switch(e.tag){case 5:return wr(e.type);case 16:return wr("Lazy");case 13:return wr("Suspense");case 19:return wr("SuspenseList");case 0:case 2:case 15:return e=Rs(e.type,!1),e;case 11:return e=Rs(e.type.render,!1),e;case 1:return e=Rs(e.type,!0),e;default:return""}}function ci(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 $n:return"Fragment";case Dn:return"Portal";case ai:return"Profiler";case ia:return"StrictMode";case oi:return"Suspense";case ui:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Au:return(e.displayName||"Context")+".Consumer";case Ou:return(e._context.displayName||"Context")+".Provider";case aa:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case oa:return t=e.displayName||null,t!==null?t:ci(e.type)||"Memo";case Xt:t=e._payload,e=e._init;try{return ci(e(t))}catch{}}return null}function bf(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 ci(t);case 8:return t===ia?"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 cn(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function Fu(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function Pf(e){var t=Fu(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 ul(e){e._valueTracker||(e._valueTracker=Pf(e))}function Bu(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=Fu(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function Ml(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 di(e,t){var n=t.checked;return ve({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function io(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=cn(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 Hu(e,t){t=t.checked,t!=null&&sa(e,"checked",t,!1)}function fi(e,t){Hu(e,t);var n=cn(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")?pi(e,t.type,n):t.hasOwnProperty("defaultValue")&&pi(e,t.type,cn(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function ao(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 pi(e,t,n){(t!=="number"||Ml(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var kr=Array.isArray;function Kn(e,t,n,r){if(e=e.options,t){t={};for(var l=0;l"+t.valueOf().toString()+"",t=cl.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function $r(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Cr={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},Lf=["Webkit","ms","Moz","O"];Object.keys(Cr).forEach(function(e){Lf.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Cr[t]=Cr[e]})});function Qu(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Cr.hasOwnProperty(e)&&Cr[e]?(""+t).trim():t+"px"}function Ku(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,l=Qu(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,l):e[n]=l}}var zf=ve({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 gi(e,t){if(t){if(zf[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 yi(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 vi=null;function ua(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var xi=null,qn=null,Xn=null;function co(e){if(e=nl(e)){if(typeof xi!="function")throw Error(L(280));var t=e.stateNode;t&&(t=ms(t),xi(e.stateNode,e.type,t))}}function qu(e){qn?Xn?Xn.push(e):Xn=[e]:qn=e}function Xu(){if(qn){var e=qn,t=Xn;if(Xn=qn=null,co(e),t)for(e=0;e>>=0,e===0?32:31-(Uf(e)/Wf|0)|0}var dl=64,fl=4194304;function jr(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 Ul(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=jr(o):(i&=a,i!==0&&(r=jr(i)))}else a=n&~l,a!==0?r=jr(a):i!==0&&(r=jr(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 el(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Et(t),e[t]=n}function qf(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=Tr),wo=" ",ko=!1;function mc(e,t){switch(e){case"keyup":return jp.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function gc(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var On=!1;function Np(e,t){switch(e){case"compositionend":return gc(t);case"keypress":return t.which!==32?null:(ko=!0,wo);case"textInput":return e=t.data,e===wo&&ko?null:e;default:return null}}function _p(e,t){if(On)return e==="compositionend"||!ya&&mc(e,t)?(e=pc(),bl=ha=Zt=null,On=!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=_o(n)}}function wc(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?wc(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function kc(){for(var e=window,t=Ml();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=Ml(e.document)}return t}function va(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 Ip(e){var t=kc(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&wc(n.ownerDocument.documentElement,n)){if(r!==null&&va(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=Co(n,i);var a=Co(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,An=null,_i=null,Pr=null,Ci=!1;function Eo(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Ci||An==null||An!==Ml(r)||(r=An,"selectionStart"in r&&va(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}),Pr&&Hr(Pr,r)||(Pr=r,r=Ql(_i,"onSelect"),0Bn||(e.current=zi[Bn],zi[Bn]=null,Bn--)}function ae(e,t){Bn++,zi[Bn]=e.current,e.current=t}var dn={},Be=pn(dn),tt=pn(!1),Cn=dn;function tr(e,t){var n=e.type.contextTypes;if(!n)return dn;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 nt(e){return e=e.childContextTypes,e!=null}function ql(){ce(tt),ce(Be)}function Io(e,t,n){if(Be.current!==dn)throw Error(L(168));ae(Be,t),ae(tt,n)}function Pc(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,bf(e)||"Unknown",l));return ve({},n,r)}function Xl(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||dn,Cn=Be.current,ae(Be,e),ae(tt,tt.current),!0}function Do(e,t,n){var r=e.stateNode;if(!r)throw Error(L(169));n?(e=Pc(e,t,Cn),r.__reactInternalMemoizedMergedChildContext=e,ce(tt),ce(Be),ae(Be,e)):ce(tt),ae(tt,n)}var At=null,gs=!1,Ks=!1;function Lc(e){At===null?At=[e]:At.push(e)}function Qp(e){gs=!0,Lc(e)}function hn(){if(!Ks&&At!==null){Ks=!0;var e=0,t=se;try{var n=At;for(se=1;e>=a,l-=a,Mt=1<<32-Et(t)+l|n<S?(I=_,_=null):I=_.sibling;var b=g(p,_,m[S],w);if(b===null){_===null&&(_=I);break}e&&_&&b.alternate===null&&t(p,_),d=i(b,d,S),P===null?E=b:P.sibling=b,P=b,_=I}if(S===m.length)return n(p,_),he&&vn(p,S),E;if(_===null){for(;SS?(I=_,_=null):I=_.sibling;var K=g(p,_,b.value,w);if(K===null){_===null&&(_=I);break}e&&_&&K.alternate===null&&t(p,_),d=i(K,d,S),P===null?E=K:P.sibling=K,P=K,_=I}if(b.done)return n(p,_),he&&vn(p,S),E;if(_===null){for(;!b.done;S++,b=m.next())b=h(p,b.value,w),b!==null&&(d=i(b,d,S),P===null?E=b:P.sibling=b,P=b);return he&&vn(p,S),E}for(_=r(p,_);!b.done;S++,b=m.next())b=x(_,p,S,b.value,w),b!==null&&(e&&b.alternate!==null&&_.delete(b.key===null?S:b.key),d=i(b,d,S),P===null?E=b:P.sibling=b,P=b);return e&&_.forEach(function(W){return t(p,W)}),he&&vn(p,S),E}function j(p,d,m,w){if(typeof m=="object"&&m!==null&&m.type===$n&&m.key===null&&(m=m.props.children),typeof m=="object"&&m!==null){switch(m.$$typeof){case ol:e:{for(var E=m.key,P=d;P!==null;){if(P.key===E){if(E=m.type,E===$n){if(P.tag===7){n(p,P.sibling),d=l(P,m.props.children),d.return=p,p=d;break e}}else if(P.elementType===E||typeof E=="object"&&E!==null&&E.$$typeof===Xt&&Ao(E)===P.type){n(p,P.sibling),d=l(P,m.props),d.ref=gr(p,P,m),d.return=p,p=d;break e}n(p,P);break}else t(p,P);P=P.sibling}m.type===$n?(d=_n(m.props.children,p.mode,w,m.key),d.return=p,p=d):(w=Ol(m.type,m.key,m.props,null,p.mode,w),w.ref=gr(p,d,m),w.return=p,p=w)}return a(p);case Dn:e:{for(P=m.key;d!==null;){if(d.key===P)if(d.tag===4&&d.stateNode.containerInfo===m.containerInfo&&d.stateNode.implementation===m.implementation){n(p,d.sibling),d=l(d,m.children||[]),d.return=p,p=d;break e}else{n(p,d);break}else t(p,d);d=d.sibling}d=ti(m,p.mode,w),d.return=p,p=d}return a(p);case Xt:return P=m._init,j(p,d,P(m._payload),w)}if(kr(m))return v(p,d,m,w);if(dr(m))return k(p,d,m,w);xl(p,m)}return typeof m=="string"&&m!==""||typeof m=="number"?(m=""+m,d!==null&&d.tag===6?(n(p,d.sibling),d=l(d,m),d.return=p,p=d):(n(p,d),d=ei(m,p.mode,w),d.return=p,p=d),a(p)):n(p,d)}return j}var rr=Dc(!0),$c=Dc(!1),Gl=pn(null),Zl=null,Wn=null,ja=null;function Sa(){ja=Wn=Zl=null}function Na(e){var t=Gl.current;ce(Gl),e._currentValue=t}function Di(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 Yn(e,t){Zl=e,ja=Wn=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(et=!0),e.firstContext=null)}function wt(e){var t=e._currentValue;if(ja!==e)if(e={context:e,memoizedValue:t,next:null},Wn===null){if(Zl===null)throw Error(L(308));Wn=e,Zl.dependencies={lanes:0,firstContext:e}}else Wn=Wn.next=e;return t}var kn=null;function _a(e){kn===null?kn=[e]:kn.push(e)}function Oc(e,t,n,r){var l=t.interleaved;return l===null?(n.next=n,_a(t)):(n.next=l.next,l.next=n),t.interleaved=n,Wt(e,r)}function Wt(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 Jt=!1;function Ca(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Ac(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 Bt(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function sn(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,re&2){var l=r.pending;return l===null?t.next=t:(t.next=l.next,l.next=t),r.pending=t,Wt(e,n)}return l=r.interleaved,l===null?(t.next=t,_a(r)):(t.next=l.next,l.next=t),r.interleaved=t,Wt(e,n)}function Ll(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,da(e,n)}}function Mo(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 es(e,t,n,r){var l=e.updateQueue;Jt=!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 y=e.alternate;y!==null&&(y=y.updateQueue,o=y.lastBaseUpdate,o!==a&&(o===null?y.firstBaseUpdate=c:o.next=c,y.lastBaseUpdate=u))}if(i!==null){var h=l.baseState;a=0,y=c=u=null,o=i;do{var g=o.lane,x=o.eventTime;if((r&g)===g){y!==null&&(y=y.next={eventTime:x,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var v=e,k=o;switch(g=t,x=n,k.tag){case 1:if(v=k.payload,typeof v=="function"){h=v.call(x,h,g);break e}h=v;break e;case 3:v.flags=v.flags&-65537|128;case 0:if(v=k.payload,g=typeof v=="function"?v.call(x,h,g):v,g==null)break e;h=ve({},h,g);break e;case 2:Jt=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,g=l.effects,g===null?l.effects=[o]:g.push(o))}else x={eventTime:x,lane:g,tag:o.tag,payload:o.payload,callback:o.callback,next:null},y===null?(c=y=x,u=h):y=y.next=x,a|=g;if(o=o.next,o===null){if(o=l.shared.pending,o===null)break;g=o,o=g.next,g.next=null,l.lastBaseUpdate=g,l.shared.pending=null}}while(!0);if(y===null&&(u=h),l.baseState=u,l.firstBaseUpdate=c,l.lastBaseUpdate=y,t=l.shared.interleaved,t!==null){l=t;do a|=l.lane,l=l.next;while(l!==t)}else i===null&&(l.shared.lanes=0);bn|=a,e.lanes=a,e.memoizedState=h}}function Fo(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=Xs.transition;Xs.transition={};try{e(!1),t()}finally{se=n,Xs.transition=r}}function td(){return kt().memoizedState}function Jp(e,t,n){var r=on(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},nd(e))rd(t,n);else if(n=Oc(e,t,n,r),n!==null){var l=qe();Tt(n,e,r,l),ld(n,t,r)}}function Yp(e,t,n){var r=on(e),l={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(nd(e))rd(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,bt(o,a)){var u=t.interleaved;u===null?(l.next=l,_a(t)):(l.next=u.next,u.next=l),t.interleaved=l;return}}catch{}finally{}n=Oc(e,t,l,r),n!==null&&(l=qe(),Tt(n,e,r,l),ld(n,t,r))}}function nd(e){var t=e.alternate;return e===ye||t!==null&&t===ye}function rd(e,t){Lr=ns=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function ld(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,da(e,n)}}var rs={readContext:wt,useCallback:Ae,useContext:Ae,useEffect:Ae,useImperativeHandle:Ae,useInsertionEffect:Ae,useLayoutEffect:Ae,useMemo:Ae,useReducer:Ae,useRef:Ae,useState:Ae,useDebugValue:Ae,useDeferredValue:Ae,useTransition:Ae,useMutableSource:Ae,useSyncExternalStore:Ae,useId:Ae,unstable_isNewReconciler:!1},Gp={readContext:wt,useCallback:function(e,t){return Lt().memoizedState=[e,t===void 0?null:t],e},useContext:wt,useEffect:Ho,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,Rl(4194308,4,Jc.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Rl(4194308,4,e,t)},useInsertionEffect:function(e,t){return Rl(4,2,e,t)},useMemo:function(e,t){var n=Lt();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=Lt();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=Jp.bind(null,ye,e),[r.memoizedState,e]},useRef:function(e){var t=Lt();return e={current:e},t.memoizedState=e},useState:Bo,useDebugValue:Ia,useDeferredValue:function(e){return Lt().memoizedState=e},useTransition:function(){var e=Bo(!1),t=e[0];return e=Xp.bind(null,e[1]),Lt().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=ye,l=Lt();if(he){if(n===void 0)throw Error(L(407));n=n()}else{if(n=t(),Pe===null)throw Error(L(349));Tn&30||Hc(r,t,n)}l.memoizedState=n;var i={value:n,getSnapshot:t};return l.queue=i,Ho(Wc.bind(null,r,i,e),[e]),r.flags|=2048,Jr(9,Uc.bind(null,r,i,n,t),void 0,null),n},useId:function(){var e=Lt(),t=Pe.identifierPrefix;if(he){var n=Ft,r=Mt;n=(r&~(1<<32-Et(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=qr++,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[zt]=t,e[Vr]=r,hd(e,t,!1,!1),t.stateNode=e;e:{switch(a=yi(n,r),n){case"dialog":ue("cancel",e),ue("close",e),l=r;break;case"iframe":case"object":case"embed":ue("load",e),l=r;break;case"video":case"audio":for(l=0;lir&&(t.flags|=128,r=!0,yr(i,!1),t.lanes=4194304)}else{if(!r)if(e=ts(a),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),yr(i,!0),i.tail===null&&i.tailMode==="hidden"&&!a.alternate&&!he)return Me(t),null}else 2*je()-i.renderingStartTime>ir&&n!==1073741824&&(t.flags|=128,r=!0,yr(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=je(),t.sibling=null,n=ge.current,ae(ge,r?n&1|2:n&1),t):(Me(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?it&1073741824&&(Me(t),t.subtreeFlags&6&&(t.flags|=8192)):Me(t),null;case 24:return null;case 25:return null}throw Error(L(156,t.tag))}function ih(e,t){switch(wa(t),t.tag){case 1:return nt(t.type)&&ql(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return lr(),ce(tt),ce(Be),ba(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Ta(t),null;case 13:if(ce(ge),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(L(340));nr()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return ce(ge),null;case 4:return lr(),null;case 10:return Na(t.type._context),null;case 22:case 23:return Fa(),null;case 24:return null;default:return null}}var kl=!1,Fe=!1,ah=typeof WeakSet=="function"?WeakSet:Set,M=null;function Vn(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){we(e,t,r)}else n.current=null}function Wi(e,t,n){try{n()}catch(r){we(e,t,r)}}var Zo=!1;function oh(e,t){if(Ei=Wl,e=kc(),va(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,y=0,h=e,g=null;t:for(;;){for(var x;h!==n||l!==0&&h.nodeType!==3||(o=a+l),h!==i||r!==0&&h.nodeType!==3||(u=a+r),h.nodeType===3&&(a+=h.nodeValue.length),(x=h.firstChild)!==null;)g=h,h=x;for(;;){if(h===e)break t;if(g===n&&++c===l&&(o=a),g===i&&++y===r&&(u=a),(x=h.nextSibling)!==null)break;h=g,g=h.parentNode}h=x}n=o===-1||u===-1?null:{start:o,end:u}}else n=null}n=n||{start:0,end:0}}else n=null;for(Ti={focusedElem:e,selectionRange:n},Wl=!1,M=t;M!==null;)if(t=M,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,M=e;else for(;M!==null;){t=M;try{var v=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(v!==null){var k=v.memoizedProps,j=v.memoizedState,p=t.stateNode,d=p.getSnapshotBeforeUpdate(t.elementType===t.type?k:St(t.type,k),j);p.__reactInternalSnapshotBeforeUpdate=d}break;case 3:var m=t.stateNode.containerInfo;m.nodeType===1?m.textContent="":m.nodeType===9&&m.documentElement&&m.removeChild(m.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(L(163))}}catch(w){we(t,t.return,w)}if(e=t.sibling,e!==null){e.return=t.return,M=e;break}M=t.return}return v=Zo,Zo=!1,v}function zr(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&&Wi(t,n,i)}l=l.next}while(l!==r)}}function xs(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 Vi(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 yd(e){var t=e.alternate;t!==null&&(e.alternate=null,yd(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[zt],delete t[Vr],delete t[Li],delete t[Wp],delete t[Vp])),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 vd(e){return e.tag===5||e.tag===3||e.tag===4}function eu(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||vd(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 Qi(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=Kl));else if(r!==4&&(e=e.child,e!==null))for(Qi(e,t,n),e=e.sibling;e!==null;)Qi(e,t,n),e=e.sibling}function Ki(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(Ki(e,t,n),e=e.sibling;e!==null;)Ki(e,t,n),e=e.sibling}var Re=null,Nt=!1;function qt(e,t,n){for(n=n.child;n!==null;)xd(e,t,n),n=n.sibling}function xd(e,t,n){if(Rt&&typeof Rt.onCommitFiberUnmount=="function")try{Rt.onCommitFiberUnmount(ds,n)}catch{}switch(n.tag){case 5:Fe||Vn(n,t);case 6:var r=Re,l=Nt;Re=null,qt(e,t,n),Re=r,Nt=l,Re!==null&&(Nt?(e=Re,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):Re.removeChild(n.stateNode));break;case 18:Re!==null&&(Nt?(e=Re,n=n.stateNode,e.nodeType===8?Qs(e.parentNode,n):e.nodeType===1&&Qs(e,n),Fr(e)):Qs(Re,n.stateNode));break;case 4:r=Re,l=Nt,Re=n.stateNode.containerInfo,Nt=!0,qt(e,t,n),Re=r,Nt=l;break;case 0:case 11:case 14:case 15:if(!Fe&&(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)&&Wi(n,t,a),l=l.next}while(l!==r)}qt(e,t,n);break;case 1:if(!Fe&&(Vn(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(o){we(n,t,o)}qt(e,t,n);break;case 21:qt(e,t,n);break;case 22:n.mode&1?(Fe=(r=Fe)||n.memoizedState!==null,qt(e,t,n),Fe=r):qt(e,t,n);break;default:qt(e,t,n)}}function tu(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new ah),t.forEach(function(r){var l=yh.bind(null,e,r);n.has(r)||(n.add(r),r.then(l,l))})}}function jt(e,t){var n=t.deletions;if(n!==null)for(var r=0;rl&&(l=a),r&=~i}if(r=l,r=je()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*ch(r/1960))-r,10e?16:e,en===null)var r=!1;else{if(e=en,en=null,is=0,re&6)throw Error(L(331));var l=re;for(re|=4,M=e.current;M!==null;){var i=M,a=i.child;if(M.flags&16){var o=i.deletions;if(o!==null){for(var u=0;uje()-Aa?Nn(e,0):Oa|=n),rt(e,t)}function Ed(e,t){t===0&&(e.mode&1?(t=fl,fl<<=1,!(fl&130023424)&&(fl=4194304)):t=1);var n=qe();e=Wt(e,t),e!==null&&(el(e,t,n),rt(e,n))}function gh(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),Ed(e,n)}function yh(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),Ed(e,n)}var Td;Td=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||tt.current)et=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return et=!1,lh(e,t,n);et=!!(e.flags&131072)}else et=!1,he&&t.flags&1048576&&zc(t,Yl,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Il(e,t),e=t.pendingProps;var l=tr(t,Be.current);Yn(t,n),l=La(null,t,r,e,l,n);var i=za();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,nt(r)?(i=!0,Xl(t)):i=!1,t.memoizedState=l.state!==null&&l.state!==void 0?l.state:null,Ca(t),l.updater=vs,t.stateNode=l,l._reactInternals=t,Oi(t,r,e,n),t=Fi(null,t,r,!0,i,n)):(t.tag=0,he&&i&&xa(t),Ke(null,t,l,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Il(e,t),e=t.pendingProps,l=r._init,r=l(r._payload),t.type=r,l=t.tag=xh(r),e=St(r,e),l){case 0:t=Mi(null,t,r,e,n);break e;case 1:t=Jo(null,t,r,e,n);break e;case 11:t=qo(null,t,r,e,n);break e;case 14:t=Xo(null,t,r,St(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:St(r,l),Mi(e,t,r,l,n);case 1:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:St(r,l),Jo(e,t,r,l,n);case 3:e:{if(dd(t),e===null)throw Error(L(387));r=t.pendingProps,i=t.memoizedState,l=i.element,Ac(e,t),es(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=sr(Error(L(423)),t),t=Yo(e,t,r,n,l);break e}else if(r!==l){l=sr(Error(L(424)),t),t=Yo(e,t,r,n,l);break e}else for(at=ln(t.stateNode.containerInfo.firstChild),ot=t,he=!0,_t=null,n=$c(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(nr(),r===l){t=Vt(e,t,n);break e}Ke(e,t,r,n)}t=t.child}return t;case 5:return Mc(t),e===null&&Ii(t),r=t.type,l=t.pendingProps,i=e!==null?e.memoizedProps:null,a=l.children,bi(r,l)?a=null:i!==null&&bi(r,i)&&(t.flags|=32),cd(e,t),Ke(e,t,a,n),t.child;case 6:return e===null&&Ii(t),null;case 13:return fd(e,t,n);case 4:return Ea(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=rr(t,null,r,n):Ke(e,t,r,n),t.child;case 11:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:St(r,l),qo(e,t,r,l,n);case 7:return Ke(e,t,t.pendingProps,n),t.child;case 8:return Ke(e,t,t.pendingProps.children,n),t.child;case 12:return Ke(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,ae(Gl,r._currentValue),r._currentValue=a,i!==null)if(bt(i.value,a)){if(i.children===l.children&&!tt.current){t=Vt(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=Bt(-1,n&-n),u.tag=2;var c=i.updateQueue;if(c!==null){c=c.shared;var y=c.pending;y===null?u.next=u:(u.next=y.next,y.next=u),c.pending=u}}i.lanes|=n,u=i.alternate,u!==null&&(u.lanes|=n),Di(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),Di(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}Ke(e,t,l.children,n),t=t.child}return t;case 9:return l=t.type,r=t.pendingProps.children,Yn(t,n),l=wt(l),r=r(l),t.flags|=1,Ke(e,t,r,n),t.child;case 14:return r=t.type,l=St(r,t.pendingProps),l=St(r.type,l),Xo(e,t,r,l,n);case 15:return od(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:St(r,l),Il(e,t),t.tag=1,nt(r)?(e=!0,Xl(t)):e=!1,Yn(t,n),sd(t,r,l),Oi(t,r,l,n),Fi(null,t,r,!0,e,n);case 19:return pd(e,t,n);case 22:return ud(e,t,n)}throw Error(L(156,t.tag))};function bd(e,t){return nc(e,t)}function vh(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 vt(e,t,n,r){return new vh(e,t,n,r)}function Ha(e){return e=e.prototype,!(!e||!e.isReactComponent)}function xh(e){if(typeof e=="function")return Ha(e)?1:0;if(e!=null){if(e=e.$$typeof,e===aa)return 11;if(e===oa)return 14}return 2}function un(e,t){var n=e.alternate;return n===null?(n=vt(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 Ol(e,t,n,r,l,i){var a=2;if(r=e,typeof e=="function")Ha(e)&&(a=1);else if(typeof e=="string")a=5;else e:switch(e){case $n:return _n(n.children,l,i,t);case ia:a=8,l|=8;break;case ai:return e=vt(12,n,t,l|2),e.elementType=ai,e.lanes=i,e;case oi:return e=vt(13,n,t,l),e.elementType=oi,e.lanes=i,e;case ui:return e=vt(19,n,t,l),e.elementType=ui,e.lanes=i,e;case Mu:return ks(n,l,i,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Ou:a=10;break e;case Au:a=9;break e;case aa:a=11;break e;case oa:a=14;break e;case Xt:a=16,r=null;break e}throw Error(L(130,e==null?e:typeof e,""))}return t=vt(a,n,t,l),t.elementType=e,t.type=r,t.lanes=i,t}function _n(e,t,n,r){return e=vt(7,e,r,t),e.lanes=n,e}function ks(e,t,n,r){return e=vt(22,e,r,t),e.elementType=Mu,e.lanes=n,e.stateNode={isHidden:!1},e}function ei(e,t,n){return e=vt(6,e,null,t),e.lanes=n,e}function ti(e,t,n){return t=vt(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function wh(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=Ds(0),this.expirationTimes=Ds(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Ds(0),this.identifierPrefix=r,this.onRecoverableError=l,this.mutableSourceEagerHydrationData=null}function Ua(e,t,n,r,l,i,a,o,u){return e=new wh(e,t,n,o,u),t===1?(t=1,i===!0&&(t|=8)):t=0,i=vt(3,null,null,t),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Ca(i),e}function kh(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Rd)}catch(e){console.error(e)}}Rd(),Ru.exports=ct;var Ch=Ru.exports,Id,uu=Ch;Id=uu.createRoot,uu.hydrateRoot;async function _e(e){const t=await fetch(e);if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()}async function Eh(){return _e("/api/archives")}async function Th(e){return _e(`/api/archives/${e}/entries`)}async function bh(e,t,n){const r=new URLSearchParams;return t&&r.set("q",t),n&&r.set("tag",n),_e(`/api/archives/${e}/entries/search?${r}`)}async function Nr(e,t){return _e(`/api/archives/${e}/entries/${t}`)}async function Ph(e,t){return _e(`/api/archives/${e}/entries/${t}/children`)}function Lh(e,t,n){return Promise.all(n.map(r=>_e(`/api/archives/${e}/entries/${t}/artifacts/${r}`)))}async function zh(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 Rh(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 Nl(e,t){return _e(`/api/archives/${e}/entries/${t}/tags`)}async function cu(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 Ih(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 du(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 Dh(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 $h(e,t){const n=await fetch(`/api/archives/${e}/tags/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(await n.text())}async function Oh(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 Ah(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 ni(e){return _e(`/api/archives/${e}/runs`)}async function _l(e){return _e(`/api/archives/${e}/tags`)}async function Mh(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 Fh(e,t){return _e(`/api/archives/${e}/captures/probe?locator=${encodeURIComponent(t)}`)}async function Bh(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 Dd(e,t){return _e(`/api/archives/${e}/capture_jobs/${t}`)}async function Hh(){return(await(await fetch("/api/auth/setup")).json()).setup_required===!0}async function Uh(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 Wh(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 Vh(){await fetch("/api/auth/logout",{method:"POST"})}async function Qh(){const e=await fetch("/api/auth/me");return e.status===401?null:e.json()}async function Kh(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 qh(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 Xh(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 Jh(){return _e("/api/auth/tokens")}async function Yh(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 Gh(e){const t=await fetch(`/api/auth/tokens/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(await t.text())}async function Ka(){return _e("/api/admin/instance-settings")}async function Al(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 Zh(){return _e("/api/admin/users")}async function em(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 tm(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 nm(){return _e("/api/admin/roles")}async function rm(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 $d(e){return _e(`/api/archives/${e}/collections`)}async function lm(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 sm(e,t){return _e(`/api/archives/${e}/collections/${t}`)}async function Od(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 im(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 am(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 om(e,t){return _e(`/api/archives/${e}/entries/${t}/collections`)}async function fu(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 um(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 cm(e){return _e(`/api/archives/${e}/blob-cleanup`)}async function dm(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 fm(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 pm(){return _e("/api/admin/cookie-rules")}async function hm(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 mm(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 gm(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 ym=window.fetch;window.fetch=async(...e)=>{var n;const t=await ym(...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 vm({onLogin:e}){const[t,n]=f.useState(""),[r,l]=f.useState(""),[i,a]=f.useState(null),[o,u]=f.useState(!1);async function c(y){y.preventDefault(),a(null),u(!0);try{const h=await Wh(t,r);e(h)}catch(h){a(h.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:y=>n(y.target.value),autoFocus:!0,required:!0,autoComplete:"username"})]}),s.jsxs("div",{className:"login-field",children:[s.jsx("label",{className:"login-label",htmlFor:"login-password",children:"Password"}),s.jsx("input",{className:"login-input",id:"login-password",type:"password",value:r,onChange:y=>l(y.target.value),required:!0,autoComplete:"current-password"})]}),i&&s.jsx("p",{className:"login-error",children:i}),s.jsx("button",{className:"login-submit",type:"submit",disabled:o,children:o?"Signing in…":"Sign in"})]})]})})}function xm({onComplete:e}){const[t,n]=f.useState(""),[r,l]=f.useState(""),[i,a]=f.useState(""),[o,u]=f.useState(null),[c,y]=f.useState(!1);async function h(g){if(g.preventDefault(),r!==i){u("Passwords do not match");return}if(r.length<8){u("Password must be at least 8 characters");return}u(null),y(!0);try{await Uh(t,r),e()}catch(x){u(x.message)}finally{y(!1)}}return s.jsx("div",{className:"setup-page",children:s.jsxs("div",{className:"setup-card",children:[s.jsx("h1",{className:"setup-brand",children:"Archivr"}),s.jsx("p",{className:"setup-tagline",children:"Create your owner account to get started."}),s.jsxs("form",{onSubmit:h,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:g=>n(g.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:g=>l(g.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:g=>a(g.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 wm({archives:e,archiveId:t,onArchiveChange:n,view:r,onViewChange:l,onCaptureClick:i}){const{currentUser:a,setCurrentUser:o}=f.useContext(Es)??{},[u,c]=f.useState(!1);async function y(){c(!0),await Vh(),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:h=>n(h.target.value),children:e.map(h=>s.jsx("option",{value:h.id,children:h.label},h.id))})}),s.jsx("nav",{className:"nav","aria-label":"Primary",children:["archive","tags","collections","runs","admin","settings"].map(h=>s.jsx("button",{className:`nav-link${r===h?" is-active":""}`,onClick:()=>l(h),children:h.charAt(0).toUpperCase()+h.slice(1)},h))}),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:y,disabled:u,children:u?"Logging out…":"Log out"})]})]})}let Gi=1;function Ad(e){const t=e.trim(),n=t.toLowerCase();for(const r of["yt:","youtube:"])if(n.startsWith(r)){const l=n.slice(r.length);return!!(l.startsWith("video/")||l.startsWith("short/")||l.startsWith("shorts/")||/^[a-z0-9_-]{11}$/i.test(l))}if(n.startsWith("ytm:"))return!n.slice(4).startsWith("playlist/");for(const r of["x:","twitter:","tweet:"])if(n.startsWith(r))return n.slice(r.length).startsWith("media:");if(n.startsWith("spotify:"))return!1;if(n.startsWith("instagram:")||n.startsWith("facebook:")||n.startsWith("tiktok:")||n.startsWith("reddit:")||n.startsWith("snapchat:"))return!0;if(n.startsWith("http://")||n.startsWith("https://")){if(/^https?:\/\/music\.youtube\.com\/watch/.test(n)||/^https?:\/\/(?:www\.)?(?:youtu\.be\/[0-9A-Za-z_-]+|youtube\.com\/watch\?v=[0-9A-Za-z_-]+|youtube\.com\/shorts\/[0-9A-Za-z_-]+)/.test(t)||n.startsWith("https://x.com/")||n.startsWith("http://x.com/")||/^https?:\/\/(?:www\.)?instagram\.com\//.test(n)||/^https?:\/\/(?:www\.)?facebook\.com\//.test(n)||n.startsWith("https://fb.watch/")||n.startsWith("http://fb.watch/")||/^https?:\/\/(?:www\.)?tiktok\.com\//.test(n)||/^https?:\/\/(?:www\.)?reddit\.com\//.test(n)||n.startsWith("https://redd.it/")||n.startsWith("http://redd.it/")||/^https?:\/\/(?:www\.)?snapchat\.com\//.test(n))return!0;if(n.startsWith("https://open.spotify.com/")||n.startsWith("http://open.spotify.com/"))return!1}return!1}function Sn(e){const t=e.trim(),n=t.toLowerCase();for(const r of["yt:","youtube:"])if(n.startsWith(r)){const l=n.slice(r.length);return l.startsWith("playlist/")||l.startsWith("@")||l.startsWith("channel/")||l.startsWith("c/")||l.startsWith("user/")}if(n.startsWith("ytm:"))return n.slice(4).startsWith("playlist/");if(n.startsWith("spotify:")){const r=n.slice(8);return r.startsWith("album:")||r.startsWith("playlist:")}if(n.startsWith("http://")||n.startsWith("https://"))try{const r=new URL(t),l=r.hostname;if((l==="youtube.com"||l==="www.youtube.com")&&(r.pathname==="/playlist"&&r.searchParams.has("list")||r.pathname.startsWith("/@")||r.pathname.startsWith("/channel/")||r.pathname.startsWith("/c/")||r.pathname.startsWith("/user/"))||l==="music.youtube.com"&&r.pathname==="/playlist"&&r.searchParams.has("list")||l==="open.spotify.com"&&(r.pathname.startsWith("/album/")||r.pathname.startsWith("/playlist/")))return!0}catch{}return!1}function In(e=""){return{id:Gi++,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 km(e,t){return e==="best"?t.map(n=>({...n,quality:"best"})):e==="audio"?t.map(n=>n.has_audio?{...n,quality:"audio"}:n.quality!==null?n:{...n,quality:null}):t.map(n=>n.qualities.includes(e)?{...n,quality:e}:n.quality!==null?n:{...n,quality:null})}function pu(e){return Array.isArray(e.playlistItems)&&e.playlistItems.some(t=>t.quality===null)}function jm({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),y=f.useRef(new Map),h=f.useRef(new Map),g=f.useRef(new Map),x=f.useRef(t);f.useEffect(()=>{x.current=t},[t]);const v=f.useRef(r),k=f.useRef(l);f.useEffect(()=>{v.current=r},[r]),f.useEffect(()=>{k.current=l},[l]);const j=f.useRef(i),p=f.useRef(a);f.useEffect(()=>{j.current=i},[i]),f.useEffect(()=>{p.current=a},[a]);const[d,m]=f.useState(()=>{try{const N=JSON.parse(sessionStorage.getItem("captureItems")||"null");if(Array.isArray(N)&&N.length>0){const F=N.filter(O=>!O.status||O.status==="idle");if(F.length>0)return F.forEach(O=>{O.id>=Gi&&(Gi=O.id+1)}),F.map(O=>({...In(O.locator),...O}))}}catch{}return[In()]});f.useEffect(()=>{sessionStorage.setItem("captureItems",JSON.stringify(d))},[d]);const[w,E]=f.useState(!1),[P,_]=f.useState(null),[S,I]=f.useState(null),[b,K]=f.useState(!0),[W,q]=f.useState(!0),[ee,me]=f.useState(!0);f.useEffect(()=>{Ka().then(N=>{I(N),K(N.cookie_ext_enabled??!0),q(N.modal_closer_enabled??!0)}).catch(()=>I({}))},[]);const de=P!==null?P:(S==null?void 0:S.ublock_enabled)??!0,[te,z]=f.useState(!1);f.useEffect(()=>{["captureDialogLocator","captureDialogError","captureDialogBusy","captureDialogJobStatus","captureDialogJobUid"].forEach(N=>sessionStorage.removeItem(N)),o.forEach(N=>{N.jobUid&&!y.current.has(N.jobUid)&&T(N.id,N.jobUid,N.locator,N.archiveId,null)})},[]),f.useEffect(()=>{const N=u.current;if(!N)return;const F=()=>{h.current.forEach(O=>clearTimeout(O)),h.current.clear(),n()};return N.addEventListener("close",F),()=>N.removeEventListener("close",F)},[n]),f.useEffect(()=>{const N=u.current;N&&(e?(c.current||m([In()]),c.current=!1,N.open||N.showModal()):(h.current.forEach(F=>clearTimeout(F)),h.current.clear(),N.open&&N.close()))},[e]),f.useEffect(()=>()=>{y.current.forEach(N=>clearInterval(N)),h.current.forEach(N=>clearTimeout(N))},[]);function T(N,F,O,H,U=null){if(y.current.has(F))return;const X=setInterval(async()=>{var pe,ze,Ue,We;try{const Ve=await Dd(H,F);if(Ve.status==="completed"){clearInterval(y.current.get(F)),y.current.delete(F),await Promise.resolve((pe=v.current)==null?void 0:pe.call(v)),(ze=p.current)==null||ze.call(p,N);try{const xe=Ve.notes_json?JSON.parse(Ve.notes_json):null;if(xe!=null&&xe.ublock_skipped||xe!=null&&xe.cookie_ext_skipped){const Qe=xe.ublock_skipped&&xe.cookie_ext_skipped?"Captured without ad-blocking or cookie-consent extension. Check ARCHIVR_UBLOCK_EXT and ARCHIVR_COOKIE_EXT in your server config.":xe.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.";k.current(Qe,O,"warning"),B(U,"warning",O)}else U||k.current(null,O,"success"),B(U,"archived")}catch{U||k.current(null,O,"success"),B(U,"archived")}}else if(Ve.status==="failed"){clearInterval(y.current.get(F)),y.current.delete(F),(Ue=p.current)==null||Ue.call(p,N);const xe=Ve.error_text||"Capture failed.";k.current(xe,O),B(U,"failed",O)}}catch(Ve){clearInterval(y.current.get(F)),y.current.delete(F),(We=p.current)==null||We.call(p,N);const xe=Ve.message||"Network error";k.current(xe,O),B(U,"failed",O)}},500);y.current.set(F,X)}function B(N,F,O=null){if(!N)return;const H=g.current.get(N);if(!H||(F==="archived"||F==="warning"?(H.archived++,F==="warning"&&(H.warnings++,O&&H.warningLocators.push(O))):(H.failed++,O&&H.failedLocators.push(O)),H.archived+H.failed0?`${U} archived (${X} with warnings)`:`${U} archived`;We=pe>0?`${Qe}, ${pe} failed`:Qe}const Ve=U===0?"error":pe>0||X>0?"warning":"success",xe=[];ze.length>0&&xe.push(`Failed: ${ze.map(Qe=>` ${Qe}`).join(` `)}`),Ue.length>0&&xe.push(`With warnings: ${Ue.map(Qe=>` ${Qe}`).join(` `)}`);const Dt=xe.length>0?xe.join(` `):null;k.current(Dt,null,Ve,We)}async function G(N,F,O,H={}){var ze,Ue;const U=x.current,X=((ze=crypto.randomUUID)==null?void 0:ze.call(crypto))??`job-${Date.now()}-${Math.random()}`,pe={ublock_enabled:de,reader_mode:te,cookie_ext_enabled:b,modal_closer_enabled:W,via_freedium:ee,...H};try{const We=await Mh(U,N,F,pe);(Ue=j.current)==null||Ue.call(j,{id:X,jobUid:We.job_uid,locator:N,archiveId:U}),T(X,We.job_uid,N,U,O)}catch(We){const Ve=We.message||"Submission failed.";k.current(Ve,N),B(O,"failed",N)}}function V(){var H,U;const N=d.filter(X=>X.locator.trim());if(N.length===0||N.some(X=>pu(X))||N.some(X=>X.probeState==="probing"||Sn(X.locator)&&X.playlistProbeState!=="done")||N.some(X=>Array.isArray(X.playlistItems)&&X.playlistItems.length===0))return;const F=N.length>1?((H=crypto.randomUUID)==null?void 0:H.call(crypto))??`batch-${Date.now()}`:null;F&&g.current.set(F,{total:N.length,archived:0,warnings:0,failed:0,failedLocators:[],warningLocators:[]});const O=N.map(X=>({locator:X.locator.trim(),quality:X.playlistItems!==null?null:X.quality||"best",extraExtensions:X.playlistItems!==null?{per_item_quality:Object.fromEntries(X.playlistItems.map(pe=>[pe.id,pe.quality])),sync:X.syncEnabled}:{}}));m([In()]),(U=u.current)==null||U.close(),O.forEach(({locator:X,quality:pe,extraExtensions:ze})=>G(X,pe,F,ze))}function fe(){m(N=>[...N,In()])}function oe(N){clearTimeout(h.current.get(N)),h.current.delete(N),m(F=>{const O=F.filter(H=>H.id!==N);return O.length===0?[In()]:O})}function $e(N,F){if(clearTimeout(h.current.get(N)),m(O=>O.map(H=>H.id===N?{...H,locator:F,probeState:"idle",probeQualities:null,probeHasAudio:!1,quality:"best",playlistProbeState:"idle",playlistInfo:null,playlistItems:null,playlistQuality:null,playlistExpanded:!1}:H)),Ad(F)){const O=setTimeout(async()=>{h.current.delete(N),m(H=>H.map(U=>U.id===N?{...U,probeState:"probing"}:U));try{const H=await Fh(x.current,F.trim());m(U=>U.map(X=>{if(X.id!==N||X.locator!==F)return X;const pe=H.qualities??[],ze=H.has_audio??!1,Ue=pe.length===0&&ze?"audio":"best";return{...X,probeState:"done",probeQualities:pe,probeHasAudio:ze,quality:Ue}}))}catch{m(H=>H.map(U=>U.id===N?{...U,probeState:"idle",probeQualities:null}:U))}},600);h.current.set(N,O)}else if(Sn(F)){const O=setTimeout(async()=>{h.current.delete(N),m(H=>H.map(U=>U.id===N?{...U,playlistProbeState:"probing"}:U));try{const H=await Bh(x.current,F.trim());m(U=>U.map(X=>X.id!==N||X.locator!==F?X:{...X,playlistProbeState:"done",playlistInfo:H,playlistItems:H.items.map(pe=>({...pe,quality:null})),playlistQuality:null}))}catch{m(H=>H.map(U=>U.id===N?{...U,playlistProbeState:"error"}:U))}},800);h.current.set(N,O)}}function Le(N,F){m(O=>O.map(H=>H.id===N?{...H,quality:F}:H))}function He(N,F){m(O=>O.map(H=>{if(H.id!==N)return H;const U=km(F,H.playlistItems);return{...H,playlistQuality:F,playlistItems:U}}))}function ft(N,F,O){m(H=>H.map(U=>U.id!==N?U:{...U,playlistItems:U.playlistItems.map(X=>X.id===F?{...X,quality:O}:X)}))}function lt(N){m(F=>F.map(O=>O.id===N?{...O,playlistExpanded:!O.playlistExpanded}:O))}function pt(N,F){m(O=>O.map(H=>H.id===N?{...H,syncEnabled:F}:H))}function ht(N,F){m(O=>O.map(H=>H.id!==N?H:{...H,playlistItems:H.playlistItems.filter(U=>U.id!==F)}))}const Ye=d.filter(N=>N.locator.trim()).length,R=d.some(N=>pu(N)),J=d.some(N=>Array.isArray(N.playlistItems)&&N.playlistItems.length===0),Se=d.some(N=>N.probeState==="probing"||Sn(N.locator)&&N.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 N;return(N=u.current)==null?void 0:N.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((N,F)=>s.jsx(Sm,{item:N,autoFocus:F===d.length-1,onLocatorChange:O=>$e(N.id,O),onQualityChange:O=>Le(N.id,O),onRemove:()=>oe(N.id),onSubmit:V,onPlaylistQualityChange:O=>He(N.id,O),onPlaylistItemQualityChange:(O,H)=>ft(N.id,O,H),onPlaylistToggle:()=>lt(N.id),onSyncChange:O=>pt(N.id,O),onPlaylistItemDelete:O=>ht(N.id,O)},N.id))}),s.jsxs("button",{type:"button",className:"capture-add-row",onClick:fe,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:()=>E(N=>!N),"aria-expanded":w,children:[s.jsx("svg",{className:`capture-chevron${w?" 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"]}),w&&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":de,className:`ext-toggle ext-toggle--sm${de?" ext-toggle--on":""}`,onClick:()=>_(N=>N===null?!de:!N),"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"}),!(S!=null&&S.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":b,className:`ext-toggle ext-toggle--sm${b?" ext-toggle--on":""}`,onClick:()=>K(N=>!N),"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":te,className:`ext-toggle ext-toggle--sm${te?" ext-toggle--on":""}`,onClick:()=>z(N=>!N),"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":W,className:`ext-toggle ext-toggle--sm${W?" ext-toggle--on":""}`,onClick:()=>q(N=>!N),"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":ee,className:`ext-toggle ext-toggle--sm${ee?" ext-toggle--on":""}`,onClick:()=>me(N=>!N),"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:V,disabled:Ye===0||R||Se||J,children:Ye>1?`Archive ${Ye}`:"Archive"}),s.jsx("button",{type:"button",className:"capture-cancel",onClick:()=>{var N;return(N=u.current)==null?void 0:N.close()},children:"Cancel"})]})]})})}function Sm({item:e,autoFocus:t,onLocatorChange:n,onQualityChange:r,onRemove:l,onSubmit:i,onPlaylistQualityChange:a,onPlaylistItemQualityChange:o,onPlaylistToggle:u,onSyncChange:c,onPlaylistItemDelete:y}){const h=f.useRef(null);f.useEffect(()=>{var v;t&&((v=h.current)==null||v.focus())},[t]);const g=(()=>{if(Sn(e.locator)){if(e.playlistProbeState==="probing")return s.jsx("span",{className:"capture-quality-probing","aria-label":"Probing playlist…",children:"…"});if(e.playlistProbeState==="done"){const v=[...new Set(e.playlistItems.flatMap(p=>p.qualities.map(d=>parseInt(d))))].sort((p,d)=>d-p),k=e.playlistItems.every(p=>p.has_audio),j=e.playlistItems.filter(p=>p.quality===null).length;return s.jsxs(s.Fragment,{children:[s.jsxs("select",{className:"capture-quality",value:e.playlistQuality??"",onChange:p=>a(p.target.value),"aria-label":"Playlist quality",children:[!e.playlistQuality&&s.jsx("option",{value:"",disabled:!0,children:"Select quality…"}),s.jsx("option",{value:"best",children:"Best quality"}),v.map(p=>s.jsxs("option",{value:`${p}p`,children:[p,"p"]},p)),k&&s.jsx("option",{value:"audio",children:"Audio only"})]}),j>0&&s.jsxs("span",{className:"capture-conflict-badge",children:[j," need selection"]})]})}return e.playlistProbeState==="error"?s.jsx("span",{className:"capture-quality-hint capture-quality-hint--error",children:"Probe failed — edit URL to retry"}):null}if(!Ad(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 v=e.probeQualities??[],k=e.probeHasAudio??!1;return v.length===0&&!k?s.jsx("span",{className:"capture-quality-hint",children:"No media detected"}):v.length===0&&k?s.jsx("select",{className:"capture-quality",value:"audio",onChange:j=>r(j.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:j=>r(j.target.value),"aria-label":"Video quality",children:[s.jsx("option",{value:"best",children:"Best quality"}),v.map(j=>s.jsx("option",{value:j,children:j},j)),k&&s.jsx("option",{value:"audio",children:"Audio only"})]})}return null})(),x=Sn(e.locator)&&e.playlistProbeState==="done"?s.jsxs("label",{className:"capture-sync-row",children:[s.jsx("input",{type:"checkbox",checked:e.syncEnabled,onChange:v=>c(v.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:[Sn(e.locator)&&e.playlistProbeState==="done"?s.jsx("button",{type:"button",className:"capture-playlist-toggle capture-playlist-toggle--left",onClick:u,"aria-label":e.playlistExpanded?"Collapse video list":"Expand video list","aria-expanded":e.playlistExpanded,children:e.playlistExpanded?"▲":"▼"}):null,s.jsx("input",{ref:h,className:"capture-input",type:"text",placeholder:"https://… · yt:ID · ytm:ID · tweet:ID · x:ID",value:e.locator,onChange:v=>n(v.target.value),onKeyDown:v=>{v.key==="Enter"&&i()},autoComplete:"off",spellCheck:!1}),g,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}),Sn(e.locator)&&e.playlistProbeState==="done"&&e.playlistExpanded?s.jsxs("div",{className:"capture-playlist-items",children:[e.playlistItems.map(v=>s.jsxs("div",{className:`capture-playlist-item${v.quality===null?" capture-playlist-item--conflict":""}`,children:[s.jsx("span",{className:"capture-playlist-item-title",children:v.title||v.url}),s.jsxs("select",{className:"capture-item-quality",value:v.quality??"",onChange:k=>o(v.id,k.target.value),"aria-label":`Quality for ${v.title||v.url}`,children:[v.quality===null&&s.jsx("option",{value:"",disabled:!0,children:"Choose…"}),s.jsx("option",{value:"best",children:"Best quality"}),v.qualities.map(k=>s.jsx("option",{value:k,children:k},k)),v.has_audio&&s.jsx("option",{value:"audio",children:"Audio only"})]}),v.quality===null&&s.jsx("span",{className:"capture-playlist-conflict-badge",children:"Choose quality"}),s.jsx("button",{type:"button",className:"capture-playlist-item-remove","aria-label":`Remove ${v.title||v.url}`,onClick:()=>y(v.id),children:"×"})]},v.id)),x]}):x]})}function Nm(){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 Gr(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 Ct(e){return _m(e)??""}function qa(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 hu={youtube:'',youtube_music:'',spotify:'',x:'',instagram:'',facebook:'',tiktok:'',reddit:'',snapchat:'',local:'',web:'',other:'?'};function Cs(e){return hu[e]??hu.other}function Md(e){return e.split("/").map(t=>t?t.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"").join("/")}function Cm({entry:e,index:t,onRowClick:n,selectedUids:r}){const l=(r==null?void 0:r.size)===1&&r.has(e.entry_uid),i=(r==null?void 0:r.size)>=2&&r.has(e.entry_uid),a=["child-entry-row",t%2===0?"child-entry-row--light":"child-entry-row--dark",l&&"is-selected",i&&"is-multi-selected"].filter(Boolean).join(" ");return s.jsxs("div",{className:a,tabIndex:0,"data-entry-uid":e.entry_uid,onMouseDown:o=>{o.shiftKey&&o.preventDefault()},onClick:o=>n(e,o),onKeyDown:o=>{o.key==="Enter"&&n(e,o)},children:[s.jsx("div",{className:"col-check","aria-hidden":"true"}),s.jsx("div",{className:"col-added",children:qa(e.archived_at)}),s.jsxs("div",{className:"col-title",children:[s.jsx("span",{className:"source-icon",children:s.jsx("span",{dangerouslySetInnerHTML:{__html:Cs(e.source_kind)}})}),s.jsx("span",{className:"entry-title",children:Ct(e.title)||Ct(e.entry_uid)})]}),s.jsx("div",{className:"col-type",children:s.jsx("span",{className:"type-pill",children:Ct(e.entity_kind)})}),s.jsx("div",{className:"col-size",children:s.jsx("span",{className:"size-total",children:Gr(e.total_artifact_bytes)})}),s.jsx("div",{className:"url-cell col-url",children:Ct(e.original_url)})]})}function Em({entry:e,archiveId:t,rowIndex:n,isSelected:r,isMultiSelected:l,onRowClick:i,selectedUids:a,deletedUids:o}){const[u,c]=f.useState(!1),[y,h]=f.useState(!1),[g,x]=f.useState(null),[v,k]=f.useState(!1),p=e.source_kind==="web"&&e.entity_kind==="page"&&e.has_favicon&&t&&!u?s.jsx("img",{src:`/api/archives/${t}/entries/${e.entry_uid}/favicon`,width:"16",height:"16",alt:"",onError:()=>c(!0),style:{objectFit:"contain"}}):s.jsx("span",{dangerouslySetInnerHTML:{__html:Cs(e.source_kind)}}),d=r||l,m=e.child_count>0;function w(_){_.stopPropagation(),i(e,{ctrlKey:!0,metaKey:!1,shiftKey:!1,preventDefault(){}})}async function E(_){if(_.stopPropagation(),y){h(!1);return}if(h(!0),g===null&&!v){k(!0);try{const S=await Ph(t,e.entry_uid);x(S)}catch{x([])}finally{k(!1)}}}const P=["entry-row-outer",n%2===0?"entry-row-outer--light":"entry-row-outer--dark",r&&"is-selected",l&&"is-multi-selected"].filter(Boolean).join(" ");return s.jsxs("div",{className:P,"data-entry-uid":e.entry_uid,children:[s.jsxs("div",{className:"entry-row-main",tabIndex:0,onMouseDown:_=>{_.shiftKey&&_.preventDefault()},onClick:_=>i(e,_),onKeyDown:_=>{_.key==="Enter"&&i(e,_)},children:[s.jsx("div",{className:"col-check",children:s.jsx("button",{type:"button",className:`row-checkbox${d?" is-checked":""}`,"aria-pressed":d,"aria-label":d?"Deselect entry":"Select entry",onClick:w,onKeyDown:_=>_.stopPropagation()})}),s.jsx("div",{className:"col-added",children:qa(e.archived_at)}),s.jsxs("div",{className:"col-title",children:[m&&s.jsx("button",{type:"button",className:`entry-expand-btn${y?" is-expanded":""}`,"aria-label":y?"Collapse children":`Expand ${e.child_count} items`,"aria-expanded":y,onClick:E,onKeyDown:_=>_.stopPropagation()}),s.jsx("span",{className:"source-icon",children:p}),s.jsx("span",{className:"entry-title",children:Ct(e.title)||Ct(e.entry_uid)}),m&&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:Ct(e.entity_kind)})}),s.jsxs("div",{className:"col-size",children:[s.jsx("span",{className:"size-total",children:Gr(e.total_artifact_bytes)}),e.cached_bytes>0&&e.cacheable_bytes>0&&s.jsxs("span",{className:"size-cached-pct",title:`${Gr(e.cached_bytes)} already on disk from an earlier entry`,children:[Math.round(e.cached_bytes/e.cacheable_bytes*100),"% cached"]})]}),s.jsx("div",{className:"url-cell col-url",children:Ct(e.original_url)})]}),y&&s.jsxs(s.Fragment,{children:[v&&s.jsx("div",{className:"child-entries-loading",children:"Loading…"}),s.jsx("div",{className:"child-entries","aria-label":`${e.child_count} child entries`,children:g&&g.filter(_=>!(o!=null&&o.has(_.entry_uid))).map((_,S)=>s.jsx(Cm,{entry:_,index:S,onRowClick:i,selectedUids:a},_.entry_uid))})]})]})}function Tm({entries:e,selectedUids:t,onRowClick:n,archiveId:r,pendingCaptures:l=[],deletedUids:i}){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(a=>a.archiveId===r).reverse().map(a=>s.jsx(Nm,{},a.id)),e.map((a,o)=>s.jsx(Em,{entry:a,rowIndex:o,archiveId:r,isSelected:t.size===1&&t.has(a.entry_uid),isMultiSelected:t.size>=2&&t.has(a.entry_uid),onRowClick:n,selectedUids:t,deletedUids:i},a.entry_uid))]})]})})}function bm(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 Pm({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 Lm({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:bm(l.started_at)}),s.jsxs("td",{children:[s.jsx(Pm,{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 zm=4;function Rm({archives:e}){const{currentUser:t}=f.useContext(Es)??{},n=t&&(t.role_bits&zm)!==0,[r,l]=f.useState("users"),[i,a]=f.useState([]),[o,u]=f.useState([]),[c,y]=f.useState(!1),[h,g]=f.useState(null),[x,v]=f.useState(""),[k,j]=f.useState(""),[p,d]=f.useState(""),[m,w]=f.useState(null),[E,P]=f.useState(!1),[_,S]=f.useState(""),[I,b]=f.useState(""),[K,W]=f.useState(null),[q,ee]=f.useState(!1),me=f.useCallback(async()=>{if(n){y(!0),g(null);try{const[T,B]=await Promise.all([Zh(),nm()]);a(T),u(B)}catch(T){g(T.message)}finally{y(!1)}}},[n]);f.useEffect(()=>{me()},[me]);async function de(T){const B=T.status==="active"?"disabled":"active";try{await tm(T.user_uid,B),a(G=>G.map(V=>V.user_uid===T.user_uid?{...V,status:B}:V))}catch(G){g(G.message)}}async function te(T){if(T.preventDefault(),!x.trim()||!k){w("Username and password required");return}P(!0),w(null);try{await em(x.trim(),k,p.trim()||void 0),v(""),j(""),d(""),await me()}catch(B){w(B.message)}finally{P(!1)}}async function z(T){if(T.preventDefault(),!_.trim()||!I.trim()){W("Slug and name required");return}ee(!0),W(null);try{await rm(_.trim(),I.trim()),S(""),b(""),await me()}catch(B){W(B.message)}finally{ee(!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"})]}),h&&s.jsx("div",{className:"form-msg form-msg--err",children:h}),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:()=>de(T),children:T.status==="active"?"Ban":"Unban"})})]},T.user_uid))})]}),s.jsx("h3",{children:"Create User"}),s.jsxs("form",{className:"admin-form",onSubmit:te,children:[s.jsx("input",{className:"admin-input",placeholder:"Username",value:x,onChange:T=>v(T.target.value),required:!0}),s.jsx("input",{className:"admin-input",type:"password",placeholder:"Password (min 8 chars)",value:k,onChange:T=>j(T.target.value),required:!0}),s.jsx("input",{className:"admin-input",type:"email",placeholder:"Email (optional)",value:p,onChange:T=>d(T.target.value)}),m&&s.jsx("div",{className:"form-msg form-msg--err",children:m}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:E,children:E?"Creating…":"Create User"})]})]}),r==="roles"&&s.jsxs("div",{className:"admin-section",children:[s.jsx("h2",{children:"Roles"}),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:z,children:[s.jsx("input",{className:"admin-input",placeholder:"Slug (e.g. moderator)",value:_,onChange:T=>S(T.target.value),required:!0}),s.jsx("input",{className:"admin-input",placeholder:"Display Name (e.g. Moderator)",value:I,onChange:T=>b(T.target.value),required:!0}),K&&s.jsx("div",{className:"form-msg form-msg--err",children:K}),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 Fd({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(Fd,{node:r,onPick:t},r.tag.tag_uid))})})]})}function mu({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(Fd,{node:o,onPick:r},o.tag.tag_uid))}):s.jsx("p",{className:"tag-picker-empty",children:"No other tags available."})]})]})})}function Bd({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 Oh(t,c),n()}catch(y){alert(y.message||"Create failed"),r()}}return s.jsx("input",{className:"tag-rename-input",autoFocus:!0,placeholder:"tag name",value:l,onChange:u=>i(u.target.value),onKeyDown:u=>{u.key==="Enter"&&u.currentTarget.blur(),u.key==="Escape"&&(a.current=!0,u.currentTarget.blur())},onBlur:()=>{a.current?(a.current=!1,r()):o()}})}function Hd({node:e,archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:c,onMoveSourceSelect:y,pendingCreateParentUid:h,onCreateDone:g,onCreateCancel:x}){var K;const v=n===e.tag.full_path,[k,j]=f.useState(!1),[p,d]=f.useState(""),m=f.useRef(!1);function w(){if(k)return;if(c){y(e);return}const W=v?null:e.tag.full_path;r(W),l("archive")}function E(W){W.stopPropagation(),!c&&(d(e.tag.slug),j(!0))}async function P(){const W=p.trim();if(!W||W===e.tag.slug){j(!1);return}try{const q=await Dh(t,e.tag.tag_uid,W);i(e.tag.full_path,q.full_path),o()}catch{}finally{j(!1)}}async function _(W){var ee;W.stopPropagation();const q=((ee=e.children)==null?void 0:ee.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 $h(t,e.tag.tag_uid),a(e.tag.full_path),o()}catch{}}const S={archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:c,onMoveSourceSelect:y,pendingCreateParentUid:h,onCreateDone:g,onCreateCancel:x},I=h===e.tag.tag_uid,b=((K=e.children)==null?void 0:K.length)>0;return s.jsxs("li",{children:[s.jsxs("div",{className:`tag-node-row${c?" tag-node-row--move-select":""}`,children:[k?s.jsx("input",{className:"tag-rename-input",autoFocus:!0,value:p,onChange:W=>d(W.target.value),onKeyDown:W=>{W.key==="Enter"&&W.currentTarget.blur(),W.key==="Escape"&&(m.current=!0,W.currentTarget.blur())},onBlur:()=>{m.current?(m.current=!1,j(!1)):P()}}):s.jsxs("button",{className:`tag-node-btn${v?" is-active":""}${c?" tag-node-btn--move-select":""}`,title:c?`Select "${e.tag.full_path}" to move`:e.tag.full_path,onClick:w,onDoubleClick:c?void 0:E,children:[s.jsx("span",{className:"tag-node-label",children:u?e.tag.name:e.tag.slug}),s.jsx("span",{className:"tag-node-count",children:e.children.length===0?`(${e.entry_count})`:`(${e.entry_count}) (${e.subtree_count} Total)`}),!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:W=>{W.stopPropagation(),E(W)},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"})})]}),!k&&!c&&s.jsx("button",{className:"remove tag-node-delete",title:`Delete "${e.tag.full_path}"`,onClick:_,"aria-label":`Delete "${e.tag.full_path}"`,children:"×"})]}),(b||I)&&s.jsx("div",{className:"tag-children",children:s.jsxs("ul",{className:"tag-tree-list",children:[e.children.map(W=>s.jsx(Hd,{node:W,...S},W.tag.tag_uid)),I&&s.jsx("li",{children:s.jsx(Bd,{parentPath:e.tag.full_path,archiveId:t,onDone:g,onCancel:x})})]})})]})}function Im({archiveId:e,tagNodes:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u}){const[c,y]=f.useState(null),[h,g]=f.useState(null);function x(){y("select-source"),g(null)}function v(){y(null),g(null)}f.useEffect(()=>{if(c!=="select-source")return;function q(ee){ee.key==="Escape"&&(ee.preventDefault(),ee.stopPropagation(),v())}return document.addEventListener("keydown",q),()=>document.removeEventListener("keydown",q)},[c]);function k(q){g(q),y("select-dest")}async function j(q){const ee=h.tag.full_path,me=h.tag.tag_uid,de=(q==null?void 0:q.tag_uid)??null;v();try{const te=await Ah(e,me,de);i(ee,te.full_path),o()}catch(te){alert(te.message||"Move failed")}}const[p,d]=f.useState(null),[m,w]=f.useState(void 0);function E(){d("select-parent"),w(void 0)}function P(){d(null),w(void 0)}function _(q){w(q??null),d("input")}function S(){d(null),w(void 0),o()}const I=c==="select-source",b=p==="input"?m?m.tag_uid:"__root__":void 0,K={archiveId:e,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:I,onMoveSourceSelect:k,pendingCreateParentUid:b,onCreateDone:S,onCreateCancel:P},W=b==="__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:I?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:v,children:"Cancel"})]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"tag-tree-title",children:"Tags"}),n&&s.jsxs("span",{className:"tag-tree-active",title:n,children:["Filtering: ",n]}),s.jsxs("div",{className:"tag-tree-actions",children:[s.jsx("button",{className:"tag-tree-action-btn",onClick:E,title:"Create a new tag",disabled:!!p||!!c,children:"+ New"}),s.jsx("button",{className:"tag-tree-action-btn",onClick:x,title:"Move a tag to a different parent",disabled:!!p||!!c||t.length===0,children:"Move"})]})]})}),t.length===0&&!W?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(Hd,{node:q,...K},q.tag.tag_uid)),W&&s.jsx("li",{children:s.jsx(Bd,{parentPath:null,archiveId:e,onDone:S,onCancel:P})})]})]}),p==="select-parent"&&s.jsx(mu,{title:"Create tag under…",tagNodes:t,excludeUid:null,onPick:_,onCancel:P}),c==="select-dest"&&h&&s.jsx(mu,{title:`Move "${h.tag.slug}" under…`,tagNodes:t,excludeUid:h.tag.tag_uid,onPick:j,onCancel:v})]})}const _r=[{value:0,label:"Private"},{value:2,label:"Users only"},{value:3,label:"Public"}],Dm=e=>{var t;return((t=_r.find(n=>n.value===e))==null?void 0:t.label)??String(e)};function $m({archiveId:e}){const[t,n]=f.useState([]),[r,l]=f.useState(!1),[i,a]=f.useState(null),[o,u]=f.useState(null),[c,y]=f.useState(null),[h,g]=f.useState(!1),[x,v]=f.useState(null),[k,j]=f.useState(""),[p,d]=f.useState(""),[m,w]=f.useState(2),[E,P]=f.useState(!1),[_,S]=f.useState(null),[I,b]=f.useState(""),[K,W]=f.useState(2),[q,ee]=f.useState(!1),[me,de]=f.useState(null),[te,z]=f.useState(!1),[T,B]=f.useState(""),G=f.useRef(null),V=t.find(R=>R.collection_uid===o)??null,fe=(V==null?void 0:V.slug)==="_default_",oe=f.useCallback(async()=>{if(e){l(!0),a(null);try{const R=await $d(e);n(R)}catch(R){a(R.message)}finally{l(!1)}}},[e]),$e=f.useCallback(async R=>{if(!R){y(null);return}g(!0),v(null);try{const J=await sm(e,R);y(J)}catch(J){v(J.message)}finally{g(!1)}},[e]);f.useEffect(()=>{oe()},[oe]),f.useEffect(()=>{$e(o)},[o,$e]),f.useEffect(()=>{te&&G.current&&G.current.focus()},[te]);async function Le(R){R.preventDefault();const J=k.trim(),Se=p.trim();if(!(!J||!Se)){P(!0),S(null);try{const N=await lm(e,J,Se,m);j(""),d(""),w(2),await oe(),u(N.collection_uid)}catch(N){S(N.message)}finally{P(!1)}}}async function He(){const R=T.trim();if(!R||!V){z(!1);return}try{await fu(e,V.collection_uid,{name:R}),await oe(),y(J=>J&&{...J,name:R})}catch(J){a(J.message)}finally{z(!1)}}async function ft(R){if(V)try{await fu(e,V.collection_uid,{default_visibility_bits:R}),await oe(),y(J=>J&&{...J,default_visibility_bits:R})}catch(J){a(J.message)}}async function lt(){if(V&&window.confirm(`Delete collection "${V.name}"? Entries will not be deleted.`))try{await um(e,V.collection_uid),u(null),y(null),await oe()}catch(R){a(R.message)}}async function pt(R){R.preventDefault();const J=I.trim();if(!(!J||!V)){ee(!0),de(null);try{await Od(e,V.collection_uid,J,K),b(""),await $e(V.collection_uid)}catch(Se){de(Se.message)}finally{ee(!1)}}}async function ht(R){if(V)try{await im(e,V.collection_uid,R),await $e(V.collection_uid)}catch(J){v(J.message)}}async function Ye(R,J){if(V)try{await am(e,V.collection_uid,R,J),y(Se=>Se&&{...Se,entries:Se.entries.map(N=>N.entry_uid===R?{...N,collection_visibility_bits:J}:N)})}catch(Se){v(Se.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(R=>s.jsxs("button",{className:`coll-sidebar-row${o===R.collection_uid?" is-active":""}`,onClick:()=>u(R.collection_uid),children:[s.jsx("span",{className:"coll-row-name",children:R.name}),s.jsx("span",{className:"coll-row-meta",children:Dm(R.default_visibility_bits)})]},R.collection_uid)),t.length===0&&!r&&s.jsx("div",{className:"muted",style:{padding:"8px 12px"},children:"No collections yet."})]}),V?s.jsxs("div",{className:"coll-detail",children:[s.jsxs("div",{className:"coll-detail-header",children:[te?s.jsx("input",{ref:G,className:"coll-rename-input",value:T,onChange:R=>B(R.target.value),onBlur:He,onKeyDown:R=>{R.key==="Enter"&&He(),R.key==="Escape"&&z(!1)}}):s.jsxs("h3",{className:`coll-detail-name${fe?"":" coll-detail-name--editable"}`,title:fe?void 0:"Click to rename",onClick:()=>{fe||(B(V.name),z(!0))},children:[(c==null?void 0:c.name)??V.name,!fe&&s.jsx("span",{className:"coll-edit-hint",children:" ✎"})]}),!fe&&s.jsx("button",{className:"coll-delete-btn",onClick:lt,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)??V.default_visibility_bits,onChange:R=>ft(Number(R.target.value)),disabled:fe,children:_r.map(R=>s.jsx("option",{value:R.value,children:R.label},R.value))})]}),s.jsxs("div",{className:"coll-entries-section",children:[s.jsx("div",{className:"coll-section-heading",children:"Entries"}),h&&s.jsx("div",{className:"muted",children:"Loading…"}),x&&s.jsx("div",{className:"collections-error",children:x}),!h&&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(R=>s.jsxs("li",{className:"coll-entry-row",children:[s.jsxs("div",{className:"coll-entry-info",children:[s.jsx("span",{className:"coll-entry-title",children:R.title||R.entry_uid}),s.jsx("span",{className:"coll-entry-kind muted",children:R.source_kind})]}),s.jsxs("div",{className:"coll-entry-actions",children:[s.jsx("select",{className:"coll-entry-vis-select",value:R.collection_visibility_bits,onChange:J=>Ye(R.entry_uid,Number(J.target.value)),children:_r.map(J=>s.jsx("option",{value:J.value,children:J.label},J.value))}),!fe&&s.jsx("button",{className:"coll-entry-remove",onClick:()=>ht(R.entry_uid),title:"Remove from collection",children:"×"})]})]},R.entry_uid))}))]}),!fe&&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:I,onChange:R=>b(R.target.value),placeholder:"entry_uid",required:!0}),s.jsx("select",{className:"coll-vis-select",value:K,onChange:R=>W(Number(R.target.value)),children:_r.map(R=>s.jsx("option",{value:R.value,children:R.label},R.value))}),s.jsx("button",{className:"coll-add-btn",type:"submit",disabled:q,children:q?"…":"Add"})]}),me&&s.jsx("div",{className:"collections-error",style:{marginTop:4},children:me})]})]}):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:Le,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:k,onChange:R=>{j(R.target.value),p||d(R.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:R=>d(R.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:m,onChange:R=>w(Number(R.target.value)),children:_r.map(R=>s.jsx("option",{value:R.value,children:R.label},R.value))})]}),_&&s.jsx("div",{className:"collections-error",children:_}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:E,children:E?"Creating…":"Create collection"})]})]})]}):s.jsx("div",{className:"view-placeholder",children:"Select an archive."})}const Om=4;function Am({tab:e,onTabChange:t,archiveId:n}){const{currentUser:r,setCurrentUser:l}=f.useContext(Es)??{},i=r&&(r.role_bits&Om)!==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(Mm,{currentUser:r,setCurrentUser:l}),e==="tokens"&&s.jsx(Fm,{}),e==="instance"&&i&&s.jsx(Bm,{}),e==="cookies"&&i&&s.jsx(Um,{}),e==="extensions"&&i&&s.jsx(Wm,{}),e==="storage"&&i&&s.jsx(Hm,{archiveId:n})]})}function Mm({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(""),[y,h]=f.useState(""),[g,x]=f.useState(""),[v,k]=f.useState(!1),[j,p]=f.useState(null);async function d(w){w.preventDefault(),i(!0),o(null);try{await Kh(n),t(E=>({...E,display_name:n||null})),o({ok:!0,text:"Saved."})}catch(E){o({ok:!1,text:E.message})}finally{i(!1)}}async function m(w){if(w.preventDefault(),y!==g){p({ok:!1,text:"Passwords do not match."});return}k(!0),p(null);try{await Xh(u,y),c(""),h(""),x(""),p({ok:!0,text:"Password changed."})}catch(E){p({ok:!1,text:E.message})}finally{k(!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:w=>r(w.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 w=>{const E=w.target.checked;try{await qh({humanize_slugs:E}),t(P=>({...P,humanize_slugs:E}))}catch{}}}),s.jsx("span",{className:"form-label",style:{margin:0},children:"Humanize tag display"})]}),s.jsx("p",{className:"muted",style:{fontSize:13,margin:"4px 0 0"},children:'When on, tag paths show as "X / Articles" instead of "x/articles".'})]}),s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Change Password"}),s.jsxs("form",{onSubmit:m,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"cur-pw",children:"Current password"}),s.jsx("input",{className:"field-input",id:"cur-pw",type:"password",value:u,onChange:w=>c(w.target.value),required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"new-pw",children:"New password"}),s.jsx("input",{className:"field-input",id:"new-pw",type:"password",value:y,onChange:w=>h(w.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:g,onChange:w=>x(w.target.value),required:!0})]}),j&&s.jsx("div",{className:`form-msg form-msg--${j.ok?"ok":"err"}`,children:j.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:v,children:v?"Changing…":"Change Password"})]})]})]})}function Fm(){const[e,t]=f.useState([]),[n,r]=f.useState(!0),[l,i]=f.useState(null),[a,o]=f.useState(""),[u,c]=f.useState(!1),[y,h]=f.useState(null),g=f.useCallback(async()=>{r(!0),i(null);try{t(await Jh())}catch(k){i(k.message)}finally{r(!1)}},[]);f.useEffect(()=>{g()},[g]);async function x(k){if(k.preventDefault(),!!a.trim()){c(!0);try{const j=await Yh(a.trim());h(j),o(""),g()}catch(j){i(j.message)}finally{c(!1)}}}async function v(k){try{await Gh(k),t(j=>j.filter(p=>p.token_uid!==k))}catch(j){i(j.message)}}return s.jsx("div",{style:{maxWidth:600},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"API Tokens"}),y&&s.jsxs("div",{className:"token-banner",children:[s.jsx("strong",{children:"Token created."})," Copy it now — it won't be shown again.",s.jsx("code",{children:y.raw_token}),s.jsx("button",{className:"token-dismiss",onClick:()=>h(null),children:"Dismiss"})]}),s.jsxs("form",{className:"token-create-row",onSubmit:x,children:[s.jsx("input",{className:"field-input field-input--flex",placeholder:"Token name",value:a,onChange:k=>o(k.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(k=>s.jsxs("div",{className:"token-row",children:[s.jsxs("div",{className:"token-row-info",children:[s.jsx("strong",{children:k.name}),s.jsxs("div",{className:"muted",children:["Created ",k.created_at.slice(0,10),k.last_used_at&&` · Last used ${k.last_used_at.slice(0,10)}`]})]}),s.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"4px 10px"},onClick:()=>v(k.token_uid),children:"Revoke"})]},k.token_uid))]})]})})}function Bm(){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 Ka())}catch(h){i(h.message)}finally{r(!1)}})()},[]);async function y(h){h.preventDefault(),o(!0),c(null);try{await Al(e),c({ok:!0,text:"Saved."})}catch(g){c({ok:!1,text:g.message})}finally{o(!1)}}return n?s.jsx("div",{className:"muted",children:"Loading…"}):l?s.jsx("div",{className:"form-msg form-msg--err",children:l}):e?s.jsx("div",{style:{maxWidth:440},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Instance Settings"}),s.jsxs("form",{onSubmit:y,children:[[["public_index_enabled","Public index (unauthenticated browsing)"],["public_entry_content_enabled","Public entry content"],["open_registration_enabled","Open registration"]].map(([h,g])=>s.jsxs("label",{className:"checkbox-row",children:[s.jsx("input",{type:"checkbox",checked:!!e[h],onChange:x=>t(v=>({...v,[h]:x.target.checked}))}),g]},h)),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:h=>t(g=>({...g,default_entry_visibility:Number(h.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 ri(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 Hm({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 y(){n("scanning"),u(null),l(null);try{const x=await cm(e);l(x),n("scanned")}catch(x){u(x.message),n("error")}}async function h(){n("deleting"),u(null);try{const x=await dm(e);a(x),n("done")}catch(x){u(x.message),n("error")}}const g=r&&r.deletable_files===0&&r.orphaned_blob_rows===0;return s.jsx("div",{style:{maxWidth:440},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Orphan Cleanup"}),s.jsxs("p",{className:"muted",style:{marginBottom:16},children:["Scan for blob files and database records that are no longer referenced by any archive entry and safely delete them."," ",s.jsx("strong",{children:"Cleanup is blocked while captures are running."})]}),!e&&s.jsx("div",{className:"muted",children:"No archive selected."}),e&&t==="idle"&&s.jsx("button",{className:"btn-ghost",onClick:y,children:"Scan for orphaned blobs"}),t==="scanning"&&s.jsx("div",{className:"muted",children:"Scanning…"}),t==="scanned"&&r&&g&&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&&!g&&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:ri(r.total_bytes)})," recoverable."]}),s.jsxs("div",{style:{display:"flex",gap:8},children:[s.jsxs("button",{className:"btn-danger",onClick:h,children:["Delete (",ri(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:ri(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 Um(){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(""),[y,h]=f.useState("{}"),[g,x]=f.useState(null),[v,k]=f.useState(!1),[j,p]=f.useState({});f.useEffect(()=>{d()},[]);async function d(){r(!0),i(null);try{t(await pm())}catch(S){i(S.message)}finally{r(!1)}}async function m(S){S.preventDefault();try{JSON.parse(y)}catch{x({ok:!1,text:'cookies must be valid JSON, e.g. {"session": "abc"}'});return}k(!0),x(null);try{await hm(a==="global"?null:u.trim(),a,y),c(""),h("{}"),o("global"),x({ok:!0,text:"Rule added."}),await d()}catch(I){x({ok:!1,text:I.message})}finally{k(!1)}}async function w(S){try{await gm(S),await d()}catch(I){i(I.message)}}function E(S){p(I=>({...I,[S.rule_uid]:{cookiesInput:S.cookies_json,saving:!1,msg:null}}))}function P(S){p(I=>{const b={...I};return delete b[S],b})}async function _(S){const I=j[S.rule_uid];try{JSON.parse(I.cookiesInput)}catch{p(b=>({...b,[S.rule_uid]:{...b[S.rule_uid],msg:{ok:!1,text:"Invalid JSON"}}}));return}p(b=>({...b,[S.rule_uid]:{...b[S.rule_uid],saving:!0,msg:null}}));try{await mm(S.rule_uid,{cookies_json:I.cookiesInput}),P(S.rule_uid),await d()}catch(b){p(K=>({...K,[S.rule_uid]:{...K[S.rule_uid],saving:!1,msg:{ok:!1,text:b.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(S=>{const I=j[S.rule_uid],b=S.url_pattern?s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"muted",children:[S.pattern_kind,":"]})," ",s.jsx("code",{children:S.url_pattern})]}):s.jsx("span",{className:"muted",children:"global (all URLs)"});return s.jsxs("tr",{children:[s.jsx("td",{children:b}),s.jsx("td",{children:I?s.jsxs(s.Fragment,{children:[s.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:12,width:"100%",minHeight:60},value:I.cookiesInput,onChange:K=>p(W=>({...W,[S.rule_uid]:{...W[S.rule_uid],cookiesInput:K.target.value}}))}),I.msg&&s.jsx("div",{className:`form-msg form-msg--${I.msg.ok?"ok":"err"}`,children:I.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:I.saving,onClick:()=>_(S),children:I.saving?"Saving…":"Save"}),s.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>P(S.rule_uid),children:"Cancel"})]})]}):s.jsx("code",{style:{fontSize:12,wordBreak:"break-all"},children:S.cookies_json})}),s.jsx("td",{children:!I&&s.jsxs("div",{style:{display:"flex",gap:6},children:[s.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>E(S),children:"Edit"}),s.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"2px 8px"},onClick:()=>w(S.rule_uid),children:"Del"})]})})]},S.rule_uid)})})]}):s.jsx("p",{className:"muted",style:{marginBottom:16},children:"No cookie rules defined."}),s.jsx("h3",{style:{marginBottom:8},children:"Add Rule"}),s.jsxs("form",{onSubmit:m,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",children:"Pattern type"}),s.jsxs("select",{className:"field-input",value:a,onChange:S=>o(S.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:S=>c(S.target.value),placeholder:a==="wildcard"?"*.youtube.com or https://example.com/*":".*\\.youtube\\.com.*",required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",children:"Cookies (JSON object)"}),s.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:13,minHeight:70},value:y,onChange:S=>h(S.target.value),placeholder:'{"SESSION": "abc123", "token": "xyz"}',required:!0})]}),g&&s.jsx("div",{className:`form-msg form-msg--${g.ok?"ok":"err"}`,children:g.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:v,children:v?"Adding…":"Add Rule"})]})]})})}function Wm(){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 Ka())}catch(j){o({ok:!1,text:j.message})}finally{r(!1)}})()},[]);async function u(j){i(!0),o(null);try{await Al({ublock_enabled:j}),t(p=>({...p,ublock_enabled:j})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}async function c(j){i(!0),o(null);try{await Al({cookie_ext_enabled:j}),t(p=>({...p,cookie_ext_enabled:j})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}async function y(j){i(!0),o(null);try{await Al({modal_closer_enabled:j}),t(p=>({...p,modal_closer_enabled:j})),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 h=(e==null?void 0:e.ublock_ext_available)??!1,g=(e==null?void 0:e.ublock_enabled)??!0,x=(e==null?void 0:e.cookie_ext_available)??!1,v=(e==null?void 0:e.cookie_ext_enabled)??!0,k=(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)."}),!h&&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":g,className:`ext-toggle${g?" ext-toggle--on":""}`,onClick:()=>u(!g),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."}),!x&&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":v,className:`ext-toggle${v?" ext-toggle--on":""}`,onClick:()=>c(!v),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":k,className:`ext-toggle${k?" ext-toggle--on":""}`,onClick:()=>y(!k),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 gu={0:"Private",1:"Public",2:"Users only",3:"Public"},Vm=()=>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 Qm({archiveId:e,selectedEntry:t,selectedUids:n,selectedEntries:r,detail:l,onTagFilterSet:i,tagNodes:a,onTagsRefresh:o,onEntryTitleChange:u,onEntryDeleted:c,onBulkDeleted:y,humanizeTags:h,onDetailRefresh:g,onOpenPreview:x,onPlay:v}){var il;const[k,j]=f.useState([]),[p,d]=f.useState(""),[m,w]=f.useState([]),[E,P]=f.useState(""),_=f.useRef(0),S=f.useRef(!1),[I,b]=f.useState(!1),[K,W]=f.useState(""),[q,ee]=f.useState("idle"),[me,de]=f.useState(""),te=f.useRef(null),[z,T]=f.useState(!1);f.useEffect(()=>{T(!1)},[(il=l==null?void 0:l.summary)==null?void 0:il.entry_uid]);const B=(n==null?void 0:n.size)>=2,[G,V]=f.useState(""),[fe,oe]=f.useState("idle"),[$e,Le]=f.useState(""),[He,ft]=f.useState([]),[lt,pt]=f.useState(""),[ht,Ye]=f.useState("idle"),[R,J]=f.useState(""),[Se,N]=f.useState("idle");f.useEffect(()=>{const D=++_.current;if(te.current&&(clearInterval(te.current),te.current=null),ee("idle"),de(""),!t||!e){j([]),w([]);return}b(!1),W(""),S.current=!1,j([]),Promise.all([Nl(e,t.entry_uid),om(e,t.entry_uid)]).then(([le,st])=>{D===_.current&&(j(le),w(st))}).catch(()=>{})},[t,e]),f.useEffect(()=>()=>{clearInterval(te.current)},[]),f.useEffect(()=>{if(!B||!e){ft([]);return}$d(e).then(ft).catch(()=>ft([]))},[B,e]),f.useEffect(()=>{V(""),oe("idle"),Le(""),pt(""),Ye("idle"),J(""),N("idle")},[n]);async function F(){const D=n.size;if(!window.confirm(`Delete ${D} entr${D===1?"y":"ies"}? This cannot be undone.`))return;N("running");const le=new Set;for(const st of n)try{await du(e,st),le.add(st)}catch{}N("idle"),y==null||y(le)}async function O(){const D=G.trim();if(D){oe("running"),Le("");try{for(const le of n)await cu(e,le,D);V(""),oe("done"),o==null||o(),setTimeout(()=>oe("idle"),1800)}catch(le){Le(le.message),oe("error")}}}async function H(){if(!lt)return;Ye("running"),J("");const D=[];for(const le of n)try{await Od(e,lt,le)}catch{D.push(le)}D.length>0?(J(`Failed for ${D.length} entr${D.length===1?"y":"ies"}.`),Ye("error")):(Ye("done"),setTimeout(()=>Ye("idle"),1800))}async function U(){const D=K.trim()||null;try{await Rh(e,t.entry_uid,D),u==null||u(t.entry_uid,D)}catch{}finally{b(!1)}}async function X(){const D=p.trim();if(!(!D||!t))try{await cu(e,t.entry_uid,D),d(""),P("");const le=await Nl(e,t.entry_uid);j(le),o()}catch(le){P(le.message)}}async function pe(D){try{await Ih(e,t.entry_uid,D);const le=await Nl(e,t.entry_uid);j(le),o()}catch{}}async function ze(){if(!(!t||!e)&&window.confirm("Delete this entry? This cannot be undone."))try{await du(e,t.entry_uid),c==null||c(t.entry_uid)}catch{}}async function Ue(){if(!t||!e||q==="running")return;const D=_.current,le=t.entry_uid;ee("running"),de("");try{const{job_uid:st}=await fm(e,le);if(_.current!==D)return;te.current=setInterval(async()=>{try{const mn=await Dd(e,st);if(mn.status==="completed"){if(clearInterval(te.current),te.current=null,_.current!==D)return;ee("done");const cr=await Nl(e,le);if(_.current!==D)return;j(cr),g==null||g()}else if(mn.status==="failed"){if(clearInterval(te.current),te.current=null,_.current!==D)return;ee("error"),de(mn.error_text||"Re-archive failed.")}}catch{if(clearInterval(te.current),te.current=null,_.current!==D)return;ee("error"),de("Network error while polling.")}},500)}catch(st){if(_.current!==D)return;ee("error"),de(st.message||"Failed to start re-archive.")}}const We=l?[["Added",qa(l.summary.archived_at)],["Source",l.summary.source_kind],["Type",l.summary.entity_kind],["Visibility",gu[l.summary.visibility]??l.summary.visibility],["Root",l.structured_root_relpath]]:[],Ve=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),xe=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv","pdf","html","htm","jpg","jpeg","png","gif","webp","avif","svg","bmp"]),Dt=l?l.artifacts.findIndex(D=>D.artifact_role==="primary_media"):-1,Qe=Dt>=0?l.artifacts[Dt]:null,ll=Qe?Qe.relpath.split(".").pop().toLowerCase():"",sl=Qe&&Ve.has(ll),Ts=Dt>=0&&t?`/api/archives/${e}/entries/${t.entry_uid}/artifacts/${Dt}`:null,bs=l&&!sl&&(l.summary.entity_kind==="tweet"||l.summary.entity_kind==="tweet_thread"||Qe&&xe.has(ll));return s.jsxs("aside",{className:"context-rail",children:[s.jsx("div",{className:"rail-eyebrow",children:"Context"}),B?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"}),$e&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:$e}),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:G,onChange:D=>V(D.target.value),onKeyDown:D=>{D.key==="Enter"&&O()}}),s.jsx("button",{className:"tag-add-btn",onClick:O,disabled:fe==="running"||!G.trim(),children:fe==="running"?"…":fe==="done"?"✓":"Add"})]})]}),He.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:lt,onChange:D=>pt(D.target.value),children:[s.jsx("option",{value:"",children:"Pick a collection…"}),He.map(D=>s.jsx("option",{value:D.collection_uid,children:D.name},D.collection_uid))]}),s.jsx("button",{className:"tag-add-btn",onClick:H,disabled:!lt||ht==="running",children:ht==="running"?"…":ht==="done"?"✓":ht==="error"?"!":"Add"})]}),R&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"6px 0 0"},children:R})]}),s.jsx("div",{className:"rail-delete-zone",children:s.jsx("button",{className:"rail-delete-btn",onClick:F,disabled:Se==="running",children:Se==="running"?"Deleting…":`Delete ${n.size} entr${n.size===1?"y":"ies"}`})})]}):t?l?s.jsxs(s.Fragment,{children:[I?s.jsx("input",{className:"rail-title-input",autoFocus:!0,value:K,onChange:D=>W(D.target.value),onKeyDown:D=>{D.key==="Enter"&&D.currentTarget.blur(),D.key==="Escape"&&(S.current=!0,D.currentTarget.blur())},onBlur:()=>{S.current?b(!1):U(),S.current=!1}}):s.jsxs("h2",{className:"rail-title rail-title--editable",title:"Click to rename",onClick:()=>{W(l.summary.title??""),b(!0)},children:[Ct(l.summary.title)||Ct(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:Cs(l.summary.source_kind)}}),s.jsx("span",{className:"u-text",children:l.summary.original_url}),s.jsx("span",{className:"ext",children:s.jsx(Vm,{})})]}),sl&&v&&s.jsx("button",{className:"rail-preview-btn",onClick:()=>v(Ts,t),children:"▶ Play"}),bs&&x&&s.jsx("button",{className:"rail-preview-btn",onClick:x,children:"Preview"}),s.jsx("div",{className:"meta-list",children:We.filter(([,D])=>D!=null&&D!=="").map(([D,le])=>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:Ct(le)})]},D))}),l.artifacts.length>0&&(()=>{const D=l.artifacts.map((ke,$t)=>({...ke,_idx:$t})),le=D.filter(ke=>ke.artifact_role==="font"),st=D.filter(ke=>ke.artifact_role!=="font"),mn=le.reduce((ke,$t)=>ke+($t.byte_size||0),0),cr=l.summary.entry_uid,gn=ke=>s.jsx("li",{children:s.jsxs("a",{href:`/api/archives/${e}/entries/${cr}/artifacts/${ke._idx}`,target:"_blank",rel:"noopener noreferrer",className:"artifact-link",children:[s.jsx("span",{className:"artifact-name",children:ke.artifact_role==="font"?ke.relpath.split("/").pop():ke.artifact_role.replace(/_/g," ")}),s.jsx("span",{className:"artifact-size",children:ke.byte_size!=null?Gr(ke.byte_size):"—"})]})},ke._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:[st.map(gn),le.length>0&&s.jsxs("li",{className:"artifact-group",children:[s.jsxs("button",{type:"button",className:"artifact-group-header artifact-link","aria-expanded":z,onClick:()=>T(ke=>!ke),children:[s.jsxs("span",{className:"artifact-name",children:[s.jsx("span",{"aria-hidden":"true",className:`artifact-group-chevron${z?" open":""}`,children:"›"}),` fonts (${le.length})`]}),s.jsx("span",{className:"artifact-size",children:Gr(mn)})]}),z&&s.jsx("ul",{className:"artifact-list artifact-group-body",children:le.map(gn)})]})]})]})})()]}):s.jsx("p",{className:"tags-empty",children:"Loading\\u2026"}):s.jsx("p",{className:"tags-empty",children:"Select an entry."}),t&&!B&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Tags"}),k.length===0?s.jsx("p",{className:"tags-empty",children:"No tags yet."}):s.jsx("div",{className:"tags-wrap",children:k.map(D=>s.jsxs("span",{className:"tag-pill",title:D.full_path,children:[h?Md(D.full_path):D.full_path,s.jsx("button",{className:"remove",title:`Remove tag ${D.full_path}`,onClick:()=>pe(D.tag_uid),children:"×"})]},D.tag_uid))}),E&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:E}),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"&&X()}}),s.jsx("button",{className:"tag-add-btn",onClick:X,children:"Add"})]})]}),m.length>0&&s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Collections"}),m.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:gu[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:Ue,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:me})]}),s.jsx("div",{className:"rail-delete-zone",children:s.jsx("button",{className:"rail-delete-btn",onClick:ze,children:"Delete entry"})})]})]})}function Km({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 yu({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 qm({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 Ud(e){return e?new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(new Date(e*1e3)):""}function vu(e){return!e||!e.includes("&")?e:e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/'/g,"'")}const Y={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"}},Ce={bg:"#000000",border:"#2f3336",text:"#e7e9ea",dim:"#71767b",accent:"#1d9bf0",codeBg:"#16181c"},li={article:{background:Ce.bg,color:Ce.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:Ce.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:Ce.border,flexShrink:0},aAuthorName:{fontSize:"15px",fontWeight:"700",color:Ce.text,lineHeight:"1.3"},aAuthorSub:{fontSize:"15px",color:Ce.dim,lineHeight:"1.3"},aDivider:{border:"none",borderTop:`1px solid ${Ce.border}`,margin:"0"},aBody:{padding:"4px 16px 0"},bH1:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:Ce.text,lineHeight:"36px",margin:"24px 0 10px"},bH2:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:Ce.text,lineHeight:"36px",margin:"24px 0 10px"},bP:{fontSize:"17px",color:Ce.text,lineHeight:"1.5",marginBottom:"16px",marginTop:"0"},bSpacer:{height:"6px",display:"block"},bQuote:{borderLeft:`3px solid ${Ce.border}`,padding:"2px 14px",margin:"14px 0",color:Ce.dim,fontSize:"17px",lineHeight:"1.5"},bHr:{border:"none",borderTop:`1px solid ${Ce.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:Ce.text,lineHeight:"1.5",marginBottom:"6px"},bTweet:{display:"flex",alignItems:"center",gap:"12px",border:`1px solid ${Ce.border}`,borderRadius:"12px",padding:"14px 16px",margin:"14px 0",color:Ce.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:Ce.text,background:"transparent"},iCode:{fontFamily:"ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace",fontSize:"0.875em",background:Ce.codeBg,padding:"2px 6px",borderRadius:"4px",color:"#e6edf3"},link:{color:Ce.accent,textDecoration:"none"}};function Xm(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 Zn(e,t,n){return e&&n[e]?n[e]:t||null}function Wd(){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 Xa(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 Vd(e,t){const n=e.expanded_url||e.url||e.text||"",r=e.display_url||e.expanded_url||e.url||e.text||"",l=Xa(e,t,e.url,e.text,e.display_url,e.expanded_url);return!l||!n?null:{...l,kind:"url",href:n,display:r}}function Qd(e,t){const n=e.screen_name||e.name||e.text||"",r=n?`@${n}`:null,l=Xa(e,t,r);return!l||!n?null:{...l,kind:"mention",screen_name:n}}const xu=/https?:\/\/[^\s<>"'\])]+/g,Jm=/[.,;:!?)()]+$/;function us(e,t){const n=[];let r=0,l;for(xu.lastIndex=0;(l=xu.exec(e))!==null;){l.index>r&&n.push(e.slice(r,l.index));let i=l[0].replace(Jm,"");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:(rVd(o,e)).filter(Boolean),...(t.user_mentions||[]).map(o=>Qd(o,e)).filter(Boolean)];if(r.length===0&&n.length===0)return us(vu(e),Y.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,y])=>c<=o&&y>=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 y=e.slice(o,c),h=r.filter(v=>v.s<=o&&v.e>=c),g=h.find(v=>v.kind==="url");if(g)return s.jsx("a",{href:g.href,target:"_blank",rel:"noopener noreferrer",style:Y.link,children:g.display||y},u);const x=h.find(v=>v.kind==="mention");return x?s.jsx("a",{href:`https://x.com/${x.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:Y.link,children:y},u):s.jsx("span",{children:us(vu(y),Y.link)},u)}).filter(o=>o!==null)}function Gm(e,t,n,r,l=Y){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=Vd(u,e);c&&i.push(c)}for(const u of r){const c=Qd(u,e);c&&i.push(c)}if(i.length===0)return us(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 y=o[c+1],h=i.filter(j=>j.s<=u&&j.e>=y),g=e.slice(u,y);let x;if(g.includes(` `)){const j=g.split(` `);x=j.flatMap((p,d)=>dj.kind==="style"&&j.style==="Code")&&(x=s.jsx("code",{style:l.iCode,children:x})),h.some(j=>j.kind==="style"&&j.style==="Bold")&&(x=s.jsx("strong",{children:x})),h.some(j=>j.kind==="style"&&j.style==="Italic")&&(x=s.jsx("em",{children:x})),h.some(j=>j.kind==="style"&&j.style==="Underline")&&(x=s.jsx("u",{children:x})),h.some(j=>j.kind==="style"&&j.style==="Strikethrough")&&(x=s.jsx("s",{children:x}));const v=h.find(j=>j.kind==="url");if(v){const j=/^https?:\/\/t\.co\//i.test(x);x=s.jsx("a",{href:v.href,target:"_blank",rel:"noopener noreferrer",style:l.link,children:j?v.display:x})}const k=h.find(j=>j.kind==="mention");return k&&(x=s.jsx("a",{href:`https://x.com/${k.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:l.link,children:x})),s.jsx("span",{children:typeof x=="string"?us(x,l.link):x},c)})}function Zm(e,t,n){const r=(n==null?void 0:n.st)||Y,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=Zn(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 y;!c.metaKey&&!c.ctrlKey&&(c.preventDefault(),(y=n==null?void 0:n.onImgClick)==null||y.call(n,u))},children:s.jsx("img",{src:u,style:r.bImg,loading:"lazy",alt:""})},a):null}case"tweet":return i.tweet_id?s.jsxs("a",{href:`https://x.com/i/status/${i.tweet_id}`,target:"_blank",rel:"noopener noreferrer",style:r.bTweet,children:[s.jsx(Wd,{}),"View post on X"]},a):null;case"link":return i.url?s.jsx("p",{style:r.bP,children:s.jsx("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",style:r.link,children:i.url})},a):null;case"markdown":{const u=i.markdown??((o=i.data)==null?void 0:o.markdown)??"";return s.jsx("pre",{style:r.bMdPre,children:s.jsx("code",{style:r.bMdCode,children:u})},a)}case"emoji":return i.url?s.jsx("img",{src:i.url,alt:"",style:{height:"1.2em",verticalAlign:"middle",margin:"0 1px"}},a):null;default:return null}})}function si(e,t,n,r){const l=(r==null?void 0:r.st)||Y,i=e.type||"",a=e.text||"",o=e.inline_style_ranges||[],u=e.data||{},c=Gm(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 y=a.match(/(?:x\.com|twitter\.com)\/i\/status\/(\d+)/);return y?s.jsxs("a",{href:`https://x.com/i/status/${y[1]}`,target:"_blank",rel:"noopener noreferrer",style:l.bTweet,children:[s.jsx(Wd,{}),"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:Zm(e,n,r)},t);default:return a?s.jsx("p",{style:l.bP,children:c},t):null}}function eg(e,t,n){const r=(n==null?void 0:n.st)||Y,l=[];let i=0;for(;i{r&&(l==null||l(!0))},[r,l]);const o=r?li:Y,u=e.cover_media||{},c=e.author||t||{},y=e.first_published_at_secs?Ud(e.first_published_at_secs):"",g=[c.screen_name?`@${c.screen_name}`:"",y].filter(Boolean).join(" · "),x=Zn(u.local_path,u.url,n),v=Zn(c.avatar_local_path,c.avatar_url,n),k=s.jsxs(s.Fragment,{children:[i&&s.jsx(Kd,{items:[{src:i,alt:""}],startIndex:0,onClose:()=>a(null)}),x&&s.jsx("a",{href:x,target:"_blank",rel:"noopener noreferrer",style:{display:"block",cursor:"zoom-in"},onClick:j=>{!j.metaKey&&!j.ctrlKey&&(j.preventDefault(),a(x))},children:s.jsx("img",{src:x,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:[v?s.jsx("img",{src:v,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"}),g&&s.jsx("div",{style:o.aAuthorSub,children:g})]})]})]}),s.jsx("hr",{style:o.aDivider}),s.jsx("div",{style:o.aBody,children:eg(e.blocks||[],n,{onImgClick:a,st:o})})]});return r?s.jsx("div",{style:li.article,children:s.jsx("div",{style:li.articleInner,children:k})}):s.jsx("div",{style:Y.article,children:k})}function ng({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:Y.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 Kd({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:Y.lightboxBackdrop,onClick:n,children:s.jsxs("div",{style:Y.lightboxContent,onClick:a=>a.stopPropagation(),children:[s.jsxs("div",{style:Y.lightboxToolbar,children:[e.length>1&&s.jsxs("span",{style:Y.lightboxCounter,children:[r+1," / ",e.length]}),s.jsx("a",{href:i.src,target:"_blank",rel:"noopener noreferrer",style:Y.lightboxLink,title:"Open in new tab",children:"↗"}),s.jsx("button",{style:Y.lightboxBtn,onClick:n,"aria-label":"Close",children:"×"})]}),s.jsx("img",{src:i.src,alt:i.alt||"",style:Y.lightboxImg}),e.length>1&&s.jsxs("div",{style:Y.lightboxNav,children:[s.jsx("button",{style:Y.lightboxNavBtn,onClick:()=>l(a=>Math.max(a-1,0)),disabled:r===0,children:"‹"}),s.jsx("button",{style:Y.lightboxNavBtn,onClick:()=>l(a=>Math.min(a+1,e.length-1)),disabled:r===e.length-1,children:"›"})]})]})})}function wu({tweet:e,isInThread:t,isLast:n,artifactMap:r}){var d,m;const[l,i]=f.useState(null),a=e.author||{},o=e.created_at_secs?Ud(e.created_at_secs):"",u=e.entities||{},c=Zn(a.avatar_local_path,a.avatar_url,r),y=t&&!n,h=e.is_quote_status===!0,g=t?Y.tweetRowThread:Y.tweetRow,x=e.full_text||"",v=((m=(d=e.extended_entities)==null?void 0:d.media)!=null&&m.length?e.extended_entities.media:u.media)||[],k=[],j=[];for(const w of v)if(w.type==="photo"){const E=Zn(w.local_path,w.media_url_https,r);E&&k.push({kind:"photo",src:E,alt:w.alt_text||""})}else if(w.type==="video"||w.type==="animated_gif"){const E=w.local_path&&r[w.local_path]||(()=>{var _,S;return(S=(((_=w.video_info)==null?void 0:_.variants)||[]).filter(I=>I.content_type==="video/mp4").sort((I,b)=>(b.bitrate||0)-(I.bitrate||0))[0])==null?void 0:S.url})();E&&j.push({kind:w.type==="animated_gif"?"gif":"video",src:E})}const p=[];for(const w of v){if(!w.url||!(w.type==="photo"?k.some(_=>_.src===Zn(w.local_path,w.media_url_https,r)):j.length>0))continue;const P=Xa(w,x,w.url);P&&p.push([P.s,P.e])}return s.jsxs(s.Fragment,{children:[l!==null&&s.jsx(Kd,{items:k,startIndex:l,onClose:()=>i(null)}),s.jsxs("div",{style:g,children:[s.jsxs("div",{style:Y.leftCol,children:[c?s.jsx("img",{src:c,style:Y.avatar,alt:a.name||""}):s.jsx("div",{style:Y.avatarPh}),y&&s.jsx("div",{style:Y.threadLine})]}),s.jsxs("div",{style:Y.rightCol,children:[s.jsxs("div",{style:Y.authorRow,children:[s.jsx("span",{style:Y.authorName,children:a.name||a.screen_name||"Unknown"}),a.screen_name&&s.jsxs("span",{style:Y.authorHandle,children:["@",a.screen_name]}),o&&s.jsxs("span",{style:Y.datePart,children:["· ",o]}),h&&s.jsx("span",{style:Y.qtBadge,title:"Quote tweet",children:"↻ QT"})]}),s.jsx("div",{style:Y.tweetText,children:Ym(x,u,p)}),k.length>0&&s.jsx("div",{style:Y.mediaGrid,children:s.jsx(ng,{photos:k,onOpen:w=>i(w)})}),j.map((w,E)=>s.jsx("div",{style:Y.mediaGrid,children:s.jsx("video",{src:w.src,style:Y.mediaVideo,controls:!0,loop:w.kind==="gif",muted:w.kind==="gif",autoPlay:w.kind==="gif"})},E)),(e.retweet_count>0||e.favorite_count>0)&&s.jsxs("div",{style:Y.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 rg({archiveId:e,entryUid:t,artifacts:n,entityKind:r,fullPage:l,onXArticle:i}){const[a,o]=f.useState(!0),[u,c]=f.useState(null),[y,h]=f.useState([]);if(f.useEffect(()=>{if(o(!0),c(null),h([]),!n||!e||!t){o(!1);return}const v=n.map((j,p)=>({...j,index:p})).filter(j=>j.artifact_role==="raw_tweet_json");if(v.length===0){c("No tweet data found."),o(!1);return}let k=!1;return Lh(e,t,v.map(j=>j.index)).then(async j=>{if(k)return;const p=/https?:\/\/t\.co\/[A-Za-z0-9]+/g,d=_=>{var I;const S=_.full_text||"";return(((I=_.entities)==null?void 0:I.urls)||[]).map(b=>{var K;if(b.fromIndex!=null&&b.toIndex!=null)return[b.fromIndex,b.toIndex];if(((K=b.indices)==null?void 0:K.length)===2)return[b.indices[0],b.indices[1]];if(b.url){const W=S.indexOf(b.url);if(W!==-1)return[W,W+b.url.length]}return null}).filter(Boolean)},m=(_,S,I)=>_.some(([b,K])=>b<=S&&K>=I),w=new Set;for(const _ of j){const S=_.full_text||"",I=d(_);let b;for(p.lastIndex=0;(b=p.exec(S))!==null;)m(I,b.index,b.index+b[0].length)||w.add(b[0])}const E=w.size>0?await zh([...w]).catch(()=>({})):{},P=j.map(_=>{var W;const S=_.full_text||"",I=d(_),b=[];let K;for(p.lastIndex=0;(K=p.exec(S))!==null;){const q=K[0],ee=E[q];ee&&ee!==q&&!m(I,K.index,K.index+q.length)&&b.push({url:q,expanded_url:ee,display_url:(()=>{try{const me=new URL(ee);return me.hostname+(me.pathname.length>1?"/…":"")}catch{return ee}})(),fromIndex:K.index,toIndex:K.index+q.length})}return b.length===0?_:{..._,entities:{..._.entities||{},urls:[...((W=_.entities)==null?void 0:W.urls)||[],...b]}}});k||h(P)}).catch(j=>{k||c(j.message||"Failed to load tweet.")}).finally(()=>{k||o(!1)}),()=>{k=!0}},[e,t,n]),a)return s.jsx("div",{style:Y.loading,children:"Loading…"});if(u)return s.jsxs("div",{style:Y.error,children:["Error: ",u]});if(y.length===0)return null;const g=Xm(e,t,n);if(r==="tweet_thread")return s.jsx("div",{style:Y.threadOuter,children:y.map((v,k)=>s.jsx(wu,{tweet:v,isInThread:!0,isLast:k===y.length-1,artifactMap:g},v.id||k))});const x=y[0];return x.is_article&&x.article?s.jsx(tg,{article:x.article,tweetAuthor:x.author,artifactMap:g,fullPage:l,onXArticle:i}):s.jsx("div",{style:Y.card,children:s.jsx(wu,{tweet:x,isInThread:!1,isLast:!0,artifactMap:g})})}const lg=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv"]),sg=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),ig=new Set(["jpg","jpeg","png","gif","webp","avif","svg","bmp"]);function qd({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 x=s.jsx(rg,{archiveId:e,entryUid:o,artifacts:a,entityKind:u,fullPage:r,onXArticle:l});return r?x:s.jsx("div",{className:"preview-tweet-wrap",children:x})}const c=a.findIndex(x=>x.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((x,v)=>s.jsxs("li",{children:[x.artifact_role,": ",x.relpath]},v))})]});const y=a[c],h=`/api/archives/${e}/entries/${o}/artifacts/${c}`,g=y.relpath.split(".").pop().toLowerCase();return lg.has(g)?s.jsx("div",{className:"preview-panel",children:s.jsx(Km,{src:h})}):sg.has(g)?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:h,controls:!0,style:{marginTop:"8px",width:"100%",maxWidth:"400px"}})]}):g==="pdf"?s.jsx("div",{className:"preview-panel",style:{flex:1,minHeight:0},children:s.jsx(yu,{src:h,type:"pdf",title:i.title,originalUrl:i.original_url})}):g==="html"||g==="htm"?s.jsx("div",{className:"preview-panel",style:{flex:1,minHeight:0},children:s.jsx(yu,{src:h,type:"page",title:i.title,originalUrl:i.original_url})}):ig.has(g)?s.jsx("div",{className:"preview-panel",style:{height:"100%"},children:s.jsx(qm,{src:h,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((x,v)=>s.jsxs("li",{children:[x.artifact_role,": ",x.relpath]},v))})]})}function ag({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(qd,{archiveId:e,entry:t,detail:n})})]})})}function ku(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 og({entry:e,src:t,archiveId:n,onClose:r}){const l=f.useRef(null),[i,a]=f.useState(!1),[o,u]=f.useState(0),[c,y]=f.useState(NaN),[h,g]=f.useState(1);f.useEffect(()=>{!l.current||!t||(l.current.load(),u(0),y(NaN),a(!1))},[t]),f.useEffect(()=>{l.current&&(l.current.volume=h)},[h]);function x(){const d=l.current;d&&(i?d.pause():d.play().catch(()=>{}))}function v(d){const m=l.current;if(!m||!isFinite(c))return;const w=Number(d.target.value);m.currentTime=w,u(w)}function k(d){g(Number(d.target.value))}const j=(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 y(((d=l.current)==null?void 0:d.duration)??NaN)},onDurationChange:()=>{var d;return y(((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:Cs(p)}}),s.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.85rem",color:"var(--ink)"},title:j,children:j})]}),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:x,"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:ku(o)}),s.jsx("input",{type:"range",min:0,max:isFinite(c)?c:0,step:.1,value:isFinite(o)?o:0,onChange:v,"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:ku(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:h,onChange:k,"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 ug({archiveId:e,entryUid:t}){var g,x;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 v=document.documentElement,k=document.body,j=v.style.colorScheme,p=k.style.background;return v.style.colorScheme="dark",k.style.background="#000",()=>{v.style.colorScheme=j,k.style.background=p}},[u]),f.useEffect(()=>{c(!1),Nr(e,t).then(v=>{r(v),i(!1)}).catch(v=>{o((v==null?void 0:v.message)||"Failed to load entry"),i(!1)})},[e,t]);const y=((g=n==null?void 0:n.summary)==null?void 0:g.title)||t,h=(x=n==null?void 0:n.summary)==null?void 0:x.original_url;return s.jsxs("div",{style:{minHeight:"100vh",display:"flex",flexDirection:"column",background:u?"#000":"var(--paper)",fontFamily:"var(--sans)"},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:u?"8px 12px":"10px 16px",borderBottom:u?"none":"1px solid var(--line)",flexShrink:0,position:u?"sticky":"relative",top:0,zIndex:20,background:u?"rgba(0,0,0,0.82)":"var(--paper-2)",backdropFilter:u?"blur(12px)":"none",WebkitBackdropFilter:u?"blur(12px)":"none"},children:[s.jsx("a",{href:"/",style:{color:u?"#1d9bf0":"var(--accent)",textDecoration:"none",fontSize:"13px",flexShrink:0},children:"← Archive"}),s.jsx("span",{style:{flex:1,fontSize:"14px",fontWeight:600,color:u?"#e7e9ea":"var(--ink)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y}),h&&s.jsx("a",{href:h,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(qd,{archiveId:e,entry:n.summary,detail:n,fullPage:!0,onXArticle:c})]})]})}const cg=7e3;function dg({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(pg,{toast:r,onDismiss:t,onIgnoreUblock:n},r.id))}):null}function fg(e){if(!e)return null;if(e.length<=52)return e;try{const{hostname:t,pathname:n,search:r}=new URL(e),l=n.split("/").filter(Boolean),i=(l[l.length-1]??"")+r,a=i?`${t}/…/${i}`:t;return a.length<=56?a:a.slice(0,53)+"…"}catch{return"…"+e.slice(-51)}}function pg({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),cg);return()=>clearTimeout(u)},[r,e.id,t]);const o=fg(e.locator);return a?s.jsx("div",{className:"toast toast--success",role:"alert","aria-atomic":"true",children:s.jsxs("div",{className:"toast-top",children:[s.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"✓"}),s.jsxs("div",{className:"toast-body",children:[s.jsx("span",{className:"toast-headline",children:e.headline||"Archived"}),o&&s.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),s.jsx("div",{className:"toast-btns",children:s.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})})]})}):i?s.jsxs("div",{className:"toast toast--warning",role:"alert","aria-atomic":"true",children:[s.jsxs("div",{className:"toast-top",children:[s.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"⚠"}),s.jsxs("div",{className:"toast-body",children:[s.jsx("span",{className:"toast-headline",children:e.headline||"Archived with warnings"}),o&&s.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),s.jsxs("div",{className:"toast-btns",children:[e.text&&s.jsx("button",{type:"button",className:"toast-view-btn",onClick:()=>l(u=>!u),"aria-expanded":r,children:r?"Hide":"Details"}),e.locator&&s.jsx("button",{type:"button",className:"toast-view-btn toast-ignore-btn",onClick:()=>{n==null||n(),t(e.id)},children:"Ignore"}),s.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})]})]}),r&&s.jsx("p",{className:"toast-warning-detail",children:e.text||"The page was captured but one or more browser extensions were unavailable (ad-blocking or cookie-consent). Check ARCHIVR_UBLOCK_EXT and ARCHIVR_COOKIE_EXT in your server config."})]}):s.jsxs("div",{className:"toast toast--error",role:"alert","aria-atomic":"true",children:[s.jsxs("div",{className:"toast-top",children:[s.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"✕"}),s.jsxs("div",{className:"toast-body",children:[s.jsx("span",{className:"toast-headline",children:e.headline||"Capture failed"}),o&&s.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),s.jsxs("div",{className:"toast-btns",children:[e.text&&s.jsx("button",{type:"button",className:"toast-view-btn",onClick:()=>l(u=>!u),children:r?"Hide":"View error"}),s.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})]})]}),r&&e.text&&s.jsx("pre",{className:"toast-error-detail",children:e.text})]})}const Es=f.createContext(null),xr=(()=>{const e=window.location.pathname.match(/^\/preview\/([^/]+)\/([^/]+)/);return e?{archiveId:e[1],entryUid:e[2]}:null})(),hg=["archive","tags","collections","runs","admin","settings"],mg=["profile","tokens","instance","cookies","extensions","storage"];function yn(){const e=window.location.pathname.split("/").filter(Boolean),t=hg.includes(e[0])?e[0]:"archive",n=t==="settings"&&mg.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 gg(e,t){return e==="archive"?"/":e==="settings"?`/settings/${t}`:`/${e}`}function yg(){const[e,t]=f.useState("loading"),[n,r]=f.useState(null);f.useEffect(()=>{(async()=>{if(await Hh()){t("setup");return}const $=await Qh();if(!$){t("login");return}r($),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:$,settingsTab:A,q:Q,tag:ne,entry:ie}=yn();E($),_(A),I(Q),m(ne),x(ie),k(null),p(ie?new Set([ie]):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([]),[y,h]=f.useState(()=>new Set),[g,x]=f.useState(()=>yn().entry),[v,k]=f.useState(null),[j,p]=f.useState(()=>{const C=yn().entry;return C?new Set([C]):new Set}),[d,m]=f.useState(()=>yn().tag),[w,E]=f.useState(()=>yn().view),[P,_]=f.useState(()=>yn().settingsTab),[S,I]=f.useState(()=>yn().q),[b,K]=f.useState(""),[W,q]=f.useState(!1),[ee,me]=f.useState([]),[de,te]=f.useState([]),[z,T]=f.useState(()=>sessionStorage.getItem("captureDialogOpen")==="true"),[B,G]=f.useState([]),V=f.useRef(0),[fe,oe]=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(fe))},[fe]);const[$e,Le]=f.useState(()=>sessionStorage.getItem("ublockWarningIgnored")==="true"),[He,ft]=f.useState(null),lt=f.useRef(0),pt=f.useRef(null),ht=f.useRef(!1),Ye=f.useRef(!0),R=f.useRef(null),J=f.useRef(0),Se=f.useRef(new Map),N=(n==null?void 0:n.humanize_slugs)??!1;f.useEffect(()=>{const C=++lt.current;ft(null),!(!v||!a)&&Nr(a,v.entry_uid).then($=>{C===lt.current&&ft($)}).catch(()=>{})},[v,a]),f.useEffect(()=>{sessionStorage.setItem("captureDialogOpen",z)},[z]);const F=f.useCallback(async(C,$,A)=>{if(C){q(!0);try{let Q;$||A?Q=await bh(C,$,A):Q=await Th(C),c(Q),p(ne=>{if(ne.size<2)return ne;const ie=new Set(Q.map(mt=>mt.entry_uid)),Oe=new Set([...ne].filter(mt=>ie.has(mt)));return Oe.size===ne.size?ne:Oe}),K(Q.length===0?"No results":`${Q.length} result${Q.length===1?"":"s"}`)}catch{c([]),K("Search failed. Try again.")}finally{q(!1)}}},[]);f.useEffect(()=>{e==="authenticated"&&Eh().then(C=>{if(i(C),C.length>0){const $=C[0].id;o($)}})},[e]),f.useEffect(()=>{if(a){if(Ye.current){Ye.current=!1,Promise.all([ni(a).then(me),_l(a).then(te)]);return}m(null),k(null),x(null),p(new Set),Promise.all([F(a,"",null),ni(a).then(me),_l(a).then(te)])}},[a]),f.useEffect(()=>{if(a===null)return;const C=setTimeout(()=>{F(a,S,d)},300);return()=>clearTimeout(C)},[S,a]),f.useEffect(()=>{a!==null&&(d!==null&&E("archive"),F(a,S,d))},[d,a]);const O=f.useCallback(C=>{o(C)},[]),H=f.useCallback(C=>{E(C),C==="tags"&&a&&_l(a).then(te)},[a]);f.useEffect(()=>{if(xr)return;const C=gg(w,P);window.location.pathname!==C&&history.pushState(null,"",C+window.location.search)},[w,P]);const U=f.useCallback(C=>{x(C?C.entry_uid:null),k(C)},[]),X=f.useCallback((C,$)=>{if(Se.current.set(C.entry_uid,C),++J.current,$.shiftKey&&R.current!==null){$.preventDefault();const A=[...document.querySelectorAll("#entries-body [data-entry-uid]")],Q=A.findIndex(Ge=>Ge.dataset.entryUid===R.current),ne=A.findIndex(Ge=>Ge.dataset.entryUid===C.entry_uid);if(Q===-1||ne===-1){R.current=C.entry_uid,p(new Set([C.entry_uid])),U(C);return}const ie=Math.min(Q,ne),Oe=Math.max(Q,ne),mt=new Set(A.slice(ie,Oe+1).map(Ge=>Ge.dataset.entryUid));p(mt),mt.size===1&&U(C)}else if($.ctrlKey||$.metaKey){R.current=C.entry_uid;const A=new Set(j);if(A.has(C.entry_uid)?A.delete(C.entry_uid):A.add(C.entry_uid),p(A),A.size===0)U(null);else if(A.size===1){const[Q]=A,ne=Se.current.get(Q)??u.find(ie=>ie.entry_uid===Q)??null;if(ne)U(ne);else{const ie=++J.current;Nr(a,Q).then(Oe=>{ie===J.current&&(Oe!=null&&Oe.summary)&&U(Oe.summary)}).catch(()=>{})}}else U(null)}else R.current=C.entry_uid,p(new Set([C.entry_uid])),U(C)},[u,j,U,a]),pe=f.useCallback(C=>{m(C)},[]),ze=f.useCallback(()=>{m(null)},[]),Ue=f.useCallback(()=>{a&&_l(a).then(te)},[a]),We=f.useCallback((C,$)=>{d===C?m($):d!=null&&d.startsWith(C+"/")&&m($+d.slice(C.length))},[d]),Ve=f.useCallback(C=>{(d===C||d!=null&&d.startsWith(C+"/"))&&m(null)},[d]),xe=f.useCallback((C,$)=>{c(A=>A.map(Q=>Q.entry_uid===C?{...Q,title:$}:Q)),k(A=>A&&A.entry_uid===C?{...A,title:$}:A),ft(A=>A&&A.summary.entry_uid===C?{...A,summary:{...A.summary,title:$}}:A)},[]),Dt=f.useCallback(()=>{if(!a||!v)return;const C=++lt.current;Nr(a,v.entry_uid).then($=>{C===lt.current&&ft($)}).catch(()=>{})},[a,v]),Qe=f.useCallback(C=>{const $=u.some(A=>A.entry_uid===C);h(A=>{const Q=new Set(A);return Q.add(C),Q}),c(A=>A.filter(Q=>Q.entry_uid!==C)),k(A=>(A==null?void 0:A.entry_uid)===C?null:A),x(A=>A===C?null:A),p(A=>{const Q=new Set(A);return Q.delete(C),Q}),$||F(a,S,d)},[u,a,S,d,F]),ll=f.useCallback(C=>{const $=new Set(u.map(Q=>Q.entry_uid)),A=[...C].some(Q=>!$.has(Q));h(Q=>{const ne=new Set(Q);return C.forEach(ie=>ne.add(ie)),ne}),c(Q=>Q.filter(ne=>!C.has(ne.entry_uid))),p(new Set),k(null),x(null),A&&F(a,S,d)},[u,a,S,d,F]);f.useEffect(()=>{if(j.size>=2)x(null),k(null);else if(j.size===1){const[C]=j;x(C)}else x(null),k(null)},[j]);const sl=f.useMemo(()=>u.filter(C=>j.has(C.entry_uid)),[u,j]);f.useEffect(()=>{if(!g||v)return;const C=u.find($=>$.entry_uid===g);C&&k(C)},[u,g,v]),f.useEffect(()=>{if(xr)return;const C=new URLSearchParams;S&&C.set("q",S),w==="archive"&&d&&C.set("tag",d),w==="archive"&&g&&C.set("entry",g);const $=C.toString(),A=window.location.pathname+($?"?"+$:"");window.location.pathname+window.location.search!==A&&history.replaceState(null,"",A)},[S,d,g,w]),f.useEffect(()=>{const C=$=>{var ie,Oe,mt,Ge;const A=$.key==="/"&&!$.metaKey&&!$.ctrlKey&&!$.altKey,Q=($.metaKey||$.ctrlKey)&&$.key==="k";if(!A&&!Q)return;const ne=(ie=document.activeElement)==null?void 0:ie.tagName;A&&(ne==="INPUT"||ne==="TEXTAREA"||ne==="SELECT")||A&&((Oe=document.activeElement)!=null&&Oe.isContentEditable)||($.preventDefault(),w==="archive"?((mt=pt.current)==null||mt.focus(),(Ge=pt.current)==null||Ge.select()):(ht.current=!0,E("archive")))};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[w]),f.useEffect(()=>{const C=$=>{var Ga,Za;if($.metaKey||$.ctrlKey||$.altKey||$.key!=="j"&&$.key!=="k")return;const A=(Ga=document.activeElement)==null?void 0:Ga.tagName;if(A==="INPUT"||A==="TEXTAREA"||A==="SELECT"||(Za=document.activeElement)!=null&&Za.isContentEditable)return;const Q=[...document.querySelectorAll("#entries-body [data-entry-uid]")];if(Q.length===0)return;const[ne]=j.size===1?j:[null],ie=ne?Q.findIndex(Kt=>Kt.dataset.entryUid===ne):-1,Oe=$.key==="j"?Math.min(ie+1,Q.length-1):Math.max(ie-1,0);if(Oe===ie&&ie!==-1)return;const mt=Q[Oe<0?0:Oe],Ge=mt.dataset.entryUid;R.current=Ge;const Zd=++J.current;p(new Set([Ge]));const Ya=Se.current.get(Ge)??u.find(Kt=>Kt.entry_uid===Ge)??null;Ya?U(Ya):Nr(a,Ge).then(Kt=>{Zd===J.current&&(Kt!=null&&Kt.summary)&&U(Kt.summary)}).catch(()=>{}),mt.scrollIntoView({block:"nearest"}),$.preventDefault()};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[j,u,U,a]),f.useEffect(()=>{w==="archive"&&ht.current&&(ht.current=!1,requestAnimationFrame(()=>{var C,$;(C=pt.current)==null||C.focus(),($=pt.current)==null||$.select()}))},[w]);const Ts=f.useCallback(()=>{T(!0)},[]),bs=f.useCallback(()=>{T(!1)},[]),il=f.useCallback(()=>{if(a)return Promise.allSettled([F(a,S,d),ni(a).then(me)])},[a,S,d,F]),D=f.useCallback((C,$,A="error",Q=null)=>{if(A==="warning"&&$e&&$)return;const ne=++V.current;G(ie=>[...ie,{id:ne,text:C,locator:$,type:A,headline:Q}])},[$e]),le=f.useCallback(C=>{G($=>$.filter(A=>A.id!==C))},[]),st=f.useCallback(()=>{sessionStorage.setItem("ublockWarningIgnored","true"),Le(!0),G(C=>C.filter($=>!($.type==="warning"&&$.locator)))},[]),mn=f.useCallback(C=>{oe($=>[...$,C])},[]),cr=f.useCallback(C=>{oe($=>$.filter(A=>A.id!==C))},[]),[gn,ke]=f.useState(null),[$t,Ja]=f.useState(null),Xd=f.useCallback(()=>{v&&ke(v.entry_uid)},[v]),Jd=f.useCallback(()=>ke(null),[]),Yd=f.useCallback((C,$)=>{Ja({src:C,entry:$})},[]),Gd=f.useCallback(()=>Ja(null),[]);return f.useEffect(()=>{ke(null)},[v]),f.useEffect(()=>{const C=$=>{var Q,ne,ie;if($.key!=="Escape"||z||gn)return;const A=(Q=document.activeElement)==null?void 0:Q.tagName;A==="INPUT"||A==="TEXTAREA"||A==="SELECT"||j.size>0&&($.preventDefault(),p(new Set),(ie=(ne=document.activeElement)==null?void 0:ne.blur)==null||ie.call(ne))};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[z,gn,j]),f.useEffect(()=>(document.body.classList.toggle("has-audio-bar",!!$t),()=>document.body.classList.remove("has-audio-bar")),[$t]),e==="loading"?s.jsx("div",{className:"auth-loading",children:"Loading\\u2026"}):e==="setup"?s.jsx(xm,{onComplete:()=>t("login")}):e==="login"?s.jsx(vm,{onLogin:C=>{r(C),t("authenticated")}}):xr?s.jsx(ug,{archiveId:xr.archiveId,entryUid:xr.entryUid}):s.jsx(Es.Provider,{value:{currentUser:n,setCurrentUser:r},children:s.jsxs(s.Fragment,{children:[s.jsx(wm,{archives:l,archiveId:a,onArchiveChange:O,view:w,onViewChange:H,onCaptureClick:Ts}),s.jsxs("main",{className:"app-shell",children:[s.jsxs("div",{className:"workspace",children:[w==="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:pt,className:"search-input",type:"search","aria-label":"Search archive","aria-busy":W,placeholder:"Search titles, URLs, types, tags…",value:S,onChange:C=>I(C.target.value)}),s.jsx("span",{className:"kbd",children:"⌘K"})]}),s.jsxs("span",{className:"result-count",children:[b&&s.jsxs(s.Fragment,{children:[s.jsx("b",{children:b.split(" ")[0]})," ",b.split(" ").slice(1).join(" ")]}),d&&s.jsxs("button",{className:"tag-filter-badge",onClick:ze,children:["× ",N?Md(d):d]})]})]}),w==="archive"&&s.jsx(Tm,{entries:u,selectedUids:j,onRowClick:X,archiveId:a,pendingCaptures:fe,deletedUids:y}),w==="runs"&&s.jsx(Lm,{runs:ee}),w==="admin"&&s.jsx(Rm,{archives:l}),w==="tags"&&s.jsx(Im,{archiveId:a,tagNodes:de,tagFilter:d,onTagFilterSet:pe,onViewChange:H,onTagRenamed:We,onTagDeleted:Ve,onTagsRefresh:Ue,humanizeTags:N}),w==="collections"&&s.jsx($m,{archiveId:a}),w==="settings"&&s.jsx(Am,{tab:P,onTabChange:_,archiveId:a})]}),s.jsx(Qm,{archiveId:a,selectedEntry:v,selectedUids:j,selectedEntries:sl,detail:He,onTagFilterSet:pe,tagNodes:de,onTagsRefresh:Ue,onEntryTitleChange:xe,onEntryDeleted:Qe,onBulkDeleted:ll,humanizeTags:N,onDetailRefresh:Dt,onOpenPreview:Xd,onPlay:Yd})]}),gn&&v&&v.entry_uid===gn&&s.jsx(ag,{archiveId:a,entry:v,detail:He,onClose:Jd}),$t&&s.jsx(og,{entry:$t.entry,src:$t.src,archiveId:a,onClose:Gd}),s.jsx(jm,{open:z,archiveId:a,onClose:bs,onCaptured:il,onToast:D,activeJobs:fe,onJobStarted:mn,onJobSettled:cr}),s.jsx(dg,{toasts:B,onDismiss:le,onIgnoreUblock:st})]})})}Id(document.getElementById("root")).render(s.jsx(f.StrictMode,{children:s.jsx(yg,{})}));