(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 Su={exports:{}},ps={},Nu={exports:{}},ne={};/** * @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 ll=Symbol.for("react.element"),tf=Symbol.for("react.portal"),nf=Symbol.for("react.fragment"),rf=Symbol.for("react.strict_mode"),lf=Symbol.for("react.profiler"),sf=Symbol.for("react.provider"),af=Symbol.for("react.context"),of=Symbol.for("react.forward_ref"),uf=Symbol.for("react.suspense"),cf=Symbol.for("react.memo"),df=Symbol.for("react.lazy"),to=Symbol.iterator;function ff(e){return e===null||typeof e!="object"?null:(e=to&&e[to]||e["@@iterator"],typeof e=="function"?e:null)}var _u={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Cu=Object.assign,Eu={};function ur(e,t,n){this.props=e,this.context=t,this.refs=Eu,this.updater=n||_u}ur.prototype.isReactComponent={};ur.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")};ur.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function bu(){}bu.prototype=ur.prototype;function ea(e,t,n){this.props=e,this.context=t,this.refs=Eu,this.updater=n||_u}var ta=ea.prototype=new bu;ta.constructor=ea;Cu(ta,ur.prototype);ta.isPureReactComponent=!0;var no=Array.isArray,Tu=Object.prototype.hasOwnProperty,na={current:null},Pu={key:!0,ref:!0,__self:!0,__source:!0};function Lu(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)&&!Pu.hasOwnProperty(r)&&(l[r]=t[r]);var o=arguments.length-2;if(o===1)l.children=n;else if(1>>1,Q=I[ee];if(0>>1;eel(Ie,U))jel(We,Ie)?(I[ee]=We,I[je]=U,ee=je):(I[ee]=Ie,I[fe]=U,ee=fe);else if(jel(We,U))I[ee]=We,I[je]=U,ee=je;else break e}}return b}function l(I,b){var U=I.sortIndex-b.sortIndex;return U!==0?U:I.id-b.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=[],g=1,h=null,m=3,x=!1,v=!1,j=!1,S=typeof setTimeout=="function"?setTimeout:null,p=typeof clearTimeout=="function"?clearTimeout:null,f=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function y(I){for(var b=n(c);b!==null;){if(b.callback===null)r(c);else if(b.startTime<=I)r(c),b.sortIndex=b.expirationTime,t(u,b);else break;b=n(c)}}function w(I){if(j=!1,y(I),!v)if(n(u)!==null)v=!0,ve(E);else{var b=n(c);b!==null&&re(w,b.startTime-I)}}function E(I,b){v=!1,j&&(j=!1,p(N),N=-1),x=!0;var U=m;try{for(y(b),h=n(u);h!==null&&(!(h.expirationTime>b)||I&&!q());){var ee=h.callback;if(typeof ee=="function"){h.callback=null,m=h.priorityLevel;var Q=ee(h.expirationTime<=b);b=e.unstable_now(),typeof Q=="function"?h.callback=Q:h===n(u)&&r(u),y(b)}else r(u);h=n(u)}if(h!==null)var de=!0;else{var fe=n(c);fe!==null&&re(w,fe.startTime-b),de=!1}return de}finally{h=null,m=U,x=!1}}var L=!1,_=null,N=-1,R=5,P=-1;function q(){return!(e.unstable_now()-PI||125ee?(I.sortIndex=U,t(c,I),n(u)===null&&I===n(c)&&(j?(p(N),N=-1):j=!0,re(w,U-ee))):(I.sortIndex=Q,t(u,I),v||x||(v=!0,ve(E))),I},e.unstable_shouldYield=q,e.unstable_wrapCallback=function(I){var b=m;return function(){var U=m;m=b;try{return I.apply(this,arguments)}finally{m=U}}}})($u);Du.exports=$u;var Sf=Du.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 Nf=d,ut=Sf;function z(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"),oi=Object.prototype.hasOwnProperty,_f=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,lo={},so={};function Cf(e){return oi.call(so,e)?!0:oi.call(lo,e)?!1:_f.test(e)?so[e]=!0:(lo[e]=!0,!1)}function Ef(e,t,n,r){if(n!==null&&n.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function bf(e,t,n,r){if(t===null||typeof t>"u"||Ef(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 Xe(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 Ae={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Ae[e]=new Xe(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];Ae[t]=new Xe(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Ae[e]=new Xe(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Ae[e]=new Xe(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){Ae[e]=new Xe(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Ae[e]=new Xe(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Ae[e]=new Xe(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Ae[e]=new Xe(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Ae[e]=new Xe(e,5,!1,e.toLowerCase(),null,!1,!1)});var la=/[\-:]([a-z])/g;function sa(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(la,sa);Ae[t]=new Xe(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(la,sa);Ae[t]=new Xe(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(la,sa);Ae[t]=new Xe(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Ae[e]=new Xe(e,1,!1,e.toLowerCase(),null,!1,!1)});Ae.xlinkHref=new Xe("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Ae[e]=new Xe(e,1,!1,e.toLowerCase(),null,!0,!0)});function ia(e,t,n,r){var l=Ae.hasOwnProperty(t)?Ae[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:"")?_r(e):""}function Tf(e){switch(e.tag){case 5:return _r(e.type);case 16:return _r("Lazy");case 13:return _r("Suspense");case 19:return _r("SuspenseList");case 0:case 2:case 15:return e=Is(e.type,!1),e;case 11:return e=Is(e.type.render,!1),e;case 1:return e=Is(e.type,!0),e;default:return""}}function fi(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 An:return"Fragment";case On:return"Portal";case ui:return"Profiler";case aa:return"StrictMode";case ci:return"Suspense";case di:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Mu:return(e.displayName||"Context")+".Consumer";case Au:return(e._context.displayName||"Context")+".Provider";case oa:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ua:return t=e.displayName||null,t!==null?t:fi(e.type)||"Memo";case Xt:t=e._payload,e=e._init;try{return fi(e(t))}catch{}}return null}function Pf(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 fi(t);case 8:return t===aa?"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 Bu(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function Lf(e){var t=Bu(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 dl(e){e._valueTracker||(e._valueTracker=Lf(e))}function Uu(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=Bu(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function Bl(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 pi(e,t){var n=t.checked;return ke({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function ao(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&&ia(e,"checked",t,!1)}function hi(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")?mi(e,t.type,n):t.hasOwnProperty("defaultValue")&&mi(e,t.type,cn(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function oo(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 mi(e,t,n){(t!=="number"||Bl(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var Cr=Array.isArray;function Xn(e,t,n,r){if(e=e.options,t){t={};for(var l=0;l"+t.valueOf().toString()+"",t=fl.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Br(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Lr={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},Rf=["Webkit","ms","Moz","O"];Object.keys(Lr).forEach(function(e){Rf.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Lr[t]=Lr[e]})});function Ku(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Lr.hasOwnProperty(e)&&Lr[e]?(""+t).trim():t+"px"}function qu(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,l=Ku(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,l):e[n]=l}}var zf=ke({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 vi(e,t){if(t){if(zf[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(z(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(z(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(z(61))}if(t.style!=null&&typeof t.style!="object")throw Error(z(62))}}function xi(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 wi=null;function ca(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var ki=null,Jn=null,Gn=null;function fo(e){if(e=al(e)){if(typeof ki!="function")throw Error(z(280));var t=e.stateNode;t&&(t=vs(t),ki(e.stateNode,e.type,t))}}function Xu(e){Jn?Gn?Gn.push(e):Gn=[e]:Jn=e}function Ju(){if(Jn){var e=Jn,t=Gn;if(Gn=Jn=null,fo(e),t)for(e=0;e>>=0,e===0?32:31-(Wf(e)/Vf|0)|0}var pl=64,hl=4194304;function Er(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 Vl(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=Er(o):(i&=a,i!==0&&(r=Er(i)))}else a=n&~l,a!==0?r=Er(a):i!==0&&(r=Er(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 sl(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Ct(t),e[t]=n}function Xf(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=zr),ko=" ",jo=!1;function gc(e,t){switch(e){case"keyup":return Sp.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function yc(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Mn=!1;function _p(e,t){switch(e){case"compositionend":return yc(t);case"keypress":return t.which!==32?null:(jo=!0,ko);case"textInput":return e=t.data,e===ko&&jo?null:e;default:return null}}function Cp(e,t){if(Mn)return e==="compositionend"||!va&&gc(e,t)?(e=hc(),Ll=ma=Zt=null,Mn=!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=Co(n)}}function kc(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?kc(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function jc(){for(var e=window,t=Bl();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=Bl(e.document)}return t}function xa(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 Dp(e){var t=jc(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&kc(n.ownerDocument.documentElement,n)){if(r!==null&&xa(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=Eo(n,i);var a=Eo(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,Fn=null,Ei=null,Dr=null,bi=!1;function bo(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;bi||Fn==null||Fn!==Bl(r)||(r=Fn,"selectionStart"in r&&xa(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}),Dr&&Kr(Dr,r)||(Dr=r,r=ql(Ei,"onSelect"),0Hn||(e.current=Ii[Hn],Ii[Hn]=null,Hn--)}function ce(e,t){Hn++,Ii[Hn]=e.current,e.current=t}var dn={},He=pn(dn),Ze=pn(!1),_n=dn;function rr(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 et(e){return e=e.childContextTypes,e!=null}function Jl(){he(Ze),he(He)}function Do(e,t,n){if(He.current!==dn)throw Error(z(168));ce(He,t),ce(Ze,n)}function Lc(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(z(108,Pf(e)||"Unknown",l));return ke({},n,r)}function Gl(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||dn,_n=He.current,ce(He,e),ce(Ze,Ze.current),!0}function $o(e,t,n){var r=e.stateNode;if(!r)throw Error(z(169));n?(e=Lc(e,t,_n),r.__reactInternalMemoizedMergedChildContext=e,he(Ze),he(He),ce(He,e)):he(Ze),ce(Ze,n)}var Ot=null,xs=!1,qs=!1;function Rc(e){Ot===null?Ot=[e]:Ot.push(e)}function Kp(e){xs=!0,Rc(e)}function hn(){if(!qs&&Ot!==null){qs=!0;var e=0,t=ae;try{var n=Ot;for(ae=1;e>=a,l-=a,At=1<<32-Ct(t)+l|n<N?(R=_,_=null):R=_.sibling;var P=m(p,_,y[N],w);if(P===null){_===null&&(_=R);break}e&&_&&P.alternate===null&&t(p,_),f=i(P,f,N),L===null?E=P:L.sibling=P,L=P,_=R}if(N===y.length)return n(p,_),ye&&yn(p,N),E;if(_===null){for(;NN?(R=_,_=null):R=_.sibling;var q=m(p,_,P.value,w);if(q===null){_===null&&(_=R);break}e&&_&&q.alternate===null&&t(p,_),f=i(q,f,N),L===null?E=q:L.sibling=q,L=q,_=R}if(P.done)return n(p,_),ye&&yn(p,N),E;if(_===null){for(;!P.done;N++,P=y.next())P=h(p,P.value,w),P!==null&&(f=i(P,f,N),L===null?E=P:L.sibling=P,L=P);return ye&&yn(p,N),E}for(_=r(p,_);!P.done;N++,P=y.next())P=x(_,p,N,P.value,w),P!==null&&(e&&P.alternate!==null&&_.delete(P.key===null?N:P.key),f=i(P,f,N),L===null?E=P:L.sibling=P,L=P);return e&&_.forEach(function(V){return t(p,V)}),ye&&yn(p,N),E}function S(p,f,y,w){if(typeof y=="object"&&y!==null&&y.type===An&&y.key===null&&(y=y.props.children),typeof y=="object"&&y!==null){switch(y.$$typeof){case cl:e:{for(var E=y.key,L=f;L!==null;){if(L.key===E){if(E=y.type,E===An){if(L.tag===7){n(p,L.sibling),f=l(L,y.props.children),f.return=p,p=f;break e}}else if(L.elementType===E||typeof E=="object"&&E!==null&&E.$$typeof===Xt&&Mo(E)===L.type){n(p,L.sibling),f=l(L,y.props),f.ref=kr(p,L,y),f.return=p,p=f;break e}n(p,L);break}else t(p,L);L=L.sibling}y.type===An?(f=Nn(y.props.children,p.mode,w,y.key),f.return=p,p=f):(w=Ml(y.type,y.key,y.props,null,p.mode,w),w.ref=kr(p,f,y),w.return=p,p=w)}return a(p);case On:e:{for(L=y.key;f!==null;){if(f.key===L)if(f.tag===4&&f.stateNode.containerInfo===y.containerInfo&&f.stateNode.implementation===y.implementation){n(p,f.sibling),f=l(f,y.children||[]),f.return=p,p=f;break e}else{n(p,f);break}else t(p,f);f=f.sibling}f=ni(y,p.mode,w),f.return=p,p=f}return a(p);case Xt:return L=y._init,S(p,f,L(y._payload),w)}if(Cr(y))return v(p,f,y,w);if(gr(y))return j(p,f,y,w);kl(p,y)}return typeof y=="string"&&y!==""||typeof y=="number"?(y=""+y,f!==null&&f.tag===6?(n(p,f.sibling),f=l(f,y),f.return=p,p=f):(n(p,f),f=ti(y,p.mode,w),f.return=p,p=f),a(p)):n(p,f)}return S}var sr=$c(!0),Oc=$c(!1),es=pn(null),ts=null,Qn=null,Sa=null;function Na(){Sa=Qn=ts=null}function _a(e){var t=es.current;he(es),e._currentValue=t}function Oi(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 Zn(e,t){ts=e,Sa=Qn=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Ye=!0),e.firstContext=null)}function xt(e){var t=e._currentValue;if(Sa!==e)if(e={context:e,memoizedValue:t,next:null},Qn===null){if(ts===null)throw Error(z(308));Qn=e,ts.dependencies={lanes:0,firstContext:e}}else Qn=Qn.next=e;return t}var wn=null;function Ca(e){wn===null?wn=[e]:wn.push(e)}function Ac(e,t,n,r){var l=t.interleaved;return l===null?(n.next=n,Ca(t)):(n.next=l.next,l.next=n),t.interleaved=n,Ht(e,r)}function Ht(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 Ea(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Mc(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 Ft(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,se&2){var l=r.pending;return l===null?t.next=t:(t.next=l.next,l.next=t),r.pending=t,Ht(e,n)}return l=r.interleaved,l===null?(t.next=t,Ca(r)):(t.next=l.next,l.next=t),r.interleaved=t,Ht(e,n)}function zl(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,fa(e,n)}}function Fo(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 ns(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 g=e.alternate;g!==null&&(g=g.updateQueue,o=g.lastBaseUpdate,o!==a&&(o===null?g.firstBaseUpdate=c:o.next=c,g.lastBaseUpdate=u))}if(i!==null){var h=l.baseState;a=0,g=c=u=null,o=i;do{var m=o.lane,x=o.eventTime;if((r&m)===m){g!==null&&(g=g.next={eventTime:x,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var v=e,j=o;switch(m=t,x=n,j.tag){case 1:if(v=j.payload,typeof v=="function"){h=v.call(x,h,m);break e}h=v;break e;case 3:v.flags=v.flags&-65537|128;case 0:if(v=j.payload,m=typeof v=="function"?v.call(x,h,m):v,m==null)break e;h=ke({},h,m);break e;case 2:Jt=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,m=l.effects,m===null?l.effects=[o]:m.push(o))}else x={eventTime:x,lane:m,tag:o.tag,payload:o.payload,callback:o.callback,next:null},g===null?(c=g=x,u=h):g=g.next=x,a|=m;if(o=o.next,o===null){if(o=l.shared.pending,o===null)break;m=o,o=m.next,m.next=null,l.lastBaseUpdate=m,l.shared.pending=null}}while(!0);if(g===null&&(u=h),l.baseState=u,l.firstBaseUpdate=c,l.lastBaseUpdate=g,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 Bo(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=Js.transition;Js.transition={};try{e(!1),t()}finally{ae=n,Js.transition=r}}function nd(){return wt().memoizedState}function Gp(e,t,n){var r=on(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},rd(e))ld(t,n);else if(n=Ac(e,t,n,r),n!==null){var l=Ke();Et(n,e,r,l),sd(n,t,r)}}function Yp(e,t,n){var r=on(e),l={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(rd(e))ld(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,Ca(t)):(l.next=u.next,u.next=l),t.interleaved=l;return}}catch{}finally{}n=Ac(e,t,l,r),n!==null&&(l=Ke(),Et(n,e,r,l),sd(n,t,r))}}function rd(e){var t=e.alternate;return e===we||t!==null&&t===we}function ld(e,t){$r=ls=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function sd(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,fa(e,n)}}var ss={readContext:xt,useCallback:Fe,useContext:Fe,useEffect:Fe,useImperativeHandle:Fe,useInsertionEffect:Fe,useLayoutEffect:Fe,useMemo:Fe,useReducer:Fe,useRef:Fe,useState:Fe,useDebugValue:Fe,useDeferredValue:Fe,useTransition:Fe,useMutableSource:Fe,useSyncExternalStore:Fe,useId:Fe,unstable_isNewReconciler:!1},Zp={readContext:xt,useCallback:function(e,t){return Lt().memoizedState=[e,t===void 0?null:t],e},useContext:xt,useEffect:Ho,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,Dl(4194308,4,Gc.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Dl(4194308,4,e,t)},useInsertionEffect:function(e,t){return Dl(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=Gp.bind(null,we,e),[r.memoizedState,e]},useRef:function(e){var t=Lt();return e={current:e},t.memoizedState=e},useState:Uo,useDebugValue:Da,useDeferredValue:function(e){return Lt().memoizedState=e},useTransition:function(){var e=Uo(!1),t=e[0];return e=Jp.bind(null,e[1]),Lt().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=we,l=Lt();if(ye){if(n===void 0)throw Error(z(407));n=n()}else{if(n=t(),ze===null)throw Error(z(349));En&30||Hc(r,t,n)}l.memoizedState=n;var i={value:n,getSnapshot:t};return l.queue=i,Ho(Vc.bind(null,r,i,e),[e]),r.flags|=2048,tl(9,Wc.bind(null,r,i,n,t),void 0,null),n},useId:function(){var e=Lt(),t=ze.identifierPrefix;if(ye){var n=Mt,r=At;n=(r&~(1<<32-Ct(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=Zr++,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[Rt]=t,e[Jr]=r,md(e,t,!1,!1),t.stateNode=e;e:{switch(a=xi(n,r),n){case"dialog":pe("cancel",e),pe("close",e),l=r;break;case"iframe":case"object":case"embed":pe("load",e),l=r;break;case"video":case"audio":for(l=0;lor&&(t.flags|=128,r=!0,jr(i,!1),t.lanes=4194304)}else{if(!r)if(e=rs(a),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),jr(i,!0),i.tail===null&&i.tailMode==="hidden"&&!a.alternate&&!ye)return Be(t),null}else 2*Ne()-i.renderingStartTime>or&&n!==1073741824&&(t.flags|=128,r=!0,jr(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=Ne(),t.sibling=null,n=xe.current,ce(xe,r?n&1|2:n&1),t):(Be(t),null);case 22:case 23:return Ba(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?it&1073741824&&(Be(t),t.subtreeFlags&6&&(t.flags|=8192)):Be(t),null;case 24:return null;case 25:return null}throw Error(z(156,t.tag))}function ah(e,t){switch(ka(t),t.tag){case 1:return et(t.type)&&Jl(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return ir(),he(Ze),he(He),Pa(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Ta(t),null;case 13:if(he(xe),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(z(340));lr()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return he(xe),null;case 4:return ir(),null;case 10:return _a(t.type._context),null;case 22:case 23:return Ba(),null;case 24:return null;default:return null}}var Sl=!1,Ue=!1,oh=typeof WeakSet=="function"?WeakSet:Set,B=null;function Kn(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){Se(e,t,r)}else n.current=null}function Qi(e,t,n){try{n()}catch(r){Se(e,t,r)}}var eu=!1;function uh(e,t){if(Ti=Ql,e=jc(),xa(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,g=0,h=e,m=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;)m=h,h=x;for(;;){if(h===e)break t;if(m===n&&++c===l&&(o=a),m===i&&++g===r&&(u=a),(x=h.nextSibling)!==null)break;h=m,m=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(Pi={focusedElem:e,selectionRange:n},Ql=!1,B=t;B!==null;)if(t=B,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,B=e;else for(;B!==null;){t=B;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 j=v.memoizedProps,S=v.memoizedState,p=t.stateNode,f=p.getSnapshotBeforeUpdate(t.elementType===t.type?j:jt(t.type,j),S);p.__reactInternalSnapshotBeforeUpdate=f}break;case 3:var y=t.stateNode.containerInfo;y.nodeType===1?y.textContent="":y.nodeType===9&&y.documentElement&&y.removeChild(y.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(z(163))}}catch(w){Se(t,t.return,w)}if(e=t.sibling,e!==null){e.return=t.return,B=e;break}B=t.return}return v=eu,eu=!1,v}function Or(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&&Qi(t,n,i)}l=l.next}while(l!==r)}}function js(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 Ki(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 vd(e){var t=e.alternate;t!==null&&(e.alternate=null,vd(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Rt],delete t[Jr],delete t[zi],delete t[Vp],delete t[Qp])),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 xd(e){return e.tag===5||e.tag===3||e.tag===4}function tu(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||xd(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=Xl));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 Xi(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(Xi(e,t,n),e=e.sibling;e!==null;)Xi(e,t,n),e=e.sibling}var $e=null,St=!1;function qt(e,t,n){for(n=n.child;n!==null;)wd(e,t,n),n=n.sibling}function wd(e,t,n){if(zt&&typeof zt.onCommitFiberUnmount=="function")try{zt.onCommitFiberUnmount(hs,n)}catch{}switch(n.tag){case 5:Ue||Kn(n,t);case 6:var r=$e,l=St;$e=null,qt(e,t,n),$e=r,St=l,$e!==null&&(St?(e=$e,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):$e.removeChild(n.stateNode));break;case 18:$e!==null&&(St?(e=$e,n=n.stateNode,e.nodeType===8?Ks(e.parentNode,n):e.nodeType===1&&Ks(e,n),Vr(e)):Ks($e,n.stateNode));break;case 4:r=$e,l=St,$e=n.stateNode.containerInfo,St=!0,qt(e,t,n),$e=r,St=l;break;case 0:case 11:case 14:case 15:if(!Ue&&(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)&&Qi(n,t,a),l=l.next}while(l!==r)}qt(e,t,n);break;case 1:if(!Ue&&(Kn(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(o){Se(n,t,o)}qt(e,t,n);break;case 21:qt(e,t,n);break;case 22:n.mode&1?(Ue=(r=Ue)||n.memoizedState!==null,qt(e,t,n),Ue=r):qt(e,t,n);break;default:qt(e,t,n)}}function nu(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new oh),t.forEach(function(r){var l=vh.bind(null,e,r);n.has(r)||(n.add(r),r.then(l,l))})}}function kt(e,t){var n=t.deletions;if(n!==null)for(var r=0;rl&&(l=a),r&=~i}if(r=l,r=Ne()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*dh(r/1960))-r,10e?16:e,en===null)var r=!1;else{if(e=en,en=null,os=0,se&6)throw Error(z(331));var l=se;for(se|=4,B=e.current;B!==null;){var i=B,a=i.child;if(B.flags&16){var o=i.deletions;if(o!==null){for(var u=0;uNe()-Ma?Sn(e,0):Aa|=n),tt(e,t)}function bd(e,t){t===0&&(e.mode&1?(t=hl,hl<<=1,!(hl&130023424)&&(hl=4194304)):t=1);var n=Ke();e=Ht(e,t),e!==null&&(sl(e,t,n),tt(e,n))}function yh(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),bd(e,n)}function vh(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(z(314))}r!==null&&r.delete(t),bd(e,n)}var Td;Td=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Ze.current)Ye=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return Ye=!1,sh(e,t,n);Ye=!!(e.flags&131072)}else Ye=!1,ye&&t.flags&1048576&&zc(t,Zl,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;$l(e,t),e=t.pendingProps;var l=rr(t,He.current);Zn(t,n),l=Ra(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,et(r)?(i=!0,Gl(t)):i=!1,t.memoizedState=l.state!==null&&l.state!==void 0?l.state:null,Ea(t),l.updater=ks,t.stateNode=l,l._reactInternals=t,Mi(t,r,e,n),t=Ui(null,t,r,!0,i,n)):(t.tag=0,ye&&i&&wa(t),Qe(null,t,l,n),t=t.child),t;case 16:r=t.elementType;e:{switch($l(e,t),e=t.pendingProps,l=r._init,r=l(r._payload),t.type=r,l=t.tag=wh(r),e=jt(r,e),l){case 0:t=Bi(null,t,r,e,n);break e;case 1:t=Go(null,t,r,e,n);break e;case 11:t=Xo(null,t,r,e,n);break e;case 14:t=Jo(null,t,r,jt(r.type,e),n);break e}throw Error(z(306,r,""))}return t;case 0:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:jt(r,l),Bi(e,t,r,l,n);case 1:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:jt(r,l),Go(e,t,r,l,n);case 3:e:{if(fd(t),e===null)throw Error(z(387));r=t.pendingProps,i=t.memoizedState,l=i.element,Mc(e,t),ns(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=ar(Error(z(423)),t),t=Yo(e,t,r,n,l);break e}else if(r!==l){l=ar(Error(z(424)),t),t=Yo(e,t,r,n,l);break e}else for(at=ln(t.stateNode.containerInfo.firstChild),ot=t,ye=!0,Nt=null,n=Oc(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(lr(),r===l){t=Wt(e,t,n);break e}Qe(e,t,r,n)}t=t.child}return t;case 5:return Fc(t),e===null&&$i(t),r=t.type,l=t.pendingProps,i=e!==null?e.memoizedProps:null,a=l.children,Li(r,l)?a=null:i!==null&&Li(r,i)&&(t.flags|=32),dd(e,t),Qe(e,t,a,n),t.child;case 6:return e===null&&$i(t),null;case 13:return pd(e,t,n);case 4:return ba(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=sr(t,null,r,n):Qe(e,t,r,n),t.child;case 11:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:jt(r,l),Xo(e,t,r,l,n);case 7:return Qe(e,t,t.pendingProps,n),t.child;case 8:return Qe(e,t,t.pendingProps.children,n),t.child;case 12:return Qe(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,ce(es,r._currentValue),r._currentValue=a,i!==null)if(bt(i.value,a)){if(i.children===l.children&&!Ze.current){t=Wt(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=Ft(-1,n&-n),u.tag=2;var c=i.updateQueue;if(c!==null){c=c.shared;var g=c.pending;g===null?u.next=u:(u.next=g.next,g.next=u),c.pending=u}}i.lanes|=n,u=i.alternate,u!==null&&(u.lanes|=n),Oi(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(z(341));a.lanes|=n,o=a.alternate,o!==null&&(o.lanes|=n),Oi(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}Qe(e,t,l.children,n),t=t.child}return t;case 9:return l=t.type,r=t.pendingProps.children,Zn(t,n),l=xt(l),r=r(l),t.flags|=1,Qe(e,t,r,n),t.child;case 14:return r=t.type,l=jt(r,t.pendingProps),l=jt(r.type,l),Jo(e,t,r,l,n);case 15:return ud(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:jt(r,l),$l(e,t),t.tag=1,et(r)?(e=!0,Gl(t)):e=!1,Zn(t,n),id(t,r,l),Mi(t,r,l,n),Ui(null,t,r,!0,e,n);case 19:return hd(e,t,n);case 22:return cd(e,t,n)}throw Error(z(156,t.tag))};function Pd(e,t){return rc(e,t)}function xh(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 yt(e,t,n,r){return new xh(e,t,n,r)}function Ha(e){return e=e.prototype,!(!e||!e.isReactComponent)}function wh(e){if(typeof e=="function")return Ha(e)?1:0;if(e!=null){if(e=e.$$typeof,e===oa)return 11;if(e===ua)return 14}return 2}function un(e,t){var n=e.alternate;return n===null?(n=yt(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 Ml(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 An:return Nn(n.children,l,i,t);case aa:a=8,l|=8;break;case ui:return e=yt(12,n,t,l|2),e.elementType=ui,e.lanes=i,e;case ci:return e=yt(13,n,t,l),e.elementType=ci,e.lanes=i,e;case di:return e=yt(19,n,t,l),e.elementType=di,e.lanes=i,e;case Fu:return Ns(n,l,i,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Au:a=10;break e;case Mu:a=9;break e;case oa:a=11;break e;case ua:a=14;break e;case Xt:a=16,r=null;break e}throw Error(z(130,e==null?e:typeof e,""))}return t=yt(a,n,t,l),t.elementType=e,t.type=r,t.lanes=i,t}function Nn(e,t,n,r){return e=yt(7,e,r,t),e.lanes=n,e}function Ns(e,t,n,r){return e=yt(22,e,r,t),e.elementType=Fu,e.lanes=n,e.stateNode={isHidden:!1},e}function ti(e,t,n){return e=yt(6,e,null,t),e.lanes=n,e}function ni(e,t,n){return t=yt(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function kh(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=$s(0),this.expirationTimes=$s(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=$s(0),this.identifierPrefix=r,this.onRecoverableError=l,this.mutableSourceEagerHydrationData=null}function Wa(e,t,n,r,l,i,a,o,u){return e=new kh(e,t,n,o,u),t===1?(t=1,i===!0&&(t|=8)):t=0,i=yt(3,null,null,t),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Ea(i),e}function jh(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Id)}catch(e){console.error(e)}}Id(),Iu.exports=ct;var Eh=Iu.exports,Dd,cu=Eh;Dd=cu.createRoot,cu.hydrateRoot;async function Ee(e){const t=await fetch(e);if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()}async function bh(){return Ee("/api/archives")}async function Th(e){return Ee(`/api/archives/${e}/entries`)}async function Ph(e,t,n){const r=new URLSearchParams;return t&&r.set("q",t),n&&r.set("tag",n),Ee(`/api/archives/${e}/entries/search?${r}`)}async function Tr(e,t){return Ee(`/api/archives/${e}/entries/${t}`)}async function Lh(e,t){return Ee(`/api/archives/${e}/entries/${t}/children`)}function Rh(e,t,n){return Promise.all(n.map(r=>Ee(`/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 Ih(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 Cl(e,t){return Ee(`/api/archives/${e}/entries/${t}/tags`)}async function du(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 Dh(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 fu(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 $h(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 Oh(e,t){const n=await fetch(`/api/archives/${e}/tags/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(await n.text())}async function Ah(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 Mh(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 ri(e){return Ee(`/api/archives/${e}/runs`)}async function El(e){return Ee(`/api/archives/${e}/tags`)}async function Fh(e,t,n=null,r=null){const l={locator:t};n&&n!=="best"&&(l.quality=n),r&&(typeof r.ublock_enabled=="boolean"&&(l.ublock_enabled=r.ublock_enabled),typeof r.reader_mode=="boolean"&&(l.reader_mode=r.reader_mode),typeof r.cookie_ext_enabled=="boolean"&&(l.cookie_ext_enabled=r.cookie_ext_enabled),typeof r.modal_closer_enabled=="boolean"&&(l.modal_closer_enabled=r.modal_closer_enabled),typeof r.via_freedium=="boolean"&&(l.via_freedium=r.via_freedium),r.per_item_quality&&typeof r.per_item_quality=="object"&&Object.keys(r.per_item_quality).length>0&&(l.per_item_quality=r.per_item_quality),r.sync===!0&&(l.sync=!0));const i=await fetch(`/api/archives/${e}/captures`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!i.ok){const a=await i.json().catch(()=>({})),o=new Error(a.error||`HTTP ${i.status}`);throw o.status=i.status,o}return i.json()}async function Bh(e,t){return Ee(`/api/archives/${e}/captures/probe?locator=${encodeURIComponent(t)}`)}async function Uh(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 $d(e,t){return Ee(`/api/archives/${e}/capture_jobs/${t}`)}async function Hh(){return(await(await fetch("/api/auth/setup")).json()).setup_required===!0}async function Wh(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 Vh(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 Qh(){await fetch("/api/auth/logout",{method:"POST"})}async function Kh(){const e=await fetch("/api/auth/me");return e.status===401?null:e.json()}async function qh(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 Xh(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 Jh(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 Gh(){return Ee("/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 Zh(e){const t=await fetch(`/api/auth/tokens/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(await t.text())}async function qa(){return Ee("/api/admin/instance-settings")}async function Fl(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 em(){return Ee("/api/admin/users")}async function tm(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 nm(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 rm(){return Ee("/api/admin/roles")}async function lm(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 Od(e){return Ee(`/api/archives/${e}/collections`)}async function sm(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 im(e,t){return Ee(`/api/archives/${e}/collections/${t}`)}async function Ad(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 am(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 om(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 um(e,t){return Ee(`/api/archives/${e}/entries/${t}/collections`)}async function pu(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 cm(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 dm(e){return Ee(`/api/archives/${e}/blob-cleanup`)}async function fm(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 pm(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 hm(e,t,n){const r=await fetch(`/api/archives/${e}/entries/${t}/artifacts/${n}/media-token`,{method:"POST"});if(!r.ok)throw new Error(`media-token ${r.status}`);return r.json()}async function mm(){return Ee("/api/admin/cookie-rules")}async function gm(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 ym(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 vm(e){const t=await fetch(`/api/admin/cookie-rules/${e}`,{method:"DELETE"});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.message||`HTTP ${t.status}`)}}function xm(e,t,n){let r;return{promise:new Promise((i,a)=>{const o=new FormData;o.append("file",t),r=new XMLHttpRequest,r.open("POST",`/api/archives/${e}/uploads`),r.upload.addEventListener("progress",u=>{u.lengthComputable&&n&&n(Math.round(u.loaded/u.total*100))}),r.addEventListener("load",()=>{if(r.status>=200&&r.status<300)try{i(JSON.parse(r.responseText))}catch{a(new Error("Invalid server response"))}else{let u=`Upload failed (${r.status})`;try{u=JSON.parse(r.responseText).message||u}catch{}a(new Error(u))}}),r.addEventListener("error",()=>a(new Error("Network error during upload"))),r.addEventListener("abort",()=>a(new Error("Upload cancelled"))),r.send(o)}),abort:()=>r==null?void 0:r.abort()}}async function li(e,t){try{await fetch(`/api/archives/${e}/uploads`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({locator:t})})}catch{}}const wm=window.fetch;window.fetch=async(...e)=>{var n;const t=await wm(...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 km({onLogin:e}){const[t,n]=d.useState(""),[r,l]=d.useState(""),[i,a]=d.useState(null),[o,u]=d.useState(!1);async function c(g){g.preventDefault(),a(null),u(!0);try{const h=await Vh(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:g=>n(g.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:g=>l(g.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 jm({onComplete:e}){const[t,n]=d.useState(""),[r,l]=d.useState(""),[i,a]=d.useState(""),[o,u]=d.useState(null),[c,g]=d.useState(!1);async function h(m){if(m.preventDefault(),r!==i){u("Passwords do not match");return}if(r.length<8){u("Password must be at least 8 characters");return}u(null),g(!0);try{await Wh(t,r),e()}catch(x){u(x.message)}finally{g(!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:m=>n(m.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:m=>l(m.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:m=>a(m.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 Sm({archives:e,archiveId:t,onArchiveChange:n,view:r,onViewChange:l,onCaptureClick:i}){const{currentUser:a,setCurrentUser:o}=d.useContext(Ps)??{},[u,c]=d.useState(!1);async function g(){c(!0),await Qh(),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:g,disabled:u,children:u?"Logging out…":"Log out"})]})]})}let ds=1;function Md(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 jn(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 $n(e=""){return{id:ds++,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 Nm(e){return{id:ds++,kind:"file",filename:e,uploadProgress:0,uploadStatus:"uploading",uploadLocator:null,uploadError:null,locator:"",quality:"best",probeState:"idle",probeQualities:null,probeHasAudio:!1,playlistProbeState:"idle",playlistInfo:null,playlistItems:null,playlistQuality:null,playlistExpanded:!1,syncEnabled:!1,error:null,status:"idle"}}function _m(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 hu(e){return Array.isArray(e.playlistItems)&&e.playlistItems.some(t=>t.quality===null)}function Cm({open:e,archiveId:t,onClose:n,onCaptured:r,onToast:l,onJobStarted:i,onJobSettled:a,activeJobs:o=[]}){const u=d.useRef(null),c=d.useRef(!0),g=d.useRef(new Map),h=d.useRef(new Map),m=d.useRef(new Map),x=d.useRef(t);d.useEffect(()=>{x.current=t},[t]);const v=d.useRef(null),[j,S]=d.useState(!1),p=d.useRef([]),f=d.useRef(!1),y=d.useRef(new Map),w=d.useRef(r),E=d.useRef(l);d.useEffect(()=>{w.current=r},[r]),d.useEffect(()=>{E.current=l},[l]);const L=d.useRef(i),_=d.useRef(a);d.useEffect(()=>{L.current=i},[i]),d.useEffect(()=>{_.current=a},[a]);const[N,R]=d.useState(()=>{try{const k=JSON.parse(sessionStorage.getItem("captureItems")||"null");if(Array.isArray(k)&&k.length>0){const M=k.filter(O=>!O.status||O.status==="idle");if(M.length>0)return M.forEach(O=>{O.id>=ds&&(ds=O.id+1)}),M.map(O=>({...$n(O.locator),...O}))}}catch{}return[$n()]});d.useEffect(()=>{sessionStorage.setItem("captureItems",JSON.stringify(N.filter(k=>k.kind!=="file")))},[N]),d.useEffect(()=>{p.current=N},[N]);const[P,q]=d.useState(!1),[V,X]=d.useState(null),[Z,me]=d.useState(null),[ve,re]=d.useState(!0),[I,b]=d.useState(!0),[U,ee]=d.useState(!0);d.useEffect(()=>{qa().then(k=>{me(k),re(k.cookie_ext_enabled??!0),b(k.modal_closer_enabled??!0)}).catch(()=>me({}))},[]);const Q=V!==null?V:(Z==null?void 0:Z.ublock_enabled)??!0,[de,fe]=d.useState(!1);d.useEffect(()=>{["captureDialogLocator","captureDialogError","captureDialogBusy","captureDialogJobStatus","captureDialogJobUid"].forEach(k=>sessionStorage.removeItem(k)),o.forEach(k=>{k.jobUid&&!g.current.has(k.jobUid)&&Ie(k.id,k.jobUid,k.locator,k.archiveId,null)})},[]),d.useEffect(()=>{const k=u.current;if(!k)return;const M=()=>{if(h.current.forEach(O=>clearTimeout(O)),h.current.clear(),!f.current){const O=x.current;p.current.forEach(D=>{var H;D.kind==="file"&&(D.uploadStatus==="uploading"?((H=y.current.get(D.id))==null||H(),y.current.delete(D.id)):D.uploadStatus==="done"&&D.uploadLocator&&li(O,D.uploadLocator).catch(()=>{}))})}f.current=!1,n()};return k.addEventListener("close",M),()=>k.removeEventListener("close",M)},[n]),d.useEffect(()=>{const k=u.current;k&&(e?(c.current||R([$n()]),c.current=!1,k.open||k.showModal()):(h.current.forEach(M=>clearTimeout(M)),h.current.clear(),k.open&&k.close()))},[e]),d.useEffect(()=>()=>{g.current.forEach(k=>clearInterval(k)),h.current.forEach(k=>clearTimeout(k))},[]);function Ie(k,M,O,D,H=null){if(g.current.has(M))return;const W=setInterval(async()=>{var oe,T,J,te;try{const be=await $d(D,M);if(be.status==="completed"){clearInterval(g.current.get(M)),g.current.delete(M),await Promise.resolve((oe=w.current)==null?void 0:oe.call(w)),(T=_.current)==null||T.call(_,k);try{const ge=be.notes_json?JSON.parse(be.notes_json):null;if(ge!=null&&ge.ublock_skipped||ge!=null&&ge.cookie_ext_skipped){const ie=ge.ublock_skipped&&ge.cookie_ext_skipped?"Captured without ad-blocking or cookie-consent extension. Check ARCHIVR_UBLOCK_EXT and ARCHIVR_COOKIE_EXT in your server config.":ge.ublock_skipped?"Captured without ad-blocking. ARCHIVR_UBLOCK=true but ARCHIVR_UBLOCK_EXT is not set or the path is invalid.":"Captured without cookie-consent extension. ARCHIVR_COOKIE_EXT is not set or the path is invalid.";E.current(ie,O,"warning"),je(H,"warning",O)}else H||E.current(null,O,"success"),je(H,"archived")}catch{H||E.current(null,O,"success"),je(H,"archived")}}else if(be.status==="failed"){clearInterval(g.current.get(M)),g.current.delete(M),(J=_.current)==null||J.call(_,k);const ge=be.error_text||"Capture failed.";E.current(ge,O),je(H,"failed",O)}}catch(be){clearInterval(g.current.get(M)),g.current.delete(M),(te=_.current)==null||te.call(_,k);const ge=be.message||"Network error";E.current(ge,O),je(H,"failed",O)}},500);g.current.set(M,W)}function je(k,M,O=null){if(!k)return;const D=m.current.get(k);if(!D||(M==="archived"||M==="warning"?(D.archived++,M==="warning"&&(D.warnings++,O&&D.warningLocators.push(O))):(D.failed++,O&&D.failedLocators.push(O)),D.archived+D.failed0?`${H} archived (${W} with warnings)`:`${H} archived`;te=oe>0?`${ie}, ${oe} failed`:ie}const be=H===0?"error":oe>0||W>0?"warning":"success",ge=[];T.length>0&&ge.push(`Failed: ${T.map(ie=>` ${ie}`).join(` `)}`),J.length>0&&ge.push(`With warnings: ${J.map(ie=>` ${ie}`).join(` `)}`);const Tt=ge.length>0?ge.join(` `):null;E.current(Tt,null,be,te)}async function We(k,M,O,D={}){var T,J;const H=x.current,W=((T=crypto.randomUUID)==null?void 0:T.call(crypto))??`job-${Date.now()}-${Math.random()}`,oe={ublock_enabled:Q,reader_mode:de,cookie_ext_enabled:ve,modal_closer_enabled:I,via_freedium:U,...D};try{const te=await Fh(H,k,M,oe);(J=L.current)==null||J.call(L,{id:W,jobUid:te.job_uid,locator:k,archiveId:H}),Ie(W,te.job_uid,k,H,O)}catch(te){const be=te.message||"Submission failed.";E.current(be,k),je(O,"failed",k),k.startsWith("file://")&&te.status&&li(H,k).catch(()=>{})}}function nt(){var D,H;if(N.some(W=>W.kind==="file"&&W.uploadStatus==="uploading"))return;const k=N.filter(W=>W.kind==="file"?W.uploadStatus==="done"&&W.uploadLocator:W.locator.trim());if(k.length===0||k.some(W=>W.kind!=="file"&&hu(W))||k.some(W=>W.kind!=="file"&&(W.probeState==="probing"||jn(W.locator)&&W.playlistProbeState!=="done"))||k.some(W=>W.kind!=="file"&&Array.isArray(W.playlistItems)&&W.playlistItems.length===0))return;const M=k.length>1?((D=crypto.randomUUID)==null?void 0:D.call(crypto))??`batch-${Date.now()}`:null;M&&m.current.set(M,{total:k.length,archived:0,warnings:0,failed:0,failedLocators:[],warningLocators:[]});const O=k.map(W=>W.kind==="file"?{locator:W.uploadLocator,quality:"best",extraExtensions:{}}:{locator:W.locator.trim(),quality:W.playlistItems!==null?null:W.quality||"best",extraExtensions:W.playlistItems!==null?{per_item_quality:Object.fromEntries(W.playlistItems.map(oe=>[oe.id,oe.quality])),sync:W.syncEnabled}:{}});f.current=!0,R([$n()]),(H=u.current)==null||H.close(),O.forEach(({locator:W,quality:oe,extraExtensions:T})=>We(W,oe,M,T))}function rt(){R(k=>[...k,$n()])}function lt(k){var O;clearTimeout(h.current.get(k)),h.current.delete(k);const M=p.current.find(D=>D.id===k);(M==null?void 0:M.kind)==="file"&&(M.uploadStatus==="uploading"?((O=y.current.get(k))==null||O(),y.current.delete(k)):M.uploadStatus==="done"&&M.uploadLocator&&li(x.current,M.uploadLocator).catch(()=>{})),R(D=>{const H=D.filter(W=>W.id!==k);return H.length===0?[$n()]:H})}function ft(k,M){if(clearTimeout(h.current.get(k)),R(O=>O.map(D=>D.id===k?{...D,locator:M,probeState:"idle",probeQualities:null,probeHasAudio:!1,quality:"best",playlistProbeState:"idle",playlistInfo:null,playlistItems:null,playlistQuality:null,playlistExpanded:!1}:D)),Md(M)){const O=setTimeout(async()=>{h.current.delete(k),R(D=>D.map(H=>H.id===k?{...H,probeState:"probing"}:H));try{const D=await Bh(x.current,M.trim());R(H=>H.map(W=>{if(W.id!==k||W.locator!==M)return W;const oe=D.qualities??[],T=D.has_audio??!1,J=oe.length===0&&T?"audio":"best";return{...W,probeState:"done",probeQualities:oe,probeHasAudio:T,quality:J}}))}catch{R(D=>D.map(H=>H.id===k?{...H,probeState:"idle",probeQualities:null}:H))}},600);h.current.set(k,O)}else if(jn(M)){const O=setTimeout(async()=>{h.current.delete(k),R(D=>D.map(H=>H.id===k?{...H,playlistProbeState:"probing"}:H));try{const D=await Uh(x.current,M.trim());R(H=>H.map(W=>W.id!==k||W.locator!==M?W:{...W,playlistProbeState:"done",playlistInfo:D,playlistItems:D.items.map(oe=>({...oe,quality:null})),playlistQuality:null}))}catch{R(D=>D.map(H=>H.id===k?{...H,playlistProbeState:"error"}:H))}},800);h.current.set(k,O)}}function pt(k,M){R(O=>O.map(D=>D.id===k?{...D,quality:M}:D))}function $(k,M){R(O=>O.map(D=>{if(D.id!==k)return D;const H=_m(M,D.playlistItems);return{...D,playlistQuality:M,playlistItems:H}}))}function G(k,M,O){R(D=>D.map(H=>H.id!==k?H:{...H,playlistItems:H.playlistItems.map(W=>W.id===M?{...W,quality:O}:W)}))}function _e(k){R(M=>M.map(O=>O.id===k?{...O,playlistExpanded:!O.playlistExpanded}:O))}function De(k,M){R(O=>O.map(D=>D.id===k?{...D,syncEnabled:M}:D))}function st(k,M){R(O=>O.map(D=>D.id!==k?D:{...D,playlistItems:D.playlistItems.filter(H=>H.id!==M)}))}function mn(k){const M=Array.from(k);M.length!==0&&M.forEach(O=>{const D=Nm(O.name);R(T=>T.length===1&&T[0].kind!=="file"&&!T[0].locator.trim()?[D]:[...T,D]);const H=x.current,{promise:W,abort:oe}=xm(H,O,T=>{R(J=>J.map(te=>te.id===D.id?{...te,uploadProgress:T}:te))});y.current.set(D.id,oe),W.then(T=>{y.current.delete(D.id),R(J=>J.map(te=>te.id===D.id?{...te,uploadStatus:"done",uploadLocator:T.locator,uploadProgress:100}:te))}).catch(T=>{y.current.delete(D.id),T.message!=="Upload cancelled"&&R(J=>J.map(te=>te.id===D.id?{...te,uploadStatus:"error",uploadError:T.message}:te))})})}function Rn(k){k.preventDefault(),k.stopPropagation(),k.dataTransfer.types.includes("Files")&&S(!0)}function Ve(k){k.currentTarget.contains(k.relatedTarget)||S(!1)}function zn(k){k.preventDefault(),k.stopPropagation(),S(!1),mn(k.dataTransfer.files)}function In(k){mn(k.target.files),k.target.value=""}const fr=N.some(k=>k.kind==="file"&&k.uploadStatus==="uploading"),Qt=N.filter(k=>k.kind==="file"?k.uploadStatus==="done"&&k.uploadLocator:k.locator.trim()).length,pr=N.some(k=>k.kind!=="file"&&hu(k)),hr=N.some(k=>k.kind!=="file"&&Array.isArray(k.playlistItems)&&k.playlistItems.length===0),mr=N.some(k=>k.kind!=="file"&&(k.probeState==="probing"||jn(k.locator)&&k.playlistProbeState!=="done"));return s.jsx("dialog",{ref:u,className:`capture-dialog${j?" capture-dialog--dragover":""}`,onDragOver:Rn,onDragLeave:Ve,onDrop:zn,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 k;return(k=u.current)==null?void 0:k.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:N.map((k,M)=>k.kind==="file"?s.jsx(bm,{item:k,onRemove:()=>lt(k.id)},k.id):s.jsx(Em,{item:k,autoFocus:M===N.length-1,onLocatorChange:O=>ft(k.id,O),onQualityChange:O=>pt(k.id,O),onRemove:()=>lt(k.id),onSubmit:nt,onPlaylistQualityChange:O=>$(k.id,O),onPlaylistItemQualityChange:(O,D)=>G(k.id,O,D),onPlaylistToggle:()=>_e(k.id),onSyncChange:O=>De(k.id,O),onPlaylistItemDelete:O=>st(k.id,O)},k.id))}),s.jsx("input",{ref:v,type:"file",multiple:!0,hidden:!0,onChange:In,"aria-hidden":"true",tabIndex:-1}),s.jsxs("div",{className:"capture-add-row-group",children:[s.jsxs("button",{type:"button",className:"capture-add-row",onClick:rt,children:[s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"14"}),s.jsx("line",{x1:"2",y1:"8",x2:"14",y2:"8"})]}),"Add URL"]}),s.jsxs("button",{type:"button",className:"capture-add-row capture-add-file",onClick:()=>{var k;return(k=v.current)==null?void 0:k.click()},children:[s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("rect",{x:"3",y:"1",width:"10",height:"14",rx:"1.5"}),s.jsx("line",{x1:"5.5",y1:"5.5",x2:"10.5",y2:"5.5"}),s.jsx("line",{x1:"5.5",y1:"8",x2:"10.5",y2:"8"}),s.jsx("line",{x1:"5.5",y1:"10.5",x2:"8.5",y2:"10.5"})]}),"Upload file"]})]}),s.jsxs("div",{className:"capture-advanced",children:[s.jsxs("button",{type:"button",className:"capture-advanced-toggle",onClick:()=>q(k=>!k),"aria-expanded":P,children:[s.jsx("svg",{className:`capture-chevron${P?" 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"]}),P&&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":Q,className:`ext-toggle ext-toggle--sm${Q?" ext-toggle--on":""}`,onClick:()=>X(k=>k===null?!Q:!k),"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"}),!(Z!=null&&Z.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":ve,className:`ext-toggle ext-toggle--sm${ve?" ext-toggle--on":""}`,onClick:()=>re(k=>!k),"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":de,className:`ext-toggle ext-toggle--sm${de?" ext-toggle--on":""}`,onClick:()=>fe(k=>!k),"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":I,className:`ext-toggle ext-toggle--sm${I?" ext-toggle--on":""}`,onClick:()=>b(k=>!k),"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":U,className:`ext-toggle ext-toggle--sm${U?" ext-toggle--on":""}`,onClick:()=>ee(k=>!k),"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:nt,disabled:Qt===0||pr||mr||hr||fr,children:Qt>1?`Archive ${Qt}`:"Archive"}),s.jsx("button",{type:"button",className:"capture-cancel",onClick:()=>{var k;return(k=u.current)==null?void 0:k.close()},children:"Cancel"})]})]})})}function Em({item:e,autoFocus:t,onLocatorChange:n,onQualityChange:r,onRemove:l,onSubmit:i,onPlaylistQualityChange:a,onPlaylistItemQualityChange:o,onPlaylistToggle:u,onSyncChange:c,onPlaylistItemDelete:g}){const h=d.useRef(null);d.useEffect(()=>{var v;t&&((v=h.current)==null||v.focus())},[t]);const m=(()=>{if(jn(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(f=>parseInt(f))))].sort((p,f)=>f-p),j=e.playlistItems.every(p=>p.has_audio),S=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)),j&&s.jsx("option",{value:"audio",children:"Audio only"})]}),S>0&&s.jsxs("span",{className:"capture-conflict-badge",children:[S," 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(!Md(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??[],j=e.probeHasAudio??!1;return v.length===0&&!j?s.jsx("span",{className:"capture-quality-hint",children:"No media detected"}):v.length===0&&j?s.jsx("select",{className:"capture-quality",value:"audio",onChange:S=>r(S.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:S=>r(S.target.value),"aria-label":"Video quality",children:[s.jsx("option",{value:"best",children:"Best quality"}),v.map(S=>s.jsx("option",{value:S,children:S},S)),j&&s.jsx("option",{value:"audio",children:"Audio only"})]})}return null})(),x=jn(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:[jn(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}),m,s.jsx("button",{type:"button",className:"capture-row-action capture-row-remove",onClick:l,"aria-label":"Remove",children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),s.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),e.error&&s.jsx("p",{className:"capture-row-error",children:e.error}),jn(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:j=>o(v.id,j.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(j=>s.jsx("option",{value:j,children:j},j)),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:()=>g(v.id),children:"×"})]},v.id)),x]}):x]})}function bm({item:e,onRemove:t}){const n=e.uploadStatus==="uploading",r=e.uploadStatus==="done",l=e.uploadStatus==="error";return s.jsxs("div",{className:"capture-row",children:[s.jsxs("div",{className:"capture-row-main",children:[s.jsx("span",{className:"capture-file-icon","aria-hidden":"true",children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",style:{width:14,height:14},children:[s.jsx("rect",{x:"3",y:"1",width:"10",height:"14",rx:"1.5"}),s.jsx("line",{x1:"5.5",y1:"5.5",x2:"10.5",y2:"5.5"}),s.jsx("line",{x1:"5.5",y1:"8",x2:"10.5",y2:"8"}),s.jsx("line",{x1:"5.5",y1:"10.5",x2:"8.5",y2:"10.5"})]})}),s.jsx("span",{className:`capture-file-name${l?" capture-file-name--error":""}`,children:e.filename}),n&&s.jsxs("span",{className:"capture-file-progress-wrap","aria-label":`Uploading ${e.uploadProgress}%`,children:[s.jsx("span",{className:"capture-file-progress-bar",children:s.jsx("span",{className:"capture-file-progress-fill",style:{width:`${e.uploadProgress}%`}})}),s.jsxs("span",{className:"capture-file-progress-pct",children:[e.uploadProgress,"%"]})]}),r&&s.jsx("span",{className:"capture-file-badge capture-file-badge--done","aria-label":"Upload complete",children:s.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{width:11,height:11},children:s.jsx("polyline",{points:"3 8.5 6.5 12 13 5"})})}),l&&s.jsx("span",{className:"capture-file-badge capture-file-badge--error",children:"!"}),s.jsx("button",{type:"button",className:"capture-row-action capture-row-remove",onClick:t,"aria-label":"Remove",disabled:n,children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),s.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),l&&s.jsx("p",{className:"capture-row-error",children:e.uploadError||"Upload failed"})]})}function Tm(){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 rl(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 _t(e){return Pm(e)??""}function Xa(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 mu={youtube:'',youtube_music:'',spotify:'',x:'',instagram:'',facebook:'',tiktok:'',reddit:'',snapchat:'',local:'',web:'',other:'?'};function Ts(e){return mu[e]??mu.other}function Fd(e){return e.split("/").map(t=>t?t.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"").join("/")}function Lm({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:Xa(e.archived_at)}),s.jsxs("div",{className:"col-title",children:[s.jsx("span",{className:"source-icon",children:s.jsx("span",{dangerouslySetInnerHTML:{__html:Ts(e.source_kind)}})}),s.jsx("span",{className:"entry-title",children:_t(e.title)||_t(e.entry_uid)})]}),s.jsx("div",{className:"col-type",children:s.jsx("span",{className:"type-pill",children:_t(e.entity_kind)})}),s.jsx("div",{className:"col-size",children:s.jsx("span",{className:"size-total",children:rl(e.total_artifact_bytes)})}),s.jsx("div",{className:"url-cell col-url",children:_t(e.original_url)})]})}function Rm({entry:e,archiveId:t,rowIndex:n,isSelected:r,isMultiSelected:l,onRowClick:i,selectedUids:a,deletedUids:o}){const[u,c]=d.useState(!1),[g,h]=d.useState(!1),[m,x]=d.useState(null),[v,j]=d.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:Ts(e.source_kind)}}),f=r||l,y=e.child_count>0;function w(_){_.stopPropagation(),i(e,{ctrlKey:!0,metaKey:!1,shiftKey:!1,preventDefault(){}})}async function E(_){if(_.stopPropagation(),g){h(!1);return}if(h(!0),m===null&&!v){j(!0);try{const N=await Lh(t,e.entry_uid);x(N)}catch{x([])}finally{j(!1)}}}const L=["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:L,"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${f?" is-checked":""}`,"aria-pressed":f,"aria-label":f?"Deselect entry":"Select entry",onClick:w,onKeyDown:_=>_.stopPropagation()})}),s.jsx("div",{className:"col-added",children:Xa(e.archived_at)}),s.jsxs("div",{className:"col-title",children:[y&&s.jsx("button",{type:"button",className:`entry-expand-btn${g?" is-expanded":""}`,"aria-label":g?"Collapse children":`Expand ${e.child_count} items`,"aria-expanded":g,onClick:E,onKeyDown:_=>_.stopPropagation()}),s.jsx("span",{className:"source-icon",children:p}),s.jsx("span",{className:"entry-title",children:_t(e.title)||_t(e.entry_uid)}),y&&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:_t(e.entity_kind)})}),s.jsxs("div",{className:"col-size",children:[s.jsx("span",{className:"size-total",children:rl(e.total_artifact_bytes)}),e.cached_bytes>0&&e.cacheable_bytes>0&&s.jsxs("span",{className:"size-cached-pct",title:`${rl(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:_t(e.original_url)})]}),g&&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:m&&m.filter(_=>!(o!=null&&o.has(_.entry_uid))).map((_,N)=>s.jsx(Lm,{entry:_,index:N,onRowClick:i,selectedUids:a},_.entry_uid))})]})]})}function zm({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(Tm,{},a.id)),e.map((a,o)=>s.jsx(Rm,{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 Im(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 Dm({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 $m({runs:e}){const[t,n]=d.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:Im(l.started_at)}),s.jsxs("td",{children:[s.jsx(Dm,{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 Om=4;function Am({archives:e}){const{currentUser:t}=d.useContext(Ps)??{},n=t&&(t.role_bits&Om)!==0,[r,l]=d.useState("users"),[i,a]=d.useState([]),[o,u]=d.useState([]),[c,g]=d.useState(!1),[h,m]=d.useState(null),[x,v]=d.useState(""),[j,S]=d.useState(""),[p,f]=d.useState(""),[y,w]=d.useState(null),[E,L]=d.useState(!1),[_,N]=d.useState(""),[R,P]=d.useState(""),[q,V]=d.useState(null),[X,Z]=d.useState(!1),me=d.useCallback(async()=>{if(n){g(!0),m(null);try{const[b,U]=await Promise.all([em(),rm()]);a(b),u(U)}catch(b){m(b.message)}finally{g(!1)}}},[n]);d.useEffect(()=>{me()},[me]);async function ve(b){const U=b.status==="active"?"disabled":"active";try{await nm(b.user_uid,U),a(ee=>ee.map(Q=>Q.user_uid===b.user_uid?{...Q,status:U}:Q))}catch(ee){m(ee.message)}}async function re(b){if(b.preventDefault(),!x.trim()||!j){w("Username and password required");return}L(!0),w(null);try{await tm(x.trim(),j,p.trim()||void 0),v(""),S(""),f(""),await me()}catch(U){w(U.message)}finally{L(!1)}}async function I(b){if(b.preventDefault(),!_.trim()||!R.trim()){V("Slug and name required");return}Z(!0),V(null);try{await lm(_.trim(),R.trim()),N(""),P(""),await me()}catch(U){V(U.message)}finally{Z(!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(b=>s.jsxs("tr",{className:b.status==="disabled"?"admin-row-disabled":"",children:[s.jsx("td",{children:b.username}),s.jsx("td",{className:"muted",children:b.email||"—"}),s.jsx("td",{children:b.role_slugs.join(", ")||"—"}),s.jsx("td",{children:s.jsx("span",{className:`status-badge status-${b.status}`,children:b.status})}),s.jsx("td",{children:s.jsx("button",{className:"admin-action-btn",onClick:()=>ve(b),children:b.status==="active"?"Ban":"Unban"})})]},b.user_uid))})]}),s.jsx("h3",{children:"Create User"}),s.jsxs("form",{className:"admin-form",onSubmit:re,children:[s.jsx("input",{className:"admin-input",placeholder:"Username",value:x,onChange:b=>v(b.target.value),required:!0}),s.jsx("input",{className:"admin-input",type:"password",placeholder:"Password (min 8 chars)",value:j,onChange:b=>S(b.target.value),required:!0}),s.jsx("input",{className:"admin-input",type:"email",placeholder:"Email (optional)",value:p,onChange:b=>f(b.target.value)}),y&&s.jsx("div",{className:"form-msg form-msg--err",children:y}),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(b=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx("code",{children:b.slug})}),s.jsx("td",{children:b.name}),s.jsx("td",{children:b.level}),s.jsx("td",{children:b.bit_position}),s.jsx("td",{children:b.is_builtin?"✓":""})]},b.role_uid))})]}),s.jsx("h3",{children:"Create Custom Role"}),s.jsxs("form",{className:"admin-form",onSubmit:I,children:[s.jsx("input",{className:"admin-input",placeholder:"Slug (e.g. moderator)",value:_,onChange:b=>N(b.target.value),required:!0}),s.jsx("input",{className:"admin-input",placeholder:"Display Name (e.g. Moderator)",value:R,onChange:b=>P(b.target.value),required:!0}),q&&s.jsx("div",{className:"form-msg form-msg--err",children:q}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:X,children:X?"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(b=>s.jsxs("div",{className:"admin-archive",children:[s.jsx("strong",{children:b.label}),s.jsx("div",{className:"muted",children:b.archive_path})]},b.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(b=>s.jsxs("div",{className:"admin-archive",children:[s.jsx("strong",{children:b.label}),s.jsx("div",{className:"muted",children:b.archive_path})]},b.id))})]})}function Bd({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(Bd,{node:r,onPick:t},r.tag.tag_uid))})})]})}function gu({title:e,tagNodes:t,excludeUid:n,onPick:r,onCancel:l}){d.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(Bd,{node:o,onPick:r},o.tag.tag_uid))}):s.jsx("p",{className:"tag-picker-empty",children:"No other tags available."})]})]})})}function Ud({parentPath:e,archiveId:t,onDone:n,onCancel:r}){const[l,i]=d.useState(""),a=d.useRef(!1);async function o(){const u=l.trim();if(!u){r();return}const c=e?`${e}/${u}`:`/${u}`;try{await Ah(t,c),n()}catch(g){alert(g.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:g,pendingCreateParentUid:h,onCreateDone:m,onCreateCancel:x}){var q;const v=n===e.tag.full_path,[j,S]=d.useState(!1),[p,f]=d.useState(""),y=d.useRef(!1);function w(){if(j)return;if(c){g(e);return}const V=v?null:e.tag.full_path;r(V),l("archive")}function E(V){V.stopPropagation(),!c&&(f(e.tag.slug),S(!0))}async function L(){const V=p.trim();if(!V||V===e.tag.slug){S(!1);return}try{const X=await $h(t,e.tag.tag_uid,V);i(e.tag.full_path,X.full_path),o()}catch{}finally{S(!1)}}async function _(V){var Z;V.stopPropagation();const X=((Z=e.children)==null?void 0:Z.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(X))try{await Oh(t,e.tag.tag_uid),a(e.tag.full_path),o()}catch{}}const N={archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:c,onMoveSourceSelect:g,pendingCreateParentUid:h,onCreateDone:m,onCreateCancel:x},R=h===e.tag.tag_uid,P=((q=e.children)==null?void 0:q.length)>0;return s.jsxs("li",{children:[s.jsxs("div",{className:`tag-node-row${c?" tag-node-row--move-select":""}`,children:[j?s.jsx("input",{className:"tag-rename-input",autoFocus:!0,value:p,onChange:V=>f(V.target.value),onKeyDown:V=>{V.key==="Enter"&&V.currentTarget.blur(),V.key==="Escape"&&(y.current=!0,V.currentTarget.blur())},onBlur:()=>{y.current?(y.current=!1,S(!1)):L()}}):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:V=>{V.stopPropagation(),E(V)},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"})})]}),!j&&!c&&s.jsx("button",{className:"remove tag-node-delete",title:`Delete "${e.tag.full_path}"`,onClick:_,"aria-label":`Delete "${e.tag.full_path}"`,children:"×"})]}),(P||R)&&s.jsx("div",{className:"tag-children",children:s.jsxs("ul",{className:"tag-tree-list",children:[e.children.map(V=>s.jsx(Hd,{node:V,...N},V.tag.tag_uid)),R&&s.jsx("li",{children:s.jsx(Ud,{parentPath:e.tag.full_path,archiveId:t,onDone:m,onCancel:x})})]})})]})}function Mm({archiveId:e,tagNodes:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u}){const[c,g]=d.useState(null),[h,m]=d.useState(null);function x(){g("select-source"),m(null)}function v(){g(null),m(null)}d.useEffect(()=>{if(c!=="select-source")return;function X(Z){Z.key==="Escape"&&(Z.preventDefault(),Z.stopPropagation(),v())}return document.addEventListener("keydown",X),()=>document.removeEventListener("keydown",X)},[c]);function j(X){m(X),g("select-dest")}async function S(X){const Z=h.tag.full_path,me=h.tag.tag_uid,ve=(X==null?void 0:X.tag_uid)??null;v();try{const re=await Mh(e,me,ve);i(Z,re.full_path),o()}catch(re){alert(re.message||"Move failed")}}const[p,f]=d.useState(null),[y,w]=d.useState(void 0);function E(){f("select-parent"),w(void 0)}function L(){f(null),w(void 0)}function _(X){w(X??null),f("input")}function N(){f(null),w(void 0),o()}const R=c==="select-source",P=p==="input"?y?y.tag_uid:"__root__":void 0,q={archiveId:e,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:R,onMoveSourceSelect:j,pendingCreateParentUid:P,onCreateDone:N,onCreateCancel:L},V=P==="__root__";return s.jsxs("section",{id:"tags-view",className:"view is-active",children:[s.jsxs("div",{className:"tag-tree",children:[s.jsx("div",{className:"tag-tree-header",children:R?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&&!V?s.jsx("p",{className:"muted",style:{padding:"8px 0"},children:"No tags yet."}):s.jsxs("ul",{className:"tag-tree-list",children:[t.map(X=>s.jsx(Hd,{node:X,...q},X.tag.tag_uid)),V&&s.jsx("li",{children:s.jsx(Ud,{parentPath:null,archiveId:e,onDone:N,onCancel:L})})]})]}),p==="select-parent"&&s.jsx(gu,{title:"Create tag under…",tagNodes:t,excludeUid:null,onPick:_,onCancel:L}),c==="select-dest"&&h&&s.jsx(gu,{title:`Move "${h.tag.slug}" under…`,tagNodes:t,excludeUid:h.tag.tag_uid,onPick:S,onCancel:v})]})}const Pr=[{value:0,label:"Private"},{value:2,label:"Users only"},{value:3,label:"Public"}],Fm=e=>{var t;return((t=Pr.find(n=>n.value===e))==null?void 0:t.label)??String(e)};function Bm({archiveId:e}){const[t,n]=d.useState([]),[r,l]=d.useState(!1),[i,a]=d.useState(null),[o,u]=d.useState(null),[c,g]=d.useState(null),[h,m]=d.useState(!1),[x,v]=d.useState(null),[j,S]=d.useState(""),[p,f]=d.useState(""),[y,w]=d.useState(2),[E,L]=d.useState(!1),[_,N]=d.useState(null),[R,P]=d.useState(""),[q,V]=d.useState(2),[X,Z]=d.useState(!1),[me,ve]=d.useState(null),[re,I]=d.useState(!1),[b,U]=d.useState(""),ee=d.useRef(null),Q=t.find($=>$.collection_uid===o)??null,de=(Q==null?void 0:Q.slug)==="_default_",fe=d.useCallback(async()=>{if(e){l(!0),a(null);try{const $=await Od(e);n($)}catch($){a($.message)}finally{l(!1)}}},[e]),Ie=d.useCallback(async $=>{if(!$){g(null);return}m(!0),v(null);try{const G=await im(e,$);g(G)}catch(G){v(G.message)}finally{m(!1)}},[e]);d.useEffect(()=>{fe()},[fe]),d.useEffect(()=>{Ie(o)},[o,Ie]),d.useEffect(()=>{re&&ee.current&&ee.current.focus()},[re]);async function je($){$.preventDefault();const G=j.trim(),_e=p.trim();if(!(!G||!_e)){L(!0),N(null);try{const De=await sm(e,G,_e,y);S(""),f(""),w(2),await fe(),u(De.collection_uid)}catch(De){N(De.message)}finally{L(!1)}}}async function We(){const $=b.trim();if(!$||!Q){I(!1);return}try{await pu(e,Q.collection_uid,{name:$}),await fe(),g(G=>G&&{...G,name:$})}catch(G){a(G.message)}finally{I(!1)}}async function nt($){if(Q)try{await pu(e,Q.collection_uid,{default_visibility_bits:$}),await fe(),g(G=>G&&{...G,default_visibility_bits:$})}catch(G){a(G.message)}}async function rt(){if(Q&&window.confirm(`Delete collection "${Q.name}"? Entries will not be deleted.`))try{await cm(e,Q.collection_uid),u(null),g(null),await fe()}catch($){a($.message)}}async function lt($){$.preventDefault();const G=R.trim();if(!(!G||!Q)){Z(!0),ve(null);try{await Ad(e,Q.collection_uid,G,q),P(""),await Ie(Q.collection_uid)}catch(_e){ve(_e.message)}finally{Z(!1)}}}async function ft($){if(Q)try{await am(e,Q.collection_uid,$),await Ie(Q.collection_uid)}catch(G){v(G.message)}}async function pt($,G){if(Q)try{await om(e,Q.collection_uid,$,G),g(_e=>_e&&{..._e,entries:_e.entries.map(De=>De.entry_uid===$?{...De,collection_visibility_bits:G}:De)})}catch(_e){v(_e.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($=>s.jsxs("button",{className:`coll-sidebar-row${o===$.collection_uid?" is-active":""}`,onClick:()=>u($.collection_uid),children:[s.jsx("span",{className:"coll-row-name",children:$.name}),s.jsx("span",{className:"coll-row-meta",children:Fm($.default_visibility_bits)})]},$.collection_uid)),t.length===0&&!r&&s.jsx("div",{className:"muted",style:{padding:"8px 12px"},children:"No collections yet."})]}),Q?s.jsxs("div",{className:"coll-detail",children:[s.jsxs("div",{className:"coll-detail-header",children:[re?s.jsx("input",{ref:ee,className:"coll-rename-input",value:b,onChange:$=>U($.target.value),onBlur:We,onKeyDown:$=>{$.key==="Enter"&&We(),$.key==="Escape"&&I(!1)}}):s.jsxs("h3",{className:`coll-detail-name${de?"":" coll-detail-name--editable"}`,title:de?void 0:"Click to rename",onClick:()=>{de||(U(Q.name),I(!0))},children:[(c==null?void 0:c.name)??Q.name,!de&&s.jsx("span",{className:"coll-edit-hint",children:" ✎"})]}),!de&&s.jsx("button",{className:"coll-delete-btn",onClick:rt,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)??Q.default_visibility_bits,onChange:$=>nt(Number($.target.value)),children:Pr.map($=>s.jsx("option",{value:$.value,children:$.label},$.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($=>s.jsxs("li",{className:"coll-entry-row",children:[s.jsxs("div",{className:"coll-entry-info",children:[s.jsx("span",{className:"coll-entry-title",children:$.title||$.entry_uid}),s.jsx("span",{className:"coll-entry-kind muted",children:$.source_kind})]}),s.jsxs("div",{className:"coll-entry-actions",children:[s.jsx("select",{className:"coll-entry-vis-select",value:$.collection_visibility_bits,onChange:G=>pt($.entry_uid,Number(G.target.value)),children:Pr.map(G=>s.jsx("option",{value:G.value,children:G.label},G.value))}),!de&&s.jsx("button",{className:"coll-entry-remove",onClick:()=>ft($.entry_uid),title:"Remove from collection",children:"×"})]})]},$.entry_uid))}))]}),!de&&s.jsxs("form",{className:"coll-add-entry-form",onSubmit:lt,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:R,onChange:$=>P($.target.value),placeholder:"entry_uid",required:!0}),s.jsx("select",{className:"coll-vis-select",value:q,onChange:$=>V(Number($.target.value)),children:Pr.map($=>s.jsx("option",{value:$.value,children:$.label},$.value))}),s.jsx("button",{className:"coll-add-btn",type:"submit",disabled:X,children:X?"…":"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:je,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:j,onChange:$=>{S($.target.value),p||f($.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:$=>f($.target.value),placeholder:"my-collection",required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"coll-vis",children:"Default visibility"}),s.jsx("select",{className:"capture-input",id:"coll-vis",style:{height:42},value:y,onChange:$=>w(Number($.target.value)),children:Pr.map($=>s.jsx("option",{value:$.value,children:$.label},$.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 Um=4;function Hm({tab:e,onTabChange:t,archiveId:n}){const{currentUser:r,setCurrentUser:l}=d.useContext(Ps)??{},i=r&&(r.role_bits&Um)!==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(Wm,{currentUser:r,setCurrentUser:l}),e==="tokens"&&s.jsx(Vm,{}),e==="instance"&&i&&s.jsx(Qm,{}),e==="cookies"&&i&&s.jsx(qm,{}),e==="extensions"&&i&&s.jsx(Xm,{}),e==="storage"&&i&&s.jsx(Km,{archiveId:n})]})}function Wm({currentUser:e,setCurrentUser:t}){const[n,r]=d.useState((e==null?void 0:e.display_name)??""),[l,i]=d.useState(!1),[a,o]=d.useState(null),[u,c]=d.useState(""),[g,h]=d.useState(""),[m,x]=d.useState(""),[v,j]=d.useState(!1),[S,p]=d.useState(null);async function f(w){w.preventDefault(),i(!0),o(null);try{await qh(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 y(w){if(w.preventDefault(),g!==m){p({ok:!1,text:"Passwords do not match."});return}j(!0),p(null);try{await Jh(u,g),c(""),h(""),x(""),p({ok:!0,text:"Password changed."})}catch(E){p({ok:!1,text:E.message})}finally{j(!1)}}return s.jsxs("div",{style:{maxWidth:440},children:[s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Display Name"}),s.jsxs("form",{onSubmit:f,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"display-name",children:"Name shown in the UI"}),s.jsx("input",{className:"field-input",id:"display-name",placeholder:(e==null?void 0:e.username)??"",value:n,onChange: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 Xh({humanize_slugs:E}),t(L=>({...L,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:y,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"cur-pw",children:"Current password"}),s.jsx("input",{className:"field-input",id:"cur-pw",type:"password",value:u,onChange: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:g,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:m,onChange:w=>x(w.target.value),required:!0})]}),S&&s.jsx("div",{className:`form-msg form-msg--${S.ok?"ok":"err"}`,children:S.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:v,children:v?"Changing…":"Change Password"})]})]})]})}function Vm(){const[e,t]=d.useState([]),[n,r]=d.useState(!0),[l,i]=d.useState(null),[a,o]=d.useState(""),[u,c]=d.useState(!1),[g,h]=d.useState(null),m=d.useCallback(async()=>{r(!0),i(null);try{t(await Gh())}catch(j){i(j.message)}finally{r(!1)}},[]);d.useEffect(()=>{m()},[m]);async function x(j){if(j.preventDefault(),!!a.trim()){c(!0);try{const S=await Yh(a.trim());h(S),o(""),m()}catch(S){i(S.message)}finally{c(!1)}}}async function v(j){try{await Zh(j),t(S=>S.filter(p=>p.token_uid!==j))}catch(S){i(S.message)}}return s.jsx("div",{style:{maxWidth:600},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"API Tokens"}),g&&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:g.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:j=>o(j.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(j=>s.jsxs("div",{className:"token-row",children:[s.jsxs("div",{className:"token-row-info",children:[s.jsx("strong",{children:j.name}),s.jsxs("div",{className:"muted",children:["Created ",j.created_at.slice(0,10),j.last_used_at&&` · Last used ${j.last_used_at.slice(0,10)}`]})]}),s.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"4px 10px"},onClick:()=>v(j.token_uid),children:"Revoke"})]},j.token_uid))]})]})})}function Qm(){const[e,t]=d.useState(null),[n,r]=d.useState(!0),[l,i]=d.useState(null),[a,o]=d.useState(!1),[u,c]=d.useState(null);d.useEffect(()=>{(async()=>{try{t(await qa())}catch(h){i(h.message)}finally{r(!1)}})()},[]);async function g(h){h.preventDefault(),o(!0),c(null);try{await Fl(e),c({ok:!0,text:"Saved."})}catch(m){c({ok:!1,text:m.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:g,children:[[["public_index_enabled","Public index (unauthenticated browsing)"],["public_entry_content_enabled","Public entry content"],["open_registration_enabled","Open registration"]].map(([h,m])=>s.jsxs("label",{className:"checkbox-row",children:[s.jsx("input",{type:"checkbox",checked:!!e[h],onChange:x=>t(v=>({...v,[h]:x.target.checked}))}),m]},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(m=>({...m,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 si(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 Km({archiveId:e}){const[t,n]=d.useState("idle"),[r,l]=d.useState(null),[i,a]=d.useState(null),[o,u]=d.useState(null);function c(){n("idle"),l(null),a(null),u(null)}async function g(){n("scanning"),u(null),l(null);try{const x=await dm(e);l(x),n("scanned")}catch(x){u(x.message),n("error")}}async function h(){n("deleting"),u(null);try{const x=await fm(e);a(x),n("done")}catch(x){u(x.message),n("error")}}const m=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:g,children:"Scan for orphaned blobs"}),t==="scanning"&&s.jsx("div",{className:"muted",children:"Scanning…"}),t==="scanned"&&r&&m&&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&&!m&&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:si(r.total_bytes)})," recoverable."]}),s.jsxs("div",{style:{display:"flex",gap:8},children:[s.jsxs("button",{className:"btn-danger",onClick:h,children:["Delete (",si(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:si(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 qm(){const[e,t]=d.useState(null),[n,r]=d.useState(!0),[l,i]=d.useState(null),[a,o]=d.useState("global"),[u,c]=d.useState(""),[g,h]=d.useState("{}"),[m,x]=d.useState(null),[v,j]=d.useState(!1),[S,p]=d.useState({});d.useEffect(()=>{f()},[]);async function f(){r(!0),i(null);try{t(await mm())}catch(N){i(N.message)}finally{r(!1)}}async function y(N){N.preventDefault();try{JSON.parse(g)}catch{x({ok:!1,text:'cookies must be valid JSON, e.g. {"session": "abc"}'});return}j(!0),x(null);try{await gm(a==="global"?null:u.trim(),a,g),c(""),h("{}"),o("global"),x({ok:!0,text:"Rule added."}),await f()}catch(R){x({ok:!1,text:R.message})}finally{j(!1)}}async function w(N){try{await vm(N),await f()}catch(R){i(R.message)}}function E(N){p(R=>({...R,[N.rule_uid]:{cookiesInput:N.cookies_json,saving:!1,msg:null}}))}function L(N){p(R=>{const P={...R};return delete P[N],P})}async function _(N){const R=S[N.rule_uid];try{JSON.parse(R.cookiesInput)}catch{p(P=>({...P,[N.rule_uid]:{...P[N.rule_uid],msg:{ok:!1,text:"Invalid JSON"}}}));return}p(P=>({...P,[N.rule_uid]:{...P[N.rule_uid],saving:!0,msg:null}}));try{await ym(N.rule_uid,{cookies_json:R.cookiesInput}),L(N.rule_uid),await f()}catch(P){p(q=>({...q,[N.rule_uid]:{...q[N.rule_uid],saving:!1,msg:{ok:!1,text:P.message}}}))}}return n?s.jsx("div",{className:"muted",children:"Loading…"}):l?s.jsx("div",{className:"form-msg form-msg--err",children:l}):s.jsx("div",{style:{maxWidth:560},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Cookie Rules"}),s.jsx("p",{className:"muted",style:{marginBottom:12},children:"Cookies are injected into every capture network request (yt-dlp, HTTP downloads, web-page snapshots). Global rules apply to all URLs; wildcard and regex rules apply only to matching URLs."}),e&&e.length>0?s.jsxs("table",{className:"data-table",style:{width:"100%",marginBottom:16},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Pattern"}),s.jsx("th",{children:"Cookies"}),s.jsx("th",{style:{width:100},children:"Actions"})]})}),s.jsx("tbody",{children:e.map(N=>{const R=S[N.rule_uid],P=N.url_pattern?s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"muted",children:[N.pattern_kind,":"]})," ",s.jsx("code",{children:N.url_pattern})]}):s.jsx("span",{className:"muted",children:"global (all URLs)"});return s.jsxs("tr",{children:[s.jsx("td",{children:P}),s.jsx("td",{children:R?s.jsxs(s.Fragment,{children:[s.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:12,width:"100%",minHeight:60},value:R.cookiesInput,onChange:q=>p(V=>({...V,[N.rule_uid]:{...V[N.rule_uid],cookiesInput:q.target.value}}))}),R.msg&&s.jsx("div",{className:`form-msg form-msg--${R.msg.ok?"ok":"err"}`,children:R.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:R.saving,onClick:()=>_(N),children:R.saving?"Saving…":"Save"}),s.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>L(N.rule_uid),children:"Cancel"})]})]}):s.jsx("code",{style:{fontSize:12,wordBreak:"break-all"},children:N.cookies_json})}),s.jsx("td",{children:!R&&s.jsxs("div",{style:{display:"flex",gap:6},children:[s.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>E(N),children:"Edit"}),s.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"2px 8px"},onClick:()=>w(N.rule_uid),children:"Del"})]})})]},N.rule_uid)})})]}):s.jsx("p",{className:"muted",style:{marginBottom:16},children:"No cookie rules defined."}),s.jsx("h3",{style:{marginBottom:8},children:"Add Rule"}),s.jsxs("form",{onSubmit:y,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",children:"Pattern type"}),s.jsxs("select",{className:"field-input",value:a,onChange:N=>o(N.target.value),children:[s.jsx("option",{value:"global",children:"Global (all URLs)"}),s.jsx("option",{value:"wildcard",children:"Wildcard (e.g. *.youtube.com)"}),s.jsx("option",{value:"regex",children:"Regex (matched against full URL)"})]})]}),a!=="global"&&s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",children:a==="wildcard"?"URL/hostname pattern":"Regex pattern"}),s.jsx("input",{className:"field-input",type:"text",value:u,onChange:N=>c(N.target.value),placeholder:a==="wildcard"?"*.youtube.com or https://example.com/*":".*\\.youtube\\.com.*",required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",children:"Cookies (JSON object)"}),s.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:13,minHeight:70},value:g,onChange:N=>h(N.target.value),placeholder:'{"SESSION": "abc123", "token": "xyz"}',required:!0})]}),m&&s.jsx("div",{className:`form-msg form-msg--${m.ok?"ok":"err"}`,children:m.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:v,children:v?"Adding…":"Add Rule"})]})]})})}function Xm(){const[e,t]=d.useState(null),[n,r]=d.useState(!0),[l,i]=d.useState(!1),[a,o]=d.useState(null);d.useEffect(()=>{(async()=>{try{t(await qa())}catch(S){o({ok:!1,text:S.message})}finally{r(!1)}})()},[]);async function u(S){i(!0),o(null);try{await Fl({ublock_enabled:S}),t(p=>({...p,ublock_enabled:S})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}async function c(S){i(!0),o(null);try{await Fl({cookie_ext_enabled:S}),t(p=>({...p,cookie_ext_enabled:S})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}async function g(S){i(!0),o(null);try{await Fl({modal_closer_enabled:S}),t(p=>({...p,modal_closer_enabled:S})),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,m=(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,j=(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":m,className:`ext-toggle${m?" ext-toggle--on":""}`,onClick:()=>u(!m),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":j,className:`ext-toggle${j?" ext-toggle--on":""}`,onClick:()=>g(!j),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 yu={0:"Private",1:"Public",2:"Users only",3:"Public"},Jm=()=>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 Gm({archiveId:e,selectedEntry:t,selectedUids:n,selectedEntries:r,detail:l,onTagFilterSet:i,tagNodes:a,onTagsRefresh:o,onEntryTitleChange:u,onEntryDeleted:c,onBulkDeleted:g,humanizeTags:h,onDetailRefresh:m,onOpenPreview:x,onPlay:v}){var oe;const[j,S]=d.useState([]),[p,f]=d.useState(""),[y,w]=d.useState([]),[E,L]=d.useState(""),_=d.useRef(0),N=d.useRef(!1),[R,P]=d.useState(!1),[q,V]=d.useState(""),[X,Z]=d.useState("idle"),[me,ve]=d.useState(""),re=d.useRef(null),[I,b]=d.useState(!1);d.useEffect(()=>{b(!1)},[(oe=l==null?void 0:l.summary)==null?void 0:oe.entry_uid]);const U=(n==null?void 0:n.size)>=2,[ee,Q]=d.useState(""),[de,fe]=d.useState("idle"),[Ie,je]=d.useState(""),[We,nt]=d.useState([]),[rt,lt]=d.useState(""),[ft,pt]=d.useState("idle"),[$,G]=d.useState(""),[_e,De]=d.useState("idle");d.useEffect(()=>{const T=++_.current;if(re.current&&(clearInterval(re.current),re.current=null),Z("idle"),ve(""),!t||!e){S([]),w([]);return}P(!1),V(""),N.current=!1,S([]),Promise.all([Cl(e,t.entry_uid),um(e,t.entry_uid)]).then(([J,te])=>{T===_.current&&(S(J),w(te))}).catch(()=>{})},[t,e]),d.useEffect(()=>()=>{clearInterval(re.current)},[]),d.useEffect(()=>{if(!U||!e){nt([]);return}Od(e).then(nt).catch(()=>nt([]))},[U,e]),d.useEffect(()=>{Q(""),fe("idle"),je(""),lt(""),pt("idle"),G(""),De("idle")},[n]);async function st(){const T=n.size;if(!window.confirm(`Delete ${T} entr${T===1?"y":"ies"}? This cannot be undone.`))return;De("running");const J=new Set;for(const te of n)try{await fu(e,te),J.add(te)}catch{}De("idle"),g==null||g(J)}async function mn(){const T=ee.trim();if(T){fe("running"),je("");try{for(const J of n)await du(e,J,T);Q(""),fe("done"),o==null||o(),setTimeout(()=>fe("idle"),1800)}catch(J){je(J.message),fe("error")}}}async function Rn(){if(!rt)return;pt("running"),G("");const T=[];for(const J of n)try{await Ad(e,rt,J)}catch{T.push(J)}T.length>0?(G(`Failed for ${T.length} entr${T.length===1?"y":"ies"}.`),pt("error")):(pt("done"),setTimeout(()=>pt("idle"),1800))}async function Ve(){const T=q.trim()||null;try{await Ih(e,t.entry_uid,T),u==null||u(t.entry_uid,T)}catch{}finally{P(!1)}}async function zn(){const T=p.trim();if(!(!T||!t))try{await du(e,t.entry_uid,T),f(""),L("");const J=await Cl(e,t.entry_uid);S(J),o()}catch(J){L(J.message)}}async function In(T){try{await Dh(e,t.entry_uid,T);const J=await Cl(e,t.entry_uid);S(J),o()}catch{}}async function fr(){if(!(!t||!e)&&window.confirm("Delete this entry? This cannot be undone."))try{await fu(e,t.entry_uid),c==null||c(t.entry_uid)}catch{}}async function Qt(){if(!t||!e||X==="running")return;const T=_.current,J=t.entry_uid;Z("running"),ve("");try{const{job_uid:te}=await pm(e,J);if(_.current!==T)return;re.current=setInterval(async()=>{try{const be=await $d(e,te);if(be.status==="completed"){if(clearInterval(re.current),re.current=null,_.current!==T)return;Z("done");const ge=await Cl(e,J);if(_.current!==T)return;S(ge),m==null||m()}else if(be.status==="failed"){if(clearInterval(re.current),re.current=null,_.current!==T)return;Z("error"),ve(be.error_text||"Re-archive failed.")}}catch{if(clearInterval(re.current),re.current=null,_.current!==T)return;Z("error"),ve("Network error while polling.")}},500)}catch(te){if(_.current!==T)return;Z("error"),ve(te.message||"Failed to start re-archive.")}}const pr=l?[["Added",Xa(l.summary.archived_at)],["Source",l.summary.source_kind],["Type",l.summary.entity_kind],["Visibility",yu[l.summary.visibility]??l.summary.visibility],["Root",l.structured_root_relpath]]:[],hr=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),mr=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv","pdf","html","htm","jpg","jpeg","png","gif","webp","avif","svg","bmp"]),k=l?l.artifacts.findIndex(T=>T.artifact_role==="primary_media"):-1,M=k>=0?l.artifacts[k]:null,O=M?M.relpath.split(".").pop().toLowerCase():"",D=M&&hr.has(O),H=k>=0&&t?`/api/archives/${e}/entries/${t.entry_uid}/artifacts/${k}`:null,W=l&&!D&&(l.summary.entity_kind==="tweet"||l.summary.entity_kind==="tweet_thread"||M&&mr.has(O));return s.jsxs("aside",{className:"context-rail",children:[s.jsx("div",{className:"rail-eyebrow",children:"Context"}),U?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"}),Ie&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:Ie}),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:ee,onChange:T=>Q(T.target.value),onKeyDown:T=>{T.key==="Enter"&&mn()}}),s.jsx("button",{className:"tag-add-btn",onClick:mn,disabled:de==="running"||!ee.trim(),children:de==="running"?"…":de==="done"?"✓":"Add"})]})]}),We.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:rt,onChange:T=>lt(T.target.value),children:[s.jsx("option",{value:"",children:"Pick a collection…"}),We.map(T=>s.jsx("option",{value:T.collection_uid,children:T.name},T.collection_uid))]}),s.jsx("button",{className:"tag-add-btn",onClick:Rn,disabled:!rt||ft==="running",children:ft==="running"?"…":ft==="done"?"✓":ft==="error"?"!":"Add"})]}),$&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"6px 0 0"},children:$})]}),s.jsx("div",{className:"rail-delete-zone",children:s.jsx("button",{className:"rail-delete-btn",onClick:st,disabled:_e==="running",children:_e==="running"?"Deleting…":`Delete ${n.size} entr${n.size===1?"y":"ies"}`})})]}):t?l?s.jsxs(s.Fragment,{children:[R?s.jsx("input",{className:"rail-title-input",autoFocus:!0,value:q,onChange:T=>V(T.target.value),onKeyDown:T=>{T.key==="Enter"&&T.currentTarget.blur(),T.key==="Escape"&&(N.current=!0,T.currentTarget.blur())},onBlur:()=>{N.current?P(!1):Ve(),N.current=!1}}):s.jsxs("h2",{className:"rail-title rail-title--editable",title:"Click to rename",onClick:()=>{V(l.summary.title??""),P(!0)},children:[_t(l.summary.title)||_t(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:Ts(l.summary.source_kind)}}),s.jsx("span",{className:"u-text",children:l.summary.original_url}),s.jsx("span",{className:"ext",children:s.jsx(Jm,{})})]}),D&&v&&s.jsx("button",{className:"rail-preview-btn",onClick:()=>v(H,t),children:"▶ Play"}),W&&x&&s.jsx("button",{className:"rail-preview-btn",onClick:x,children:"Preview"}),s.jsx("div",{className:"meta-list",children:pr.filter(([,T])=>T!=null&&T!=="").map(([T,J])=>s.jsxs("div",{className:"meta-item",children:[s.jsx("span",{className:"meta-k",children:T}),s.jsx("span",{className:`meta-v${T==="Root"?" mono":""}`,children:_t(J)})]},T))}),l.artifacts.length>0&&(()=>{const T=l.artifacts.map((ie,Dt)=>({...ie,_idx:Dt})),J=T.filter(ie=>ie.artifact_role==="font"),te=T.filter(ie=>ie.artifact_role!=="font"),be=J.reduce((ie,Dt)=>ie+(Dt.byte_size||0),0),ge=l.summary.entry_uid,Tt=ie=>s.jsx("li",{children:s.jsxs("a",{href:`/api/archives/${e}/entries/${ge}/artifacts/${ie._idx}`,target:"_blank",rel:"noopener noreferrer",className:"artifact-link",children:[s.jsx("span",{className:"artifact-name",children:ie.artifact_role==="font"?ie.relpath.split("/").pop():ie.artifact_role.replace(/_/g," ")}),s.jsx("span",{className:"artifact-size",children:ie.byte_size!=null?rl(ie.byte_size):"—"})]})},ie._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:[te.map(Tt),J.length>0&&s.jsxs("li",{className:"artifact-group",children:[s.jsxs("button",{type:"button",className:"artifact-group-header artifact-link","aria-expanded":I,onClick:()=>b(ie=>!ie),children:[s.jsxs("span",{className:"artifact-name",children:[s.jsx("span",{"aria-hidden":"true",className:`artifact-group-chevron${I?" open":""}`,children:"›"}),` fonts (${J.length})`]}),s.jsx("span",{className:"artifact-size",children:rl(be)})]}),I&&s.jsx("ul",{className:"artifact-list artifact-group-body",children:J.map(Tt)})]})]})]})})()]}):s.jsx("p",{className:"tags-empty",children:"Loading\\u2026"}):s.jsx("p",{className:"tags-empty",children:"Select an entry."}),t&&!U&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Tags"}),j.length===0?s.jsx("p",{className:"tags-empty",children:"No tags yet."}):s.jsx("div",{className:"tags-wrap",children:j.map(T=>s.jsxs("span",{className:"tag-pill",title:T.full_path,children:[h?Fd(T.full_path):T.full_path,s.jsx("button",{className:"remove",title:`Remove tag ${T.full_path}`,onClick:()=>In(T.tag_uid),children:"×"})]},T.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:T=>f(T.target.value),onKeyDown:T=>{T.key==="Enter"&&zn()}}),s.jsx("button",{className:"tag-add-btn",onClick:zn,children:"Add"})]})]}),y.length>0&&s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Collections"}),y.map(T=>s.jsxs("div",{className:"coll-row",children:[s.jsx("span",{className:"coll-name",children:T.collection_uid}),s.jsx("span",{className:"vis-badge",children:yu[T.visibility_bits]??`bits:${T.visibility_bits}`})]},T.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:Qt,disabled:X==="running",children:X==="running"?"Re-archiving…":"Re-archive"}),X==="done"&&s.jsx("p",{className:"form-msg form-msg--ok",style:{marginTop:"6px"},children:"Re-archived successfully."}),X==="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:fr,children:"Delete entry"})})]})]})}const Ym=/\/api\/archives\/([^/]+)\/entries\/([^/]+)\/artifacts\/(\d+)/;function Zm(){return s.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[s.jsx("path",{d:"M5 17H3a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h18a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-2"}),s.jsx("polygon",{points:"12 15 17 21 7 21 12 15"})]})}function eg({src:e,contentType:t="video/mp4"}){const n=d.useRef(null),[r,l]=d.useState(null),[i,a]=d.useState(!1),[o,u]=d.useState(!1);d.useEffect(()=>{if(!e){l(null);return}const h=e.match(Ym);if(!h){l(e);return}let m=!1;return l(null),hm(h[1],h[2],parseInt(h[3],10)).then(({url:x})=>{m||l(x)}).catch(()=>{m||l(e)}),()=>{m=!0}},[e]),d.useEffect(()=>{n.current&&n.current.load()},[r]),d.useEffect(()=>{u(typeof HTMLVideoElement<"u"&&"webkitShowPlaybackTargetPicker"in HTMLVideoElement.prototype)},[]),d.useEffect(()=>{var m;const h=x=>{if(x)try{cast.framework.CastContext.getInstance().setOptions({receiverApplicationId:chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,autoJoinPolicy:chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}),a(!0)}catch{}};if((m=window.cast)!=null&&m.framework)h(!0);else if(window.__onGCastApiAvailable=h,!document.querySelector('script[src*="cast_sender"]')){const x=document.createElement("script");x.src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1",document.head.appendChild(x)}},[]),d.useEffect(()=>{if(!i||!r)return;const h=cast.framework.CastContext.getInstance(),{CastContextEventType:m,SessionState:x}=cast.framework,v=S=>{if(!S)return;const p=new chrome.cast.media.MediaInfo(window.location.origin+r,t);S.loadMedia(new chrome.cast.media.LoadRequest(p)).catch(()=>{})};v(h.getCurrentSession());const j=S=>{(S.sessionState===x.SESSION_STARTED||S.sessionState===x.SESSION_RESUMED)&&v(h.getCurrentSession())};return h.addEventListener(m.SESSION_STATE_CHANGED,j),()=>h.removeEventListener(m.SESSION_STATE_CHANGED,j)},[i,r,t]);const c=()=>{var h,m;(m=(h=n.current)==null?void 0:h.webkitShowPlaybackTargetPicker)==null||m.call(h)},g=i||o;return s.jsx("div",{className:"preview-video-wrap",style:{position:"relative"},children:e?s.jsxs(s.Fragment,{children:[r?s.jsxs("video",{ref:n,controls:!0,autoPlay:!1,playsInline:!0,"x-webkit-airplay":"allow",style:{width:"100%",maxHeight:"100%",display:"block"},children:[s.jsx("source",{src:r}),"Your browser does not support the video element."]}):s.jsx("div",{className:"video-tv-loading","aria-label":"Loading video…"}),g&&r&&s.jsxs("div",{className:"video-tv-controls",children:[o&&s.jsx("button",{className:"video-tv-btn",title:"AirPlay to device","aria-label":"AirPlay to device",onClick:c,children:s.jsx(Zm,{})}),i&&s.jsx("google-cast-launcher",{className:"video-tv-btn",title:"Cast to TV"})]})]}):s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No video available"})})}function vu({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 tg({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 Wd(e){return e?new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(new Date(e*1e3)):""}function xu(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"}},Te={bg:"#000000",border:"#2f3336",text:"#e7e9ea",dim:"#71767b",accent:"#1d9bf0",codeBg:"#16181c"},ii={article:{background:Te.bg,color:Te.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:Te.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:Te.border,flexShrink:0},aAuthorName:{fontSize:"15px",fontWeight:"700",color:Te.text,lineHeight:"1.3"},aAuthorSub:{fontSize:"15px",color:Te.dim,lineHeight:"1.3"},aDivider:{border:"none",borderTop:`1px solid ${Te.border}`,margin:"0"},aBody:{padding:"4px 16px 0"},bH1:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:Te.text,lineHeight:"36px",margin:"24px 0 10px"},bH2:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:Te.text,lineHeight:"36px",margin:"24px 0 10px"},bP:{fontSize:"17px",color:Te.text,lineHeight:"1.5",marginBottom:"16px",marginTop:"0"},bSpacer:{height:"6px",display:"block"},bQuote:{borderLeft:`3px solid ${Te.border}`,padding:"2px 14px",margin:"14px 0",color:Te.dim,fontSize:"17px",lineHeight:"1.5"},bHr:{border:"none",borderTop:`1px solid ${Te.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:Te.text,lineHeight:"1.5",marginBottom:"6px"},bTweet:{display:"flex",alignItems:"center",gap:"12px",border:`1px solid ${Te.border}`,borderRadius:"12px",padding:"14px 16px",margin:"14px 0",color:Te.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:Te.text,background:"transparent"},iCode:{fontFamily:"ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace",fontSize:"0.875em",background:Te.codeBg,padding:"2px 6px",borderRadius:"4px",color:"#e6edf3"},link:{color:Te.accent,textDecoration:"none"}};function ng(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 tr(e,t,n){return e&&n[e]?n[e]:t||null}function Vd(){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 Ja(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 Qd(e,t){const n=e.expanded_url||e.url||e.text||"",r=e.display_url||e.expanded_url||e.url||e.text||"",l=Ja(e,t,e.url,e.text,e.display_url,e.expanded_url);return!l||!n?null:{...l,kind:"url",href:n,display:r}}function Kd(e,t){const n=e.screen_name||e.name||e.text||"",r=n?`@${n}`:null,l=Ja(e,t,r);return!l||!n?null:{...l,kind:"mention",screen_name:n}}const wu=/https?:\/\/[^\s<>"'\])]+/g,rg=/[.,;:!?)()]+$/;function fs(e,t){const n=[];let r=0,l;for(wu.lastIndex=0;(l=wu.exec(e))!==null;){l.index>r&&n.push(e.slice(r,l.index));let i=l[0].replace(rg,"");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:(rQd(o,e)).filter(Boolean),...(t.user_mentions||[]).map(o=>Kd(o,e)).filter(Boolean)];if(r.length===0&&n.length===0)return fs(xu(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,g])=>c<=o&&g>=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 g=e.slice(o,c),h=r.filter(v=>v.s<=o&&v.e>=c),m=h.find(v=>v.kind==="url");if(m)return s.jsx("a",{href:m.href,target:"_blank",rel:"noopener noreferrer",style:Y.link,children:m.display||g},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:g},u):s.jsx("span",{children:fs(xu(g),Y.link)},u)}).filter(o=>o!==null)}function sg(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=Qd(u,e);c&&i.push(c)}for(const u of r){const c=Kd(u,e);c&&i.push(c)}if(i.length===0)return fs(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 g=o[c+1],h=i.filter(S=>S.s<=u&&S.e>=g),m=e.slice(u,g);let x;if(m.includes(` `)){const S=m.split(` `);x=S.flatMap((p,f)=>fS.kind==="style"&&S.style==="Code")&&(x=s.jsx("code",{style:l.iCode,children:x})),h.some(S=>S.kind==="style"&&S.style==="Bold")&&(x=s.jsx("strong",{children:x})),h.some(S=>S.kind==="style"&&S.style==="Italic")&&(x=s.jsx("em",{children:x})),h.some(S=>S.kind==="style"&&S.style==="Underline")&&(x=s.jsx("u",{children:x})),h.some(S=>S.kind==="style"&&S.style==="Strikethrough")&&(x=s.jsx("s",{children:x}));const v=h.find(S=>S.kind==="url");if(v){const S=/^https?:\/\/t\.co\//i.test(x);x=s.jsx("a",{href:v.href,target:"_blank",rel:"noopener noreferrer",style:l.link,children:S?v.display:x})}const j=h.find(S=>S.kind==="mention");return j&&(x=s.jsx("a",{href:`https://x.com/${j.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:l.link,children:x})),s.jsx("span",{children:typeof x=="string"?fs(x,l.link):x},c)})}function ig(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=tr(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 g;!c.metaKey&&!c.ctrlKey&&(c.preventDefault(),(g=n==null?void 0:n.onImgClick)==null||g.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(Vd,{}),"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 ai(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=sg(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 g=a.match(/(?:x\.com|twitter\.com)\/i\/status\/(\d+)/);return g?s.jsxs("a",{href:`https://x.com/i/status/${g[1]}`,target:"_blank",rel:"noopener noreferrer",style:l.bTweet,children:[s.jsx(Vd,{}),"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:ig(e,n,r)},t);default:return a?s.jsx("p",{style:l.bP,children:c},t):null}}function ag(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?ii:Y,u=e.cover_media||{},c=e.author||t||{},g=e.first_published_at_secs?Wd(e.first_published_at_secs):"",m=[c.screen_name?`@${c.screen_name}`:"",g].filter(Boolean).join(" · "),x=tr(u.local_path,u.url,n),v=tr(c.avatar_local_path,c.avatar_url,n),j=s.jsxs(s.Fragment,{children:[i&&s.jsx(qd,{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:S=>{!S.metaKey&&!S.ctrlKey&&(S.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"}),m&&s.jsx("div",{style:o.aAuthorSub,children:m})]})]})]}),s.jsx("hr",{style:o.aDivider}),s.jsx("div",{style:o.aBody,children:ag(e.blocks||[],n,{onImgClick:a,st:o})})]});return r?s.jsx("div",{style:ii.article,children:s.jsx("div",{style:ii.articleInner,children:j})}):s.jsx("div",{style:Y.article,children:j})}function ug({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 qd({items:e,startIndex:t,onClose:n}){const[r,l]=d.useState(t);d.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 ku({tweet:e,isInThread:t,isLast:n,artifactMap:r}){var f,y;const[l,i]=d.useState(null),a=e.author||{},o=e.created_at_secs?Wd(e.created_at_secs):"",u=e.entities||{},c=tr(a.avatar_local_path,a.avatar_url,r),g=t&&!n,h=e.is_quote_status===!0,m=t?Y.tweetRowThread:Y.tweetRow,x=e.full_text||"",v=((y=(f=e.extended_entities)==null?void 0:f.media)!=null&&y.length?e.extended_entities.media:u.media)||[],j=[],S=[];for(const w of v)if(w.type==="photo"){const E=tr(w.local_path,w.media_url_https,r);E&&j.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 _,N;return(N=(((_=w.video_info)==null?void 0:_.variants)||[]).filter(R=>R.content_type==="video/mp4").sort((R,P)=>(P.bitrate||0)-(R.bitrate||0))[0])==null?void 0:N.url})();E&&S.push({kind:w.type==="animated_gif"?"gif":"video",src:E})}const p=[];for(const w of v){if(!w.url||!(w.type==="photo"?j.some(_=>_.src===tr(w.local_path,w.media_url_https,r)):S.length>0))continue;const L=Ja(w,x,w.url);L&&p.push([L.s,L.e])}return s.jsxs(s.Fragment,{children:[l!==null&&s.jsx(qd,{items:j,startIndex:l,onClose:()=>i(null)}),s.jsxs("div",{style:m,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}),g&&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:lg(x,u,p)}),j.length>0&&s.jsx("div",{style:Y.mediaGrid,children:s.jsx(ug,{photos:j,onOpen:w=>i(w)})}),S.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 cg({archiveId:e,entryUid:t,artifacts:n,entityKind:r,fullPage:l,onXArticle:i}){const[a,o]=d.useState(!0),[u,c]=d.useState(null),[g,h]=d.useState([]);if(d.useEffect(()=>{if(o(!0),c(null),h([]),!n||!e||!t){o(!1);return}const v=n.map((S,p)=>({...S,index:p})).filter(S=>S.artifact_role==="raw_tweet_json");if(v.length===0){c("No tweet data found."),o(!1);return}let j=!1;return Rh(e,t,v.map(S=>S.index)).then(async S=>{if(j)return;const p=/https?:\/\/t\.co\/[A-Za-z0-9]+/g,f=_=>{var R;const N=_.full_text||"";return(((R=_.entities)==null?void 0:R.urls)||[]).map(P=>{var q;if(P.fromIndex!=null&&P.toIndex!=null)return[P.fromIndex,P.toIndex];if(((q=P.indices)==null?void 0:q.length)===2)return[P.indices[0],P.indices[1]];if(P.url){const V=N.indexOf(P.url);if(V!==-1)return[V,V+P.url.length]}return null}).filter(Boolean)},y=(_,N,R)=>_.some(([P,q])=>P<=N&&q>=R),w=new Set;for(const _ of S){const N=_.full_text||"",R=f(_);let P;for(p.lastIndex=0;(P=p.exec(N))!==null;)y(R,P.index,P.index+P[0].length)||w.add(P[0])}const E=w.size>0?await zh([...w]).catch(()=>({})):{},L=S.map(_=>{var V;const N=_.full_text||"",R=f(_),P=[];let q;for(p.lastIndex=0;(q=p.exec(N))!==null;){const X=q[0],Z=E[X];Z&&Z!==X&&!y(R,q.index,q.index+X.length)&&P.push({url:X,expanded_url:Z,display_url:(()=>{try{const me=new URL(Z);return me.hostname+(me.pathname.length>1?"/…":"")}catch{return Z}})(),fromIndex:q.index,toIndex:q.index+X.length})}return P.length===0?_:{..._,entities:{..._.entities||{},urls:[...((V=_.entities)==null?void 0:V.urls)||[],...P]}}});j||h(L)}).catch(S=>{j||c(S.message||"Failed to load tweet.")}).finally(()=>{j||o(!1)}),()=>{j=!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(g.length===0)return null;const m=ng(e,t,n);if(r==="tweet_thread")return s.jsx("div",{style:Y.threadOuter,children:g.map((v,j)=>s.jsx(ku,{tweet:v,isInThread:!0,isLast:j===g.length-1,artifactMap:m},v.id||j))});const x=g[0];return x.is_article&&x.article?s.jsx(og,{article:x.article,tweetAuthor:x.author,artifactMap:m,fullPage:l,onXArticle:i}):s.jsx("div",{style:Y.card,children:s.jsx(ku,{tweet:x,isInThread:!1,isLast:!0,artifactMap:m})})}const dg=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv"]),fg=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),pg=new Set(["jpg","jpeg","png","gif","webp","avif","svg","bmp"]),hg={mp4:"video/mp4",webm:"video/webm",mov:"video/quicktime",mkv:"video/x-matroska",avi:"video/x-msvideo",m4v:"video/mp4",ogv:"video/ogg"};function Xd({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(cg,{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 g=a[c],h=`/api/archives/${e}/entries/${o}/artifacts/${c}`,m=g.relpath.split(".").pop().toLowerCase();return dg.has(m)?s.jsx("div",{className:"preview-panel",children:s.jsx(eg,{src:h,contentType:hg[m]||"video/mp4"})}):fg.has(m)?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"}})]}):m==="pdf"?s.jsx("div",{className:"preview-panel",style:{flex:1,minHeight:0},children:s.jsx(vu,{src:h,type:"pdf",title:i.title,originalUrl:i.original_url})}):m==="html"||m==="htm"?s.jsx("div",{className:"preview-panel",style:{flex:1,minHeight:0},children:s.jsx(vu,{src:h,type:"page",title:i.title,originalUrl:i.original_url})}):pg.has(m)?s.jsx("div",{className:"preview-panel",style:{height:"100%"},children:s.jsx(tg,{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 mg({archiveId:e,entry:t,detail:n,onClose:r}){var l,i;return d.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(Xd,{archiveId:e,entry:t,detail:n})})]})})}function ju(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 gg({entry:e,src:t,archiveId:n,onClose:r}){const l=d.useRef(null),[i,a]=d.useState(!1),[o,u]=d.useState(0),[c,g]=d.useState(NaN),[h,m]=d.useState(1);d.useEffect(()=>{!l.current||!t||(l.current.load(),u(0),g(NaN),a(!1))},[t]),d.useEffect(()=>{l.current&&(l.current.volume=h)},[h]);function x(){const f=l.current;f&&(i?f.pause():f.play().catch(()=>{}))}function v(f){const y=l.current;if(!y||!isFinite(c))return;const w=Number(f.target.value);y.currentTime=w,u(w)}function j(f){m(Number(f.target.value))}const S=(e==null?void 0:e.title)||(e==null?void 0:e.entry_uid)||"Unknown",p=(e==null?void 0:e.source_kind)||"other";return s.jsxs(s.Fragment,{children:[s.jsx("audio",{ref:l,src:t||void 0,preload:"auto",onPlay:()=>a(!0),onPause:()=>a(!1),onEnded:()=>a(!1),onTimeUpdate:()=>{var f;return u(((f=l.current)==null?void 0:f.currentTime)??0)},onLoadedMetadata:()=>{var f;return g(((f=l.current)==null?void 0:f.duration)??NaN)},onDurationChange:()=>{var f;return g(((f=l.current)==null?void 0:f.duration)??NaN)},style:{display:"none"}}),s.jsxs("div",{className:"audio-bar",style:{position:"fixed",bottom:0,left:0,right:0,zIndex:100,background:"var(--paper-3)",borderTop:"1px solid var(--line)",display:"flex",alignItems:"center",gap:"16px",padding:"0 16px",height:"56px",fontFamily:"var(--sans)"},children:[s.jsxs("div",{className:"audio-bar-info",style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0,flex:"0 1 220px",overflow:"hidden"},children:[s.jsx("span",{className:"source-icon",style:{flexShrink:0,width:"18px",height:"18px",display:"flex",alignItems:"center"},dangerouslySetInnerHTML:{__html:Ts(p)}}),s.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.85rem",color:"var(--ink)"},title:S,children:S})]}),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:ju(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:ju(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:j,"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 yg({archiveId:e,entryUid:t}){var m,x;const[n,r]=d.useState(null),[l,i]=d.useState(!0),[a,o]=d.useState(null),[u,c]=d.useState(!1);d.useEffect(()=>{if(!u)return;const v=document.documentElement,j=document.body,S=v.style.colorScheme,p=j.style.background;return v.style.colorScheme="dark",j.style.background="#000",()=>{v.style.colorScheme=S,j.style.background=p}},[u]),d.useEffect(()=>{c(!1),Tr(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 g=((m=n==null?void 0:n.summary)==null?void 0:m.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:g}),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(Xd,{archiveId:e,entry:n.summary,detail:n,fullPage:!0,onXArticle:c})]})]})}const vg=7e3;function xg({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(kg,{toast:r,onDismiss:t,onIgnoreUblock:n},r.id))}):null}function wg(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 kg({toast:e,onDismiss:t,onIgnoreUblock:n}){const[r,l]=d.useState(!1),i=e.type==="warning",a=e.type==="success";d.useEffect(()=>{if(r)return;const u=setTimeout(()=>t(e.id),vg);return()=>clearTimeout(u)},[r,e.id,t]);const o=wg(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 Ps=d.createContext(null),Nr=(()=>{const e=window.location.pathname.match(/^\/preview\/([^/]+)\/([^/]+)/);return e?{archiveId:e[1],entryUid:e[2]}:null})(),jg=["archive","tags","collections","runs","admin","settings"],Sg=["profile","tokens","instance","cookies","extensions","storage"];function gn(){const e=window.location.pathname.split("/").filter(Boolean),t=jg.includes(e[0])?e[0]:"archive",n=t==="settings"&&Sg.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 Ng(e,t){return e==="archive"?"/":e==="settings"?`/settings/${t}`:`/${e}`}function _g(){const[e,t]=d.useState("loading"),[n,r]=d.useState(null);d.useEffect(()=>{(async()=>{if(await Hh()){t("setup");return}const A=await Kh();if(!A){t("login");return}r(A),t("authenticated")})()},[]),d.useEffect(()=>{const C=()=>{r(null),t("login")};return window.addEventListener("auth:expired",C),()=>window.removeEventListener("auth:expired",C)},[]),d.useEffect(()=>{const C=()=>{const{view:A,settingsTab:F,q:K,tag:le,entry:ue}=gn();E(A),_(F),R(K),y(le),x(ue),j(null),p(ue?new Set([ue]):new Set)};return window.addEventListener("popstate",C),()=>window.removeEventListener("popstate",C)},[]);const[l,i]=d.useState([]),[a,o]=d.useState(null),[u,c]=d.useState([]),[g,h]=d.useState(()=>new Set),[m,x]=d.useState(()=>gn().entry),[v,j]=d.useState(null),[S,p]=d.useState(()=>{const C=gn().entry;return C?new Set([C]):new Set}),[f,y]=d.useState(()=>gn().tag),[w,E]=d.useState(()=>gn().view),[L,_]=d.useState(()=>gn().settingsTab),[N,R]=d.useState(()=>gn().q),[P,q]=d.useState(""),[V,X]=d.useState(!1),[Z,me]=d.useState([]),[ve,re]=d.useState([]),[I,b]=d.useState(()=>sessionStorage.getItem("captureDialogOpen")==="true"),[U,ee]=d.useState([]),Q=d.useRef(0),[de,fe]=d.useState(()=>{try{const C=JSON.parse(sessionStorage.getItem("pendingCaptures")||"[]");if(Array.isArray(C))return C}catch{}return[]});d.useEffect(()=>{sessionStorage.setItem("pendingCaptures",JSON.stringify(de))},[de]);const[Ie,je]=d.useState(()=>sessionStorage.getItem("ublockWarningIgnored")==="true"),[We,nt]=d.useState(null),rt=d.useRef(0),lt=d.useRef(null),ft=d.useRef(!1),pt=d.useRef(!0),$=d.useRef(null),G=d.useRef(0),_e=d.useRef(new Map),De=(n==null?void 0:n.humanize_slugs)??!1;d.useEffect(()=>{const C=++rt.current;nt(null),!(!v||!a)&&Tr(a,v.entry_uid).then(A=>{C===rt.current&&nt(A)}).catch(()=>{})},[v,a]),d.useEffect(()=>{sessionStorage.setItem("captureDialogOpen",I)},[I]);const st=d.useCallback(async(C,A,F)=>{if(C){X(!0);try{let K;A||F?K=await Ph(C,A,F):K=await Th(C),c(K),p(le=>{if(le.size<2)return le;const ue=new Set(K.map(ht=>ht.entry_uid)),Me=new Set([...le].filter(ht=>ue.has(ht)));return Me.size===le.size?le:Me}),q(K.length===0?"No results":`${K.length} result${K.length===1?"":"s"}`)}catch{c([]),q("Search failed. Try again.")}finally{X(!1)}}},[]);d.useEffect(()=>{e==="authenticated"&&bh().then(C=>{if(i(C),C.length>0){const A=C[0].id;o(A)}})},[e]),d.useEffect(()=>{if(a){if(pt.current){pt.current=!1,Promise.all([ri(a).then(me),El(a).then(re)]);return}y(null),j(null),x(null),p(new Set),Promise.all([st(a,"",null),ri(a).then(me),El(a).then(re)])}},[a]),d.useEffect(()=>{if(a===null)return;const C=setTimeout(()=>{st(a,N,f)},300);return()=>clearTimeout(C)},[N,a]),d.useEffect(()=>{a!==null&&(f!==null&&E("archive"),st(a,N,f))},[f,a]);const mn=d.useCallback(C=>{o(C)},[]),Rn=d.useCallback(C=>{E(C),C==="tags"&&a&&El(a).then(re)},[a]);d.useEffect(()=>{if(Nr)return;const C=Ng(w,L);window.location.pathname!==C&&history.pushState(null,"",C+window.location.search)},[w,L]);const Ve=d.useCallback(C=>{x(C?C.entry_uid:null),j(C)},[]),zn=d.useCallback((C,A)=>{if(_e.current.set(C.entry_uid,C),++G.current,A.shiftKey&&$.current!==null){A.preventDefault();const F=[...document.querySelectorAll("#entries-body [data-entry-uid]")],K=F.findIndex(Je=>Je.dataset.entryUid===$.current),le=F.findIndex(Je=>Je.dataset.entryUid===C.entry_uid);if(K===-1||le===-1){$.current=C.entry_uid,p(new Set([C.entry_uid])),Ve(C);return}const ue=Math.min(K,le),Me=Math.max(K,le),ht=new Set(F.slice(ue,Me+1).map(Je=>Je.dataset.entryUid));p(ht),ht.size===1&&Ve(C)}else if(A.ctrlKey||A.metaKey){$.current=C.entry_uid;const F=new Set(S);if(F.has(C.entry_uid)?F.delete(C.entry_uid):F.add(C.entry_uid),p(F),F.size===0)Ve(null);else if(F.size===1){const[K]=F,le=_e.current.get(K)??u.find(ue=>ue.entry_uid===K)??null;if(le)Ve(le);else{const ue=++G.current;Tr(a,K).then(Me=>{ue===G.current&&(Me!=null&&Me.summary)&&Ve(Me.summary)}).catch(()=>{})}}else Ve(null)}else $.current=C.entry_uid,p(new Set([C.entry_uid])),Ve(C)},[u,S,Ve,a]),In=d.useCallback(C=>{y(C)},[]),fr=d.useCallback(()=>{y(null)},[]),Qt=d.useCallback(()=>{a&&El(a).then(re)},[a]),pr=d.useCallback((C,A)=>{f===C?y(A):f!=null&&f.startsWith(C+"/")&&y(A+f.slice(C.length))},[f]),hr=d.useCallback(C=>{(f===C||f!=null&&f.startsWith(C+"/"))&&y(null)},[f]),mr=d.useCallback((C,A)=>{c(F=>F.map(K=>K.entry_uid===C?{...K,title:A}:K)),j(F=>F&&F.entry_uid===C?{...F,title:A}:F),nt(F=>F&&F.summary.entry_uid===C?{...F,summary:{...F.summary,title:A}}:F)},[]),k=d.useCallback(()=>{if(!a||!v)return;const C=++rt.current;Tr(a,v.entry_uid).then(A=>{C===rt.current&&nt(A)}).catch(()=>{})},[a,v]),M=d.useCallback(C=>{const A=u.some(F=>F.entry_uid===C);h(F=>{const K=new Set(F);return K.add(C),K}),c(F=>F.filter(K=>K.entry_uid!==C)),j(F=>(F==null?void 0:F.entry_uid)===C?null:F),x(F=>F===C?null:F),p(F=>{const K=new Set(F);return K.delete(C),K}),A||st(a,N,f)},[u,a,N,f,st]),O=d.useCallback(C=>{const A=new Set(u.map(K=>K.entry_uid)),F=[...C].some(K=>!A.has(K));h(K=>{const le=new Set(K);return C.forEach(ue=>le.add(ue)),le}),c(K=>K.filter(le=>!C.has(le.entry_uid))),p(new Set),j(null),x(null),F&&st(a,N,f)},[u,a,N,f,st]);d.useEffect(()=>{if(S.size>=2)x(null),j(null);else if(S.size===1){const[C]=S;x(C)}else x(null),j(null)},[S]);const D=d.useMemo(()=>u.filter(C=>S.has(C.entry_uid)),[u,S]);d.useEffect(()=>{if(!m||v)return;const C=u.find(A=>A.entry_uid===m);C&&j(C)},[u,m,v]),d.useEffect(()=>{if(Nr)return;const C=new URLSearchParams;N&&C.set("q",N),w==="archive"&&f&&C.set("tag",f),w==="archive"&&m&&C.set("entry",m);const A=C.toString(),F=window.location.pathname+(A?"?"+A:"");window.location.pathname+window.location.search!==F&&history.replaceState(null,"",F)},[N,f,m,w]),d.useEffect(()=>{const C=A=>{var ue,Me,ht,Je;const F=A.key==="/"&&!A.metaKey&&!A.ctrlKey&&!A.altKey,K=(A.metaKey||A.ctrlKey)&&A.key==="k";if(!F&&!K)return;const le=(ue=document.activeElement)==null?void 0:ue.tagName;F&&(le==="INPUT"||le==="TEXTAREA"||le==="SELECT")||F&&((Me=document.activeElement)!=null&&Me.isContentEditable)||(A.preventDefault(),w==="archive"?((ht=lt.current)==null||ht.focus(),(Je=lt.current)==null||Je.select()):(ft.current=!0,E("archive")))};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[w]),d.useEffect(()=>{const C=A=>{var Za,eo;if(A.metaKey||A.ctrlKey||A.altKey||A.key!=="j"&&A.key!=="k")return;const F=(Za=document.activeElement)==null?void 0:Za.tagName;if(F==="INPUT"||F==="TEXTAREA"||F==="SELECT"||(eo=document.activeElement)!=null&&eo.isContentEditable)return;const K=[...document.querySelectorAll("#entries-body [data-entry-uid]")];if(K.length===0)return;const[le]=S.size===1?S:[null],ue=le?K.findIndex(Kt=>Kt.dataset.entryUid===le):-1,Me=A.key==="j"?Math.min(ue+1,K.length-1):Math.max(ue-1,0);if(Me===ue&&ue!==-1)return;const ht=K[Me<0?0:Me],Je=ht.dataset.entryUid;$.current=Je;const ef=++G.current;p(new Set([Je]));const Ya=_e.current.get(Je)??u.find(Kt=>Kt.entry_uid===Je)??null;Ya?Ve(Ya):Tr(a,Je).then(Kt=>{ef===G.current&&(Kt!=null&&Kt.summary)&&Ve(Kt.summary)}).catch(()=>{}),ht.scrollIntoView({block:"nearest"}),A.preventDefault()};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[S,u,Ve,a]),d.useEffect(()=>{w==="archive"&&ft.current&&(ft.current=!1,requestAnimationFrame(()=>{var C,A;(C=lt.current)==null||C.focus(),(A=lt.current)==null||A.select()}))},[w]);const H=d.useCallback(()=>{b(!0)},[]),W=d.useCallback(()=>{b(!1)},[]),oe=d.useCallback(()=>{if(a)return Promise.allSettled([st(a,N,f),ri(a).then(me)])},[a,N,f,st]),T=d.useCallback((C,A,F="error",K=null)=>{if(F==="warning"&&Ie&&A)return;const le=++Q.current;ee(ue=>[...ue,{id:le,text:C,locator:A,type:F,headline:K}])},[Ie]),J=d.useCallback(C=>{ee(A=>A.filter(F=>F.id!==C))},[]),te=d.useCallback(()=>{sessionStorage.setItem("ublockWarningIgnored","true"),je(!0),ee(C=>C.filter(A=>!(A.type==="warning"&&A.locator)))},[]),be=d.useCallback(C=>{fe(A=>[...A,C])},[]),ge=d.useCallback(C=>{fe(A=>A.filter(F=>F.id!==C))},[]),[Tt,ie]=d.useState(null),[Dt,Ga]=d.useState(null),Jd=d.useCallback(()=>{v&&ie(v.entry_uid)},[v]),Gd=d.useCallback(()=>ie(null),[]),Yd=d.useCallback((C,A)=>{Ga({src:C,entry:A})},[]),Zd=d.useCallback(()=>Ga(null),[]);return d.useEffect(()=>{ie(null)},[v]),d.useEffect(()=>{const C=A=>{var K,le,ue;if(A.key!=="Escape"||I||Tt)return;const F=(K=document.activeElement)==null?void 0:K.tagName;F==="INPUT"||F==="TEXTAREA"||F==="SELECT"||S.size>0&&(A.preventDefault(),p(new Set),(ue=(le=document.activeElement)==null?void 0:le.blur)==null||ue.call(le))};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[I,Tt,S]),d.useEffect(()=>(document.body.classList.toggle("has-audio-bar",!!Dt),()=>document.body.classList.remove("has-audio-bar")),[Dt]),e==="loading"?s.jsx("div",{className:"auth-loading",children:"Loading\\u2026"}):e==="setup"?s.jsx(jm,{onComplete:()=>t("login")}):e==="login"?s.jsx(km,{onLogin:C=>{r(C),t("authenticated")}}):Nr?s.jsx(yg,{archiveId:Nr.archiveId,entryUid:Nr.entryUid}):s.jsx(Ps.Provider,{value:{currentUser:n,setCurrentUser:r},children:s.jsxs(s.Fragment,{children:[s.jsx(Sm,{archives:l,archiveId:a,onArchiveChange:mn,view:w,onViewChange:Rn,onCaptureClick:H}),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:lt,className:"search-input",type:"search","aria-label":"Search archive","aria-busy":V,placeholder:"Search titles, URLs, types, tags…",value:N,onChange:C=>R(C.target.value)}),s.jsx("span",{className:"kbd",children:"⌘K"})]}),s.jsxs("span",{className:"result-count",children:[P&&s.jsxs(s.Fragment,{children:[s.jsx("b",{children:P.split(" ")[0]})," ",P.split(" ").slice(1).join(" ")]}),f&&s.jsxs("button",{className:"tag-filter-badge",onClick:fr,children:["× ",De?Fd(f):f]})]})]}),w==="archive"&&s.jsx(zm,{entries:u,selectedUids:S,onRowClick:zn,archiveId:a,pendingCaptures:de,deletedUids:g}),w==="runs"&&s.jsx($m,{runs:Z}),w==="admin"&&s.jsx(Am,{archives:l}),w==="tags"&&s.jsx(Mm,{archiveId:a,tagNodes:ve,tagFilter:f,onTagFilterSet:In,onViewChange:Rn,onTagRenamed:pr,onTagDeleted:hr,onTagsRefresh:Qt,humanizeTags:De}),w==="collections"&&s.jsx(Bm,{archiveId:a}),w==="settings"&&s.jsx(Hm,{tab:L,onTabChange:_,archiveId:a})]}),s.jsx(Gm,{archiveId:a,selectedEntry:v,selectedUids:S,selectedEntries:D,detail:We,onTagFilterSet:In,tagNodes:ve,onTagsRefresh:Qt,onEntryTitleChange:mr,onEntryDeleted:M,onBulkDeleted:O,humanizeTags:De,onDetailRefresh:k,onOpenPreview:Jd,onPlay:Yd})]}),Tt&&v&&v.entry_uid===Tt&&s.jsx(mg,{archiveId:a,entry:v,detail:We,onClose:Gd}),Dt&&s.jsx(gg,{entry:Dt.entry,src:Dt.src,archiveId:a,onClose:Zd}),s.jsx(Cm,{open:I,archiveId:a,onClose:W,onCaptured:oe,onToast:T,activeJobs:de,onJobStarted:be,onJobSettled:ge}),s.jsx(xg,{toasts:U,onDismiss:J,onIgnoreUblock:te})]})})}Dd(document.getElementById("root")).render(s.jsx(d.StrictMode,{children:s.jsx(_g,{})}));