(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 s of l)if(s.type==="childList")for(const a of s.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&r(a)}).observe(document,{childList:!0,subtree:!0});function n(l){const s={};return l.integrity&&(s.integrity=l.integrity),l.referrerPolicy&&(s.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?s.credentials="include":l.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function r(l){if(l.ep)return;l.ep=!0;const s=n(l);fetch(l.href,s)}})();var Po={exports:{}},Nl={},Lo={exports:{}},Q={};/** * @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 xr=Symbol.for("react.element"),cd=Symbol.for("react.portal"),dd=Symbol.for("react.fragment"),fd=Symbol.for("react.strict_mode"),pd=Symbol.for("react.profiler"),hd=Symbol.for("react.provider"),md=Symbol.for("react.context"),gd=Symbol.for("react.forward_ref"),vd=Symbol.for("react.suspense"),yd=Symbol.for("react.memo"),xd=Symbol.for("react.lazy"),ua=Symbol.iterator;function wd(e){return e===null||typeof e!="object"?null:(e=ua&&e[ua]||e["@@iterator"],typeof e=="function"?e:null)}var Ro={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},zo=Object.assign,Do={};function Ln(e,t,n){this.props=e,this.context=t,this.refs=Do,this.updater=n||Ro}Ln.prototype.isReactComponent={};Ln.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")};Ln.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function $o(){}$o.prototype=Ln.prototype;function fi(e,t,n){this.props=e,this.context=t,this.refs=Do,this.updater=n||Ro}var pi=fi.prototype=new $o;pi.constructor=fi;zo(pi,Ln.prototype);pi.isPureReactComponent=!0;var ca=Array.isArray,Oo=Object.prototype.hasOwnProperty,hi={current:null},Io={key:!0,ref:!0,__self:!0,__source:!0};function Fo(e,t,n){var r,l={},s=null,a=null;if(t!=null)for(r in t.ref!==void 0&&(a=t.ref),t.key!==void 0&&(s=""+t.key),t)Oo.call(t,r)&&!Io.hasOwnProperty(r)&&(l[r]=t[r]);var o=arguments.length-2;if(o===1)l.children=n;else if(1>>1,C=L[j];if(0>>1;jl(B,D))Yl(W,B)?(L[j]=W,L[Y]=D,j=Y):(L[j]=B,L[A]=D,j=A);else if(Yl(W,D))L[j]=W,L[Y]=D,j=Y;else break e}}return k}function l(L,k){var D=L.sortIndex-k.sortIndex;return D!==0?D:L.id-k.id}if(typeof performance=="object"&&typeof performance.now=="function"){var s=performance;e.unstable_now=function(){return s.now()}}else{var a=Date,o=a.now();e.unstable_now=function(){return a.now()-o}}var u=[],c=[],v=1,m=null,f=3,x=!1,y=!1,w=!1,z=typeof setTimeout=="function"?setTimeout:null,h=typeof clearTimeout=="function"?clearTimeout:null,d=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function g(L){for(var k=n(c);k!==null;){if(k.callback===null)r(c);else if(k.startTime<=L)r(c),k.sortIndex=k.expirationTime,t(u,k);else break;k=n(c)}}function S(L){if(w=!1,g(L),!y)if(n(u)!==null)y=!0,Re(N);else{var k=n(c);k!==null&&ye(S,k.startTime-L)}}function N(L,k){y=!1,w&&(w=!1,h(_),_=-1),x=!0;var D=f;try{for(g(k),m=n(u);m!==null&&(!(m.expirationTime>k)||L&&!V());){var j=m.callback;if(typeof j=="function"){m.callback=null,f=m.priorityLevel;var C=j(m.expirationTime<=k);k=e.unstable_now(),typeof C=="function"?m.callback=C:m===n(u)&&r(u),g(k)}else r(u);m=n(u)}if(m!==null)var M=!0;else{var A=n(c);A!==null&&ye(S,A.startTime-k),M=!1}return M}finally{m=null,f=D,x=!1}}var T=!1,P=null,_=-1,F=5,I=-1;function V(){return!(e.unstable_now()-IL||125j?(L.sortIndex=D,t(c,L),n(u)===null&&L===n(c)&&(w?(h(_),_=-1):w=!0,ye(S,D-j))):(L.sortIndex=C,t(u,L),y||x||(y=!0,Re(N))),L},e.unstable_shouldYield=V,e.unstable_wrapCallback=function(L){var k=f;return function(){var D=f;f=k;try{return L.apply(this,arguments)}finally{f=D}}}})(Uo);Bo.exports=Uo;var Rd=Bo.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 zd=p,Be=Rd;function E(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"),vs=Object.prototype.hasOwnProperty,Dd=/^[: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]*$/,fa={},pa={};function $d(e){return vs.call(pa,e)?!0:vs.call(fa,e)?!1:Dd.test(e)?pa[e]=!0:(fa[e]=!0,!1)}function Od(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 Id(e,t,n,r){if(t===null||typeof t>"u"||Od(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 Le(e,t,n,r,l,s,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=s,this.removeEmptyString=a}var ke={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){ke[e]=new Le(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];ke[t]=new Le(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){ke[e]=new Le(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){ke[e]=new Le(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){ke[e]=new Le(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){ke[e]=new Le(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){ke[e]=new Le(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){ke[e]=new Le(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){ke[e]=new Le(e,5,!1,e.toLowerCase(),null,!1,!1)});var gi=/[\-:]([a-z])/g;function vi(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(gi,vi);ke[t]=new Le(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(gi,vi);ke[t]=new Le(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(gi,vi);ke[t]=new Le(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){ke[e]=new Le(e,1,!1,e.toLowerCase(),null,!1,!1)});ke.xlinkHref=new Le("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){ke[e]=new Le(e,1,!1,e.toLowerCase(),null,!0,!0)});function yi(e,t,n,r){var l=ke.hasOwnProperty(t)?ke[t]:null;(l!==null?l.type!==0:r||!(2o||l[a]!==s[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{Hl=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?Un(e):""}function Fd(e){switch(e.tag){case 5:return Un(e.type);case 16:return Un("Lazy");case 13:return Un("Suspense");case 19:return Un("SuspenseList");case 0:case 2:case 15:return e=Wl(e.type,!1),e;case 11:return e=Wl(e.type.render,!1),e;case 1:return e=Wl(e.type,!0),e;default:return""}}function ks(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 sn:return"Fragment";case ln:return"Portal";case ys:return"Profiler";case xi:return"StrictMode";case xs:return"Suspense";case ws:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Vo:return(e.displayName||"Context")+".Consumer";case Wo:return(e._context.displayName||"Context")+".Provider";case wi:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ki:return t=e.displayName||null,t!==null?t:ks(e.type)||"Memo";case jt:t=e._payload,e=e._init;try{return ks(e(t))}catch{}}return null}function Md(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 ks(t);case 8:return t===xi?"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 It(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function Ko(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function Ad(e){var t=Ko(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,s=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return l.call(this)},set:function(a){r=""+a,s.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 Cr(e){e._valueTracker||(e._valueTracker=Ad(e))}function Xo(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=Ko(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function el(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 js(e,t){var n=t.checked;return ie({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function ma(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=It(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 Jo(e,t){t=t.checked,t!=null&&yi(e,"checked",t,!1)}function Ss(e,t){Jo(e,t);var n=It(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")?Ns(e,t.type,n):t.hasOwnProperty("defaultValue")&&Ns(e,t.type,It(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function ga(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 Ns(e,t,n){(t!=="number"||el(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var Hn=Array.isArray;function vn(e,t,n,r){if(e=e.options,t){t={};for(var l=0;l"+t.valueOf().toString()+"",t=Er.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function rr(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Kn={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},bd=["Webkit","ms","Moz","O"];Object.keys(Kn).forEach(function(e){bd.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Kn[t]=Kn[e]})});function Zo(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Kn.hasOwnProperty(e)&&Kn[e]?(""+t).trim():t+"px"}function eu(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,l=Zo(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,l):e[n]=l}}var Bd=ie({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 Es(e,t){if(t){if(Bd[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(E(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(E(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(E(61))}if(t.style!=null&&typeof t.style!="object")throw Error(E(62))}}function Ts(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 Ps=null;function ji(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Ls=null,yn=null,xn=null;function xa(e){if(e=jr(e)){if(typeof Ls!="function")throw Error(E(280));var t=e.stateNode;t&&(t=Pl(t),Ls(e.stateNode,e.type,t))}}function tu(e){yn?xn?xn.push(e):xn=[e]:yn=e}function nu(){if(yn){var e=yn,t=xn;if(xn=yn=null,xa(e),t)for(e=0;e>>=0,e===0?32:31-(qd(e)/Zd|0)|0}var Tr=64,Pr=4194304;function Wn(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 ll(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,l=e.suspendedLanes,s=e.pingedLanes,a=n&268435455;if(a!==0){var o=a&~l;o!==0?r=Wn(o):(s&=a,s!==0&&(r=Wn(s)))}else a=n&~l,a!==0?r=Wn(a):s!==0&&(r=Wn(s));if(r===0)return 0;if(t!==0&&t!==r&&!(t&l)&&(l=r&-r,s=t&-t,l>=s||l===16&&(s&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 wr(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-tt(t),e[t]=n}function rf(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=Jn),Ta=" ",Pa=!1;function ju(e,t){switch(e){case"keyup":return zf.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Su(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var an=!1;function $f(e,t){switch(e){case"compositionend":return Su(t);case"keypress":return t.which!==32?null:(Pa=!0,Ta);case"textInput":return e=t.data,e===Ta&&Pa?null:e;default:return null}}function Of(e,t){if(an)return e==="compositionend"||!Li&&ju(e,t)?(e=wu(),Vr=Ei=Ct=null,an=!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=Da(n)}}function Eu(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?Eu(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function Tu(){for(var e=window,t=el();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=el(e.document)}return t}function Ri(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 Wf(e){var t=Tu(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&Eu(n.ownerDocument.documentElement,n)){if(r!==null&&Ri(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,s=Math.min(r.start,l);r=r.end===void 0?s:Math.min(r.end,l),!e.extend&&s>r&&(l=r,r=s,s=l),l=$a(n,s);var a=$a(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(),s>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,on=null,Is=null,Gn=null,Fs=!1;function Oa(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Fs||on==null||on!==el(r)||(r=on,"selectionStart"in r&&Ri(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}),Gn&&ur(Gn,r)||(Gn=r,r=al(Is,"onSelect"),0dn||(e.current=Hs[dn],Hs[dn]=null,dn--)}function ee(e,t){dn++,Hs[dn]=e.current,e.current=t}var Ft={},Ce=At(Ft),$e=At(!1),Jt=Ft;function Nn(e,t){var n=e.type.contextTypes;if(!n)return Ft;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var l={},s;for(s in n)l[s]=t[s];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=l),l}function Oe(e){return e=e.childContextTypes,e!=null}function ul(){ne($e),ne(Ce)}function Ua(e,t,n){if(Ce.current!==Ft)throw Error(E(168));ee(Ce,t),ee($e,n)}function Fu(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(E(108,Md(e)||"Unknown",l));return ie({},n,r)}function cl(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Ft,Jt=Ce.current,ee(Ce,e),ee($e,$e.current),!0}function Ha(e,t,n){var r=e.stateNode;if(!r)throw Error(E(169));n?(e=Fu(e,t,Jt),r.__reactInternalMemoizedMergedChildContext=e,ne($e),ne(Ce),ee(Ce,e)):ne($e),ee($e,n)}var ft=null,Ll=!1,ls=!1;function Mu(e){ft===null?ft=[e]:ft.push(e)}function np(e){Ll=!0,Mu(e)}function bt(){if(!ls&&ft!==null){ls=!0;var e=0,t=q;try{var n=ft;for(q=1;e>=a,l-=a,pt=1<<32-tt(t)+l|n<_?(F=P,P=null):F=P.sibling;var I=f(h,P,g[_],S);if(I===null){P===null&&(P=F);break}e&&P&&I.alternate===null&&t(h,P),d=s(I,d,_),T===null?N=I:T.sibling=I,T=I,P=F}if(_===g.length)return n(h,P),re&&Bt(h,_),N;if(P===null){for(;__?(F=P,P=null):F=P.sibling;var V=f(h,P,I.value,S);if(V===null){P===null&&(P=F);break}e&&P&&V.alternate===null&&t(h,P),d=s(V,d,_),T===null?N=V:T.sibling=V,T=V,P=F}if(I.done)return n(h,P),re&&Bt(h,_),N;if(P===null){for(;!I.done;_++,I=g.next())I=m(h,I.value,S),I!==null&&(d=s(I,d,_),T===null?N=I:T.sibling=I,T=I);return re&&Bt(h,_),N}for(P=r(h,P);!I.done;_++,I=g.next())I=x(P,h,_,I.value,S),I!==null&&(e&&I.alternate!==null&&P.delete(I.key===null?_:I.key),d=s(I,d,_),T===null?N=I:T.sibling=I,T=I);return e&&P.forEach(function(J){return t(h,J)}),re&&Bt(h,_),N}function z(h,d,g,S){if(typeof g=="object"&&g!==null&&g.type===sn&&g.key===null&&(g=g.props.children),typeof g=="object"&&g!==null){switch(g.$$typeof){case _r:e:{for(var N=g.key,T=d;T!==null;){if(T.key===N){if(N=g.type,N===sn){if(T.tag===7){n(h,T.sibling),d=l(T,g.props.children),d.return=h,h=d;break e}}else if(T.elementType===N||typeof N=="object"&&N!==null&&N.$$typeof===jt&&Qa(N)===T.type){n(h,T.sibling),d=l(T,g.props),d.ref=Mn(h,T,g),d.return=h,h=d;break e}n(h,T);break}else t(h,T);T=T.sibling}g.type===sn?(d=Xt(g.props.children,h.mode,S,g.key),d.return=h,h=d):(S=Zr(g.type,g.key,g.props,null,h.mode,S),S.ref=Mn(h,d,g),S.return=h,h=S)}return a(h);case ln:e:{for(T=g.key;d!==null;){if(d.key===T)if(d.tag===4&&d.stateNode.containerInfo===g.containerInfo&&d.stateNode.implementation===g.implementation){n(h,d.sibling),d=l(d,g.children||[]),d.return=h,h=d;break e}else{n(h,d);break}else t(h,d);d=d.sibling}d=fs(g,h.mode,S),d.return=h,h=d}return a(h);case jt:return T=g._init,z(h,d,T(g._payload),S)}if(Hn(g))return y(h,d,g,S);if(Dn(g))return w(h,d,g,S);Ir(h,g)}return typeof g=="string"&&g!==""||typeof g=="number"?(g=""+g,d!==null&&d.tag===6?(n(h,d.sibling),d=l(d,g),d.return=h,h=d):(n(h,d),d=ds(g,h.mode,S),d.return=h,h=d),a(h)):n(h,d)}return z}var Cn=Uu(!0),Hu=Uu(!1),pl=At(null),hl=null,hn=null,Oi=null;function Ii(){Oi=hn=hl=null}function Fi(e){var t=pl.current;ne(pl),e._currentValue=t}function Qs(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 kn(e,t){hl=e,Oi=hn=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(De=!0),e.firstContext=null)}function Je(e){var t=e._currentValue;if(Oi!==e)if(e={context:e,memoizedValue:t,next:null},hn===null){if(hl===null)throw Error(E(308));hn=e,hl.dependencies={lanes:0,firstContext:e}}else hn=hn.next=e;return t}var Wt=null;function Mi(e){Wt===null?Wt=[e]:Wt.push(e)}function Wu(e,t,n,r){var l=t.interleaved;return l===null?(n.next=n,Mi(t)):(n.next=l.next,l.next=n),t.interleaved=n,yt(e,r)}function yt(e,t){e.lanes|=t;var n=e.alternate;for(n!==null&&(n.lanes|=t),n=e,e=e.return;e!==null;)e.childLanes|=t,n=e.alternate,n!==null&&(n.childLanes|=t),n=e,e=e.return;return n.tag===3?n.stateNode:null}var St=!1;function Ai(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Vu(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 mt(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function zt(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,X&2){var l=r.pending;return l===null?t.next=t:(t.next=l.next,l.next=t),r.pending=t,yt(e,n)}return l=r.interleaved,l===null?(t.next=t,Mi(r)):(t.next=l.next,l.next=t),r.interleaved=t,yt(e,n)}function Kr(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,Ni(e,n)}}function Ka(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var l=null,s=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};s===null?l=s=a:s=s.next=a,n=n.next}while(n!==null);s===null?l=s=t:s=s.next=t}else l=s=t;n={baseState:r.baseState,firstBaseUpdate:l,lastBaseUpdate:s,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 ml(e,t,n,r){var l=e.updateQueue;St=!1;var s=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?s=c:a.next=c,a=u;var v=e.alternate;v!==null&&(v=v.updateQueue,o=v.lastBaseUpdate,o!==a&&(o===null?v.firstBaseUpdate=c:o.next=c,v.lastBaseUpdate=u))}if(s!==null){var m=l.baseState;a=0,v=c=u=null,o=s;do{var f=o.lane,x=o.eventTime;if((r&f)===f){v!==null&&(v=v.next={eventTime:x,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var y=e,w=o;switch(f=t,x=n,w.tag){case 1:if(y=w.payload,typeof y=="function"){m=y.call(x,m,f);break e}m=y;break e;case 3:y.flags=y.flags&-65537|128;case 0:if(y=w.payload,f=typeof y=="function"?y.call(x,m,f):y,f==null)break e;m=ie({},m,f);break e;case 2:St=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,f=l.effects,f===null?l.effects=[o]:f.push(o))}else x={eventTime:x,lane:f,tag:o.tag,payload:o.payload,callback:o.callback,next:null},v===null?(c=v=x,u=m):v=v.next=x,a|=f;if(o=o.next,o===null){if(o=l.shared.pending,o===null)break;f=o,o=f.next,f.next=null,l.lastBaseUpdate=f,l.shared.pending=null}}while(!0);if(v===null&&(u=m),l.baseState=u,l.firstBaseUpdate=c,l.lastBaseUpdate=v,t=l.shared.interleaved,t!==null){l=t;do a|=l.lane,l=l.next;while(l!==t)}else s===null&&(l.shared.lanes=0);qt|=a,e.lanes=a,e.memoizedState=m}}function Xa(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=is.transition;is.transition={};try{e(!1),t()}finally{q=n,is.transition=r}}function oc(){return Ye().memoizedState}function ip(e,t,n){var r=$t(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},uc(e))cc(t,n);else if(n=Wu(e,t,n,r),n!==null){var l=Te();nt(n,e,r,l),dc(n,t,r)}}function ap(e,t,n){var r=$t(e),l={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(uc(e))cc(t,l);else{var s=e.alternate;if(e.lanes===0&&(s===null||s.lanes===0)&&(s=t.lastRenderedReducer,s!==null))try{var a=t.lastRenderedState,o=s(a,n);if(l.hasEagerState=!0,l.eagerState=o,rt(o,a)){var u=t.interleaved;u===null?(l.next=l,Mi(t)):(l.next=u.next,u.next=l),t.interleaved=l;return}}catch{}finally{}n=Wu(e,t,l,r),n!==null&&(l=Te(),nt(n,e,r,l),dc(n,t,r))}}function uc(e){var t=e.alternate;return e===se||t!==null&&t===se}function cc(e,t){qn=vl=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function dc(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Ni(e,n)}}var yl={readContext:Je,useCallback:Se,useContext:Se,useEffect:Se,useImperativeHandle:Se,useInsertionEffect:Se,useLayoutEffect:Se,useMemo:Se,useReducer:Se,useRef:Se,useState:Se,useDebugValue:Se,useDeferredValue:Se,useTransition:Se,useMutableSource:Se,useSyncExternalStore:Se,useId:Se,unstable_isNewReconciler:!1},op={readContext:Je,useCallback:function(e,t){return st().memoizedState=[e,t===void 0?null:t],e},useContext:Je,useEffect:Ya,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,Jr(4194308,4,rc.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Jr(4194308,4,e,t)},useInsertionEffect:function(e,t){return Jr(4,2,e,t)},useMemo:function(e,t){var n=st();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=st();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=ip.bind(null,se,e),[r.memoizedState,e]},useRef:function(e){var t=st();return e={current:e},t.memoizedState=e},useState:Ja,useDebugValue:Ki,useDeferredValue:function(e){return st().memoizedState=e},useTransition:function(){var e=Ja(!1),t=e[0];return e=sp.bind(null,e[1]),st().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=se,l=st();if(re){if(n===void 0)throw Error(E(407));n=n()}else{if(n=t(),me===null)throw Error(E(349));Gt&30||Ju(r,t,n)}l.memoizedState=n;var s={value:n,getSnapshot:t};return l.queue=s,Ya(Gu.bind(null,r,s,e),[e]),r.flags|=2048,vr(9,Yu.bind(null,r,s,n,t),void 0,null),n},useId:function(){var e=st(),t=me.identifierPrefix;if(re){var n=ht,r=pt;n=(r&~(1<<32-tt(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=mr++,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[it]=t,e[fr]=r,kc(e,t,!1,!1),t.stateNode=e;e:{switch(a=Ts(n,r),n){case"dialog":te("cancel",e),te("close",e),l=r;break;case"iframe":case"object":case"embed":te("load",e),l=r;break;case"video":case"audio":for(l=0;lPn&&(t.flags|=128,r=!0,An(s,!1),t.lanes=4194304)}else{if(!r)if(e=gl(a),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),An(s,!0),s.tail===null&&s.tailMode==="hidden"&&!a.alternate&&!re)return Ne(t),null}else 2*oe()-s.renderingStartTime>Pn&&n!==1073741824&&(t.flags|=128,r=!0,An(s,!1),t.lanes=4194304);s.isBackwards?(a.sibling=t.child,t.child=a):(n=s.last,n!==null?n.sibling=a:t.child=a,s.last=a)}return s.tail!==null?(t=s.tail,s.rendering=t,s.tail=t.sibling,s.renderingStartTime=oe(),t.sibling=null,n=le.current,ee(le,r?n&1|2:n&1),t):(Ne(t),null);case 22:case 23:return Zi(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?Me&1073741824&&(Ne(t),t.subtreeFlags&6&&(t.flags|=8192)):Ne(t),null;case 24:return null;case 25:return null}throw Error(E(156,t.tag))}function gp(e,t){switch(Di(t),t.tag){case 1:return Oe(t.type)&&ul(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return En(),ne($e),ne(Ce),Ui(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Bi(t),null;case 13:if(ne(le),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(E(340));_n()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return ne(le),null;case 4:return En(),null;case 10:return Fi(t.type._context),null;case 22:case 23:return Zi(),null;case 24:return null;default:return null}}var Mr=!1,_e=!1,vp=typeof WeakSet=="function"?WeakSet:Set,$=null;function mn(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){ae(e,t,r)}else n.current=null}function ti(e,t,n){try{n()}catch(r){ae(e,t,r)}}var ao=!1;function yp(e,t){if(Ms=sl,e=Tu(),Ri(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,s=r.focusNode;r=r.focusOffset;try{n.nodeType,s.nodeType}catch{n=null;break e}var a=0,o=-1,u=-1,c=0,v=0,m=e,f=null;t:for(;;){for(var x;m!==n||l!==0&&m.nodeType!==3||(o=a+l),m!==s||r!==0&&m.nodeType!==3||(u=a+r),m.nodeType===3&&(a+=m.nodeValue.length),(x=m.firstChild)!==null;)f=m,m=x;for(;;){if(m===e)break t;if(f===n&&++c===l&&(o=a),f===s&&++v===r&&(u=a),(x=m.nextSibling)!==null)break;m=f,f=m.parentNode}m=x}n=o===-1||u===-1?null:{start:o,end:u}}else n=null}n=n||{start:0,end:0}}else n=null;for(As={focusedElem:e,selectionRange:n},sl=!1,$=t;$!==null;)if(t=$,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,$=e;else for(;$!==null;){t=$;try{var y=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(y!==null){var w=y.memoizedProps,z=y.memoizedState,h=t.stateNode,d=h.getSnapshotBeforeUpdate(t.elementType===t.type?w:qe(t.type,w),z);h.__reactInternalSnapshotBeforeUpdate=d}break;case 3:var g=t.stateNode.containerInfo;g.nodeType===1?g.textContent="":g.nodeType===9&&g.documentElement&&g.removeChild(g.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(E(163))}}catch(S){ae(t,t.return,S)}if(e=t.sibling,e!==null){e.return=t.return,$=e;break}$=t.return}return y=ao,ao=!1,y}function Zn(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 s=l.destroy;l.destroy=void 0,s!==void 0&&ti(t,n,s)}l=l.next}while(l!==r)}}function Dl(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 ni(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 Nc(e){var t=e.alternate;t!==null&&(e.alternate=null,Nc(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[it],delete t[fr],delete t[Us],delete t[ep],delete t[tp])),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 _c(e){return e.tag===5||e.tag===3||e.tag===4}function oo(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||_c(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 ri(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=ol));else if(r!==4&&(e=e.child,e!==null))for(ri(e,t,n),e=e.sibling;e!==null;)ri(e,t,n),e=e.sibling}function li(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(li(e,t,n),e=e.sibling;e!==null;)li(e,t,n),e=e.sibling}var xe=null,Ze=!1;function kt(e,t,n){for(n=n.child;n!==null;)Cc(e,t,n),n=n.sibling}function Cc(e,t,n){if(at&&typeof at.onCommitFiberUnmount=="function")try{at.onCommitFiberUnmount(_l,n)}catch{}switch(n.tag){case 5:_e||mn(n,t);case 6:var r=xe,l=Ze;xe=null,kt(e,t,n),xe=r,Ze=l,xe!==null&&(Ze?(e=xe,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):xe.removeChild(n.stateNode));break;case 18:xe!==null&&(Ze?(e=xe,n=n.stateNode,e.nodeType===8?rs(e.parentNode,n):e.nodeType===1&&rs(e,n),ar(e)):rs(xe,n.stateNode));break;case 4:r=xe,l=Ze,xe=n.stateNode.containerInfo,Ze=!0,kt(e,t,n),xe=r,Ze=l;break;case 0:case 11:case 14:case 15:if(!_e&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){l=r=r.next;do{var s=l,a=s.destroy;s=s.tag,a!==void 0&&(s&2||s&4)&&ti(n,t,a),l=l.next}while(l!==r)}kt(e,t,n);break;case 1:if(!_e&&(mn(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(o){ae(n,t,o)}kt(e,t,n);break;case 21:kt(e,t,n);break;case 22:n.mode&1?(_e=(r=_e)||n.memoizedState!==null,kt(e,t,n),_e=r):kt(e,t,n);break;default:kt(e,t,n)}}function uo(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new vp),t.forEach(function(r){var l=Ep.bind(null,e,r);n.has(r)||(n.add(r),r.then(l,l))})}}function Ge(e,t){var n=t.deletions;if(n!==null)for(var r=0;rl&&(l=a),r&=~s}if(r=l,r=oe()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*wp(r/1960))-r,10e?16:e,Et===null)var r=!1;else{if(e=Et,Et=null,kl=0,X&6)throw Error(E(331));var l=X;for(X|=4,$=e.current;$!==null;){var s=$,a=s.child;if($.flags&16){var o=s.deletions;if(o!==null){for(var u=0;uoe()-Gi?Kt(e,0):Yi|=n),Ie(e,t)}function $c(e,t){t===0&&(e.mode&1?(t=Pr,Pr<<=1,!(Pr&130023424)&&(Pr=4194304)):t=1);var n=Te();e=yt(e,t),e!==null&&(wr(e,t,n),Ie(e,n))}function Cp(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),$c(e,n)}function Ep(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(E(314))}r!==null&&r.delete(t),$c(e,n)}var Oc;Oc=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||$e.current)De=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return De=!1,hp(e,t,n);De=!!(e.flags&131072)}else De=!1,re&&t.flags&1048576&&Au(t,fl,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Yr(e,t),e=t.pendingProps;var l=Nn(t,Ce.current);kn(t,n),l=Wi(null,t,r,e,l,n);var s=Vi();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,Oe(r)?(s=!0,cl(t)):s=!1,t.memoizedState=l.state!==null&&l.state!==void 0?l.state:null,Ai(t),l.updater=zl,t.stateNode=l,l._reactInternals=t,Xs(t,r,e,n),t=Gs(null,t,r,!0,s,n)):(t.tag=0,re&&s&&zi(t),Ee(null,t,l,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Yr(e,t),e=t.pendingProps,l=r._init,r=l(r._payload),t.type=r,l=t.tag=Pp(r),e=qe(r,e),l){case 0:t=Ys(null,t,r,e,n);break e;case 1:t=lo(null,t,r,e,n);break e;case 11:t=no(null,t,r,e,n);break e;case 14:t=ro(null,t,r,qe(r.type,e),n);break e}throw Error(E(306,r,""))}return t;case 0:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:qe(r,l),Ys(e,t,r,l,n);case 1:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:qe(r,l),lo(e,t,r,l,n);case 3:e:{if(yc(t),e===null)throw Error(E(387));r=t.pendingProps,s=t.memoizedState,l=s.element,Vu(e,t),ml(t,r,null,n);var a=t.memoizedState;if(r=a.element,s.isDehydrated)if(s={element:r,isDehydrated:!1,cache:a.cache,pendingSuspenseBoundaries:a.pendingSuspenseBoundaries,transitions:a.transitions},t.updateQueue.baseState=s,t.memoizedState=s,t.flags&256){l=Tn(Error(E(423)),t),t=so(e,t,r,n,l);break e}else if(r!==l){l=Tn(Error(E(424)),t),t=so(e,t,r,n,l);break e}else for(Ae=Rt(t.stateNode.containerInfo.firstChild),be=t,re=!0,et=null,n=Hu(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(_n(),r===l){t=xt(e,t,n);break e}Ee(e,t,r,n)}t=t.child}return t;case 5:return Qu(t),e===null&&Vs(t),r=t.type,l=t.pendingProps,s=e!==null?e.memoizedProps:null,a=l.children,bs(r,l)?a=null:s!==null&&bs(r,s)&&(t.flags|=32),vc(e,t),Ee(e,t,a,n),t.child;case 6:return e===null&&Vs(t),null;case 13:return xc(e,t,n);case 4:return bi(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=Cn(t,null,r,n):Ee(e,t,r,n),t.child;case 11:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:qe(r,l),no(e,t,r,l,n);case 7:return Ee(e,t,t.pendingProps,n),t.child;case 8:return Ee(e,t,t.pendingProps.children,n),t.child;case 12:return Ee(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,l=t.pendingProps,s=t.memoizedProps,a=l.value,ee(pl,r._currentValue),r._currentValue=a,s!==null)if(rt(s.value,a)){if(s.children===l.children&&!$e.current){t=xt(e,t,n);break e}}else for(s=t.child,s!==null&&(s.return=t);s!==null;){var o=s.dependencies;if(o!==null){a=s.child;for(var u=o.firstContext;u!==null;){if(u.context===r){if(s.tag===1){u=mt(-1,n&-n),u.tag=2;var c=s.updateQueue;if(c!==null){c=c.shared;var v=c.pending;v===null?u.next=u:(u.next=v.next,v.next=u),c.pending=u}}s.lanes|=n,u=s.alternate,u!==null&&(u.lanes|=n),Qs(s.return,n,t),o.lanes|=n;break}u=u.next}}else if(s.tag===10)a=s.type===t.type?null:s.child;else if(s.tag===18){if(a=s.return,a===null)throw Error(E(341));a.lanes|=n,o=a.alternate,o!==null&&(o.lanes|=n),Qs(a,n,t),a=s.sibling}else a=s.child;if(a!==null)a.return=s;else for(a=s;a!==null;){if(a===t){a=null;break}if(s=a.sibling,s!==null){s.return=a.return,a=s;break}a=a.return}s=a}Ee(e,t,l.children,n),t=t.child}return t;case 9:return l=t.type,r=t.pendingProps.children,kn(t,n),l=Je(l),r=r(l),t.flags|=1,Ee(e,t,r,n),t.child;case 14:return r=t.type,l=qe(r,t.pendingProps),l=qe(r.type,l),ro(e,t,r,l,n);case 15:return mc(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:qe(r,l),Yr(e,t),t.tag=1,Oe(r)?(e=!0,cl(t)):e=!1,kn(t,n),fc(t,r,l),Xs(t,r,l,n),Gs(null,t,r,!0,e,n);case 19:return wc(e,t,n);case 22:return gc(e,t,n)}throw Error(E(156,t.tag))};function Ic(e,t){return uu(e,t)}function Tp(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 Ke(e,t,n,r){return new Tp(e,t,n,r)}function ta(e){return e=e.prototype,!(!e||!e.isReactComponent)}function Pp(e){if(typeof e=="function")return ta(e)?1:0;if(e!=null){if(e=e.$$typeof,e===wi)return 11;if(e===ki)return 14}return 2}function Ot(e,t){var n=e.alternate;return n===null?(n=Ke(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 Zr(e,t,n,r,l,s){var a=2;if(r=e,typeof e=="function")ta(e)&&(a=1);else if(typeof e=="string")a=5;else e:switch(e){case sn:return Xt(n.children,l,s,t);case xi:a=8,l|=8;break;case ys:return e=Ke(12,n,t,l|2),e.elementType=ys,e.lanes=s,e;case xs:return e=Ke(13,n,t,l),e.elementType=xs,e.lanes=s,e;case ws:return e=Ke(19,n,t,l),e.elementType=ws,e.lanes=s,e;case Qo:return Ol(n,l,s,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Wo:a=10;break e;case Vo:a=9;break e;case wi:a=11;break e;case ki:a=14;break e;case jt:a=16,r=null;break e}throw Error(E(130,e==null?e:typeof e,""))}return t=Ke(a,n,t,l),t.elementType=e,t.type=r,t.lanes=s,t}function Xt(e,t,n,r){return e=Ke(7,e,r,t),e.lanes=n,e}function Ol(e,t,n,r){return e=Ke(22,e,r,t),e.elementType=Qo,e.lanes=n,e.stateNode={isHidden:!1},e}function ds(e,t,n){return e=Ke(6,e,null,t),e.lanes=n,e}function fs(e,t,n){return t=Ke(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function Lp(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=Ql(0),this.expirationTimes=Ql(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Ql(0),this.identifierPrefix=r,this.onRecoverableError=l,this.mutableSourceEagerHydrationData=null}function na(e,t,n,r,l,s,a,o,u){return e=new Lp(e,t,n,o,u),t===1?(t=1,s===!0&&(t|=8)):t=0,s=Ke(3,null,null,t),e.current=s,s.stateNode=e,s.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Ai(s),e}function Rp(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(bc)}catch(e){console.error(e)}}bc(),bo.exports=Ue;var Ip=bo.exports,Bc,yo=Ip;Bc=yo.createRoot,yo.hydrateRoot;async function ge(e){const t=await fetch(e);if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()}async function Fp(){return ge("/api/archives")}async function Mp(e){return ge(`/api/archives/${e}/entries`)}async function Ap(e,t,n){const r=new URLSearchParams;return t&&r.set("q",t),n&&r.set("tag",n),ge(`/api/archives/${e}/entries/search?${r}`)}async function xo(e,t){return ge(`/api/archives/${e}/entries/${t}`)}async function bp(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 Br(e,t){return ge(`/api/archives/${e}/entries/${t}/tags`)}async function Bp(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 Up(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 Hp(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 Wp(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 Vp(e,t){const n=await fetch(`/api/archives/${e}/tags/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(await n.text())}async function wo(e){return ge(`/api/archives/${e}/runs`)}async function ps(e){return ge(`/api/archives/${e}/tags`)}async function Qp(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));const s=await fetch(`/api/archives/${e}/captures`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!s.ok){const a=await s.json().catch(()=>({}));throw new Error(a.error||`HTTP ${s.status}`)}return s.json()}async function Kp(e,t){return ge(`/api/archives/${e}/captures/probe?locator=${encodeURIComponent(t)}`)}async function Uc(e,t){return ge(`/api/archives/${e}/capture_jobs/${t}`)}async function Xp(){return(await(await fetch("/api/auth/setup")).json()).setup_required===!0}async function Jp(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 Yp(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 Gp(){await fetch("/api/auth/logout",{method:"POST"})}async function qp(){const e=await fetch("/api/auth/me");return e.status===401?null:e.json()}async function Zp(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 eh(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 th(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 nh(){return ge("/api/auth/tokens")}async function rh(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 lh(e){const t=await fetch(`/api/auth/tokens/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(await t.text())}async function ia(){return ge("/api/admin/instance-settings")}async function ui(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 sh(){return ge("/api/admin/users")}async function ih(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 ah(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 oh(){return ge("/api/admin/roles")}async function uh(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 ch(e){return ge(`/api/archives/${e}/collections`)}async function dh(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 s=await l.json().catch(()=>({error:l.statusText}));throw new Error(s.error||l.statusText)}return l.json()}async function fh(e,t){return ge(`/api/archives/${e}/collections/${t}`)}async function ph(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 s=await l.json().catch(()=>({error:l.statusText}));throw new Error(s.error||l.statusText)}}async function hh(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 mh(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 s=await l.json().catch(()=>({error:l.statusText}));throw new Error(s.error||l.statusText)}}async function gh(e,t){return ge(`/api/archives/${e}/entries/${t}/collections`)}async function ko(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 vh(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 yh(e){return ge(`/api/archives/${e}/blob-cleanup`)}async function xh(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 wh(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 kh(){return ge("/api/admin/cookie-rules")}async function jh(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 Sh(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 Nh(e){const t=await fetch(`/api/admin/cookie-rules/${e}`,{method:"DELETE"});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.message||`HTTP ${t.status}`)}}const _h=window.fetch;window.fetch=async(...e)=>{var n;const t=await _h(...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 Ch({onLogin:e}){const[t,n]=p.useState(""),[r,l]=p.useState(""),[s,a]=p.useState(null),[o,u]=p.useState(!1);async function c(v){v.preventDefault(),a(null),u(!0);try{const m=await Yp(t,r);e(m)}catch(m){a(m.message)}finally{u(!1)}}return i.jsx("div",{className:"login-page",children:i.jsxs("div",{className:"login-card",children:[i.jsx("h1",{className:"login-brand",children:"Archivr"}),i.jsx("p",{className:"login-tagline",children:"Sign in to your archive"}),i.jsxs("form",{onSubmit:c,children:[i.jsxs("div",{className:"login-field",children:[i.jsx("label",{className:"login-label",htmlFor:"login-username",children:"Username"}),i.jsx("input",{className:"login-input",id:"login-username",type:"text",value:t,onChange:v=>n(v.target.value),autoFocus:!0,required:!0,autoComplete:"username"})]}),i.jsxs("div",{className:"login-field",children:[i.jsx("label",{className:"login-label",htmlFor:"login-password",children:"Password"}),i.jsx("input",{className:"login-input",id:"login-password",type:"password",value:r,onChange:v=>l(v.target.value),required:!0,autoComplete:"current-password"})]}),s&&i.jsx("p",{className:"login-error",children:s}),i.jsx("button",{className:"login-submit",type:"submit",disabled:o,children:o?"Signing in…":"Sign in"})]})]})})}function Eh({onComplete:e}){const[t,n]=p.useState(""),[r,l]=p.useState(""),[s,a]=p.useState(""),[o,u]=p.useState(null),[c,v]=p.useState(!1);async function m(f){if(f.preventDefault(),r!==s){u("Passwords do not match");return}if(r.length<8){u("Password must be at least 8 characters");return}u(null),v(!0);try{await Jp(t,r),e()}catch(x){u(x.message)}finally{v(!1)}}return i.jsx("div",{className:"setup-page",children:i.jsxs("div",{className:"setup-card",children:[i.jsx("h1",{className:"setup-brand",children:"Archivr"}),i.jsx("p",{className:"setup-tagline",children:"Create your owner account to get started."}),i.jsxs("form",{onSubmit:m,children:[i.jsxs("div",{className:"setup-field",children:[i.jsx("label",{className:"setup-label",htmlFor:"setup-username",children:"Username"}),i.jsx("input",{className:"setup-input",id:"setup-username",type:"text",value:t,onChange:f=>n(f.target.value),autoFocus:!0,required:!0,autoComplete:"username"})]}),i.jsxs("div",{className:"setup-field",children:[i.jsx("label",{className:"setup-label",htmlFor:"setup-password",children:"Password"}),i.jsx("input",{className:"setup-input",id:"setup-password",type:"password",value:r,onChange:f=>l(f.target.value),required:!0,autoComplete:"new-password"})]}),i.jsxs("div",{className:"setup-field",children:[i.jsx("label",{className:"setup-label",htmlFor:"setup-confirm",children:"Confirm password"}),i.jsx("input",{className:"setup-input",id:"setup-confirm",type:"password",value:s,onChange:f=>a(f.target.value),required:!0,autoComplete:"new-password"})]}),o&&i.jsx("p",{className:"setup-error",children:o}),i.jsx("button",{className:"setup-submit",type:"submit",disabled:c,children:c?"Creating account…":"Create account"})]})]})})}function Th({archives:e,archiveId:t,onArchiveChange:n,view:r,onViewChange:l,onCaptureClick:s}){const{currentUser:a,setCurrentUser:o}=p.useContext(bl)??{},[u,c]=p.useState(!1);async function v(){c(!0),await Gp(),o(null),window.location.reload()}return i.jsxs("header",{className:"topbar",children:[i.jsx("div",{className:"brand",children:"Archivr"}),i.jsx("div",{className:"switcher",children:i.jsx("select",{"aria-label":"Select archive",value:t??"",onChange:m=>n(m.target.value),children:e.map(m=>i.jsx("option",{value:m.id,children:m.label},m.id))})}),i.jsx("nav",{className:"nav","aria-label":"Primary",children:["archive","tags","collections","runs","admin","settings"].map(m=>i.jsx("button",{className:`nav-link${r===m?" is-active":""}`,onClick:()=>l(m),children:m.charAt(0).toUpperCase()+m.slice(1)},m))}),i.jsx("button",{className:"capture-button",onClick:s,children:"Capture"}),a&&i.jsxs("div",{className:"user-menu",children:[i.jsx("span",{className:"user-name",children:a.display_name||a.username}),i.jsx("button",{className:"logout-btn",onClick:v,disabled:u,children:u?"Logging out…":"Log out"})]})]})}let ci=1;function Hc(e){const t=e.trim(),n=t.toLowerCase();for(const r of["yt:","youtube:"])if(n.startsWith(r)){const l=n.slice(r.length);return l.startsWith("video/")||l.startsWith("short/")||l.startsWith("shorts/")}if(n.startsWith("ytm:"))return!n.slice(4).startsWith("playlist/");for(const r of["x:","twitter:","tweet:"])if(n.startsWith(r))return n.slice(r.length).startsWith("media:");if(n.startsWith("spotify:"))return!1;if(n.startsWith("instagram:")||n.startsWith("facebook:")||n.startsWith("tiktok:")||n.startsWith("reddit:")||n.startsWith("snapchat:"))return!0;if(n.startsWith("http://")||n.startsWith("https://")){if(/^https?:\/\/music\.youtube\.com\/watch/.test(n)||/^https?:\/\/(?:www\.)?(?:youtu\.be\/[0-9A-Za-z_-]+|youtube\.com\/watch\?v=[0-9A-Za-z_-]+|youtube\.com\/shorts\/[0-9A-Za-z_-]+)/.test(t)||n.startsWith("https://x.com/")||n.startsWith("http://x.com/")||/^https?:\/\/(?:www\.)?instagram\.com\//.test(n)||/^https?:\/\/(?:www\.)?facebook\.com\//.test(n)||n.startsWith("https://fb.watch/")||n.startsWith("http://fb.watch/")||/^https?:\/\/(?:www\.)?tiktok\.com\//.test(n)||/^https?:\/\/(?:www\.)?reddit\.com\//.test(n)||n.startsWith("https://redd.it/")||n.startsWith("http://redd.it/")||/^https?:\/\/(?:www\.)?snapchat\.com\//.test(n))return!0;if(n.startsWith("https://open.spotify.com/")||n.startsWith("http://open.spotify.com/"))return!1}return!1}function Bn(e=""){return{id:ci++,locator:e,quality:"best",probeState:"idle",probeQualities:null,probeHasAudio:!1,status:"idle",error:null,jobUid:null,archiveId:null}}function jo(e){return e.some(t=>t.status==="submitting"||t.status==="running")}function Ph({open:e,archiveId:t,onClose:n,onCaptured:r,onToast:l}){const s=p.useRef(null),a=p.useRef(!0),o=p.useRef(new Map),u=p.useRef(new Map),c=p.useRef(new Map),v=p.useRef(t);p.useEffect(()=>{v.current=t},[t]);const m=p.useRef(r),f=p.useRef(l);p.useEffect(()=>{m.current=r},[r]),p.useEffect(()=>{f.current=l},[l]);const[x,y]=p.useState(()=>{try{const j=JSON.parse(sessionStorage.getItem("captureItems")||"null");if(Array.isArray(j)&&j.length>0)return j.forEach(C=>{C.id>=ci&&(ci=C.id+1)}),j}catch{}return[Bn()]});p.useEffect(()=>{sessionStorage.setItem("captureItems",JSON.stringify(x))},[x]);const[w,z]=p.useState(!1),[h,d]=p.useState(null),[g,S]=p.useState(null),[N,T]=p.useState(!0);p.useEffect(()=>{ia().then(j=>{S(j),T(j.cookie_ext_enabled??!0)}).catch(()=>S({}))},[]);const P=h!==null?h:(g==null?void 0:g.ublock_enabled)??!0,[_,F]=p.useState(!1);p.useEffect(()=>{["captureDialogLocator","captureDialogError","captureDialogBusy","captureDialogJobStatus","captureDialogJobUid"].forEach(j=>sessionStorage.removeItem(j)),y(j=>j.map(C=>C.status==="submitting"?{...C,status:"idle",error:null}:C)),x.forEach(j=>{j.status==="running"&&j.jobUid&&j.archiveId&&!o.current.has(j.jobUid)&&I(j.id,j.jobUid,j.locator,j.archiveId)})},[]),p.useEffect(()=>{const j=s.current;if(!j)return;const C=()=>{u.current.forEach(M=>clearTimeout(M)),u.current.clear(),n()};return j.addEventListener("close",C),()=>j.removeEventListener("close",C)},[n]),p.useEffect(()=>{const j=s.current;j&&(e?(!a.current&&!jo(x)&&y([Bn()]),a.current=!1,j.open||j.showModal()):(u.current.forEach(C=>clearTimeout(C)),u.current.clear(),j.open&&j.close()))},[e]),p.useEffect(()=>()=>{o.current.forEach(j=>clearInterval(j)),u.current.forEach(j=>clearTimeout(j))},[]);function I(j,C,M,A,B=null){if(o.current.has(C))return;const Y=setInterval(async()=>{try{const W=await Uc(A,C);if(W.status==="completed"){clearInterval(o.current.get(C)),o.current.delete(C),y(K=>K.map(G=>G.id===j?{...G,status:"completed"}:G)),setTimeout(()=>{y(K=>{const G=K.filter(de=>de.id!==j);return G.length===0?[Bn()]:G})},1400),m.current();try{const K=W.notes_json?JSON.parse(W.notes_json):null;if(K!=null&&K.ublock_skipped||K!=null&&K.cookie_ext_skipped){const de=K.ublock_skipped&&K.cookie_ext_skipped?"Captured without ad-blocking or cookie-consent extension. Check ARCHIVR_UBLOCK_EXT and ARCHIVR_COOKIE_EXT in your server config.":K.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.";f.current(de,M,"warning"),V(B,"warning",M)}else B||f.current(null,M,"success"),V(B,"archived")}catch{B||f.current(null,M,"success"),V(B,"archived")}}else if(W.status==="failed"){clearInterval(o.current.get(C)),o.current.delete(C);const K=W.error_text||"Capture failed.";y(G=>G.map(de=>de.id===j?{...de,status:"failed",error:K}:de)),f.current(K,M),V(B,"failed",M)}}catch(W){clearInterval(o.current.get(C)),o.current.delete(C);const K=W.message||"Network error";y(G=>G.map(de=>de.id===j?{...de,status:"failed",error:K}:de)),f.current(K,M),V(B,"failed",M)}},500);o.current.set(C,Y)}function V(j,C,M=null){if(!j)return;const A=c.current.get(j);if(!A||(C==="archived"||C==="warning"?(A.archived++,C==="warning"&&(A.warnings++,M&&A.warningLocators.push(M))):(A.failed++,M&&A.failedLocators.push(M)),A.archived+A.failed0?`${B} archived (${Y} with warnings)`:`${B} archived`;de=W>0?`${H}, ${W} failed`:H}const nn=B===0?"error":W>0||Y>0?"warning":"success",ut=[];K.length>0&&ut.push(`Failed: ${K.map(H=>` ${H}`).join(` `)}`),G.length>0&&ut.push(`With warnings: ${G.map(H=>` ${H}`).join(` `)}`);const R=ut.length>0?ut.join(` `):null;f.current(R,null,nn,de)}async function J(j,C=null){if(!j.locator.trim())return;const M=t,A=j.locator.trim(),B=j.quality||"best";y(Y=>Y.map(W=>W.id===j.id?{...W,status:"submitting",error:null}:W));try{const W=await Qp(M,A,B,{ublock_enabled:P,reader_mode:_,cookie_ext_enabled:N});y(K=>K.map(G=>G.id===j.id?{...G,status:"running",jobUid:W.job_uid,archiveId:M}:G)),I(j.id,W.job_uid,A,M,C)}catch(Y){const W=Y.message||"Submission failed.";y(K=>K.map(G=>G.id===j.id?{...G,status:"failed",error:W}:G)),f.current(W,A),V(C,"failed",A)}}function ue(){var M,A;const j=x.filter(B=>B.status==="idle"&&B.locator.trim());if(j.length===0)return;const C=j.length>1?((M=crypto.randomUUID)==null?void 0:M.call(crypto))??`batch-${Date.now()}`:null;C&&c.current.set(C,{total:j.length,archived:0,warnings:0,failed:0,failedLocators:[],warningLocators:[]}),j.forEach(B=>J(B,C)),(A=s.current)==null||A.close()}function ve(){y(j=>[...j,Bn()])}function je(j){clearTimeout(u.current.get(j)),u.current.delete(j),y(C=>{const M=C.filter(A=>A.id!==j);return M.length===0?[Bn()]:M})}function Re(j){y(C=>C.map(M=>M.id===j?{...M,status:"idle",error:null}:M))}function ye(j,C){if(clearTimeout(u.current.get(j)),y(A=>A.map(B=>B.id===j?{...B,locator:C,probeState:"idle",probeQualities:null,probeHasAudio:!1,quality:"best"}:B)),!Hc(C))return;const M=setTimeout(async()=>{u.current.delete(j),y(A=>A.map(B=>B.id===j?{...B,probeState:"probing"}:B));try{const A=await Kp(v.current,C.trim());y(B=>B.map(Y=>{if(Y.id!==j||Y.locator!==C)return Y;const W=A.qualities??[],K=A.has_audio??!1,G=W.length===0&&K?"audio":"best";return{...Y,probeState:"done",probeQualities:W,probeHasAudio:K,quality:G}}))}catch{y(A=>A.map(B=>B.id===j?{...B,probeState:"idle",probeQualities:null}:B))}},600);u.current.set(j,M)}function L(j,C){y(M=>M.map(A=>A.id===j?{...A,quality:C}:A))}const k=x.filter(j=>j.status==="idle"&&j.locator.trim()).length,D=jo(x);return i.jsx("dialog",{ref:s,className:"capture-dialog",children:i.jsxs("div",{className:"capture-dialog-inner",children:[i.jsxs("div",{className:"capture-dialog-header",children:[i.jsx("h2",{className:"capture-dialog-title",children:"Capture"}),i.jsx("button",{type:"button",className:"capture-dialog-close",onClick:()=>{var j;return(j=s.current)==null?void 0:j.close()},"aria-label":"Close",children:i.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[i.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),i.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),i.jsx("div",{className:"capture-rows",children:x.map((j,C)=>i.jsx(Lh,{item:j,autoFocus:C===x.length-1&&j.status==="idle",onLocatorChange:M=>ye(j.id,M),onQualityChange:M=>L(j.id,M),onRemove:()=>je(j.id),onReset:()=>Re(j.id),onSubmit:ue},j.id))}),i.jsxs("button",{type:"button",className:"capture-add-row",onClick:ve,children:[i.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[i.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"14"}),i.jsx("line",{x1:"2",y1:"8",x2:"14",y2:"8"})]}),"Add another"]}),i.jsxs("div",{className:"capture-advanced",children:[i.jsxs("button",{type:"button",className:"capture-advanced-toggle",onClick:()=>z(j=>!j),"aria-expanded":w,children:[i.jsx("svg",{className:`capture-chevron${w?" capture-chevron--open":""}`,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:i.jsx("polyline",{points:"4 6 8 10 12 6"})}),"Advanced options"]}),w&&i.jsxs("div",{className:"capture-advanced-panel",children:[i.jsxs("label",{className:"capture-ext-row",children:[i.jsxs("span",{className:"capture-ext-label",children:[i.jsx("span",{className:"capture-ext-name",children:"uBlock Origin Lite"}),i.jsx("span",{className:"capture-ext-desc",children:"Block ads during this capture"})]}),i.jsx("button",{type:"button",role:"switch","aria-checked":P,className:`ext-toggle ext-toggle--sm${P?" ext-toggle--on":""}`,onClick:()=>d(j=>j===null?!P:!j),"aria-label":"Toggle uBlock for this capture",children:i.jsx("span",{className:"ext-toggle-knob"})})]}),i.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[i.jsxs("span",{className:"capture-ext-label",children:[i.jsx("span",{className:"capture-ext-name",children:"Block cookie banners"}),i.jsx("span",{className:"capture-ext-desc",children:"Dismiss cookie consent banners during this capture"}),!(g!=null&&g.cookie_ext_available)&&i.jsxs("span",{className:"capture-ext-hint",children:["Not configured — set ",i.jsx("code",{children:"ARCHIVR_COOKIE_EXT"})]})]}),i.jsx("button",{type:"button",role:"switch","aria-checked":N,className:`ext-toggle ext-toggle--sm${N?" ext-toggle--on":""}`,onClick:()=>T(j=>!j),"aria-label":"Toggle cookie banner blocking for this capture",children:i.jsx("span",{className:"ext-toggle-knob"})})]}),i.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[i.jsxs("span",{className:"capture-ext-label",children:[i.jsx("span",{className:"capture-ext-name",children:"Reader mode"}),i.jsx("span",{className:"capture-ext-desc",children:"Distil to article text via Readability (off by default)"})]}),i.jsx("button",{type:"button",role:"switch","aria-checked":_,className:`ext-toggle ext-toggle--sm${_?" ext-toggle--on":""}`,onClick:()=>F(j=>!j),"aria-label":"Toggle reader mode for this capture",children:i.jsx("span",{className:"ext-toggle-knob"})})]})]})]}),i.jsxs("div",{className:"capture-actions",children:[i.jsx("button",{type:"button",className:"capture-submit",onClick:ue,disabled:k===0,children:k>1?`Archive ${k}`:"Archive"}),i.jsx("button",{type:"button",className:"capture-cancel",onClick:()=>{var j;return(j=s.current)==null?void 0:j.close()},children:D?"Close":"Cancel"})]})]})})}function Lh({item:e,autoFocus:t,onLocatorChange:n,onQualityChange:r,onRemove:l,onReset:s,onSubmit:a}){const o=p.useRef(null),u=e.status==="submitting"||e.status==="running";p.useEffect(()=>{var v;t&&e.status==="idle"&&((v=o.current)==null||v.focus())},[t]);const c=(()=>{if(e.status==="completed"||u||!Hc(e.locator))return null;if(e.probeState==="probing")return i.jsx("span",{className:"capture-quality-probing","aria-label":"Checking available qualities",children:"…"});if(e.probeState==="done"){const v=e.probeQualities??[],m=e.probeHasAudio??!1;return v.length===0&&!m?i.jsx("span",{className:"capture-quality-hint",children:"No media detected"}):v.length===0&&m?i.jsx("select",{className:"capture-quality",value:"audio",onChange:f=>r(f.target.value),"aria-label":"Video quality",children:i.jsx("option",{value:"audio",children:"Audio only"})}):i.jsxs("select",{className:"capture-quality",value:e.quality||"best",onChange:f=>r(f.target.value),"aria-label":"Video quality",children:[i.jsx("option",{value:"best",children:"Best quality"}),v.map(f=>i.jsx("option",{value:f,children:f},f)),m&&i.jsx("option",{value:"audio",children:"Audio only"})]})}return null})();return i.jsxs("div",{className:`capture-row capture-row--${e.status}`,children:[i.jsxs("div",{className:"capture-row-main",children:[i.jsx(Rh,{status:e.status}),i.jsx("input",{ref:o,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"&&a()},disabled:u||e.status==="completed",autoComplete:"off",spellCheck:!1}),c,e.status==="failed"&&i.jsx("button",{type:"button",className:"capture-row-action",onClick:s,title:"Retry",children:i.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M13 2.5A7 7 0 1 1 6.5 1"}),i.jsx("polyline",{points:"6.5 1 4 3.5 6.5 6"})]})}),!u&&e.status!=="completed"&&e.status!=="failed"&&i.jsx("button",{type:"button",className:"capture-row-action capture-row-remove",onClick:l,"aria-label":"Remove",children:i.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[i.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),i.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),e.error&&i.jsx("p",{className:"capture-row-error",children:e.error})]})}function Rh({status:e}){return e==="submitting"||e==="running"?i.jsx("span",{className:"cap-dot cap-dot--running","aria-label":"Running",children:i.jsx("span",{className:"cap-spinner"})}):e==="completed"?i.jsx("span",{className:"cap-dot cap-dot--ok","aria-label":"Done",children:"✓"}):e==="failed"?i.jsx("span",{className:"cap-dot cap-dot--err","aria-label":"Failed",children:"✕"}):i.jsx("span",{className:"cap-dot cap-dot--idle","aria-hidden":"true"})}function di(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 Qt(e){return zh(e)??""}function Wc(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 So={youtube:'',youtube_music:'',spotify:'',x:'',instagram:'',facebook:'',tiktok:'',reddit:'',snapchat:'',local:'',web:'',other:'?'};function aa(e){return So[e]??So.other}function Vc(e){return e.split("/").map(t=>t?t.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"").join("/")}function Dh({entry:e,archiveId:t,isSelected:n,onSelect:r}){const[l,s]=p.useState(!1),o=e.source_kind==="web"&&e.entity_kind==="page"&&e.has_favicon&&t&&!l?i.jsx("img",{src:`/api/archives/${t}/entries/${e.entry_uid}/favicon`,width:"16",height:"16",alt:"",onError:()=>s(!0),style:{objectFit:"contain"}}):i.jsx("span",{dangerouslySetInnerHTML:{__html:aa(e.source_kind)}});return i.jsxs("div",{className:n?"is-selected":void 0,tabIndex:0,"data-entry-uid":e.entry_uid,onClick:r,onKeyDown:u=>{u.key==="Enter"&&r()},children:[i.jsx("div",{className:"col-added",children:Wc(e.archived_at)}),i.jsxs("div",{className:"col-title",children:[i.jsx("span",{className:"source-icon",children:o}),i.jsx("span",{className:"entry-title",children:Qt(e.title)||Qt(e.entry_uid)})]}),i.jsx("div",{className:"col-type",children:i.jsx("span",{className:"type-pill",children:Qt(e.entity_kind)})}),i.jsxs("div",{className:"col-size",children:[i.jsx("span",{className:"size-total",children:di(e.total_artifact_bytes)}),e.cached_bytes>0&&e.total_artifact_bytes>0&&i.jsxs("span",{className:"size-cached-pct",title:`${di(e.cached_bytes)} already on disk from an earlier entry`,children:[Math.round(e.cached_bytes/e.total_artifact_bytes*100),"% cached"]})]}),i.jsx("div",{className:"url-cell col-url",children:Qt(e.original_url)})]})}function $h({entries:e,selectedEntryUid:t,onSelectEntry:n,archiveId:r}){return i.jsx("section",{id:"archive-view",className:"view is-active",children:i.jsxs("div",{className:"entry-table",children:[i.jsxs("div",{className:"entry-header-row",children:[i.jsx("div",{className:"col-added",children:"Added"}),i.jsx("div",{className:"col-title",children:"Title"}),i.jsx("div",{className:"col-type",children:"Type"}),i.jsx("div",{className:"col-size",children:"Size"}),i.jsx("div",{className:"col-url",children:"Original URL"})]}),i.jsx("div",{id:"entries-body",children:e.map(l=>i.jsx(Dh,{entry:l,archiveId:r,isSelected:l.entry_uid===t,onSelect:()=>n(l)},l.entry_uid))})]})})}function Oh(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 Ih({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 i.jsx("span",{className:`run-status ${t}`,children:n})}function Fh({runs:e}){const[t,n]=p.useState(null);function r(l){n(s=>s===l?null:l)}return i.jsx("section",{id:"runs-view",className:"view is-active",children:i.jsxs("table",{className:"entry-table",children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{children:"Started"}),i.jsx("th",{children:"Status"}),i.jsx("th",{children:"Requested"}),i.jsx("th",{children:"Completed"}),i.jsx("th",{children:"Failed"})]})}),i.jsx("tbody",{children:e.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:5,style:{color:"var(--muted)",padding:"24px 16px",textAlign:"center"},children:"No runs yet."})}):e.map(l=>{const s=l.status==="failed"&&l.error_summary,a=t===l.run_uid;return[i.jsxs("tr",{className:s?"run-row run-row--failed":"run-row",onClick:s?()=>r(l.run_uid):void 0,title:s?a?"Click to hide error":"Click to view error":void 0,children:[i.jsx("td",{children:Oh(l.started_at)}),i.jsxs("td",{children:[i.jsx(Ih,{status:l.status}),s&&i.jsx("span",{className:"run-expand-hint","aria-hidden":"true",children:a?"▴":"▾"})]}),i.jsx("td",{children:l.requested_count??"—"}),i.jsx("td",{children:l.completed_count??"—"}),i.jsx("td",{children:l.failed_count??"—"})]},l.run_uid),s&&a&&i.jsx("tr",{className:"run-error-row",children:i.jsx("td",{colSpan:5,children:i.jsx("pre",{className:"run-error-detail",children:l.error_summary})})},`${l.run_uid}-detail`)]})})]})})}const Mh=4;function Ah({archives:e}){const{currentUser:t}=p.useContext(bl)??{},n=t&&(t.role_bits&Mh)!==0,[r,l]=p.useState("users"),[s,a]=p.useState([]),[o,u]=p.useState([]),[c,v]=p.useState(!1),[m,f]=p.useState(null),[x,y]=p.useState(""),[w,z]=p.useState(""),[h,d]=p.useState(""),[g,S]=p.useState(null),[N,T]=p.useState(!1),[P,_]=p.useState(""),[F,I]=p.useState(""),[V,J]=p.useState(null),[ue,ve]=p.useState(!1),je=p.useCallback(async()=>{if(n){v(!0),f(null);try{const[k,D]=await Promise.all([sh(),oh()]);a(k),u(D)}catch(k){f(k.message)}finally{v(!1)}}},[n]);p.useEffect(()=>{je()},[je]);async function Re(k){const D=k.status==="active"?"disabled":"active";try{await ah(k.user_uid,D),a(j=>j.map(C=>C.user_uid===k.user_uid?{...C,status:D}:C))}catch(j){f(j.message)}}async function ye(k){if(k.preventDefault(),!x.trim()||!w){S("Username and password required");return}T(!0),S(null);try{await ih(x.trim(),w,h.trim()||void 0),y(""),z(""),d(""),await je()}catch(D){S(D.message)}finally{T(!1)}}async function L(k){if(k.preventDefault(),!P.trim()||!F.trim()){J("Slug and name required");return}ve(!0),J(null);try{await uh(P.trim(),F.trim()),_(""),I(""),await je()}catch(D){J(D.message)}finally{ve(!1)}}return n?i.jsxs("section",{id:"admin-view",className:"view admin-view is-active",children:[i.jsx("h1",{children:"Admin"}),i.jsxs("div",{className:"view-tabs",children:[i.jsx("button",{className:`view-tab${r==="users"?" is-active":""}`,onClick:()=>l("users"),children:"Users"}),i.jsx("button",{className:`view-tab${r==="roles"?" is-active":""}`,onClick:()=>l("roles"),children:"Roles"}),i.jsx("button",{className:`view-tab${r==="archives"?" is-active":""}`,onClick:()=>l("archives"),children:"Archives"})]}),m&&i.jsx("div",{className:"form-msg form-msg--err",children:m}),r==="users"&&i.jsxs("div",{className:"admin-section",children:[i.jsx("h2",{children:"Users"}),c?i.jsx("p",{className:"muted",children:"Loading…"}):i.jsxs("table",{className:"admin-table",children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{children:"Username"}),i.jsx("th",{children:"Email"}),i.jsx("th",{children:"Roles"}),i.jsx("th",{children:"Status"}),i.jsx("th",{children:"Actions"})]})}),i.jsx("tbody",{children:s.map(k=>i.jsxs("tr",{className:k.status==="disabled"?"admin-row-disabled":"",children:[i.jsx("td",{children:k.username}),i.jsx("td",{className:"muted",children:k.email||"—"}),i.jsx("td",{children:k.role_slugs.join(", ")||"—"}),i.jsx("td",{children:i.jsx("span",{className:`status-badge status-${k.status}`,children:k.status})}),i.jsx("td",{children:i.jsx("button",{className:"admin-action-btn",onClick:()=>Re(k),children:k.status==="active"?"Ban":"Unban"})})]},k.user_uid))})]}),i.jsx("h3",{children:"Create User"}),i.jsxs("form",{className:"admin-form",onSubmit:ye,children:[i.jsx("input",{className:"admin-input",placeholder:"Username",value:x,onChange:k=>y(k.target.value),required:!0}),i.jsx("input",{className:"admin-input",type:"password",placeholder:"Password (min 8 chars)",value:w,onChange:k=>z(k.target.value),required:!0}),i.jsx("input",{className:"admin-input",type:"email",placeholder:"Email (optional)",value:h,onChange:k=>d(k.target.value)}),g&&i.jsx("div",{className:"form-msg form-msg--err",children:g}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:N,children:N?"Creating…":"Create User"})]})]}),r==="roles"&&i.jsxs("div",{className:"admin-section",children:[i.jsx("h2",{children:"Roles"}),c?i.jsx("p",{className:"muted",children:"Loading…"}):i.jsxs("table",{className:"admin-table",children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{children:"Slug"}),i.jsx("th",{children:"Name"}),i.jsx("th",{children:"Level"}),i.jsx("th",{children:"Bit"}),i.jsx("th",{children:"Built-in"})]})}),i.jsx("tbody",{children:o.map(k=>i.jsxs("tr",{children:[i.jsx("td",{children:i.jsx("code",{children:k.slug})}),i.jsx("td",{children:k.name}),i.jsx("td",{children:k.level}),i.jsx("td",{children:k.bit_position}),i.jsx("td",{children:k.is_builtin?"✓":""})]},k.role_uid))})]}),i.jsx("h3",{children:"Create Custom Role"}),i.jsxs("form",{className:"admin-form",onSubmit:L,children:[i.jsx("input",{className:"admin-input",placeholder:"Slug (e.g. moderator)",value:P,onChange:k=>_(k.target.value),required:!0}),i.jsx("input",{className:"admin-input",placeholder:"Display Name (e.g. Moderator)",value:F,onChange:k=>I(k.target.value),required:!0}),V&&i.jsx("div",{className:"form-msg form-msg--err",children:V}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:ue,children:ue?"Creating…":"Create Role"})]})]}),r==="archives"&&i.jsxs("div",{className:"admin-section",children:[i.jsx("h2",{children:"Mounted Archives"}),i.jsx("div",{className:"admin-list",children:e.map(k=>i.jsxs("div",{className:"admin-archive",children:[i.jsx("strong",{children:k.label}),i.jsx("div",{className:"muted",children:k.archive_path})]},k.id))})]})]}):i.jsxs("section",{id:"admin-view",className:"view admin-view is-active",children:[i.jsx("h1",{children:"Admin"}),i.jsx("p",{className:"muted",children:"You need admin privileges to access this panel."}),i.jsx("h2",{children:"Mounted Archives"}),i.jsx("div",{className:"admin-list",children:e.map(k=>i.jsxs("div",{className:"admin-archive",children:[i.jsx("strong",{children:k.label}),i.jsx("div",{className:"muted",children:k.archive_path})]},k.id))})]})}function Qc({node:e,archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u}){var S;const c=n===e.tag.full_path,[v,m]=p.useState(!1),[f,x]=p.useState(""),y=p.useRef(!1);function w(){if(v)return;const N=c?null:e.tag.full_path;r(N),l("archive")}function z(N){N.stopPropagation(),x(e.tag.slug),m(!0)}async function h(){const N=f.trim();if(!N||N===e.tag.slug){m(!1);return}try{const T=await Wp(t,e.tag.tag_uid,N);s(e.tag.full_path,T.full_path),o()}catch{}finally{m(!1)}}async function d(N){var P;N.stopPropagation();const T=((P=e.children)==null?void 0:P.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(T))try{await Vp(t,e.tag.tag_uid),a(e.tag.full_path),o()}catch{}}const g={archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u};return i.jsxs("li",{children:[i.jsxs("div",{className:"tag-node-row",children:[v?i.jsx("input",{className:"tag-rename-input",autoFocus:!0,value:f,onChange:N=>x(N.target.value),onKeyDown:N=>{N.key==="Enter"&&N.currentTarget.blur(),N.key==="Escape"&&(y.current=!0,N.currentTarget.blur())},onBlur:()=>{y.current?(y.current=!1,m(!1)):h()}}):i.jsxs("button",{className:`tag-node-btn${c?" is-active":""}`,title:e.tag.full_path,onClick:w,onDoubleClick:z,children:[u?e.tag.name:e.tag.slug,i.jsx("svg",{className:"edit-icon",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",onClick:N=>{N.stopPropagation(),z(N)},children:i.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),i.jsx("button",{className:"remove tag-node-delete",title:`Delete tag ${e.tag.full_path}`,onClick:d,"aria-label":`Delete tag ${e.tag.full_path}`,children:"×"})]}),((S=e.children)==null?void 0:S.length)>0&&i.jsx("div",{className:"tag-children",children:i.jsx("ul",{className:"tag-tree-list",children:e.children.map(N=>i.jsx(Qc,{node:N,...g},N.tag.tag_uid))})})]})}function bh({archiveId:e,tagNodes:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u}){return i.jsx("section",{id:"tags-view",className:"view is-active",children:i.jsxs("div",{className:"tag-tree",children:[i.jsxs("div",{className:"tag-tree-header",children:[i.jsx("span",{className:"tag-tree-title",children:"Tags"}),n&&i.jsxs("span",{className:"tag-tree-active",children:["Filtering: ",n]})]}),t.length===0?i.jsx("p",{className:"muted",style:{padding:"8px 0"},children:"No tags yet."}):i.jsx("ul",{className:"tag-tree-list",children:t.map(c=>i.jsx(Qc,{node:c,archiveId:e,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u},c.tag.tag_uid))})]})})}const Qn=[{value:0,label:"Private"},{value:2,label:"Users only"},{value:3,label:"Public"}],Bh=e=>{var t;return((t=Qn.find(n=>n.value===e))==null?void 0:t.label)??String(e)};function Uh({archiveId:e}){const[t,n]=p.useState([]),[r,l]=p.useState(!1),[s,a]=p.useState(null),[o,u]=p.useState(null),[c,v]=p.useState(null),[m,f]=p.useState(!1),[x,y]=p.useState(null),[w,z]=p.useState(""),[h,d]=p.useState(""),[g,S]=p.useState(2),[N,T]=p.useState(!1),[P,_]=p.useState(null),[F,I]=p.useState(""),[V,J]=p.useState(2),[ue,ve]=p.useState(!1),[je,Re]=p.useState(null),[ye,L]=p.useState(!1),[k,D]=p.useState(""),j=p.useRef(null),C=t.find(R=>R.collection_uid===o)??null,M=(C==null?void 0:C.slug)==="_default_",A=p.useCallback(async()=>{if(e){l(!0),a(null);try{const R=await ch(e);n(R)}catch(R){a(R.message)}finally{l(!1)}}},[e]),B=p.useCallback(async R=>{if(!R){v(null);return}f(!0),y(null);try{const H=await fh(e,R);v(H)}catch(H){y(H.message)}finally{f(!1)}},[e]);p.useEffect(()=>{A()},[A]),p.useEffect(()=>{B(o)},[o,B]),p.useEffect(()=>{ye&&j.current&&j.current.focus()},[ye]);async function Y(R){R.preventDefault();const H=w.trim(),Fe=h.trim();if(!(!H||!Fe)){T(!0),_(null);try{const ct=await dh(e,H,Fe,g);z(""),d(""),S(2),await A(),u(ct.collection_uid)}catch(ct){_(ct.message)}finally{T(!1)}}}async function W(){const R=k.trim();if(!R||!C){L(!1);return}try{await ko(e,C.collection_uid,{name:R}),await A(),v(H=>H&&{...H,name:R})}catch(H){a(H.message)}finally{L(!1)}}async function K(R){if(C)try{await ko(e,C.collection_uid,{default_visibility_bits:R}),await A(),v(H=>H&&{...H,default_visibility_bits:R})}catch(H){a(H.message)}}async function G(){if(C&&window.confirm(`Delete collection "${C.name}"? Entries will not be deleted.`))try{await vh(e,C.collection_uid),u(null),v(null),await A()}catch(R){a(R.message)}}async function de(R){R.preventDefault();const H=F.trim();if(!(!H||!C)){ve(!0),Re(null);try{await ph(e,C.collection_uid,H,V),I(""),await B(C.collection_uid)}catch(Fe){Re(Fe.message)}finally{ve(!1)}}}async function nn(R){if(C)try{await hh(e,C.collection_uid,R),await B(C.collection_uid)}catch(H){y(H.message)}}async function ut(R,H){if(C)try{await mh(e,C.collection_uid,R,H),v(Fe=>Fe&&{...Fe,entries:Fe.entries.map(ct=>ct.entry_uid===R?{...ct,collection_visibility_bits:H}:ct)})}catch(Fe){y(Fe.message)}}return e?i.jsxs("div",{className:"collections-view",children:[i.jsx("h2",{className:"collections-heading",children:"Collections"}),r&&i.jsx("div",{className:"muted",children:"Loading…"}),s&&i.jsxs("div",{className:"collections-error",children:[s," ",i.jsx("button",{onClick:()=>a(null),className:"coll-dismiss",children:"×"})]}),i.jsxs("div",{className:"collections-layout",children:[i.jsxs("div",{className:"collections-sidebar",children:[t.map(R=>i.jsxs("button",{className:`coll-sidebar-row${o===R.collection_uid?" is-active":""}`,onClick:()=>u(R.collection_uid),children:[i.jsx("span",{className:"coll-row-name",children:R.name}),i.jsx("span",{className:"coll-row-meta",children:Bh(R.default_visibility_bits)})]},R.collection_uid)),t.length===0&&!r&&i.jsx("div",{className:"muted",style:{padding:"8px 12px"},children:"No collections yet."})]}),C?i.jsxs("div",{className:"coll-detail",children:[i.jsxs("div",{className:"coll-detail-header",children:[ye?i.jsx("input",{ref:j,className:"coll-rename-input",value:k,onChange:R=>D(R.target.value),onBlur:W,onKeyDown:R=>{R.key==="Enter"&&W(),R.key==="Escape"&&L(!1)}}):i.jsxs("h3",{className:`coll-detail-name${M?"":" coll-detail-name--editable"}`,title:M?void 0:"Click to rename",onClick:()=>{M||(D(C.name),L(!0))},children:[(c==null?void 0:c.name)??C.name,!M&&i.jsx("span",{className:"coll-edit-hint",children:" ✎"})]}),!M&&i.jsx("button",{className:"coll-delete-btn",onClick:G,title:"Delete collection",children:"Delete"})]}),i.jsxs("div",{className:"coll-detail-vis",children:[i.jsx("span",{className:"coll-vis-label",children:"Default visibility"}),i.jsx("select",{className:"coll-vis-select",value:(c==null?void 0:c.default_visibility_bits)??C.default_visibility_bits,onChange:R=>K(Number(R.target.value)),disabled:M,children:Qn.map(R=>i.jsx("option",{value:R.value,children:R.label},R.value))})]}),i.jsxs("div",{className:"coll-entries-section",children:[i.jsx("div",{className:"coll-section-heading",children:"Entries"}),m&&i.jsx("div",{className:"muted",children:"Loading…"}),x&&i.jsx("div",{className:"collections-error",children:x}),!m&&c&&(c.entries.length===0?i.jsx("div",{className:"muted",children:"No entries in this collection."}):i.jsx("ul",{className:"coll-entries-list",children:c.entries.map(R=>i.jsxs("li",{className:"coll-entry-row",children:[i.jsxs("div",{className:"coll-entry-info",children:[i.jsx("span",{className:"coll-entry-title",children:R.title||R.entry_uid}),i.jsx("span",{className:"coll-entry-kind muted",children:R.source_kind})]}),i.jsxs("div",{className:"coll-entry-actions",children:[i.jsx("select",{className:"coll-entry-vis-select",value:R.collection_visibility_bits,onChange:H=>ut(R.entry_uid,Number(H.target.value)),children:Qn.map(H=>i.jsx("option",{value:H.value,children:H.label},H.value))}),!M&&i.jsx("button",{className:"coll-entry-remove",onClick:()=>nn(R.entry_uid),title:"Remove from collection",children:"×"})]})]},R.entry_uid))}))]}),!M&&i.jsxs("form",{className:"coll-add-entry-form",onSubmit:de,children:[i.jsx("div",{className:"coll-section-heading",children:"Add entry"}),i.jsxs("div",{className:"coll-add-entry-row",children:[i.jsx("input",{className:"coll-add-entry-input",type:"text",value:F,onChange:R=>I(R.target.value),placeholder:"entry_uid",required:!0}),i.jsx("select",{className:"coll-vis-select",value:V,onChange:R=>J(Number(R.target.value)),children:Qn.map(R=>i.jsx("option",{value:R.value,children:R.label},R.value))}),i.jsx("button",{className:"coll-add-btn",type:"submit",disabled:ue,children:ue?"…":"Add"})]}),je&&i.jsx("div",{className:"collections-error",style:{marginTop:4},children:je})]})]}):i.jsx("div",{className:"coll-detail coll-detail--empty",children:i.jsx("div",{className:"muted",children:"Select a collection to view details."})})]}),i.jsxs("details",{className:"coll-create-details",children:[i.jsx("summary",{children:"+ Create collection"}),i.jsxs("form",{className:"coll-create-form",onSubmit:Y,children:[i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"coll-name",children:"Name"}),i.jsx("input",{className:"capture-input",id:"coll-name",type:"text",value:w,onChange:R=>{z(R.target.value),h||d(R.target.value.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},placeholder:"My Collection",required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"coll-slug",children:"Slug"}),i.jsx("input",{className:"capture-input",id:"coll-slug",type:"text",value:h,onChange:R=>d(R.target.value),placeholder:"my-collection",required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"coll-vis",children:"Default visibility"}),i.jsx("select",{className:"capture-input",id:"coll-vis",style:{height:42},value:g,onChange:R=>S(Number(R.target.value)),children:Qn.map(R=>i.jsx("option",{value:R.value,children:R.label},R.value))})]}),P&&i.jsx("div",{className:"collections-error",children:P}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:N,children:N?"Creating…":"Create collection"})]})]})]}):i.jsx("div",{className:"view-placeholder",children:"Select an archive."})}const Hh=4;function Wh({tab:e,onTabChange:t,archiveId:n}){const{currentUser:r,setCurrentUser:l}=p.useContext(bl)??{},s=r&&(r.role_bits&Hh)!==0,a=["profile","tokens",...s?["instance","cookies","extensions","storage"]:[]],o={profile:"Profile",tokens:"API Tokens",instance:"Instance",cookies:"Cookies",extensions:"Extensions",storage:"Storage"};return i.jsxs("section",{className:"admin-view",children:[i.jsx("h1",{children:"Settings"}),i.jsx("div",{className:"view-tabs",children:a.map(u=>i.jsx("button",{className:`view-tab${e===u?" is-active":""}`,onClick:()=>t(u),children:o[u]},u))}),e==="profile"&&i.jsx(Vh,{currentUser:r,setCurrentUser:l}),e==="tokens"&&i.jsx(Qh,{}),e==="instance"&&s&&i.jsx(Kh,{}),e==="cookies"&&s&&i.jsx(Jh,{}),e==="extensions"&&s&&i.jsx(Yh,{}),e==="storage"&&s&&i.jsx(Xh,{archiveId:n})]})}function Vh({currentUser:e,setCurrentUser:t}){const[n,r]=p.useState((e==null?void 0:e.display_name)??""),[l,s]=p.useState(!1),[a,o]=p.useState(null),[u,c]=p.useState(""),[v,m]=p.useState(""),[f,x]=p.useState(""),[y,w]=p.useState(!1),[z,h]=p.useState(null);async function d(S){S.preventDefault(),s(!0),o(null);try{await Zp(n),t(N=>({...N,display_name:n||null})),o({ok:!0,text:"Saved."})}catch(N){o({ok:!1,text:N.message})}finally{s(!1)}}async function g(S){if(S.preventDefault(),v!==f){h({ok:!1,text:"Passwords do not match."});return}w(!0),h(null);try{await th(u,v),c(""),m(""),x(""),h({ok:!0,text:"Password changed."})}catch(N){h({ok:!1,text:N.message})}finally{w(!1)}}return i.jsxs("div",{style:{maxWidth:440},children:[i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Display Name"}),i.jsxs("form",{onSubmit:d,children:[i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"display-name",children:"Name shown in the UI"}),i.jsx("input",{className:"field-input",id:"display-name",placeholder:(e==null?void 0:e.username)??"",value:n,onChange:S=>r(S.target.value)})]}),a&&i.jsx("div",{className:`form-msg form-msg--${a.ok?"ok":"err"}`,children:a.text}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:l,children:l?"Saving…":"Save"})]})]}),i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Display Preferences"}),i.jsxs("label",{className:"checkbox-row",children:[i.jsx("input",{type:"checkbox",checked:(e==null?void 0:e.humanize_slugs)??!1,onChange:async S=>{const N=S.target.checked;try{await eh({humanize_slugs:N}),t(T=>({...T,humanize_slugs:N}))}catch{}}}),i.jsx("span",{className:"form-label",style:{margin:0},children:"Humanize tag display"})]}),i.jsx("p",{className:"muted",style:{fontSize:13,margin:"4px 0 0"},children:'When on, tag paths show as "X / Articles" instead of "x/articles".'})]}),i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Change Password"}),i.jsxs("form",{onSubmit:g,children:[i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"cur-pw",children:"Current password"}),i.jsx("input",{className:"field-input",id:"cur-pw",type:"password",value:u,onChange:S=>c(S.target.value),required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"new-pw",children:"New password"}),i.jsx("input",{className:"field-input",id:"new-pw",type:"password",value:v,onChange:S=>m(S.target.value),required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"confirm-pw",children:"Confirm new password"}),i.jsx("input",{className:"field-input",id:"confirm-pw",type:"password",value:f,onChange:S=>x(S.target.value),required:!0})]}),z&&i.jsx("div",{className:`form-msg form-msg--${z.ok?"ok":"err"}`,children:z.text}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:y,children:y?"Changing…":"Change Password"})]})]})]})}function Qh(){const[e,t]=p.useState([]),[n,r]=p.useState(!0),[l,s]=p.useState(null),[a,o]=p.useState(""),[u,c]=p.useState(!1),[v,m]=p.useState(null),f=p.useCallback(async()=>{r(!0),s(null);try{t(await nh())}catch(w){s(w.message)}finally{r(!1)}},[]);p.useEffect(()=>{f()},[f]);async function x(w){if(w.preventDefault(),!!a.trim()){c(!0);try{const z=await rh(a.trim());m(z),o(""),f()}catch(z){s(z.message)}finally{c(!1)}}}async function y(w){try{await lh(w),t(z=>z.filter(h=>h.token_uid!==w))}catch(z){s(z.message)}}return i.jsx("div",{style:{maxWidth:600},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"API Tokens"}),v&&i.jsxs("div",{className:"token-banner",children:[i.jsx("strong",{children:"Token created."})," Copy it now — it won't be shown again.",i.jsx("code",{children:v.raw_token}),i.jsx("button",{className:"token-dismiss",onClick:()=>m(null),children:"Dismiss"})]}),i.jsxs("form",{className:"token-create-row",onSubmit:x,children:[i.jsx("input",{className:"field-input field-input--flex",placeholder:"Token name",value:a,onChange:w=>o(w.target.value),required:!0}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:u,children:u?"Creating…":"Create token"})]}),l&&i.jsx("div",{className:"form-msg form-msg--err",children:l}),n?i.jsx("div",{className:"muted",children:"Loading…"}):i.jsxs("div",{children:[e.length===0&&i.jsx("div",{className:"muted",children:"No tokens yet."}),e.map(w=>i.jsxs("div",{className:"token-row",children:[i.jsxs("div",{className:"token-row-info",children:[i.jsx("strong",{children:w.name}),i.jsxs("div",{className:"muted",children:["Created ",w.created_at.slice(0,10),w.last_used_at&&` · Last used ${w.last_used_at.slice(0,10)}`]})]}),i.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"4px 10px"},onClick:()=>y(w.token_uid),children:"Revoke"})]},w.token_uid))]})]})})}function Kh(){const[e,t]=p.useState(null),[n,r]=p.useState(!0),[l,s]=p.useState(null),[a,o]=p.useState(!1),[u,c]=p.useState(null);p.useEffect(()=>{(async()=>{try{t(await ia())}catch(m){s(m.message)}finally{r(!1)}})()},[]);async function v(m){m.preventDefault(),o(!0),c(null);try{await ui(e),c({ok:!0,text:"Saved."})}catch(f){c({ok:!1,text:f.message})}finally{o(!1)}}return n?i.jsx("div",{className:"muted",children:"Loading…"}):l?i.jsx("div",{className:"form-msg form-msg--err",children:l}):e?i.jsx("div",{style:{maxWidth:440},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Instance Settings"}),i.jsxs("form",{onSubmit:v,children:[[["public_index_enabled","Public index (unauthenticated browsing)"],["public_entry_content_enabled","Public entry content"],["open_registration_enabled","Open registration"]].map(([m,f])=>i.jsxs("label",{className:"checkbox-row",children:[i.jsx("input",{type:"checkbox",checked:!!e[m],onChange:x=>t(y=>({...y,[m]:x.target.checked}))}),f]},m)),i.jsxs("div",{className:"form-field",style:{marginTop:4},children:[i.jsx("label",{className:"form-label",children:"Default entry visibility"}),i.jsxs("select",{className:"field-input",value:e.default_entry_visibility,onChange:m=>t(f=>({...f,default_entry_visibility:Number(m.target.value)})),children:[i.jsx("option",{value:0,children:"Private"}),i.jsx("option",{value:2,children:"Unlisted"}),i.jsx("option",{value:3,children:"Public"})]})]}),u&&i.jsx("div",{className:`form-msg form-msg--${u.ok?"ok":"err"}`,children:u.text}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:a,children:a?"Saving…":"Save Settings"})]})]})}):null}function hs(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 Xh({archiveId:e}){const[t,n]=p.useState("idle"),[r,l]=p.useState(null),[s,a]=p.useState(null),[o,u]=p.useState(null);function c(){n("idle"),l(null),a(null),u(null)}async function v(){n("scanning"),u(null),l(null);try{const x=await yh(e);l(x),n("scanned")}catch(x){u(x.message),n("error")}}async function m(){n("deleting"),u(null);try{const x=await xh(e);a(x),n("done")}catch(x){u(x.message),n("error")}}const f=r&&r.deletable_files===0&&r.orphaned_blob_rows===0;return i.jsx("div",{style:{maxWidth:440},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Orphan Cleanup"}),i.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."," ",i.jsx("strong",{children:"Cleanup is blocked while captures are running."})]}),!e&&i.jsx("div",{className:"muted",children:"No archive selected."}),e&&t==="idle"&&i.jsx("button",{className:"btn-ghost",onClick:v,children:"Scan for orphaned blobs"}),t==="scanning"&&i.jsx("div",{className:"muted",children:"Scanning…"}),t==="scanned"&&r&&f&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"form-msg form-msg--ok",children:"Archive is clean — nothing to remove."}),i.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:c,children:"Done"})]}),t==="scanned"&&r&&!f&&i.jsxs("div",{children:[i.jsxs("div",{style:{marginBottom:14,lineHeight:1.6},children:["Found ",i.jsx("strong",{children:r.deletable_files})," unreferenced file",r.deletable_files!==1?"s":""," ","and ",i.jsx("strong",{children:r.orphaned_blob_rows})," orphaned DB record",r.orphaned_blob_rows!==1?"s":""," ","— ",i.jsx("strong",{children:hs(r.total_bytes)})," recoverable."]}),i.jsxs("div",{style:{display:"flex",gap:8},children:[i.jsxs("button",{className:"btn-danger",onClick:m,children:["Delete (",hs(r.total_bytes),")"]}),i.jsx("button",{className:"btn-ghost",onClick:c,children:"Cancel"})]})]}),t==="deleting"&&i.jsx("div",{className:"muted",children:"Deleting…"}),t==="done"&&s&&i.jsxs("div",{children:[i.jsxs("div",{className:"form-msg form-msg--ok",children:["Freed ",i.jsx("strong",{children:hs(s.freed_bytes)})," ","— removed ",s.deleted_files," file",s.deleted_files!==1?"s":""," ","and ",s.deleted_blob_rows," DB record",s.deleted_blob_rows!==1?"s":"","."]}),s.errors&&s.errors.length>0&&i.jsxs("div",{className:"form-msg form-msg--err",style:{marginTop:6},children:[s.errors.length," file",s.errors.length!==1?"s":""," could not be deleted."]}),i.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:c,children:"Scan again"})]}),t==="error"&&i.jsxs("div",{children:[i.jsx("div",{className:"form-msg form-msg--err",children:o}),i.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:c,children:"Try again"})]})]})})}function Jh(){const[e,t]=p.useState(null),[n,r]=p.useState(!0),[l,s]=p.useState(null),[a,o]=p.useState("global"),[u,c]=p.useState(""),[v,m]=p.useState("{}"),[f,x]=p.useState(null),[y,w]=p.useState(!1),[z,h]=p.useState({});p.useEffect(()=>{d()},[]);async function d(){r(!0),s(null);try{t(await kh())}catch(_){s(_.message)}finally{r(!1)}}async function g(_){_.preventDefault();try{JSON.parse(v)}catch{x({ok:!1,text:'cookies must be valid JSON, e.g. {"session": "abc"}'});return}w(!0),x(null);try{await jh(a==="global"?null:u.trim(),a,v),c(""),m("{}"),o("global"),x({ok:!0,text:"Rule added."}),await d()}catch(F){x({ok:!1,text:F.message})}finally{w(!1)}}async function S(_){try{await Nh(_),await d()}catch(F){s(F.message)}}function N(_){h(F=>({...F,[_.rule_uid]:{cookiesInput:_.cookies_json,saving:!1,msg:null}}))}function T(_){h(F=>{const I={...F};return delete I[_],I})}async function P(_){const F=z[_.rule_uid];try{JSON.parse(F.cookiesInput)}catch{h(I=>({...I,[_.rule_uid]:{...I[_.rule_uid],msg:{ok:!1,text:"Invalid JSON"}}}));return}h(I=>({...I,[_.rule_uid]:{...I[_.rule_uid],saving:!0,msg:null}}));try{await Sh(_.rule_uid,{cookies_json:F.cookiesInput}),T(_.rule_uid),await d()}catch(I){h(V=>({...V,[_.rule_uid]:{...V[_.rule_uid],saving:!1,msg:{ok:!1,text:I.message}}}))}}return n?i.jsx("div",{className:"muted",children:"Loading…"}):l?i.jsx("div",{className:"form-msg form-msg--err",children:l}):i.jsx("div",{style:{maxWidth:560},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Cookie Rules"}),i.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?i.jsxs("table",{className:"data-table",style:{width:"100%",marginBottom:16},children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{children:"Pattern"}),i.jsx("th",{children:"Cookies"}),i.jsx("th",{style:{width:100},children:"Actions"})]})}),i.jsx("tbody",{children:e.map(_=>{const F=z[_.rule_uid],I=_.url_pattern?i.jsxs(i.Fragment,{children:[i.jsxs("span",{className:"muted",children:[_.pattern_kind,":"]})," ",i.jsx("code",{children:_.url_pattern})]}):i.jsx("span",{className:"muted",children:"global (all URLs)"});return i.jsxs("tr",{children:[i.jsx("td",{children:I}),i.jsx("td",{children:F?i.jsxs(i.Fragment,{children:[i.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:12,width:"100%",minHeight:60},value:F.cookiesInput,onChange:V=>h(J=>({...J,[_.rule_uid]:{...J[_.rule_uid],cookiesInput:V.target.value}}))}),F.msg&&i.jsx("div",{className:`form-msg form-msg--${F.msg.ok?"ok":"err"}`,children:F.msg.text}),i.jsxs("div",{style:{display:"flex",gap:8,marginTop:4},children:[i.jsx("button",{className:"btn-primary",style:{fontSize:12,padding:"2px 8px"},disabled:F.saving,onClick:()=>P(_),children:F.saving?"Saving…":"Save"}),i.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>T(_.rule_uid),children:"Cancel"})]})]}):i.jsx("code",{style:{fontSize:12,wordBreak:"break-all"},children:_.cookies_json})}),i.jsx("td",{children:!F&&i.jsxs("div",{style:{display:"flex",gap:6},children:[i.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>N(_),children:"Edit"}),i.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"2px 8px"},onClick:()=>S(_.rule_uid),children:"Del"})]})})]},_.rule_uid)})})]}):i.jsx("p",{className:"muted",style:{marginBottom:16},children:"No cookie rules defined."}),i.jsx("h3",{style:{marginBottom:8},children:"Add Rule"}),i.jsxs("form",{onSubmit:g,children:[i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",children:"Pattern type"}),i.jsxs("select",{className:"field-input",value:a,onChange:_=>o(_.target.value),children:[i.jsx("option",{value:"global",children:"Global (all URLs)"}),i.jsx("option",{value:"wildcard",children:"Wildcard (e.g. *.youtube.com)"}),i.jsx("option",{value:"regex",children:"Regex (matched against full URL)"})]})]}),a!=="global"&&i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",children:a==="wildcard"?"URL/hostname pattern":"Regex pattern"}),i.jsx("input",{className:"field-input",type:"text",value:u,onChange:_=>c(_.target.value),placeholder:a==="wildcard"?"*.youtube.com or https://example.com/*":".*\\.youtube\\.com.*",required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",children:"Cookies (JSON object)"}),i.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:13,minHeight:70},value:v,onChange:_=>m(_.target.value),placeholder:'{"SESSION": "abc123", "token": "xyz"}',required:!0})]}),f&&i.jsx("div",{className:`form-msg form-msg--${f.ok?"ok":"err"}`,children:f.text}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:y,children:y?"Adding…":"Add Rule"})]})]})})}function Yh(){const[e,t]=p.useState(null),[n,r]=p.useState(!0),[l,s]=p.useState(!1),[a,o]=p.useState(null);p.useEffect(()=>{(async()=>{try{t(await ia())}catch(y){o({ok:!1,text:y.message})}finally{r(!1)}})()},[]);async function u(y){s(!0),o(null);try{await ui({ublock_enabled:y}),t(w=>({...w,ublock_enabled:y})),o({ok:!0,text:"Saved."})}catch(w){o({ok:!1,text:w.message})}finally{s(!1)}}async function c(y){s(!0),o(null);try{await ui({cookie_ext_enabled:y}),t(w=>({...w,cookie_ext_enabled:y})),o({ok:!0,text:"Saved."})}catch(w){o({ok:!1,text:w.message})}finally{s(!1)}}if(n)return i.jsx("div",{className:"muted",children:"Loading\\u2026"});const v=(e==null?void 0:e.ublock_ext_available)??!1,m=(e==null?void 0:e.ublock_enabled)??!0,f=(e==null?void 0:e.cookie_ext_available)??!1,x=(e==null?void 0:e.cookie_ext_enabled)??!0;return i.jsx("div",{style:{maxWidth:560},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Extensions"}),i.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."}),i.jsx("div",{className:"ext-card",children:i.jsxs("div",{className:"ext-card-header",children:[i.jsxs("div",{className:"ext-card-info",children:[i.jsx("span",{className:"ext-card-name",children:"uBlock Origin Lite"}),i.jsx("span",{className:"ext-card-desc",children:"Blocks ads, trackers, and other page clutter during archiving via Chrome’s declarativeNetRequest API (Manifest V3)."}),!v&&i.jsxs("span",{className:"ext-card-hint",children:["Not configured — set ",i.jsx("code",{children:"ARCHIVR_UBLOCK_EXT"})," to the unpacked extension directory to enable."]})]}),i.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:i.jsx("span",{className:"ext-toggle-knob"})})]})}),i.jsx("div",{className:"ext-card",children:i.jsxs("div",{className:"ext-card-header",children:[i.jsxs("div",{className:"ext-card-info",children:[i.jsx("span",{className:"ext-card-name",children:"I Still Don’t Care About Cookies"}),i.jsx("span",{className:"ext-card-desc",children:"Dismiss cookie consent banners during archiving."}),!f&&i.jsxs("span",{className:"ext-card-hint",children:["Not configured — set ",i.jsx("code",{children:"ARCHIVR_COOKIE_EXT"})," to the unpacked extension directory to enable."]})]}),i.jsx("button",{type:"button",role:"switch","aria-checked":x,className:`ext-toggle${x?" ext-toggle--on":""}`,onClick:()=>c(!x),disabled:l,"aria-label":"Toggle I Still Don't Care About Cookies",children:i.jsx("span",{className:"ext-toggle-knob"})})]})}),a&&i.jsx("div",{className:`form-msg form-msg--${a.ok?"ok":"err"}`,children:a.text})]})})}const No={0:"Private",1:"Public",2:"Users only",3:"Public"},Gh=()=>i.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:i.jsx("path",{d:"M7 17 17 7M9 7h8v8"})});function qh({archiveId:e,selectedEntry:t,detail:n,onTagFilterSet:r,tagNodes:l,onTagsRefresh:s,onEntryTitleChange:a,onEntryDeleted:o,humanizeTags:u,onDetailRefresh:c}){const[v,m]=p.useState([]),[f,x]=p.useState(""),[y,w]=p.useState([]),[z,h]=p.useState(""),d=p.useRef(0),g=p.useRef(!1),[S,N]=p.useState(!1),[T,P]=p.useState(""),[_,F]=p.useState("idle"),[I,V]=p.useState(""),J=p.useRef(null);p.useEffect(()=>{const k=++d.current;if(J.current&&(clearInterval(J.current),J.current=null),F("idle"),V(""),!t||!e){m([]),w([]);return}N(!1),P(""),g.current=!1,m([]),Promise.all([Br(e,t.entry_uid),gh(e,t.entry_uid)]).then(([D,j])=>{k===d.current&&(m(D),w(j))}).catch(()=>{})},[t,e]),p.useEffect(()=>()=>{clearInterval(J.current)},[]);async function ue(){const k=T.trim()||null;try{await bp(e,t.entry_uid,k),a==null||a(t.entry_uid,k)}catch{}finally{N(!1)}}async function ve(){const k=f.trim();if(!(!k||!t))try{await Bp(e,t.entry_uid,k),x(""),h("");const D=await Br(e,t.entry_uid);m(D),s()}catch(D){h(D.message)}}async function je(k){try{await Up(e,t.entry_uid,k);const D=await Br(e,t.entry_uid);m(D),s()}catch{}}async function Re(){if(!(!t||!e)&&window.confirm("Delete this entry? This cannot be undone."))try{await Hp(e,t.entry_uid),o==null||o(t.entry_uid)}catch{}}async function ye(){if(!t||!e||_==="running")return;const k=d.current,D=t.entry_uid;F("running"),V("");try{const{job_uid:j}=await wh(e,D);if(d.current!==k)return;J.current=setInterval(async()=>{try{const C=await Uc(e,j);if(C.status==="completed"){if(clearInterval(J.current),J.current=null,d.current!==k)return;F("done");const M=await Br(e,D);if(d.current!==k)return;m(M),c==null||c()}else if(C.status==="failed"){if(clearInterval(J.current),J.current=null,d.current!==k)return;F("error"),V(C.error_text||"Re-archive failed.")}}catch{if(clearInterval(J.current),J.current=null,d.current!==k)return;F("error"),V("Network error while polling.")}},500)}catch(j){if(d.current!==k)return;F("error"),V(j.message||"Failed to start re-archive.")}}const L=n?[["Added",Wc(n.summary.archived_at)],["Source",n.summary.source_kind],["Type",n.summary.entity_kind],["Visibility",No[n.summary.visibility]??n.summary.visibility],["Root",n.structured_root_relpath]]:[];return i.jsxs("aside",{className:"context-rail",children:[i.jsx("div",{className:"rail-eyebrow",children:"Context"}),t?n?i.jsxs(i.Fragment,{children:[S?i.jsx("input",{className:"rail-title-input",autoFocus:!0,value:T,onChange:k=>P(k.target.value),onKeyDown:k=>{k.key==="Enter"&&k.currentTarget.blur(),k.key==="Escape"&&(g.current=!0,k.currentTarget.blur())},onBlur:()=>{g.current?N(!1):ue(),g.current=!1}}):i.jsxs("h2",{className:"rail-title rail-title--editable",title:"Click to rename",onClick:()=>{P(n.summary.title??""),N(!0)},children:[Qt(n.summary.title)||Qt(n.summary.entry_uid),i.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:i.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),n.summary.original_url&&i.jsxs("a",{className:"url-tile",href:n.summary.original_url,target:"_blank",rel:"noopener noreferrer",children:[i.jsx("span",{className:"ico",dangerouslySetInnerHTML:{__html:aa(n.summary.source_kind)}}),i.jsx("span",{className:"u-text",children:n.summary.original_url}),i.jsx("span",{className:"ext",children:i.jsx(Gh,{})})]}),i.jsx("div",{className:"meta-list",children:L.filter(([,k])=>k!=null&&k!=="").map(([k,D])=>i.jsxs("div",{className:"meta-item",children:[i.jsx("span",{className:"meta-k",children:k}),i.jsx("span",{className:`meta-v${k==="Root"?" mono":""}`,children:Qt(D)})]},k))}),n.artifacts.length>0&&i.jsxs("div",{className:"rail-section",children:[i.jsxs("div",{className:"rail-section-heading",children:["Artifacts ",i.jsx("span",{className:"num",children:n.artifacts.length})]}),i.jsx("ul",{className:"artifact-list",children:n.artifacts.map((k,D)=>i.jsx("li",{children:i.jsxs("a",{href:`/api/archives/${e}/entries/${n.summary.entry_uid}/artifacts/${D}`,target:"_blank",rel:"noopener noreferrer",className:"artifact-link",children:[i.jsx("span",{className:"artifact-name",children:k.artifact_role.replace(/_/g," ")}),i.jsx("span",{className:"artifact-size",children:k.byte_size!=null?di(k.byte_size):"—"})]})},D))})]})]}):i.jsx("p",{className:"tags-empty",children:"Loading…"}):i.jsx("p",{className:"tags-empty",children:"Select an entry."}),t&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"rail-section",children:[i.jsx("div",{className:"rail-section-heading",children:"Tags"}),v.length===0?i.jsx("p",{className:"tags-empty",children:"No tags yet."}):i.jsx("div",{className:"tags-wrap",children:v.map(k=>i.jsxs("span",{className:"tag-pill",title:k.full_path,children:[u?Vc(k.full_path):k.full_path,i.jsx("button",{className:"remove",title:`Remove tag ${k.full_path}`,onClick:()=>je(k.tag_uid),children:"×"})]},k.tag_uid))}),z&&i.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:z}),i.jsxs("div",{className:"tag-input-wrap",children:[i.jsx("span",{className:"hash",children:"/"}),i.jsx("input",{className:"tag-input",type:"text",placeholder:"science/cs",autoComplete:"off",value:f,onChange:k=>x(k.target.value),onKeyDown:k=>{k.key==="Enter"&&ve()}}),i.jsx("button",{className:"tag-add-btn",onClick:ve,children:"Add"})]})]}),y.length>0&&i.jsxs("div",{className:"rail-section",children:[i.jsx("div",{className:"rail-section-heading",children:"Collections"}),y.map(k=>i.jsxs("div",{className:"coll-row",children:[i.jsx("span",{className:"coll-name",children:k.collection_uid}),i.jsx("span",{className:"vis-badge",children:No[k.visibility_bits]??`bits:${k.visibility_bits}`})]},k.collection_uid))]}),n&&(n.summary.entity_kind==="tweet"||n.summary.entity_kind==="tweet_thread")&&i.jsxs("div",{className:"rail-section",children:[i.jsx("div",{className:"rail-section-heading",children:"Actions"}),i.jsx("button",{className:"rail-rearchive-btn",onClick:ye,disabled:_==="running",children:_==="running"?"Re-archiving…":"Re-archive"}),_==="done"&&i.jsx("p",{className:"form-msg form-msg--ok",style:{marginTop:"6px"},children:"Re-archived successfully."}),_==="error"&&i.jsx("p",{className:"form-msg form-msg--err",style:{marginTop:"6px"},children:I})]}),i.jsx("div",{className:"rail-delete-zone",children:i.jsx("button",{className:"rail-delete-btn",onClick:Re,children:"Delete entry"})})]})]})}function Zh({src:e}){const t=p.useRef(null);return p.useEffect(()=>{t.current&&t.current.load()},[e]),i.jsx("div",{className:"preview-video-wrap",style:{background:"#111",display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",minHeight:"240px"},children:e?i.jsxs("video",{ref:t,controls:!0,autoPlay:!1,style:{width:"100%",maxHeight:"100%",display:"block"},children:[i.jsx("source",{src:e}),"Your browser does not support the video element."]}):i.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No video available"})})}function _o({src:e,type:t}){return i.jsx("div",{className:"preview-iframe-wrap",style:{height:"100%",display:"flex",flexDirection:"column"},children:t==="page"?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"preview-iframe-toolbar",style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 10px",borderBottom:"1px solid var(--line-soft)",background:"var(--paper-2)",flexShrink:0},children:[i.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.8rem",color:"var(--muted)",fontFamily:"var(--sans)"},children:e}),i.jsx("a",{href:e,target:"_blank",rel:"noreferrer noopener",style:{fontSize:"0.8rem",color:"var(--accent)",textDecoration:"none",whiteSpace:"nowrap",fontFamily:"var(--sans)"},children:"Open in new tab ↗"})]}),i.jsx("iframe",{src:e,sandbox:"allow-scripts allow-same-origin allow-popups",referrerPolicy:"no-referrer",style:{flex:1,border:"none",width:"100%"},title:"Page preview"})]}):i.jsxs(i.Fragment,{children:[i.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--line-soft)",background:"var(--paper-2)",flexShrink:0,fontSize:"0.85rem",color:"var(--muted)",fontFamily:"var(--sans)"},children:"PDF Document"}),i.jsx("iframe",{src:e,style:{flex:1,border:"none",width:"100%"},title:"PDF preview"})]})})}function em({src:e,alt:t}){return i.jsx("div",{className:"preview-image-wrap",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",background:"var(--paper-2)",overflow:"hidden"},children:i.jsx("a",{href:e,target:"_blank",rel:"noreferrer noopener",style:{display:"contents"},children:i.jsx("img",{src:e,alt:t||"",style:{objectFit:"contain",maxHeight:"100%",maxWidth:"100%",display:"block",cursor:"pointer"}})})})}function Kc(e){return e?new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(new Date(e*1e3)):""}const b={card:{background:"var(--paper)",border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",maxWidth:"598px",margin:"0 auto",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},threadOuter:{border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",maxWidth:"598px",margin:"0 auto",background:"var(--paper)",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},tweetRow:{display:"flex",gap:"12px",padding:"16px"},tweetRowThread:{display:"flex",gap:"12px",padding:"16px 16px 0"},leftCol:{display:"flex",flexDirection:"column",alignItems:"center",flexShrink:0,width:"40px"},rightCol:{flex:1,minWidth:0,paddingBottom:"16px"},avatar:{width:"40px",height:"40px",borderRadius:"50%",objectFit:"cover",flexShrink:0,display:"block"},avatarPh:{width:"40px",height:"40px",borderRadius:"50%",background:"var(--line)",flexShrink:0},threadLine:{flex:1,width:"2px",background:"var(--line-soft, var(--line))",margin:"4px 0",minHeight:"16px",borderRadius:"1px"},authorRow:{display:"flex",alignItems:"baseline",gap:"4px",flexWrap:"wrap",marginBottom:"6px",lineHeight:"1.3"},authorName:{fontWeight:"700",fontSize:"15px",color:"var(--ink)"},authorHandle:{fontSize:"14px",color:"var(--muted)"},datePart:{fontSize:"14px",color:"var(--muted)"},tweetText:{fontSize:"15px",lineHeight:"1.6",color:"var(--ink)",whiteSpace:"pre-line",marginBottom:"10px",wordBreak:"break-word"},stats:{display:"flex",gap:"16px",fontSize:"14px",color:"var(--muted)"},link:{color:"var(--accent)",textDecoration:"none"},loading:{padding:"32px 16px",textAlign:"center",color:"var(--muted)",fontSize:"15px"},error:{padding:"32px 16px",textAlign:"center",color:"var(--alert)",fontSize:"15px"},article:{maxWidth:"598px",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:"420px"},aMeta:{padding:"20px 16px 0"},aTweetTitle:{fontSize:"23px",fontWeight:"800",letterSpacing:"-0.3px",color:"var(--ink)",lineHeight:"1.3",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:"var(--line)",flexShrink:0},aAuthorName:{fontSize:"15px",fontWeight:"700",color:"var(--ink)",lineHeight:"1.3"},aAuthorSub:{fontSize:"15px",color:"var(--muted)",lineHeight:"1.3"},aDivider:{border:"none",borderTop:"1px solid var(--line)",margin:"0"},aBody:{padding:"4px 16px 24px"},bH1:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:"var(--ink)",lineHeight:"1.25",margin:"24px 0 10px"},bH2:{fontSize:"20px",fontWeight:"700",letterSpacing:"-0.2px",color:"var(--ink)",lineHeight:"1.3",margin:"22px 0 8px"},bP:{fontSize:"17px",color:"var(--ink)",lineHeight:"1.7",marginBottom:"16px",marginTop:"0"},bSpacer:{height:"6px",display:"block"},bQuote:{borderLeft:"3px solid var(--line)",padding:"2px 14px",margin:"14px 0",color:"var(--muted)",fontSize:"17px",lineHeight:"1.65"},bHr:{border:"none",borderTop:"1px solid var(--line)",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:"var(--ink)",lineHeight:"1.65",marginBottom:"6px"},bTweet:{display:"flex",alignItems:"center",gap:"12px",border:"1px solid var(--line)",borderRadius:"12px",padding:"14px 16px",margin:"14px 0",color:"var(--muted)",fontSize:"15px",textDecoration:"none"},bMdPre:{borderRadius:"8px",margin:"12px 0",overflow:"auto",background:"var(--paper-3, var(--field))",padding:"14px 16px"},bMdCode:{fontFamily:"ui-monospace, 'Cascadia Code', 'Fira Code', Menlo, Consolas, monospace",fontSize:"13px",lineHeight:"1.65",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:"2px 6px",borderRadius:"4px",color:"var(--ink)"}};function Xc(){return i.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",style:{flexShrink:0,color:"var(--ink)"},children:i.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 tm(e,t){if(!e)return null;const n=(t.urls||[]).filter(o=>o.fromIndex!=null&&o.toIndex!=null),r=(t.user_mentions||[]).filter(o=>o.fromIndex!=null&&o.toIndex!=null);if(n.length===0&&r.length===0)return e;const l=[...n.map(o=>({s:o.fromIndex,e:o.toIndex,kind:"url",href:o.expanded_url,display:o.display_url})),...r.map(o=>({s:o.fromIndex,e:o.toIndex,kind:"mention",screen_name:o.screen_name}))],s=new Set([0,e.length]);for(const o of l)o.s>=0&&o.s<=e.length&&s.add(o.s),o.e>=0&&o.e<=e.length&&s.add(o.e);const a=[...s].sort((o,u)=>o-u);return a.slice(0,-1).map((o,u)=>{const c=a[u+1],v=e.slice(o,c),m=l.filter(y=>y.s<=o&&y.e>=c),f=m.find(y=>y.kind==="url");if(f)return i.jsx("a",{href:f.href,target:"_blank",rel:"noopener noreferrer",style:b.link,children:f.display||v},u);const x=m.find(y=>y.kind==="mention");return x?i.jsx("a",{href:`https://x.com/${x.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:b.link,children:v},u):i.jsx("span",{children:v},u)})}function nm(e,t,n,r){if(!e)return null;t=t||[],n=n||[],r=r||[];const l=[];for(const o of t)o.length>0&&l.push({s:o.offset,e:o.offset+o.length,kind:"style",style:o.style});for(const o of n)l.push({s:o.fromIndex,e:o.toIndex,kind:"url",href:o.text});for(const o of r)l.push({s:o.fromIndex,e:o.toIndex,kind:"mention",name:o.text});if(l.length===0)return e;const s=new Set([0,e.length]);for(const o of l)o.s>=0&&o.s<=e.length&&s.add(o.s),o.e>=0&&o.e<=e.length&&s.add(o.e);const a=[...s].sort((o,u)=>o-u);return a.slice(0,-1).map((o,u)=>{const c=a[u+1],v=l.filter(w=>w.s<=o&&w.e>=c),m=e.slice(o,c);let f;if(m.includes(` `)){const w=m.split(` `);f=w.flatMap((z,h)=>hw.kind==="style"&&w.style==="Code")&&(f=i.jsx("code",{style:b.iCode,children:f})),v.some(w=>w.kind==="style"&&w.style==="Bold")&&(f=i.jsx("strong",{children:f})),v.some(w=>w.kind==="style"&&w.style==="Italic")&&(f=i.jsx("em",{children:f})),v.some(w=>w.kind==="style"&&w.style==="Underline")&&(f=i.jsx("u",{children:f})),v.some(w=>w.kind==="style"&&w.style==="Strikethrough")&&(f=i.jsx("s",{children:f}));const x=v.find(w=>w.kind==="url");x&&(f=i.jsx("a",{href:x.href,target:"_blank",rel:"noopener noreferrer",style:b.link,children:f}));const y=v.find(w=>w.kind==="mention");return y&&(f=i.jsx("a",{href:`https://x.com/${y.name}`,target:"_blank",rel:"noopener noreferrer",style:b.link,children:f})),i.jsx("span",{children:f},u)})}function rm(e){const t=e.resolved_entities||[];return t.length===0?null:t.map((n,r)=>{var l;switch(n.type){case"divider":return i.jsx("hr",{style:b.bHr},r);case"media":return n.url?i.jsx("img",{src:n.url,style:b.bImg,loading:"lazy",alt:""},r):null;case"tweet":return n.tweet_id?i.jsxs("a",{href:`https://x.com/i/status/${n.tweet_id}`,target:"_blank",rel:"noopener noreferrer",style:b.bTweet,children:[i.jsx(Xc,{}),"View post on X"]},r):null;case"link":return n.url?i.jsx("p",{style:b.bP,children:i.jsx("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",style:b.link,children:n.url})},r):null;case"markdown":{const s=n.markdown??((l=n.data)==null?void 0:l.markdown)??"";return i.jsx("pre",{style:b.bMdPre,children:i.jsx("code",{style:b.bMdCode,children:s})},r)}case"emoji":return n.url?i.jsx("img",{src:n.url,alt:"",style:{height:"1.2em",verticalAlign:"middle",margin:"0 1px"}},r):null;default:return null}})}function ms(e,t){const n=e.type||"",r=e.text||"",l=e.inline_style_ranges||[],s=e.data||{},a=nm(r,l,s.urls||[],s.mentions||[]);switch(n){case"header-one":return i.jsx("h1",{style:b.bH1,children:a},t);case"header-two":{const o=r.match(/(?:x\.com|twitter\.com)\/i\/status\/(\d+)/);return o?i.jsxs("a",{href:`https://x.com/i/status/${o[1]}`,target:"_blank",rel:"noopener noreferrer",style:b.bTweet,children:[i.jsx(Xc,{}),"View post on X"]},t):i.jsx("h2",{style:b.bH2,children:a},t)}case"unstyled":return r.trim()?i.jsx("p",{style:b.bP,children:a},t):i.jsx("span",{style:b.bSpacer},t);case"blockquote":return i.jsx("blockquote",{style:b.bQuote,children:a},t);case"unordered-list-item":case"ordered-list-item":return i.jsx("li",{style:b.bLi,children:a},t);case"atomic":return i.jsx("span",{children:rm(e)},t);default:return r?i.jsx("p",{style:b.bP,children:a},t):null}}function lm(e){const t=[];let n=0;for(;n0||e.favorite_count>0)&&i.jsxs("div",{style:b.stats,children:[e.favorite_count>0&&i.jsxs("span",{children:["❤️ ",e.favorite_count.toLocaleString()]}),e.retweet_count>0&&i.jsxs("span",{children:["🔁 ",e.retweet_count.toLocaleString()]})]})]})]})}function im({archiveId:e,entryUid:t,artifacts:n,entityKind:r}){const[l,s]=p.useState(!0),[a,o]=p.useState(null),[u,c]=p.useState([]);if(p.useEffect(()=>{if(s(!0),o(null),c([]),!n||!e||!t){s(!1);return}const m=n.map((x,y)=>({...x,index:y})).filter(x=>x.artifact_role==="raw_tweet_json");if(m.length===0){o("No tweet data found."),s(!1);return}let f=!1;return Promise.all(m.map(x=>fetch(`/api/archives/${e}/entries/${t}/artifacts/${x.index}`).then(y=>{if(!y.ok)throw new Error(`HTTP ${y.status}`);return y.json()}))).then(x=>{f||c(x)}).catch(x=>{f||o(x.message||"Failed to load tweet.")}).finally(()=>{f||s(!1)}),()=>{f=!0}},[e,t,n]),l)return i.jsx("div",{style:b.loading,children:"Loading…"});if(a)return i.jsxs("div",{style:b.error,children:["Error: ",a]});if(u.length===0)return null;if(r==="tweet_thread")return i.jsx("div",{style:b.threadOuter,children:u.map((m,f)=>i.jsx(Co,{tweet:m,isInThread:!0,isLast:f===u.length-1},m.id||f))});const v=u[0];return v.is_article&&v.article?i.jsx(sm,{article:v.article,tweetAuthor:v.author}):i.jsx("div",{style:b.card,children:i.jsx(Co,{tweet:v,isInThread:!1,isLast:!0})})}const am=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv"]),Eo=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),om=new Set(["jpg","jpeg","png","gif","webp","avif","svg","bmp"]);function um({archiveId:e,entry:t,detail:n,onSetAudio:r}){const l=p.useMemo(()=>{if(!n||!t)return null;const{artifacts:x,summary:y}=n,w=x.findIndex(h=>h.artifact_role==="primary_media");if(w===-1)return null;const z=x[w].relpath.split(".").pop().toLowerCase();return Eo.has(z)?{entry:t,src:`/api/archives/${e}/entries/${y.entry_uid}/artifacts/${w}`,archiveId:e}:null},[n,t,e]);if(p.useEffect(()=>{l&&r&&r(l)},[l]),!t)return i.jsx("div",{className:"preview-panel preview-panel--empty",children:i.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"Select an entry to preview"})});if(!n)return i.jsx("div",{className:"preview-panel preview-panel--loading",children:i.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"Loading…"})});const{summary:s,artifacts:a}=n,o=s.entry_uid,u=s.entity_kind;if(u==="tweet"||u==="tweet_thread")return i.jsx("div",{className:"preview-panel",children:i.jsx(im,{archiveId:e,entryUid:o,artifacts:a,entityKind:u})});const c=a.findIndex(x=>x.artifact_role==="primary_media");if(c===-1)return i.jsxs("div",{className:"preview-panel preview-panel--no-preview",children:[i.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No preview available"}),a.length>0&&i.jsx("ul",{style:{marginTop:"12px",paddingLeft:"20px",fontSize:"0.8rem",color:"var(--muted-2)",fontFamily:"var(--sans)"},children:a.map((x,y)=>i.jsxs("li",{children:[x.artifact_role,": ",x.relpath]},y))})]});const v=a[c],m=`/api/archives/${e}/entries/${o}/artifacts/${c}`,f=v.relpath.split(".").pop().toLowerCase();return am.has(f)?i.jsx("div",{className:"preview-panel",children:i.jsx(Zh,{src:m})}):Eo.has(f)?i.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:[i.jsx("span",{style:{fontSize:"2.5rem"},children:"🎵"}),i.jsx("span",{style:{color:"var(--ink)",fontSize:"1rem",fontWeight:600},children:s.title||o}),i.jsx("span",{style:{color:"var(--muted)",fontSize:"0.85rem"},children:"Playing in audio bar below"}),i.jsx("audio",{src:m,controls:!0,style:{marginTop:"12px",width:"100%",maxWidth:"400px"}})]}):f==="pdf"?i.jsx("div",{className:"preview-panel",style:{height:"100%"},children:i.jsx(_o,{src:m,type:"pdf"})}):f==="html"||f==="htm"?i.jsx("div",{className:"preview-panel",style:{height:"100%"},children:i.jsx(_o,{src:m,type:"page"})}):om.has(f)?i.jsx("div",{className:"preview-panel",style:{height:"100%"},children:i.jsx(em,{src:m,alt:s.title||"Image"})}):i.jsxs("div",{className:"preview-panel preview-panel--no-preview",children:[i.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No preview available"}),i.jsx("ul",{style:{marginTop:"12px",paddingLeft:"20px",fontSize:"0.8rem",color:"var(--muted-2)",fontFamily:"var(--sans)"},children:a.map((x,y)=>i.jsxs("li",{children:[x.artifact_role,": ",x.relpath]},y))})]})}function To(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 cm({entry:e,src:t,archiveId:n,onClose:r}){const l=p.useRef(null),[s,a]=p.useState(!1),[o,u]=p.useState(0),[c,v]=p.useState(NaN),[m,f]=p.useState(1);p.useEffect(()=>{!l.current||!t||(l.current.load(),l.current.play().then(()=>{a(!0)}).catch(()=>{a(!1)}),u(0),v(NaN))},[t]),p.useEffect(()=>{l.current&&(l.current.volume=m)},[m]);function x(){const d=l.current;d&&(s?d.pause():d.play().catch(()=>{}))}function y(d){const g=l.current;if(!g||!isFinite(c))return;const S=Number(d.target.value);g.currentTime=S,u(S)}function w(d){f(Number(d.target.value))}const z=(e==null?void 0:e.title)||(e==null?void 0:e.entry_uid)||"Unknown",h=(e==null?void 0:e.source_kind)||"other";return i.jsxs(i.Fragment,{children:[i.jsx("audio",{ref:l,src:t||void 0,preload:"auto",onPlay:()=>a(!0),onPause:()=>a(!1),onEnded:()=>a(!1),onTimeUpdate:()=>{var d;return u(((d=l.current)==null?void 0:d.currentTime)??0)},onLoadedMetadata:()=>{var d;return v(((d=l.current)==null?void 0:d.duration)??NaN)},onDurationChange:()=>{var d;return v(((d=l.current)==null?void 0:d.duration)??NaN)},style:{display:"none"}}),i.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:[i.jsxs("div",{className:"audio-bar-info",style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0,flex:"0 1 220px",overflow:"hidden"},children:[i.jsx("span",{className:"source-icon",style:{flexShrink:0,width:"18px",height:"18px",display:"flex",alignItems:"center"},dangerouslySetInnerHTML:{__html:aa(h)}}),i.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.85rem",color:"var(--ink)"},title:z,children:z})]}),i.jsxs("div",{className:"audio-bar-controls",style:{display:"flex",alignItems:"center",gap:"10px",flex:"1 1 0",minWidth:0},children:[i.jsx("button",{onClick:x,"aria-label":s?"Pause":"Play",style:{background:"none",border:"none",cursor:"pointer",padding:"4px",color:"var(--ink)",flexShrink:0,fontSize:"1.2rem",lineHeight:1},children:s?"⏸":"▶"}),i.jsx("span",{style:{fontSize:"0.75rem",color:"var(--muted)",whiteSpace:"nowrap",flexShrink:0},children:To(o)}),i.jsx("input",{type:"range",min:0,max:isFinite(c)?c:0,step:.1,value:isFinite(o)?o:0,onChange:y,"aria-label":"Seek",style:{flex:1,minWidth:0,accentColor:"var(--accent)"}}),i.jsx("span",{style:{fontSize:"0.75rem",color:"var(--muted)",whiteSpace:"nowrap",flexShrink:0},children:To(c)})]}),i.jsxs("div",{className:"audio-bar-right",style:{display:"flex",alignItems:"center",gap:"8px",flex:"0 1 160px"},children:[i.jsx("span",{style:{fontSize:"0.85rem",color:"var(--muted)",flexShrink:0},children:"🔊"}),i.jsx("input",{type:"range",min:0,max:1,step:.01,value:m,onChange:w,"aria-label":"Volume",style:{width:"80px",accentColor:"var(--accent)"}}),i.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:"✕"})]})]})]})}const dm=7e3;function fm({toasts:e,onDismiss:t,onIgnoreUblock:n}){return e.length?i.jsx("div",{className:"toast-stack",role:"log","aria-live":"polite","aria-label":"Notifications",children:e.map(r=>i.jsx(hm,{toast:r,onDismiss:t,onIgnoreUblock:n},r.id))}):null}function pm(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),s=(l[l.length-1]??"")+r,a=s?`${t}/…/${s}`:t;return a.length<=56?a:a.slice(0,53)+"…"}catch{return"…"+e.slice(-51)}}function hm({toast:e,onDismiss:t,onIgnoreUblock:n}){const[r,l]=p.useState(!1),s=e.type==="warning",a=e.type==="success";p.useEffect(()=>{if(r)return;const u=setTimeout(()=>t(e.id),dm);return()=>clearTimeout(u)},[r,e.id,t]);const o=pm(e.locator);return a?i.jsx("div",{className:"toast toast--success",role:"alert","aria-atomic":"true",children:i.jsxs("div",{className:"toast-top",children:[i.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"✓"}),i.jsxs("div",{className:"toast-body",children:[i.jsx("span",{className:"toast-headline",children:e.headline||"Archived"}),o&&i.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),i.jsx("div",{className:"toast-btns",children:i.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})})]})}):s?i.jsxs("div",{className:"toast toast--warning",role:"alert","aria-atomic":"true",children:[i.jsxs("div",{className:"toast-top",children:[i.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"⚠"}),i.jsxs("div",{className:"toast-body",children:[i.jsx("span",{className:"toast-headline",children:e.headline||"Archived with warnings"}),o&&i.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),i.jsxs("div",{className:"toast-btns",children:[e.text&&i.jsx("button",{type:"button",className:"toast-view-btn",onClick:()=>l(u=>!u),"aria-expanded":r,children:r?"Hide":"Details"}),e.locator&&i.jsx("button",{type:"button",className:"toast-view-btn toast-ignore-btn",onClick:()=>{n==null||n(),t(e.id)},children:"Ignore"}),i.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})]})]}),r&&i.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."})]}):i.jsxs("div",{className:"toast toast--error",role:"alert","aria-atomic":"true",children:[i.jsxs("div",{className:"toast-top",children:[i.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"✕"}),i.jsxs("div",{className:"toast-body",children:[i.jsx("span",{className:"toast-headline",children:e.headline||"Capture failed"}),o&&i.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),i.jsxs("div",{className:"toast-btns",children:[e.text&&i.jsx("button",{type:"button",className:"toast-view-btn",onClick:()=>l(u=>!u),children:r?"Hide":"View error"}),i.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})]})]}),r&&e.text&&i.jsx("pre",{className:"toast-error-detail",children:e.text})]})}const bl=p.createContext(null),mm=["archive","tags","collections","runs","admin","settings"],gm=["profile","tokens","instance","storage"];function gs(){const e=window.location.pathname.split("/").filter(Boolean),t=mm.includes(e[0])?e[0]:"archive",n=t==="settings"&&gm.includes(e[1])?e[1]:"profile";return{view:t,settingsTab:n}}function vm(e,t){return e==="archive"?"/":e==="settings"?`/settings/${t}`:`/${e}`}function ym(){const[e,t]=p.useState("loading"),[n,r]=p.useState(null);p.useEffect(()=>{(async()=>{if(await Xp()){t("setup");return}const U=await qp();if(!U){t("login");return}r(U),t("authenticated")})()},[]),p.useEffect(()=>{const O=()=>{r(null),t("login")};return window.addEventListener("auth:expired",O),()=>window.removeEventListener("auth:expired",O)},[]),p.useEffect(()=>{const O=()=>{const{view:U,settingsTab:Z}=gs();h(U),g(Z)};return window.addEventListener("popstate",O),()=>window.removeEventListener("popstate",O)},[]);const[l,s]=p.useState([]),[a,o]=p.useState(null),[u,c]=p.useState([]),[v,m]=p.useState(null),[f,x]=p.useState(null),[y,w]=p.useState(null),[z,h]=p.useState(()=>gs().view),[d,g]=p.useState(()=>gs().settingsTab),[S,N]=p.useState(""),[T,P]=p.useState(""),[_,F]=p.useState(!1),[I,V]=p.useState([]),[J,ue]=p.useState([]),[ve,je]=p.useState(()=>sessionStorage.getItem("captureDialogOpen")==="true"),[Re,ye]=p.useState([]),L=p.useRef(0),[k,D]=p.useState(()=>sessionStorage.getItem("ublockWarningIgnored")==="true"),[j,C]=p.useState(null),M=p.useRef(0),[A,B]=p.useState(null),Y=(n==null?void 0:n.humanize_slugs)??!1;p.useEffect(()=>{const O=++M.current;C(null),!(!f||!a)&&xo(a,f.entry_uid).then(U=>{O===M.current&&C(U)}).catch(()=>{})},[f,a]),p.useEffect(()=>{sessionStorage.setItem("captureDialogOpen",ve)},[ve]);const W=p.useCallback(async(O,U,Z)=>{if(O){F(!0);try{let We;U||Z?We=await Ap(O,U,Z):We=await Mp(O),c(We),P(We.length===0?"No results":`${We.length} result${We.length===1?"":"s"}`)}catch{c([]),P("Search failed. Try again.")}finally{F(!1)}}},[]);p.useEffect(()=>{e==="authenticated"&&Fp().then(O=>{if(s(O),O.length>0){const U=O[0].id;o(U)}})},[e]),p.useEffect(()=>{a&&(w(null),x(null),m(null),Promise.all([W(a,"",null),wo(a).then(V),ps(a).then(ue)]))},[a]),p.useEffect(()=>{if(a===null)return;const O=setTimeout(()=>{W(a,S,y)},300);return()=>clearTimeout(O)},[S,a]),p.useEffect(()=>{a!==null&&(y!==null&&h("archive"),W(a,S,y))},[y,a]);const K=p.useCallback(O=>{o(O)},[]),G=p.useCallback(O=>{h(O),O==="tags"&&a&&ps(a).then(ue)},[a]);p.useEffect(()=>{const O=vm(z,d);window.location.pathname!==O&&history.pushState(null,"",O)},[z,d]);const de=p.useCallback(O=>{m(O?O.entry_uid:null),x(O)},[]),nn=p.useCallback(O=>{w(O)},[]),ut=p.useCallback(()=>{w(null)},[]),R=p.useCallback(()=>{a&&ps(a).then(ue)},[a]),H=p.useCallback((O,U)=>{y===O?w(U):y!=null&&y.startsWith(O+"/")&&w(U+y.slice(O.length))},[y]),Fe=p.useCallback(O=>{(y===O||y!=null&&y.startsWith(O+"/"))&&w(null)},[y]),ct=p.useCallback((O,U)=>{c(Z=>Z.map(We=>We.entry_uid===O?{...We,title:U}:We)),x(Z=>Z&&Z.entry_uid===O?{...Z,title:U}:Z),C(Z=>Z&&Z.summary.entry_uid===O?{...Z,summary:{...Z.summary,title:U}}:Z)},[]),Jc=p.useCallback(()=>{if(!a||!f)return;const O=++M.current;xo(a,f.entry_uid).then(U=>{O===M.current&&C(U)}).catch(()=>{})},[a,f]),Yc=p.useCallback(O=>{c(U=>U.filter(Z=>Z.entry_uid!==O)),x(U=>(U==null?void 0:U.entry_uid)===O?null:U),m(U=>U===O?null:U)},[]),Gc=p.useCallback(()=>{je(!0)},[]),qc=p.useCallback(()=>{je(!1)},[]),Zc=p.useCallback(()=>{a&&Promise.all([W(a,S,y),wo(a).then(V)])},[a,S,y,W]),ed=p.useCallback((O,U,Z="error",We=null)=>{if(Z==="warning"&&k&&U)return;const od=++L.current;ye(ud=>[...ud,{id:od,text:O,locator:U,type:Z,headline:We}])},[k]),td=p.useCallback(O=>{ye(U=>U.filter(Z=>Z.id!==O))},[]),nd=p.useCallback(()=>{sessionStorage.setItem("ublockWarningIgnored","true"),D(!0),ye(O=>O.filter(U=>!(U.type==="warning"&&U.locator)))},[]),rd=p.useCallback(({entry:O,src:U,archiveId:Z})=>{B({entry:O,src:U,archiveId:Z})},[]),ld=p.useCallback(()=>{B(null)},[]),sd=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv"]),id=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),ad=new Set([...sd,...id,"pdf","html","htm","jpg","jpeg","png","gif","webp","avif","svg","bmp"]),oa=z==="archive"&&f&&(()=>{if(f.entity_kind==="tweet"||f.entity_kind==="tweet_thread")return!0;if(!j)return!1;const O=j.artifacts.find(Z=>Z.artifact_role==="primary_media");if(!O)return!1;const U=O.relpath.split(".").pop().toLowerCase();return ad.has(U)})();return e==="loading"?i.jsx("div",{className:"auth-loading",children:"Loading\\u2026"}):e==="setup"?i.jsx(Eh,{onComplete:()=>t("login")}):e==="login"?i.jsx(Ch,{onLogin:O=>{r(O),t("authenticated")}}):i.jsx(bl.Provider,{value:{currentUser:n,setCurrentUser:r},children:i.jsxs(i.Fragment,{children:[i.jsx(Th,{archives:l,archiveId:a,onArchiveChange:K,view:z,onViewChange:G,onCaptureClick:Gc}),i.jsxs("main",{className:`app-shell${oa?" has-preview":""}${A?" audio-playing":""}`,children:[i.jsxs("div",{className:"workspace",children:[z==="archive"&&i.jsxs("div",{className:"toolbar",children:[i.jsxs("div",{className:"search-field",children:[i.jsx("span",{className:"ico","aria-hidden":"true",children:i.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[i.jsx("circle",{cx:"11",cy:"11",r:"7"}),i.jsx("line",{x1:"16.5",y1:"16.5",x2:"21",y2:"21"})]})}),i.jsx("input",{className:"search-input",type:"search","aria-label":"Search archive","aria-busy":_,placeholder:"Search titles, URLs, types, tags…",value:S,onChange:O=>N(O.target.value)}),i.jsx("span",{className:"kbd",children:"⌘K"})]}),i.jsxs("span",{className:"result-count",children:[T&&i.jsxs(i.Fragment,{children:[i.jsx("b",{children:T.split(" ")[0]})," ",T.split(" ").slice(1).join(" ")]}),y&&i.jsxs("button",{className:"tag-filter-badge",onClick:ut,children:["× ",Y?Vc(y):y]})]})]}),z==="archive"&&i.jsx($h,{entries:u,selectedEntryUid:v,onSelectEntry:de,archiveId:a,tagFilter:y,onClearTagFilter:ut,searchQuery:S,onSearchChange:N,resultCount:T,searchBusy:_}),z==="runs"&&i.jsx(Fh,{runs:I}),z==="admin"&&i.jsx(Ah,{archives:l}),z==="tags"&&i.jsx(bh,{archiveId:a,tagNodes:J,tagFilter:y,onTagFilterSet:nn,onViewChange:G,onTagRenamed:H,onTagDeleted:Fe,onTagsRefresh:R,humanizeTags:Y}),z==="collections"&&i.jsx(Uh,{archiveId:a}),z==="settings"&&i.jsx(Wh,{tab:d,onTabChange:g,archiveId:a})]}),oa&&i.jsx("div",{className:"preview-pane",children:i.jsx(um,{archiveId:a,entry:f,detail:j,onSetAudio:rd})}),i.jsx(qh,{archiveId:a,selectedEntry:f,detail:j,onTagFilterSet:nn,tagNodes:J,onTagsRefresh:R,onEntryTitleChange:ct,onEntryDeleted:Yc,humanizeTags:Y,onDetailRefresh:Jc})]}),A&&i.jsx(cm,{entry:A.entry,src:A.src,archiveId:A.archiveId,onClose:ld}),i.jsx(Ph,{open:ve,archiveId:a,onClose:qc,onCaptured:Zc,onToast:ed}),i.jsx(fm,{toasts:Re,onDismiss:td,onIgnoreUblock:nd})]})})}Bc(document.getElementById("root")).render(i.jsx(p.StrictMode,{children:i.jsx(ym,{})}));