(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 Fo={exports:{}},Rl={},Mo={exports:{}},J={};/** * @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 Sr=Symbol.for("react.element"),jd=Symbol.for("react.portal"),Sd=Symbol.for("react.fragment"),Nd=Symbol.for("react.strict_mode"),_d=Symbol.for("react.profiler"),Cd=Symbol.for("react.provider"),Ed=Symbol.for("react.context"),Td=Symbol.for("react.forward_ref"),Pd=Symbol.for("react.suspense"),Ld=Symbol.for("react.memo"),Rd=Symbol.for("react.lazy"),wa=Symbol.iterator;function zd(e){return e===null||typeof e!="object"?null:(e=wa&&e[wa]||e["@@iterator"],typeof e=="function"?e:null)}var Bo={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Uo=Object.assign,Ho={};function zn(e,t,n){this.props=e,this.context=t,this.refs=Ho,this.updater=n||Bo}zn.prototype.isReactComponent={};zn.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")};zn.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function Wo(){}Wo.prototype=zn.prototype;function ki(e,t,n){this.props=e,this.context=t,this.refs=Ho,this.updater=n||Bo}var ji=ki.prototype=new Wo;ji.constructor=ki;Uo(ji,zn.prototype);ji.isPureReactComponent=!0;var ka=Array.isArray,Vo=Object.prototype.hasOwnProperty,Si={current:null},Qo={key:!0,ref:!0,__self:!0,__source:!0};function Ko(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)Vo.call(t,r)&&!Qo.hasOwnProperty(r)&&(l[r]=t[r]);var o=arguments.length-2;if(o===1)l.children=n;else if(1>>1,M=R[X];if(0>>1;Xl(B,F))Hl(V,B)?(R[X]=V,R[H]=F,X=H):(R[X]=B,R[$]=F,X=$);else if(Hl(V,F))R[X]=V,R[H]=F,X=H;else break e}}return _}function l(R,_){var F=R.sortIndex-_.sortIndex;return F!==0?F:R.id-_.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=[],g=1,m=null,d=3,k=!1,x=!1,w=!1,C=typeof setTimeout=="function"?setTimeout:null,h=typeof clearTimeout=="function"?clearTimeout:null,f=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function v(R){for(var _=n(c);_!==null;){if(_.callback===null)r(c);else if(_.startTime<=R)r(c),_.sortIndex=_.expirationTime,t(u,_);else break;_=n(c)}}function y(R){if(w=!1,v(R),!x)if(n(u)!==null)x=!0,Re(j);else{var _=n(c);_!==null&&je(y,_.startTime-R)}}function j(R,_){x=!1,w&&(w=!1,h(S),S=-1),k=!0;var F=d;try{for(v(_),m=n(u);m!==null&&(!(m.expirationTime>_)||R&&!Q());){var X=m.callback;if(typeof X=="function"){m.callback=null,d=m.priorityLevel;var M=X(m.expirationTime<=_);_=e.unstable_now(),typeof M=="function"?m.callback=M:m===n(u)&&r(u),v(_)}else r(u);m=n(u)}if(m!==null)var N=!0;else{var $=n(c);$!==null&&je(y,$.startTime-_),N=!1}return N}finally{m=null,d=F,k=!1}}var E=!1,T=null,S=-1,b=5,I=-1;function Q(){return!(e.unstable_now()-IR||125X?(R.sortIndex=F,t(c,R),n(u)===null&&R===n(c)&&(w?(h(S),S=-1):w=!0,je(y,F-X))):(R.sortIndex=M,t(u,R),x||k||(x=!0,Re(j))),R},e.unstable_shouldYield=Q,e.unstable_wrapCallback=function(R){var _=d;return function(){var F=d;d=_;try{return R.apply(this,arguments)}finally{d=F}}}})(Yo);Go.exports=Yo;var Hd=Go.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 Wd=p,Ve=Hd;function P(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"),Cs=Object.prototype.hasOwnProperty,Vd=/^[: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]*$/,Sa={},Na={};function Qd(e){return Cs.call(Na,e)?!0:Cs.call(Sa,e)?!1:Vd.test(e)?Na[e]=!0:(Sa[e]=!0,!1)}function Kd(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 Xd(e,t,n,r){if(t===null||typeof t>"u"||Kd(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 $e(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 _e={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){_e[e]=new $e(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];_e[t]=new $e(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){_e[e]=new $e(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){_e[e]=new $e(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){_e[e]=new $e(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){_e[e]=new $e(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){_e[e]=new $e(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){_e[e]=new $e(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){_e[e]=new $e(e,5,!1,e.toLowerCase(),null,!1,!1)});var _i=/[\-:]([a-z])/g;function Ci(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(_i,Ci);_e[t]=new $e(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(_i,Ci);_e[t]=new $e(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(_i,Ci);_e[t]=new $e(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){_e[e]=new $e(e,1,!1,e.toLowerCase(),null,!1,!1)});_e.xlinkHref=new $e("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){_e[e]=new $e(e,1,!1,e.toLowerCase(),null,!0,!0)});function Ei(e,t,n,r){var l=_e.hasOwnProperty(t)?_e[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{Zl=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?Qn(e):""}function Jd(e){switch(e.tag){case 5:return Qn(e.type);case 16:return Qn("Lazy");case 13:return Qn("Suspense");case 19:return Qn("SuspenseList");case 0:case 2:case 15:return e=es(e.type,!1),e;case 11:return e=es(e.type.render,!1),e;case 1:return e=es(e.type,!0),e;default:return""}}function Ls(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case an:return"Fragment";case sn:return"Portal";case Es:return"Profiler";case Ti:return"StrictMode";case Ts:return"Suspense";case Ps:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case tu:return(e.displayName||"Context")+".Consumer";case eu:return(e._context.displayName||"Context")+".Provider";case Pi:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Li:return t=e.displayName||null,t!==null?t:Ls(e.type)||"Memo";case St:t=e._payload,e=e._init;try{return Ls(e(t))}catch{}}return null}function qd(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 Ls(t);case 8:return t===Ti?"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 Ot(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function ru(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function Gd(e){var t=ru(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 Lr(e){e._valueTracker||(e._valueTracker=Gd(e))}function lu(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=ru(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function il(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 Rs(e,t){var n=t.checked;return de({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function Ca(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=Ot(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 su(e,t){t=t.checked,t!=null&&Ei(e,"checked",t,!1)}function zs(e,t){su(e,t);var n=Ot(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")?bs(e,t.type,n):t.hasOwnProperty("defaultValue")&&bs(e,t.type,Ot(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function Ea(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 bs(e,t,n){(t!=="number"||il(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var Kn=Array.isArray;function yn(e,t,n,r){if(e=e.options,t){t={};for(var l=0;l"+t.valueOf().toString()+"",t=Rr.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function ar(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Gn={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},Yd=["Webkit","ms","Moz","O"];Object.keys(Gn).forEach(function(e){Yd.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Gn[t]=Gn[e]})});function uu(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Gn.hasOwnProperty(e)&&Gn[e]?(""+t).trim():t+"px"}function cu(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,l=uu(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,l):e[n]=l}}var Zd=de({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 $s(e,t){if(t){if(Zd[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(P(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(P(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(P(61))}if(t.style!=null&&typeof t.style!="object")throw Error(P(62))}}function Os(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 As=null;function Ri(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Fs=null,xn=null,wn=null;function La(e){if(e=Cr(e)){if(typeof Fs!="function")throw Error(P(280));var t=e.stateNode;t&&(t=$l(t),Fs(e.stateNode,e.type,t))}}function du(e){xn?wn?wn.push(e):wn=[e]:xn=e}function fu(){if(xn){var e=xn,t=wn;if(wn=xn=null,La(e),t)for(e=0;e>>=0,e===0?32:31-(df(e)/ff|0)|0}var zr=64,br=4194304;function Xn(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 cl(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=Xn(o):(s&=a,s!==0&&(r=Xn(s)))}else a=n&~l,a!==0?r=Xn(a):s!==0&&(r=Xn(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 Nr(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-lt(t),e[t]=n}function gf(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=Zn),Fa=" ",Ma=!1;function zu(e,t){switch(e){case"keyup":return Wf.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function bu(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var on=!1;function Qf(e,t){switch(e){case"compositionend":return bu(t);case"keypress":return t.which!==32?null:(Ma=!0,Fa);case"textInput":return e=t.data,e===Fa&&Ma?null:e;default:return null}}function Kf(e,t){if(on)return e==="compositionend"||!Fi&&zu(e,t)?(e=Lu(),qr=$i=Et=null,on=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:n,offset:t-e};e=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=Wa(n)}}function Ou(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?Ou(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function Au(){for(var e=window,t=il();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=il(e.document)}return t}function Mi(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 np(e){var t=Au(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&Ou(n.ownerDocument.documentElement,n)){if(r!==null&&Mi(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=Va(n,s);var a=Va(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,un=null,Vs=null,tr=null,Qs=!1;function Qa(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Qs||un==null||un!==il(r)||(r=un,"selectionStart"in r&&Mi(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}),tr&&pr(tr,r)||(tr=r,r=pl(Vs,"onSelect"),0fn||(e.current=Ys[fn],Ys[fn]=null,fn--)}function re(e,t){fn++,Ys[fn]=e.current,e.current=t}var At={},Le=Mt(At),Fe=Mt(!1),qt=At;function Cn(e,t){var n=e.type.contextTypes;if(!n)return At;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 Me(e){return e=e.childContextTypes,e!=null}function ml(){ie(Fe),ie(Le)}function Za(e,t,n){if(Le.current!==At)throw Error(P(168));re(Le,t),re(Fe,n)}function Ku(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(P(108,qd(e)||"Unknown",l));return de({},n,r)}function gl(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||At,qt=Le.current,re(Le,e),re(Fe,Fe.current),!0}function eo(e,t,n){var r=e.stateNode;if(!r)throw Error(P(169));n?(e=Ku(e,t,qt),r.__reactInternalMemoizedMergedChildContext=e,ie(Fe),ie(Le),re(Le,e)):ie(Fe),re(Fe,n)}var pt=null,Ol=!1,hs=!1;function Xu(e){pt===null?pt=[e]:pt.push(e)}function hp(e){Ol=!0,Xu(e)}function Bt(){if(!hs&&pt!==null){hs=!0;var e=0,t=ee;try{var n=pt;for(ee=1;e>=a,l-=a,ht=1<<32-lt(t)+l|n<S?(b=T,T=null):b=T.sibling;var I=d(h,T,v[S],y);if(I===null){T===null&&(T=b);break}e&&T&&I.alternate===null&&t(h,T),f=s(I,f,S),E===null?j=I:E.sibling=I,E=I,T=b}if(S===v.length)return n(h,T),oe&&Ut(h,S),j;if(T===null){for(;SS?(b=T,T=null):b=T.sibling;var Q=d(h,T,I.value,y);if(Q===null){T===null&&(T=b);break}e&&T&&Q.alternate===null&&t(h,T),f=s(Q,f,S),E===null?j=Q:E.sibling=Q,E=Q,T=b}if(I.done)return n(h,T),oe&&Ut(h,S),j;if(T===null){for(;!I.done;S++,I=v.next())I=m(h,I.value,y),I!==null&&(f=s(I,f,S),E===null?j=I:E.sibling=I,E=I);return oe&&Ut(h,S),j}for(T=r(h,T);!I.done;S++,I=v.next())I=k(T,h,S,I.value,y),I!==null&&(e&&I.alternate!==null&&T.delete(I.key===null?S:I.key),f=s(I,f,S),E===null?j=I:E.sibling=I,E=I);return e&&T.forEach(function(te){return t(h,te)}),oe&&Ut(h,S),j}function C(h,f,v,y){if(typeof v=="object"&&v!==null&&v.type===an&&v.key===null&&(v=v.props.children),typeof v=="object"&&v!==null){switch(v.$$typeof){case Pr:e:{for(var j=v.key,E=f;E!==null;){if(E.key===j){if(j=v.type,j===an){if(E.tag===7){n(h,E.sibling),f=l(E,v.props.children),f.return=h,h=f;break e}}else if(E.elementType===j||typeof j=="object"&&j!==null&&j.$$typeof===St&&ro(j)===E.type){n(h,E.sibling),f=l(E,v.props),f.ref=Bn(h,E,v),f.return=h,h=f;break e}n(h,E);break}else t(h,E);E=E.sibling}v.type===an?(f=Jt(v.props.children,h.mode,y,v.key),f.return=h,h=f):(y=ll(v.type,v.key,v.props,null,h.mode,y),y.ref=Bn(h,f,v),y.return=h,h=y)}return a(h);case sn:e:{for(E=v.key;f!==null;){if(f.key===E)if(f.tag===4&&f.stateNode.containerInfo===v.containerInfo&&f.stateNode.implementation===v.implementation){n(h,f.sibling),f=l(f,v.children||[]),f.return=h,h=f;break e}else{n(h,f);break}else t(h,f);f=f.sibling}f=js(v,h.mode,y),f.return=h,h=f}return a(h);case St:return E=v._init,C(h,f,E(v._payload),y)}if(Kn(v))return x(h,f,v,y);if($n(v))return w(h,f,v,y);Mr(h,v)}return typeof v=="string"&&v!==""||typeof v=="number"?(v=""+v,f!==null&&f.tag===6?(n(h,f.sibling),f=l(f,v),f.return=h,h=f):(n(h,f),f=ks(v,h.mode,y),f.return=h,h=f),a(h)):n(h,f)}return C}var Tn=Yu(!0),Zu=Yu(!1),xl=Mt(null),wl=null,mn=null,Wi=null;function Vi(){Wi=mn=wl=null}function Qi(e){var t=xl.current;ie(xl),e._currentValue=t}function ti(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 jn(e,t){wl=e,Wi=mn=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Ae=!0),e.firstContext=null)}function Ye(e){var t=e._currentValue;if(Wi!==e)if(e={context:e,memoizedValue:t,next:null},mn===null){if(wl===null)throw Error(P(308));mn=e,wl.dependencies={lanes:0,firstContext:e}}else mn=mn.next=e;return t}var Vt=null;function Ki(e){Vt===null?Vt=[e]:Vt.push(e)}function ec(e,t,n,r){var l=t.interleaved;return l===null?(n.next=n,Ki(t)):(n.next=l.next,l.next=n),t.interleaved=n,xt(e,r)}function xt(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 Nt=!1;function Xi(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function tc(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 gt(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function bt(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Y&2){var l=r.pending;return l===null?t.next=t:(t.next=l.next,l.next=t),r.pending=t,xt(e,n)}return l=r.interleaved,l===null?(t.next=t,Ki(r)):(t.next=l.next,l.next=t),r.interleaved=t,xt(e,n)}function Yr(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,bi(e,n)}}function lo(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 kl(e,t,n,r){var l=e.updateQueue;Nt=!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 g=e.alternate;g!==null&&(g=g.updateQueue,o=g.lastBaseUpdate,o!==a&&(o===null?g.firstBaseUpdate=c:o.next=c,g.lastBaseUpdate=u))}if(s!==null){var m=l.baseState;a=0,g=c=u=null,o=s;do{var d=o.lane,k=o.eventTime;if((r&d)===d){g!==null&&(g=g.next={eventTime:k,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var x=e,w=o;switch(d=t,k=n,w.tag){case 1:if(x=w.payload,typeof x=="function"){m=x.call(k,m,d);break e}m=x;break e;case 3:x.flags=x.flags&-65537|128;case 0:if(x=w.payload,d=typeof x=="function"?x.call(k,m,d):x,d==null)break e;m=de({},m,d);break e;case 2:Nt=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,d=l.effects,d===null?l.effects=[o]:d.push(o))}else k={eventTime:k,lane:d,tag:o.tag,payload:o.payload,callback:o.callback,next:null},g===null?(c=g=k,u=m):g=g.next=k,a|=d;if(o=o.next,o===null){if(o=l.shared.pending,o===null)break;d=o,o=d.next,d.next=null,l.lastBaseUpdate=d,l.shared.pending=null}}while(!0);if(g===null&&(u=m),l.baseState=u,l.firstBaseUpdate=c,l.lastBaseUpdate=g,t=l.shared.interleaved,t!==null){l=t;do a|=l.lane,l=l.next;while(l!==t)}else s===null&&(l.shared.lanes=0);Zt|=a,e.lanes=a,e.memoizedState=m}}function so(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=gs.transition;gs.transition={};try{e(!1),t()}finally{ee=n,gs.transition=r}}function yc(){return Ze().memoizedState}function yp(e,t,n){var r=It(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},xc(e))wc(t,n);else if(n=ec(e,t,n,r),n!==null){var l=De();st(n,e,r,l),kc(n,t,r)}}function xp(e,t,n){var r=It(e),l={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(xc(e))wc(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,it(o,a)){var u=t.interleaved;u===null?(l.next=l,Ki(t)):(l.next=u.next,u.next=l),t.interleaved=l;return}}catch{}finally{}n=ec(e,t,l,r),n!==null&&(l=De(),st(n,e,r,l),kc(n,t,r))}}function xc(e){var t=e.alternate;return e===ce||t!==null&&t===ce}function wc(e,t){nr=Sl=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function kc(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,bi(e,n)}}var Nl={readContext:Ye,useCallback:Ee,useContext:Ee,useEffect:Ee,useImperativeHandle:Ee,useInsertionEffect:Ee,useLayoutEffect:Ee,useMemo:Ee,useReducer:Ee,useRef:Ee,useState:Ee,useDebugValue:Ee,useDeferredValue:Ee,useTransition:Ee,useMutableSource:Ee,useSyncExternalStore:Ee,useId:Ee,unstable_isNewReconciler:!1},wp={readContext:Ye,useCallback:function(e,t){return ot().memoizedState=[e,t===void 0?null:t],e},useContext:Ye,useEffect:ao,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,el(4194308,4,pc.bind(null,t,e),n)},useLayoutEffect:function(e,t){return el(4194308,4,e,t)},useInsertionEffect:function(e,t){return el(4,2,e,t)},useMemo:function(e,t){var n=ot();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=ot();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=yp.bind(null,ce,e),[r.memoizedState,e]},useRef:function(e){var t=ot();return e={current:e},t.memoizedState=e},useState:io,useDebugValue:na,useDeferredValue:function(e){return ot().memoizedState=e},useTransition:function(){var e=io(!1),t=e[0];return e=vp.bind(null,e[1]),ot().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=ce,l=ot();if(oe){if(n===void 0)throw Error(P(407));n=n()}else{if(n=t(),we===null)throw Error(P(349));Yt&30||sc(r,t,n)}l.memoizedState=n;var s={value:n,getSnapshot:t};return l.queue=s,ao(ac.bind(null,r,s,e),[e]),r.flags|=2048,kr(9,ic.bind(null,r,s,n,t),void 0,null),n},useId:function(){var e=ot(),t=we.identifierPrefix;if(oe){var n=mt,r=ht;n=(r&~(1<<32-lt(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=xr++,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[ut]=t,e[gr]=r,Rc(e,t,!1,!1),t.stateNode=e;e:{switch(a=Os(n,r),n){case"dialog":se("cancel",e),se("close",e),l=r;break;case"iframe":case"object":case"embed":se("load",e),l=r;break;case"video":case"audio":for(l=0;lRn&&(t.flags|=128,r=!0,Un(s,!1),t.lanes=4194304)}else{if(!r)if(e=jl(a),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Un(s,!0),s.tail===null&&s.tailMode==="hidden"&&!a.alternate&&!oe)return Te(t),null}else 2*pe()-s.renderingStartTime>Rn&&n!==1073741824&&(t.flags|=128,r=!0,Un(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=pe(),t.sibling=null,n=ue.current,re(ue,r?n&1|2:n&1),t):(Te(t),null);case 22:case 23:return oa(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?Ue&1073741824&&(Te(t),t.subtreeFlags&6&&(t.flags|=8192)):Te(t),null;case 24:return null;case 25:return null}throw Error(P(156,t.tag))}function Tp(e,t){switch(Ui(t),t.tag){case 1:return Me(t.type)&&ml(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return Pn(),ie(Fe),ie(Le),Gi(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return qi(t),null;case 13:if(ie(ue),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(P(340));En()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return ie(ue),null;case 4:return Pn(),null;case 10:return Qi(t.type._context),null;case 22:case 23:return oa(),null;case 24:return null;default:return null}}var Ur=!1,Pe=!1,Pp=typeof WeakSet=="function"?WeakSet:Set,A=null;function gn(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){fe(e,t,r)}else n.current=null}function ci(e,t,n){try{n()}catch(r){fe(e,t,r)}}var xo=!1;function Lp(e,t){if(Ks=dl,e=Au(),Mi(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,g=0,m=e,d=null;t:for(;;){for(var k;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),(k=m.firstChild)!==null;)d=m,m=k;for(;;){if(m===e)break t;if(d===n&&++c===l&&(o=a),d===s&&++g===r&&(u=a),(k=m.nextSibling)!==null)break;m=d,d=m.parentNode}m=k}n=o===-1||u===-1?null:{start:o,end:u}}else n=null}n=n||{start:0,end:0}}else n=null;for(Xs={focusedElem:e,selectionRange:n},dl=!1,A=t;A!==null;)if(t=A,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,A=e;else for(;A!==null;){t=A;try{var x=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(x!==null){var w=x.memoizedProps,C=x.memoizedState,h=t.stateNode,f=h.getSnapshotBeforeUpdate(t.elementType===t.type?w:tt(t.type,w),C);h.__reactInternalSnapshotBeforeUpdate=f}break;case 3:var v=t.stateNode.containerInfo;v.nodeType===1?v.textContent="":v.nodeType===9&&v.documentElement&&v.removeChild(v.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(P(163))}}catch(y){fe(t,t.return,y)}if(e=t.sibling,e!==null){e.return=t.return,A=e;break}A=t.return}return x=xo,xo=!1,x}function rr(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&&ci(t,n,s)}l=l.next}while(l!==r)}}function Ml(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 di(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 Dc(e){var t=e.alternate;t!==null&&(e.alternate=null,Dc(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[ut],delete t[gr],delete t[Gs],delete t[fp],delete t[pp])),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 Ic(e){return e.tag===5||e.tag===3||e.tag===4}function wo(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Ic(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 fi(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=hl));else if(r!==4&&(e=e.child,e!==null))for(fi(e,t,n),e=e.sibling;e!==null;)fi(e,t,n),e=e.sibling}function pi(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(pi(e,t,n),e=e.sibling;e!==null;)pi(e,t,n),e=e.sibling}var Se=null,nt=!1;function jt(e,t,n){for(n=n.child;n!==null;)$c(e,t,n),n=n.sibling}function $c(e,t,n){if(ct&&typeof ct.onCommitFiberUnmount=="function")try{ct.onCommitFiberUnmount(zl,n)}catch{}switch(n.tag){case 5:Pe||gn(n,t);case 6:var r=Se,l=nt;Se=null,jt(e,t,n),Se=r,nt=l,Se!==null&&(nt?(e=Se,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):Se.removeChild(n.stateNode));break;case 18:Se!==null&&(nt?(e=Se,n=n.stateNode,e.nodeType===8?ps(e.parentNode,n):e.nodeType===1&&ps(e,n),dr(e)):ps(Se,n.stateNode));break;case 4:r=Se,l=nt,Se=n.stateNode.containerInfo,nt=!0,jt(e,t,n),Se=r,nt=l;break;case 0:case 11:case 14:case 15:if(!Pe&&(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)&&ci(n,t,a),l=l.next}while(l!==r)}jt(e,t,n);break;case 1:if(!Pe&&(gn(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(o){fe(n,t,o)}jt(e,t,n);break;case 21:jt(e,t,n);break;case 22:n.mode&1?(Pe=(r=Pe)||n.memoizedState!==null,jt(e,t,n),Pe=r):jt(e,t,n);break;default:jt(e,t,n)}}function ko(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new Pp),t.forEach(function(r){var l=Fp.bind(null,e,r);n.has(r)||(n.add(r),r.then(l,l))})}}function et(e,t){var n=t.deletions;if(n!==null)for(var r=0;rl&&(l=a),r&=~s}if(r=l,r=pe()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*zp(r/1960))-r,10e?16:e,Tt===null)var r=!1;else{if(e=Tt,Tt=null,El=0,Y&6)throw Error(P(331));var l=Y;for(Y|=4,A=e.current;A!==null;){var s=A,a=s.child;if(A.flags&16){var o=s.deletions;if(o!==null){for(var u=0;upe()-ia?Xt(e,0):sa|=n),Be(e,t)}function Wc(e,t){t===0&&(e.mode&1?(t=br,br<<=1,!(br&130023424)&&(br=4194304)):t=1);var n=De();e=xt(e,t),e!==null&&(Nr(e,t,n),Be(e,n))}function Ap(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),Wc(e,n)}function Fp(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(P(314))}r!==null&&r.delete(t),Wc(e,n)}var Vc;Vc=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Fe.current)Ae=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return Ae=!1,Cp(e,t,n);Ae=!!(e.flags&131072)}else Ae=!1,oe&&t.flags&1048576&&Ju(t,yl,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;tl(e,t),e=t.pendingProps;var l=Cn(t,Le.current);jn(t,n),l=Zi(null,t,r,e,l,n);var s=ea();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,Me(r)?(s=!0,gl(t)):s=!1,t.memoizedState=l.state!==null&&l.state!==void 0?l.state:null,Xi(t),l.updater=Fl,t.stateNode=l,l._reactInternals=t,ri(t,r,e,n),t=ii(null,t,r,!0,s,n)):(t.tag=0,oe&&s&&Bi(t),be(null,t,l,n),t=t.child),t;case 16:r=t.elementType;e:{switch(tl(e,t),e=t.pendingProps,l=r._init,r=l(r._payload),t.type=r,l=t.tag=Bp(r),e=tt(r,e),l){case 0:t=si(null,t,r,e,n);break e;case 1:t=go(null,t,r,e,n);break e;case 11:t=ho(null,t,r,e,n);break e;case 14:t=mo(null,t,r,tt(r.type,e),n);break e}throw Error(P(306,r,""))}return t;case 0:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:tt(r,l),si(e,t,r,l,n);case 1:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:tt(r,l),go(e,t,r,l,n);case 3:e:{if(Tc(t),e===null)throw Error(P(387));r=t.pendingProps,s=t.memoizedState,l=s.element,tc(e,t),kl(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=Ln(Error(P(423)),t),t=vo(e,t,r,n,l);break e}else if(r!==l){l=Ln(Error(P(424)),t),t=vo(e,t,r,n,l);break e}else for(He=zt(t.stateNode.containerInfo.firstChild),We=t,oe=!0,rt=null,n=Zu(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(En(),r===l){t=wt(e,t,n);break e}be(e,t,r,n)}t=t.child}return t;case 5:return nc(t),e===null&&ei(t),r=t.type,l=t.pendingProps,s=e!==null?e.memoizedProps:null,a=l.children,Js(r,l)?a=null:s!==null&&Js(r,s)&&(t.flags|=32),Ec(e,t),be(e,t,a,n),t.child;case 6:return e===null&&ei(t),null;case 13:return Pc(e,t,n);case 4:return Ji(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=Tn(t,null,r,n):be(e,t,r,n),t.child;case 11:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:tt(r,l),ho(e,t,r,l,n);case 7:return be(e,t,t.pendingProps,n),t.child;case 8:return be(e,t,t.pendingProps.children,n),t.child;case 12:return be(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,re(xl,r._currentValue),r._currentValue=a,s!==null)if(it(s.value,a)){if(s.children===l.children&&!Fe.current){t=wt(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=gt(-1,n&-n),u.tag=2;var c=s.updateQueue;if(c!==null){c=c.shared;var g=c.pending;g===null?u.next=u:(u.next=g.next,g.next=u),c.pending=u}}s.lanes|=n,u=s.alternate,u!==null&&(u.lanes|=n),ti(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(P(341));a.lanes|=n,o=a.alternate,o!==null&&(o.lanes|=n),ti(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}be(e,t,l.children,n),t=t.child}return t;case 9:return l=t.type,r=t.pendingProps.children,jn(t,n),l=Ye(l),r=r(l),t.flags|=1,be(e,t,r,n),t.child;case 14:return r=t.type,l=tt(r,t.pendingProps),l=tt(r.type,l),mo(e,t,r,l,n);case 15:return _c(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:tt(r,l),tl(e,t),t.tag=1,Me(r)?(e=!0,gl(t)):e=!1,jn(t,n),jc(t,r,l),ri(t,r,l,n),ii(null,t,r,!0,e,n);case 19:return Lc(e,t,n);case 22:return Cc(e,t,n)}throw Error(P(156,t.tag))};function Qc(e,t){return xu(e,t)}function Mp(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 qe(e,t,n,r){return new Mp(e,t,n,r)}function ca(e){return e=e.prototype,!(!e||!e.isReactComponent)}function Bp(e){if(typeof e=="function")return ca(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Pi)return 11;if(e===Li)return 14}return 2}function $t(e,t){var n=e.alternate;return n===null?(n=qe(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 ll(e,t,n,r,l,s){var a=2;if(r=e,typeof e=="function")ca(e)&&(a=1);else if(typeof e=="string")a=5;else e:switch(e){case an:return Jt(n.children,l,s,t);case Ti:a=8,l|=8;break;case Es:return e=qe(12,n,t,l|2),e.elementType=Es,e.lanes=s,e;case Ts:return e=qe(13,n,t,l),e.elementType=Ts,e.lanes=s,e;case Ps:return e=qe(19,n,t,l),e.elementType=Ps,e.lanes=s,e;case nu:return Ul(n,l,s,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case eu:a=10;break e;case tu:a=9;break e;case Pi:a=11;break e;case Li:a=14;break e;case St:a=16,r=null;break e}throw Error(P(130,e==null?e:typeof e,""))}return t=qe(a,n,t,l),t.elementType=e,t.type=r,t.lanes=s,t}function Jt(e,t,n,r){return e=qe(7,e,r,t),e.lanes=n,e}function Ul(e,t,n,r){return e=qe(22,e,r,t),e.elementType=nu,e.lanes=n,e.stateNode={isHidden:!1},e}function ks(e,t,n){return e=qe(6,e,null,t),e.lanes=n,e}function js(e,t,n){return t=qe(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function Up(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=ns(0),this.expirationTimes=ns(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=ns(0),this.identifierPrefix=r,this.onRecoverableError=l,this.mutableSourceEagerHydrationData=null}function da(e,t,n,r,l,s,a,o,u){return e=new Up(e,t,n,o,u),t===1?(t=1,s===!0&&(t|=8)):t=0,s=qe(3,null,null,t),e.current=s,s.stateNode=e,s.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Xi(s),e}function Hp(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(qc)}catch(e){console.error(e)}}qc(),qo.exports=Qe;var Xp=qo.exports,Gc,Po=Xp;Gc=Po.createRoot,Po.hydrateRoot;async function ve(e){const t=await fetch(e);if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()}async function Jp(){return ve("/api/archives")}async function qp(e){return ve(`/api/archives/${e}/entries`)}async function Gp(e,t,n){const r=new URLSearchParams;return t&&r.set("q",t),n&&r.set("tag",n),ve(`/api/archives/${e}/entries/search?${r}`)}async function yi(e,t){return ve(`/api/archives/${e}/entries/${t}`)}function Yp(e,t,n){return Promise.all(n.map(r=>ve(`/api/archives/${e}/entries/${t}/artifacts/${r}`)))}async function Zp(e){if(!e||e.length===0)return{};const t=await fetch("/api/util/resolve-tco",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?t.json():{}}async function eh(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 Vr(e,t){return ve(`/api/archives/${e}/entries/${t}/tags`)}async function th(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 nh(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 rh(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 lh(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 sh(e,t){const n=await fetch(`/api/archives/${e}/tags/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(await n.text())}async function Ss(e){return ve(`/api/archives/${e}/runs`)}async function Qr(e){return ve(`/api/archives/${e}/tags`)}async function ih(e,t,n=null,r=null){const l={locator:t};n&&n!=="best"&&(l.quality=n),r&&(typeof r.ublock_enabled=="boolean"&&(l.ublock_enabled=r.ublock_enabled),typeof r.reader_mode=="boolean"&&(l.reader_mode=r.reader_mode),typeof r.cookie_ext_enabled=="boolean"&&(l.cookie_ext_enabled=r.cookie_ext_enabled),typeof r.modal_closer_enabled=="boolean"&&(l.modal_closer_enabled=r.modal_closer_enabled));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 ah(e,t){return ve(`/api/archives/${e}/captures/probe?locator=${encodeURIComponent(t)}`)}async function Yc(e,t){return ve(`/api/archives/${e}/capture_jobs/${t}`)}async function oh(){return(await(await fetch("/api/auth/setup")).json()).setup_required===!0}async function uh(e,t){const n=await fetch("/api/auth/setup",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({username:e,password:t})});if(!n.ok)throw new Error((await n.json()).error||"Setup failed");return n.json()}async function ch(e,t){const n=await fetch("/api/auth/login",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({username:e,password:t})});if(!n.ok)throw new Error((await n.json()).error||"Login failed");return n.json()}async function dh(){await fetch("/api/auth/logout",{method:"POST"})}async function fh(){const e=await fetch("/api/auth/me");return e.status===401?null:e.json()}async function ph(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 hh(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 mh(e,t){const n=await fetch("/api/auth/me",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({current_password:e,new_password:t})});if(!n.ok){let r=await n.text();try{r=JSON.parse(r).error??r}catch{}throw new Error(r)}}async function gh(){return ve("/api/auth/tokens")}async function vh(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 yh(e){const t=await fetch(`/api/auth/tokens/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(await t.text())}async function ma(){return ve("/api/admin/instance-settings")}async function sl(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 xh(){return ve("/api/admin/users")}async function wh(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 kh(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 jh(){return ve("/api/admin/roles")}async function Sh(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 Nh(e){return ve(`/api/archives/${e}/collections`)}async function _h(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 Ch(e,t){return ve(`/api/archives/${e}/collections/${t}`)}async function Eh(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 Th(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 Ph(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 Lh(e,t){return ve(`/api/archives/${e}/entries/${t}/collections`)}async function Lo(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 Rh(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 zh(e){return ve(`/api/archives/${e}/blob-cleanup`)}async function bh(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 Dh(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 Ih(){return ve("/api/admin/cookie-rules")}async function $h(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 Oh(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 Ah(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 Fh=window.fetch;window.fetch=async(...e)=>{var n;const t=await Fh(...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 Mh({onLogin:e}){const[t,n]=p.useState(""),[r,l]=p.useState(""),[s,a]=p.useState(null),[o,u]=p.useState(!1);async function c(g){g.preventDefault(),a(null),u(!0);try{const m=await ch(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:g=>n(g.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:g=>l(g.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 Bh({onComplete:e}){const[t,n]=p.useState(""),[r,l]=p.useState(""),[s,a]=p.useState(""),[o,u]=p.useState(null),[c,g]=p.useState(!1);async function m(d){if(d.preventDefault(),r!==s){u("Passwords do not match");return}if(r.length<8){u("Password must be at least 8 characters");return}u(null),g(!0);try{await uh(t,r),e()}catch(k){u(k.message)}finally{g(!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:d=>n(d.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:d=>l(d.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:d=>a(d.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 Uh({archives:e,archiveId:t,onArchiveChange:n,view:r,onViewChange:l,onCaptureClick:s}){const{currentUser:a,setCurrentUser:o}=p.useContext(Kl)??{},[u,c]=p.useState(!1);async function g(){c(!0),await dh(),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:g,disabled:u,children:u?"Logging out…":"Log out"})]})]})}let xi=1;function Zc(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 Wn(e=""){return{id:xi++,locator:e,quality:"best",probeState:"idle",probeQualities:null,probeHasAudio:!1,status:"idle",error:null,jobUid:null,archiveId:null}}function Ro(e){return e.some(t=>t.status==="submitting"||t.status==="running")}function Hh({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),g=p.useRef(t);p.useEffect(()=>{g.current=t},[t]);const m=p.useRef(r),d=p.useRef(l);p.useEffect(()=>{m.current=r},[r]),p.useEffect(()=>{d.current=l},[l]);const[k,x]=p.useState(()=>{try{const N=JSON.parse(sessionStorage.getItem("captureItems")||"null");if(Array.isArray(N)&&N.length>0)return N.forEach($=>{$.id>=xi&&(xi=$.id+1)}),N}catch{}return[Wn()]});p.useEffect(()=>{sessionStorage.setItem("captureItems",JSON.stringify(k))},[k]);const[w,C]=p.useState(!1),[h,f]=p.useState(null),[v,y]=p.useState(null),[j,E]=p.useState(!0),[T,S]=p.useState(!0);p.useEffect(()=>{ma().then(N=>{y(N),E(N.cookie_ext_enabled??!0),S(N.modal_closer_enabled??!0)}).catch(()=>y({}))},[]);const b=h!==null?h:(v==null?void 0:v.ublock_enabled)??!0,[I,Q]=p.useState(!1);p.useEffect(()=>{["captureDialogLocator","captureDialogError","captureDialogBusy","captureDialogJobStatus","captureDialogJobUid"].forEach(N=>sessionStorage.removeItem(N)),x(N=>N.map($=>$.status==="submitting"?{...$,status:"idle",error:null}:$)),k.forEach(N=>{N.status==="running"&&N.jobUid&&N.archiveId&&!o.current.has(N.jobUid)&&te(N.id,N.jobUid,N.locator,N.archiveId)})},[]),p.useEffect(()=>{const N=s.current;if(!N)return;const $=()=>{u.current.forEach(B=>clearTimeout(B)),u.current.clear(),n()};return N.addEventListener("close",$),()=>N.removeEventListener("close",$)},[n]),p.useEffect(()=>{const N=s.current;N&&(e?(!a.current&&!Ro(k)&&x([Wn()]),a.current=!1,N.open||N.showModal()):(u.current.forEach($=>clearTimeout($)),u.current.clear(),N.open&&N.close()))},[e]),p.useEffect(()=>()=>{o.current.forEach(N=>clearInterval(N)),u.current.forEach(N=>clearTimeout(N))},[]);function te(N,$,B,H,V=null){if(o.current.has($))return;const le=setInterval(async()=>{try{const L=await Yc(H,$);if(L.status==="completed"){clearInterval(o.current.get($)),o.current.delete($),x(W=>W.map(q=>q.id===N?{...q,status:"completed"}:q)),setTimeout(()=>{x(W=>{const q=W.filter(ae=>ae.id!==N);return q.length===0?[Wn()]:q})},1400),m.current();try{const W=L.notes_json?JSON.parse(L.notes_json):null;if(W!=null&&W.ublock_skipped||W!=null&&W.cookie_ext_skipped){const ae=W.ublock_skipped&&W.cookie_ext_skipped?"Captured without ad-blocking or cookie-consent extension. Check ARCHIVR_UBLOCK_EXT and ARCHIVR_COOKIE_EXT in your server config.":W.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.";d.current(ae,B,"warning"),G(V,"warning",B)}else V||d.current(null,B,"success"),G(V,"archived")}catch{V||d.current(null,B,"success"),G(V,"archived")}}else if(L.status==="failed"){clearInterval(o.current.get($)),o.current.delete($);const W=L.error_text||"Capture failed.";x(q=>q.map(ae=>ae.id===N?{...ae,status:"failed",error:W}:ae)),d.current(W,B),G(V,"failed",B)}}catch(L){clearInterval(o.current.get($)),o.current.delete($);const W=L.message||"Network error";x(q=>q.map(ae=>ae.id===N?{...ae,status:"failed",error:W}:ae)),d.current(W,B),G(V,"failed",B)}},500);o.current.set($,le)}function G(N,$,B=null){if(!N)return;const H=c.current.get(N);if(!H||($==="archived"||$==="warning"?(H.archived++,$==="warning"&&(H.warnings++,B&&H.warningLocators.push(B))):(H.failed++,B&&H.failedLocators.push(B)),H.archived+H.failed0?`${V} archived (${le} with warnings)`:`${V} archived`;ae=L>0?`${Ce}, ${L} failed`:Ce}const z=V===0?"error":L>0||le>0?"warning":"success",K=[];W.length>0&&K.push(`Failed: ${W.map(Ce=>` ${Ce}`).join(` `)}`),q.length>0&&K.push(`With warnings: ${q.map(Ce=>` ${Ce}`).join(` `)}`);const ze=K.length>0?K.join(` `):null;d.current(ze,null,z,ae)}async function ne(N,$=null){if(!N.locator.trim())return;const B=t,H=N.locator.trim(),V=N.quality||"best";x(le=>le.map(L=>L.id===N.id?{...L,status:"submitting",error:null}:L));try{const L=await ih(B,H,V,{ublock_enabled:b,reader_mode:I,cookie_ext_enabled:j,modal_closer_enabled:T});x(W=>W.map(q=>q.id===N.id?{...q,status:"running",jobUid:L.job_uid,archiveId:B}:q)),te(N.id,L.job_uid,H,B,$)}catch(le){const L=le.message||"Submission failed.";x(W=>W.map(q=>q.id===N.id?{...q,status:"failed",error:L}:q)),d.current(L,H),G($,"failed",H)}}function ke(){var B,H;const N=k.filter(V=>V.status==="idle"&&V.locator.trim());if(N.length===0)return;const $=N.length>1?((B=crypto.randomUUID)==null?void 0:B.call(crypto))??`batch-${Date.now()}`:null;$&&c.current.set($,{total:N.length,archived:0,warnings:0,failed:0,failedLocators:[],warningLocators:[]}),N.forEach(V=>ne(V,$)),(H=s.current)==null||H.close()}function Re(){x(N=>[...N,Wn()])}function je(N){clearTimeout(u.current.get(N)),u.current.delete(N),x($=>{const B=$.filter(H=>H.id!==N);return B.length===0?[Wn()]:B})}function R(N){x($=>$.map(B=>B.id===N?{...B,status:"idle",error:null}:B))}function _(N,$){if(clearTimeout(u.current.get(N)),x(H=>H.map(V=>V.id===N?{...V,locator:$,probeState:"idle",probeQualities:null,probeHasAudio:!1,quality:"best"}:V)),!Zc($))return;const B=setTimeout(async()=>{u.current.delete(N),x(H=>H.map(V=>V.id===N?{...V,probeState:"probing"}:V));try{const H=await ah(g.current,$.trim());x(V=>V.map(le=>{if(le.id!==N||le.locator!==$)return le;const L=H.qualities??[],W=H.has_audio??!1,q=L.length===0&&W?"audio":"best";return{...le,probeState:"done",probeQualities:L,probeHasAudio:W,quality:q}}))}catch{x(H=>H.map(V=>V.id===N?{...V,probeState:"idle",probeQualities:null}:V))}},600);u.current.set(N,B)}function F(N,$){x(B=>B.map(H=>H.id===N?{...H,quality:$}:H))}const X=k.filter(N=>N.status==="idle"&&N.locator.trim()).length,M=Ro(k);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 N;return(N=s.current)==null?void 0:N.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:k.map((N,$)=>i.jsx(Wh,{item:N,autoFocus:$===k.length-1&&N.status==="idle",onLocatorChange:B=>_(N.id,B),onQualityChange:B=>F(N.id,B),onRemove:()=>je(N.id),onReset:()=>R(N.id),onSubmit:ke},N.id))}),i.jsxs("button",{type:"button",className:"capture-add-row",onClick:Re,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:()=>C(N=>!N),"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":b,className:`ext-toggle ext-toggle--sm${b?" ext-toggle--on":""}`,onClick:()=>f(N=>N===null?!b:!N),"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"}),!(v!=null&&v.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":j,className:`ext-toggle ext-toggle--sm${j?" ext-toggle--on":""}`,onClick:()=>E(N=>!N),"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":I,className:`ext-toggle ext-toggle--sm${I?" ext-toggle--on":""}`,onClick:()=>Q(N=>!N),"aria-label":"Toggle reader mode 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:"Close modals and dialogs"}),i.jsx("span",{className:"capture-ext-desc",children:"Auto-dismiss cookie banners and overlays during this capture"})]}),i.jsx("button",{type:"button",role:"switch","aria-checked":T,className:`ext-toggle ext-toggle--sm${T?" ext-toggle--on":""}`,onClick:()=>S(N=>!N),"aria-label":"Toggle modal closer 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:ke,disabled:X===0,children:X>1?`Archive ${X}`:"Archive"}),i.jsx("button",{type:"button",className:"capture-cancel",onClick:()=>{var N;return(N=s.current)==null?void 0:N.close()},children:M?"Close":"Cancel"})]})]})})}function Wh({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 g;t&&e.status==="idle"&&((g=o.current)==null||g.focus())},[t]);const c=(()=>{if(e.status==="completed"||u||!Zc(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 g=e.probeQualities??[],m=e.probeHasAudio??!1;return g.length===0&&!m?i.jsx("span",{className:"capture-quality-hint",children:"No media detected"}):g.length===0&&m?i.jsx("select",{className:"capture-quality",value:"audio",onChange:d=>r(d.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:d=>r(d.target.value),"aria-label":"Video quality",children:[i.jsx("option",{value:"best",children:"Best quality"}),g.map(d=>i.jsx("option",{value:d,children:d},d)),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(Vh,{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:g=>n(g.target.value),onKeyDown:g=>{g.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 Vh({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 wi(e){if(!e)return"0 B";const t=["B","KB","MB","GB"];let n=e,r=0;for(;n>=1024&&r").replace(/"/g,'"').replace(/'/g,"'").replace(/'/g,"'")}function Kt(e){return Qh(e)??""}function ed(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 zo={youtube:'',youtube_music:'',spotify:'',x:'',instagram:'',facebook:'',tiktok:'',reddit:'',snapchat:'',local:'',web:'',other:'?'};function ga(e){return zo[e]??zo.other}function td(e){return e.split("/").map(t=>t?t.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"").join("/")}function Kh({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:ga(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:ed(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:Kt(e.title)||Kt(e.entry_uid)})]}),i.jsx("div",{className:"col-type",children:i.jsx("span",{className:"type-pill",children:Kt(e.entity_kind)})}),i.jsxs("div",{className:"col-size",children:[i.jsx("span",{className:"size-total",children:wi(e.total_artifact_bytes)}),e.cached_bytes>0&&e.total_artifact_bytes>0&&i.jsxs("span",{className:"size-cached-pct",title:`${wi(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:Kt(e.original_url)})]})}function Xh({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(Kh,{entry:l,archiveId:r,isSelected:l.entry_uid===t,onSelect:()=>n(l)},l.entry_uid))})]})})}function Jh(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 qh({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 Gh({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:Jh(l.started_at)}),i.jsxs("td",{children:[i.jsx(qh,{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 Yh=4;function Zh({archives:e}){const{currentUser:t}=p.useContext(Kl)??{},n=t&&(t.role_bits&Yh)!==0,[r,l]=p.useState("users"),[s,a]=p.useState([]),[o,u]=p.useState([]),[c,g]=p.useState(!1),[m,d]=p.useState(null),[k,x]=p.useState(""),[w,C]=p.useState(""),[h,f]=p.useState(""),[v,y]=p.useState(null),[j,E]=p.useState(!1),[T,S]=p.useState(""),[b,I]=p.useState(""),[Q,te]=p.useState(null),[G,ne]=p.useState(!1),ke=p.useCallback(async()=>{if(n){g(!0),d(null);try{const[_,F]=await Promise.all([xh(),jh()]);a(_),u(F)}catch(_){d(_.message)}finally{g(!1)}}},[n]);p.useEffect(()=>{ke()},[ke]);async function Re(_){const F=_.status==="active"?"disabled":"active";try{await kh(_.user_uid,F),a(X=>X.map(M=>M.user_uid===_.user_uid?{...M,status:F}:M))}catch(X){d(X.message)}}async function je(_){if(_.preventDefault(),!k.trim()||!w){y("Username and password required");return}E(!0),y(null);try{await wh(k.trim(),w,h.trim()||void 0),x(""),C(""),f(""),await ke()}catch(F){y(F.message)}finally{E(!1)}}async function R(_){if(_.preventDefault(),!T.trim()||!b.trim()){te("Slug and name required");return}ne(!0),te(null);try{await Sh(T.trim(),b.trim()),S(""),I(""),await ke()}catch(F){te(F.message)}finally{ne(!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(_=>i.jsxs("tr",{className:_.status==="disabled"?"admin-row-disabled":"",children:[i.jsx("td",{children:_.username}),i.jsx("td",{className:"muted",children:_.email||"—"}),i.jsx("td",{children:_.role_slugs.join(", ")||"—"}),i.jsx("td",{children:i.jsx("span",{className:`status-badge status-${_.status}`,children:_.status})}),i.jsx("td",{children:i.jsx("button",{className:"admin-action-btn",onClick:()=>Re(_),children:_.status==="active"?"Ban":"Unban"})})]},_.user_uid))})]}),i.jsx("h3",{children:"Create User"}),i.jsxs("form",{className:"admin-form",onSubmit:je,children:[i.jsx("input",{className:"admin-input",placeholder:"Username",value:k,onChange:_=>x(_.target.value),required:!0}),i.jsx("input",{className:"admin-input",type:"password",placeholder:"Password (min 8 chars)",value:w,onChange:_=>C(_.target.value),required:!0}),i.jsx("input",{className:"admin-input",type:"email",placeholder:"Email (optional)",value:h,onChange:_=>f(_.target.value)}),v&&i.jsx("div",{className:"form-msg form-msg--err",children:v}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:j,children:j?"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(_=>i.jsxs("tr",{children:[i.jsx("td",{children:i.jsx("code",{children:_.slug})}),i.jsx("td",{children:_.name}),i.jsx("td",{children:_.level}),i.jsx("td",{children:_.bit_position}),i.jsx("td",{children:_.is_builtin?"✓":""})]},_.role_uid))})]}),i.jsx("h3",{children:"Create Custom Role"}),i.jsxs("form",{className:"admin-form",onSubmit:R,children:[i.jsx("input",{className:"admin-input",placeholder:"Slug (e.g. moderator)",value:T,onChange:_=>S(_.target.value),required:!0}),i.jsx("input",{className:"admin-input",placeholder:"Display Name (e.g. Moderator)",value:b,onChange:_=>I(_.target.value),required:!0}),Q&&i.jsx("div",{className:"form-msg form-msg--err",children:Q}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:G,children:G?"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(_=>i.jsxs("div",{className:"admin-archive",children:[i.jsx("strong",{children:_.label}),i.jsx("div",{className:"muted",children:_.archive_path})]},_.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(_=>i.jsxs("div",{className:"admin-archive",children:[i.jsx("strong",{children:_.label}),i.jsx("div",{className:"muted",children:_.archive_path})]},_.id))})]})}function nd({node:e,archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u}){var y;const c=n===e.tag.full_path,[g,m]=p.useState(!1),[d,k]=p.useState(""),x=p.useRef(!1);function w(){if(g)return;const j=c?null:e.tag.full_path;r(j),l("archive")}function C(j){j.stopPropagation(),k(e.tag.slug),m(!0)}async function h(){const j=d.trim();if(!j||j===e.tag.slug){m(!1);return}try{const E=await lh(t,e.tag.tag_uid,j);s(e.tag.full_path,E.full_path),o()}catch{}finally{m(!1)}}async function f(j){var T;j.stopPropagation();const E=((T=e.children)==null?void 0:T.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(E))try{await sh(t,e.tag.tag_uid),a(e.tag.full_path),o()}catch{}}const v={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:[g?i.jsx("input",{className:"tag-rename-input",autoFocus:!0,value:d,onChange:j=>k(j.target.value),onKeyDown:j=>{j.key==="Enter"&&j.currentTarget.blur(),j.key==="Escape"&&(x.current=!0,j.currentTarget.blur())},onBlur:()=>{x.current?(x.current=!1,m(!1)):h()}}):i.jsxs("button",{className:`tag-node-btn${c?" is-active":""}`,title:e.tag.full_path,onClick:w,onDoubleClick:C,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:j=>{j.stopPropagation(),C(j)},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:f,"aria-label":`Delete tag ${e.tag.full_path}`,children:"×"})]}),((y=e.children)==null?void 0:y.length)>0&&i.jsx("div",{className:"tag-children",children:i.jsx("ul",{className:"tag-tree-list",children:e.children.map(j=>i.jsx(nd,{node:j,...v},j.tag.tag_uid))})})]})}function em({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(nd,{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"}],tm=e=>{var t;return((t=qn.find(n=>n.value===e))==null?void 0:t.label)??String(e)};function nm({archiveId:e}){const[t,n]=p.useState([]),[r,l]=p.useState(!1),[s,a]=p.useState(null),[o,u]=p.useState(null),[c,g]=p.useState(null),[m,d]=p.useState(!1),[k,x]=p.useState(null),[w,C]=p.useState(""),[h,f]=p.useState(""),[v,y]=p.useState(2),[j,E]=p.useState(!1),[T,S]=p.useState(null),[b,I]=p.useState(""),[Q,te]=p.useState(2),[G,ne]=p.useState(!1),[ke,Re]=p.useState(null),[je,R]=p.useState(!1),[_,F]=p.useState(""),X=p.useRef(null),M=t.find(z=>z.collection_uid===o)??null,N=(M==null?void 0:M.slug)==="_default_",$=p.useCallback(async()=>{if(e){l(!0),a(null);try{const z=await Nh(e);n(z)}catch(z){a(z.message)}finally{l(!1)}}},[e]),B=p.useCallback(async z=>{if(!z){g(null);return}d(!0),x(null);try{const K=await Ch(e,z);g(K)}catch(K){x(K.message)}finally{d(!1)}},[e]);p.useEffect(()=>{$()},[$]),p.useEffect(()=>{B(o)},[o,B]),p.useEffect(()=>{je&&X.current&&X.current.focus()},[je]);async function H(z){z.preventDefault();const K=w.trim(),ze=h.trim();if(!(!K||!ze)){E(!0),S(null);try{const Ce=await _h(e,K,ze,v);C(""),f(""),y(2),await $(),u(Ce.collection_uid)}catch(Ce){S(Ce.message)}finally{E(!1)}}}async function V(){const z=_.trim();if(!z||!M){R(!1);return}try{await Lo(e,M.collection_uid,{name:z}),await $(),g(K=>K&&{...K,name:z})}catch(K){a(K.message)}finally{R(!1)}}async function le(z){if(M)try{await Lo(e,M.collection_uid,{default_visibility_bits:z}),await $(),g(K=>K&&{...K,default_visibility_bits:z})}catch(K){a(K.message)}}async function L(){if(M&&window.confirm(`Delete collection "${M.name}"? Entries will not be deleted.`))try{await Rh(e,M.collection_uid),u(null),g(null),await $()}catch(z){a(z.message)}}async function W(z){z.preventDefault();const K=b.trim();if(!(!K||!M)){ne(!0),Re(null);try{await Eh(e,M.collection_uid,K,Q),I(""),await B(M.collection_uid)}catch(ze){Re(ze.message)}finally{ne(!1)}}}async function q(z){if(M)try{await Th(e,M.collection_uid,z),await B(M.collection_uid)}catch(K){x(K.message)}}async function ae(z,K){if(M)try{await Ph(e,M.collection_uid,z,K),g(ze=>ze&&{...ze,entries:ze.entries.map(Ce=>Ce.entry_uid===z?{...Ce,collection_visibility_bits:K}:Ce)})}catch(ze){x(ze.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(z=>i.jsxs("button",{className:`coll-sidebar-row${o===z.collection_uid?" is-active":""}`,onClick:()=>u(z.collection_uid),children:[i.jsx("span",{className:"coll-row-name",children:z.name}),i.jsx("span",{className:"coll-row-meta",children:tm(z.default_visibility_bits)})]},z.collection_uid)),t.length===0&&!r&&i.jsx("div",{className:"muted",style:{padding:"8px 12px"},children:"No collections yet."})]}),M?i.jsxs("div",{className:"coll-detail",children:[i.jsxs("div",{className:"coll-detail-header",children:[je?i.jsx("input",{ref:X,className:"coll-rename-input",value:_,onChange:z=>F(z.target.value),onBlur:V,onKeyDown:z=>{z.key==="Enter"&&V(),z.key==="Escape"&&R(!1)}}):i.jsxs("h3",{className:`coll-detail-name${N?"":" coll-detail-name--editable"}`,title:N?void 0:"Click to rename",onClick:()=>{N||(F(M.name),R(!0))},children:[(c==null?void 0:c.name)??M.name,!N&&i.jsx("span",{className:"coll-edit-hint",children:" ✎"})]}),!N&&i.jsx("button",{className:"coll-delete-btn",onClick:L,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)??M.default_visibility_bits,onChange:z=>le(Number(z.target.value)),disabled:N,children:qn.map(z=>i.jsx("option",{value:z.value,children:z.label},z.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…"}),k&&i.jsx("div",{className:"collections-error",children:k}),!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(z=>i.jsxs("li",{className:"coll-entry-row",children:[i.jsxs("div",{className:"coll-entry-info",children:[i.jsx("span",{className:"coll-entry-title",children:z.title||z.entry_uid}),i.jsx("span",{className:"coll-entry-kind muted",children:z.source_kind})]}),i.jsxs("div",{className:"coll-entry-actions",children:[i.jsx("select",{className:"coll-entry-vis-select",value:z.collection_visibility_bits,onChange:K=>ae(z.entry_uid,Number(K.target.value)),children:qn.map(K=>i.jsx("option",{value:K.value,children:K.label},K.value))}),!N&&i.jsx("button",{className:"coll-entry-remove",onClick:()=>q(z.entry_uid),title:"Remove from collection",children:"×"})]})]},z.entry_uid))}))]}),!N&&i.jsxs("form",{className:"coll-add-entry-form",onSubmit:W,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:b,onChange:z=>I(z.target.value),placeholder:"entry_uid",required:!0}),i.jsx("select",{className:"coll-vis-select",value:Q,onChange:z=>te(Number(z.target.value)),children:qn.map(z=>i.jsx("option",{value:z.value,children:z.label},z.value))}),i.jsx("button",{className:"coll-add-btn",type:"submit",disabled:G,children:G?"…":"Add"})]}),ke&&i.jsx("div",{className:"collections-error",style:{marginTop:4},children:ke})]})]}):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:H,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:z=>{C(z.target.value),h||f(z.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:z=>f(z.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:v,onChange:z=>y(Number(z.target.value)),children:qn.map(z=>i.jsx("option",{value:z.value,children:z.label},z.value))})]}),T&&i.jsx("div",{className:"collections-error",children:T}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:j,children:j?"Creating…":"Create collection"})]})]})]}):i.jsx("div",{className:"view-placeholder",children:"Select an archive."})}const rm=4;function lm({tab:e,onTabChange:t,archiveId:n}){const{currentUser:r,setCurrentUser:l}=p.useContext(Kl)??{},s=r&&(r.role_bits&rm)!==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(sm,{currentUser:r,setCurrentUser:l}),e==="tokens"&&i.jsx(im,{}),e==="instance"&&s&&i.jsx(am,{}),e==="cookies"&&s&&i.jsx(um,{}),e==="extensions"&&s&&i.jsx(cm,{}),e==="storage"&&s&&i.jsx(om,{archiveId:n})]})}function sm({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(""),[g,m]=p.useState(""),[d,k]=p.useState(""),[x,w]=p.useState(!1),[C,h]=p.useState(null);async function f(y){y.preventDefault(),s(!0),o(null);try{await ph(n),t(j=>({...j,display_name:n||null})),o({ok:!0,text:"Saved."})}catch(j){o({ok:!1,text:j.message})}finally{s(!1)}}async function v(y){if(y.preventDefault(),g!==d){h({ok:!1,text:"Passwords do not match."});return}w(!0),h(null);try{await mh(u,g),c(""),m(""),k(""),h({ok:!0,text:"Password changed."})}catch(j){h({ok:!1,text:j.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:f,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:y=>r(y.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 y=>{const j=y.target.checked;try{await hh({humanize_slugs:j}),t(E=>({...E,humanize_slugs:j}))}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:v,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:y=>c(y.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:g,onChange:y=>m(y.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:d,onChange:y=>k(y.target.value),required:!0})]}),C&&i.jsx("div",{className:`form-msg form-msg--${C.ok?"ok":"err"}`,children:C.text}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:x,children:x?"Changing…":"Change Password"})]})]})]})}function im(){const[e,t]=p.useState([]),[n,r]=p.useState(!0),[l,s]=p.useState(null),[a,o]=p.useState(""),[u,c]=p.useState(!1),[g,m]=p.useState(null),d=p.useCallback(async()=>{r(!0),s(null);try{t(await gh())}catch(w){s(w.message)}finally{r(!1)}},[]);p.useEffect(()=>{d()},[d]);async function k(w){if(w.preventDefault(),!!a.trim()){c(!0);try{const C=await vh(a.trim());m(C),o(""),d()}catch(C){s(C.message)}finally{c(!1)}}}async function x(w){try{await yh(w),t(C=>C.filter(h=>h.token_uid!==w))}catch(C){s(C.message)}}return i.jsx("div",{style:{maxWidth:600},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"API Tokens"}),g&&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:g.raw_token}),i.jsx("button",{className:"token-dismiss",onClick:()=>m(null),children:"Dismiss"})]}),i.jsxs("form",{className:"token-create-row",onSubmit:k,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:()=>x(w.token_uid),children:"Revoke"})]},w.token_uid))]})]})})}function am(){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 ma())}catch(m){s(m.message)}finally{r(!1)}})()},[]);async function g(m){m.preventDefault(),o(!0),c(null);try{await sl(e),c({ok:!0,text:"Saved."})}catch(d){c({ok:!1,text:d.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:g,children:[[["public_index_enabled","Public index (unauthenticated browsing)"],["public_entry_content_enabled","Public entry content"],["open_registration_enabled","Open registration"]].map(([m,d])=>i.jsxs("label",{className:"checkbox-row",children:[i.jsx("input",{type:"checkbox",checked:!!e[m],onChange:k=>t(x=>({...x,[m]:k.target.checked}))}),d]},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(d=>({...d,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 Ns(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 om({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 g(){n("scanning"),u(null),l(null);try{const k=await zh(e);l(k),n("scanned")}catch(k){u(k.message),n("error")}}async function m(){n("deleting"),u(null);try{const k=await bh(e);a(k),n("done")}catch(k){u(k.message),n("error")}}const d=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:g,children:"Scan for orphaned blobs"}),t==="scanning"&&i.jsx("div",{className:"muted",children:"Scanning…"}),t==="scanned"&&r&&d&&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&&!d&&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:Ns(r.total_bytes)})," recoverable."]}),i.jsxs("div",{style:{display:"flex",gap:8},children:[i.jsxs("button",{className:"btn-danger",onClick:m,children:["Delete (",Ns(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:Ns(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 um(){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(""),[g,m]=p.useState("{}"),[d,k]=p.useState(null),[x,w]=p.useState(!1),[C,h]=p.useState({});p.useEffect(()=>{f()},[]);async function f(){r(!0),s(null);try{t(await Ih())}catch(S){s(S.message)}finally{r(!1)}}async function v(S){S.preventDefault();try{JSON.parse(g)}catch{k({ok:!1,text:'cookies must be valid JSON, e.g. {"session": "abc"}'});return}w(!0),k(null);try{await $h(a==="global"?null:u.trim(),a,g),c(""),m("{}"),o("global"),k({ok:!0,text:"Rule added."}),await f()}catch(b){k({ok:!1,text:b.message})}finally{w(!1)}}async function y(S){try{await Ah(S),await f()}catch(b){s(b.message)}}function j(S){h(b=>({...b,[S.rule_uid]:{cookiesInput:S.cookies_json,saving:!1,msg:null}}))}function E(S){h(b=>{const I={...b};return delete I[S],I})}async function T(S){const b=C[S.rule_uid];try{JSON.parse(b.cookiesInput)}catch{h(I=>({...I,[S.rule_uid]:{...I[S.rule_uid],msg:{ok:!1,text:"Invalid JSON"}}}));return}h(I=>({...I,[S.rule_uid]:{...I[S.rule_uid],saving:!0,msg:null}}));try{await Oh(S.rule_uid,{cookies_json:b.cookiesInput}),E(S.rule_uid),await f()}catch(I){h(Q=>({...Q,[S.rule_uid]:{...Q[S.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(S=>{const b=C[S.rule_uid],I=S.url_pattern?i.jsxs(i.Fragment,{children:[i.jsxs("span",{className:"muted",children:[S.pattern_kind,":"]})," ",i.jsx("code",{children:S.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:b?i.jsxs(i.Fragment,{children:[i.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:12,width:"100%",minHeight:60},value:b.cookiesInput,onChange:Q=>h(te=>({...te,[S.rule_uid]:{...te[S.rule_uid],cookiesInput:Q.target.value}}))}),b.msg&&i.jsx("div",{className:`form-msg form-msg--${b.msg.ok?"ok":"err"}`,children:b.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:b.saving,onClick:()=>T(S),children:b.saving?"Saving…":"Save"}),i.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>E(S.rule_uid),children:"Cancel"})]})]}):i.jsx("code",{style:{fontSize:12,wordBreak:"break-all"},children:S.cookies_json})}),i.jsx("td",{children:!b&&i.jsxs("div",{style:{display:"flex",gap:6},children:[i.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>j(S),children:"Edit"}),i.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"2px 8px"},onClick:()=>y(S.rule_uid),children:"Del"})]})})]},S.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:v,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:S=>o(S.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:S=>c(S.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:g,onChange:S=>m(S.target.value),placeholder:'{"SESSION": "abc123", "token": "xyz"}',required:!0})]}),d&&i.jsx("div",{className:`form-msg form-msg--${d.ok?"ok":"err"}`,children:d.text}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:x,children:x?"Adding…":"Add Rule"})]})]})})}function cm(){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 ma())}catch(C){o({ok:!1,text:C.message})}finally{r(!1)}})()},[]);async function u(C){s(!0),o(null);try{await sl({ublock_enabled:C}),t(h=>({...h,ublock_enabled:C})),o({ok:!0,text:"Saved."})}catch(h){o({ok:!1,text:h.message})}finally{s(!1)}}async function c(C){s(!0),o(null);try{await sl({cookie_ext_enabled:C}),t(h=>({...h,cookie_ext_enabled:C})),o({ok:!0,text:"Saved."})}catch(h){o({ok:!1,text:h.message})}finally{s(!1)}}async function g(C){s(!0),o(null);try{await sl({modal_closer_enabled:C}),t(h=>({...h,modal_closer_enabled:C})),o({ok:!0,text:"Saved."})}catch(h){o({ok:!1,text:h.message})}finally{s(!1)}}if(n)return i.jsx("div",{className:"muted",children:"Loading\\u2026"});const m=(e==null?void 0:e.ublock_ext_available)??!1,d=(e==null?void 0:e.ublock_enabled)??!0,k=(e==null?void 0:e.cookie_ext_available)??!1,x=(e==null?void 0:e.cookie_ext_enabled)??!0,w=(e==null?void 0:e.modal_closer_enabled)??!0;return i.jsx("div",{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.jsxs("div",{className:"ext-grid",children:[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)."}),!m&&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":d,className:`ext-toggle${d?" ext-toggle--on":""}`,onClick:()=>u(!d),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."}),!k&&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"})})]})}),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:"Modal & Dialog Closer"}),i.jsx("span",{className:"ext-card-desc",children:"Auto-dismiss cookie banners, consent overlays, and other modal dialogs before a WebPage capture is taken. Implemented as an injected browser script; no external extension required."})]}),i.jsx("button",{type:"button",role:"switch","aria-checked":w,className:`ext-toggle${w?" ext-toggle--on":""}`,onClick:()=>g(!w),disabled:l,"aria-label":"Toggle Modal and Dialog Closer",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 bo={0:"Private",1:"Public",2:"Users only",3:"Public"},dm=()=>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 fm({archiveId:e,selectedEntry:t,detail:n,onTagFilterSet:r,tagNodes:l,onTagsRefresh:s,onEntryTitleChange:a,onEntryDeleted:o,humanizeTags:u,onDetailRefresh:c,onOpenPreview:g,onPlay:m}){const[d,k]=p.useState([]),[x,w]=p.useState(""),[C,h]=p.useState([]),[f,v]=p.useState(""),y=p.useRef(0),j=p.useRef(!1),[E,T]=p.useState(!1),[S,b]=p.useState(""),[I,Q]=p.useState("idle"),[te,G]=p.useState(""),ne=p.useRef(null);p.useEffect(()=>{const L=++y.current;if(ne.current&&(clearInterval(ne.current),ne.current=null),Q("idle"),G(""),!t||!e){k([]),h([]);return}T(!1),b(""),j.current=!1,k([]),Promise.all([Vr(e,t.entry_uid),Lh(e,t.entry_uid)]).then(([W,q])=>{L===y.current&&(k(W),h(q))}).catch(()=>{})},[t,e]),p.useEffect(()=>()=>{clearInterval(ne.current)},[]);async function ke(){const L=S.trim()||null;try{await eh(e,t.entry_uid,L),a==null||a(t.entry_uid,L)}catch{}finally{T(!1)}}async function Re(){const L=x.trim();if(!(!L||!t))try{await th(e,t.entry_uid,L),w(""),v("");const W=await Vr(e,t.entry_uid);k(W),s()}catch(W){v(W.message)}}async function je(L){try{await nh(e,t.entry_uid,L);const W=await Vr(e,t.entry_uid);k(W),s()}catch{}}async function R(){if(!(!t||!e)&&window.confirm("Delete this entry? This cannot be undone."))try{await rh(e,t.entry_uid),o==null||o(t.entry_uid)}catch{}}async function _(){if(!t||!e||I==="running")return;const L=y.current,W=t.entry_uid;Q("running"),G("");try{const{job_uid:q}=await Dh(e,W);if(y.current!==L)return;ne.current=setInterval(async()=>{try{const ae=await Yc(e,q);if(ae.status==="completed"){if(clearInterval(ne.current),ne.current=null,y.current!==L)return;Q("done");const z=await Vr(e,W);if(y.current!==L)return;k(z),c==null||c()}else if(ae.status==="failed"){if(clearInterval(ne.current),ne.current=null,y.current!==L)return;Q("error"),G(ae.error_text||"Re-archive failed.")}}catch{if(clearInterval(ne.current),ne.current=null,y.current!==L)return;Q("error"),G("Network error while polling.")}},500)}catch(q){if(y.current!==L)return;Q("error"),G(q.message||"Failed to start re-archive.")}}const F=n?[["Added",ed(n.summary.archived_at)],["Source",n.summary.source_kind],["Type",n.summary.entity_kind],["Visibility",bo[n.summary.visibility]??n.summary.visibility],["Root",n.structured_root_relpath]]:[],X=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),M=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv","pdf","html","htm","jpg","jpeg","png","gif","webp","avif","svg","bmp"]),N=n?n.artifacts.findIndex(L=>L.artifact_role==="primary_media"):-1,$=N>=0?n.artifacts[N]:null,B=$?$.relpath.split(".").pop().toLowerCase():"",H=$&&X.has(B),V=N>=0&&t?`/api/archives/${e}/entries/${t.entry_uid}/artifacts/${N}`:null,le=n&&!H&&(n.summary.entity_kind==="tweet"||n.summary.entity_kind==="tweet_thread"||$&&M.has(B));return i.jsxs("aside",{className:"context-rail",children:[i.jsx("div",{className:"rail-eyebrow",children:"Context"}),t?n?i.jsxs(i.Fragment,{children:[E?i.jsx("input",{className:"rail-title-input",autoFocus:!0,value:S,onChange:L=>b(L.target.value),onKeyDown:L=>{L.key==="Enter"&&L.currentTarget.blur(),L.key==="Escape"&&(j.current=!0,L.currentTarget.blur())},onBlur:()=>{j.current?T(!1):ke(),j.current=!1}}):i.jsxs("h2",{className:"rail-title rail-title--editable",title:"Click to rename",onClick:()=>{b(n.summary.title??""),T(!0)},children:[Kt(n.summary.title)||Kt(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:ga(n.summary.source_kind)}}),i.jsx("span",{className:"u-text",children:n.summary.original_url}),i.jsx("span",{className:"ext",children:i.jsx(dm,{})})]}),H&&m&&i.jsx("button",{className:"rail-preview-btn",onClick:()=>m(V,t),children:"▶ Play"}),le&&g&&i.jsx("button",{className:"rail-preview-btn",onClick:g,children:"Preview"}),i.jsx("div",{className:"meta-list",children:F.filter(([,L])=>L!=null&&L!=="").map(([L,W])=>i.jsxs("div",{className:"meta-item",children:[i.jsx("span",{className:"meta-k",children:L}),i.jsx("span",{className:`meta-v${L==="Root"?" mono":""}`,children:Kt(W)})]},L))}),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((L,W)=>i.jsx("li",{children:i.jsxs("a",{href:`/api/archives/${e}/entries/${n.summary.entry_uid}/artifacts/${W}`,target:"_blank",rel:"noopener noreferrer",className:"artifact-link",children:[i.jsx("span",{className:"artifact-name",children:L.artifact_role.replace(/_/g," ")}),i.jsx("span",{className:"artifact-size",children:L.byte_size!=null?wi(L.byte_size):"—"})]})},W))})]})]}):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"}),d.length===0?i.jsx("p",{className:"tags-empty",children:"No tags yet."}):i.jsx("div",{className:"tags-wrap",children:d.map(L=>i.jsxs("span",{className:"tag-pill",title:L.full_path,children:[u?td(L.full_path):L.full_path,i.jsx("button",{className:"remove",title:`Remove tag ${L.full_path}`,onClick:()=>je(L.tag_uid),children:"×"})]},L.tag_uid))}),f&&i.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:f}),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:x,onChange:L=>w(L.target.value),onKeyDown:L=>{L.key==="Enter"&&Re()}}),i.jsx("button",{className:"tag-add-btn",onClick:Re,children:"Add"})]})]}),C.length>0&&i.jsxs("div",{className:"rail-section",children:[i.jsx("div",{className:"rail-section-heading",children:"Collections"}),C.map(L=>i.jsxs("div",{className:"coll-row",children:[i.jsx("span",{className:"coll-name",children:L.collection_uid}),i.jsx("span",{className:"vis-badge",children:bo[L.visibility_bits]??`bits:${L.visibility_bits}`})]},L.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:_,disabled:I==="running",children:I==="running"?"Re-archiving…":"Re-archive"}),I==="done"&&i.jsx("p",{className:"form-msg form-msg--ok",style:{marginTop:"6px"},children:"Re-archived successfully."}),I==="error"&&i.jsx("p",{className:"form-msg form-msg--err",style:{marginTop:"6px"},children:te})]}),i.jsx("div",{className:"rail-delete-zone",children:i.jsx("button",{className:"rail-delete-btn",onClick:R,children:"Delete entry"})})]})]})}function pm({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 Do({src:e,type:t,title:n,originalUrl:r}){const l=r||e,s=n||null;return i.jsxs("div",{className:"preview-iframe-wrap",style:{flex:1,minHeight:0,display:"flex",flexDirection:"column"},children:[i.jsxs("div",{className:"preview-iframe-toolbar",style:{display:"flex",flexDirection:"column",gap:"2px",padding:"6px 12px",borderBottom:"1px solid var(--line-soft)",background:"var(--paper-2)",flexShrink:0},children:[s&&i.jsx("span",{style:{fontSize:"0.85rem",fontWeight:600,color:"var(--ink)",fontFamily:"var(--sans)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s}),i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[i.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.78rem",color:"var(--muted)",fontFamily:"var(--sans)"},children:l}),i.jsx("a",{href:e,target:"_blank",rel:"noreferrer noopener",style:{fontSize:"0.78rem",color:"var(--accent)",textDecoration:"none",whiteSpace:"nowrap",fontFamily:"var(--sans)",flexShrink:0},children:t==="pdf"?"Open PDF ↗":"Open in new tab ↗"})]})]}),i.jsx("iframe",{src:e,sandbox:"allow-same-origin allow-popups",allow:"autoplay 'none'",referrerPolicy:"no-referrer",style:{flex:1,border:"none",width:"100%",minHeight:0},title:s||(t==="pdf"?"PDF preview":"Page preview")})]})}function hm({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 rd(e){return e?new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(new Date(e*1e3)):""}function Io(e){return!e||!e.includes("&")?e:e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/'/g,"'")}const O={card:{background:"var(--paper)",border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",maxWidth:"560px",margin:"0 auto",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},threadOuter:{border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",maxWidth:"560px",margin:"0 auto",background:"var(--paper)",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},tweetRow:{display:"flex",gap:"10px",padding:"10px 12px"},tweetRowThread:{display:"flex",gap:"10px",padding:"10px 12px 0"},leftCol:{display:"flex",flexDirection:"column",alignItems:"center",flexShrink:0,width:"36px"},rightCol:{flex:1,minWidth:0,paddingBottom:"8px"},avatar:{width:"36px",height:"36px",borderRadius:"50%",objectFit:"cover",flexShrink:0,display:"block"},avatarPh:{width:"36px",height:"36px",borderRadius:"50%",background:"var(--line)",flexShrink:0},threadLine:{flex:1,width:"2px",background:"var(--line-soft, var(--line))",margin:"4px 0",minHeight:"12px",borderRadius:"1px"},authorRow:{display:"flex",alignItems:"baseline",gap:"4px",flexWrap:"wrap",marginBottom:"4px",lineHeight:"1.3"},authorName:{fontWeight:"700",fontSize:"14px",color:"var(--ink)"},authorHandle:{fontSize:"13px",color:"var(--muted)"},datePart:{fontSize:"13px",color:"var(--muted)"},tweetText:{fontSize:"14px",lineHeight:"1.5",color:"var(--ink)",whiteSpace:"pre-line",marginBottom:"8px",wordBreak:"break-word"},stats:{display:"flex",gap:"12px",fontSize:"13px",color:"var(--muted)"},link:{color:"var(--accent)",textDecoration:"none"},loading:{padding:"24px 16px",textAlign:"center",color:"var(--muted)",fontSize:"14px"},error:{padding:"24px 16px",textAlign:"center",color:"var(--alert)",fontSize:"14px"},mediaGrid:{marginBottom:"8px",borderRadius:"10px",overflow:"hidden",border:"1px solid var(--line)"},mediaImg:{display:"block",width:"100%",objectFit:"cover",maxHeight:"260px"},mediaVideo:{display:"block",width:"100%",maxHeight:"260px",background:"#000"},article:{maxWidth:"560px",margin:"0 auto",border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",background:"var(--paper)",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},aCover:{width:"100%",display:"block",objectFit:"cover",maxHeight:"280px"},aMeta:{padding:"10px 14px 0"},aTweetTitle:{fontSize:"20px",fontWeight:"800",letterSpacing:"-0.3px",color:"var(--ink)",lineHeight:"1.3",marginBottom:"8px"},aAuthorRow:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},aAvatar:{width:"36px",height:"36px",borderRadius:"50%",objectFit:"cover",flexShrink:0,display:"block"},aAvatarPh:{width:"36px",height:"36px",borderRadius:"50%",background:"var(--line)",flexShrink:0},aAuthorName:{fontSize:"14px",fontWeight:"700",color:"var(--ink)",lineHeight:"1.3"},aAuthorSub:{fontSize:"13px",color:"var(--muted)",lineHeight:"1.3"},aDivider:{border:"none",borderTop:"1px solid var(--line)",margin:"0"},aBody:{padding:"4px 14px 16px"},bH1:{fontSize:"22px",fontWeight:"800",letterSpacing:"-0.4px",color:"var(--ink)",lineHeight:"1.25",margin:"16px 0 6px"},bH2:{fontSize:"18px",fontWeight:"700",letterSpacing:"-0.2px",color:"var(--ink)",lineHeight:"1.3",margin:"14px 0 4px"},bP:{fontSize:"15px",color:"var(--ink)",lineHeight:"1.65",marginBottom:"12px",marginTop:"0"},bSpacer:{height:"4px",display:"block"},bQuote:{borderLeft:"3px solid var(--line)",padding:"2px 12px",margin:"12px 0",color:"var(--muted)",fontSize:"15px",lineHeight:"1.6"},bHr:{border:"none",borderTop:"1px solid var(--line)",margin:"14px 0"},bImg:{width:"100%",display:"block",borderRadius:"8px",margin:"12px 0"},bUl:{margin:"8px 0 12px",paddingLeft:"24px"},bOl:{margin:"8px 0 12px",paddingLeft:"24px"},bLi:{fontSize:"15px",color:"var(--ink)",lineHeight:"1.6",marginBottom:"4px"},bTweet:{display:"flex",alignItems:"center",gap:"10px",border:"1px solid var(--line)",borderRadius:"10px",padding:"10px 14px",margin:"12px 0",color:"var(--muted)",fontSize:"14px",textDecoration:"none"},bMdPre:{borderRadius:"8px",margin:"10px 0",overflow:"auto",background:"var(--paper-3, var(--field))",padding:"12px 14px"},bMdCode:{fontFamily:"ui-monospace, 'Cascadia Code', 'Fira Code', Menlo, Consolas, monospace",fontSize:"12px",lineHeight:"1.6",color:"var(--ink)",background:"transparent",display:"block"},iCode:{fontFamily:"ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace",fontSize:"0.875em",background:"var(--paper-3, var(--field))",padding:"1px 5px",borderRadius:"4px",color:"var(--ink)"},qtBadge:{fontSize:"11px",color:"var(--muted)",display:"inline-flex",alignItems:"center",gap:"2px",marginLeft:"4px",letterSpacing:"0.03em",flexShrink:0},lightboxBackdrop:{position:"fixed",inset:0,zIndex:500,background:"rgba(0,0,0,0.92)",display:"flex",alignItems:"center",justifyContent:"center",padding:"20px"},lightboxContent:{display:"flex",flexDirection:"column",alignItems:"center",gap:"10px",maxWidth:"90vw",maxHeight:"90vh"},lightboxToolbar:{display:"flex",alignItems:"center",gap:"10px",alignSelf:"flex-end"},lightboxImg:{maxWidth:"88vw",maxHeight:"80vh",objectFit:"contain",borderRadius:"6px",display:"block"},lightboxNav:{display:"flex",gap:"12px",alignItems:"center"},lightboxNavBtn:{background:"rgba(255,255,255,0.18)",border:"none",color:"#fff",fontSize:"20px",cursor:"pointer",borderRadius:"50%",width:"36px",height:"36px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,flexShrink:0},lightboxBtn:{background:"rgba(255,255,255,0.18)",border:"none",color:"#fff",fontSize:"16px",cursor:"pointer",borderRadius:"50%",width:"30px",height:"30px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,flexShrink:0},lightboxLink:{color:"rgba(255,255,255,0.7)",textDecoration:"none",fontSize:"14px"},lightboxCounter:{color:"rgba(255,255,255,0.6)",fontSize:"13px"}};function mm(e,t,n){const r={};return n&&n.forEach((l,s)=>{l.relpath&&(r[l.relpath]=`/api/archives/${e}/entries/${t}/artifacts/${s}`)}),r}function Nn(e,t,n){return e&&n[e]?n[e]:t||null}function ld(){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 va(e,t,...n){var r;if(e.fromIndex!=null&&e.toIndex!=null)return{s:e.fromIndex,e:e.toIndex};if(((r=e.indices)==null?void 0:r.length)===2)return{s:e.indices[0],e:e.indices[1]};if(t)for(const l of n){if(!l)continue;const s=t.indexOf(l);if(s!==-1)return{s,e:s+l.length}}return null}function sd(e,t){const n=e.expanded_url||e.url||e.text||"",r=e.display_url||e.expanded_url||e.url||e.text||"",l=va(e,t,e.url,e.text,e.display_url,e.expanded_url);return!l||!n?null:{...l,kind:"url",href:n,display:r}}function id(e,t){const n=e.screen_name||e.name||e.text||"",r=n?`@${n}`:null,l=va(e,t,r);return!l||!n?null:{...l,kind:"mention",screen_name:n}}const $o=/https?:\/\/[^\s<>"'\])]+/g,gm=/[.,;:!?)()]+$/;function Ll(e,t){const n=[];let r=0,l;for($o.lastIndex=0;(l=$o.exec(e))!==null;){l.index>r&&n.push(e.slice(r,l.index));let s=l[0].replace(gm,"");n.push(i.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",style:t,children:s},l.index));const a=l[0].slice(s.length);a&&n.push(a),r=l.index+l[0].length}return r===0?e:(rsd(o,e)).filter(Boolean),...(t.user_mentions||[]).map(o=>id(o,e)).filter(Boolean)];if(r.length===0&&n.length===0)return Ll(Io(e),O.link);const l=new Set([0,e.length]);for(const o of r)o.s>=0&&o.s<=e.length&&l.add(o.s),o.e>=0&&o.e<=e.length&&l.add(o.e);for(const[o,u]of n)o>=0&&o<=e.length&&l.add(o),u>=0&&u<=e.length&&l.add(u);const s=(o,u)=>n.some(([c,g])=>c<=o&&g>=u),a=[...l].sort((o,u)=>o-u);return a.slice(0,-1).map((o,u)=>{const c=a[u+1];if(s(o,c))return null;const g=e.slice(o,c),m=r.filter(x=>x.s<=o&&x.e>=c),d=m.find(x=>x.kind==="url");if(d)return i.jsx("a",{href:d.href,target:"_blank",rel:"noopener noreferrer",style:O.link,children:d.display||g},u);const k=m.find(x=>x.kind==="mention");return k?i.jsx("a",{href:`https://x.com/${k.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:O.link,children:g},u):i.jsx("span",{children:Ll(Io(g),O.link)},u)}).filter(o=>o!==null)}function ym(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){const u=sd(o,e);u&&l.push(u)}for(const o of r){const u=id(o,e);u&&l.push(u)}if(l.length===0)return Ll(e,O.link);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],g=l.filter(w=>w.s<=o&&w.e>=c),m=e.slice(o,c);let d;if(m.includes(` `)){const w=m.split(` `);d=w.flatMap((C,h)=>hw.kind==="style"&&w.style==="Code")&&(d=i.jsx("code",{style:O.iCode,children:d})),g.some(w=>w.kind==="style"&&w.style==="Bold")&&(d=i.jsx("strong",{children:d})),g.some(w=>w.kind==="style"&&w.style==="Italic")&&(d=i.jsx("em",{children:d})),g.some(w=>w.kind==="style"&&w.style==="Underline")&&(d=i.jsx("u",{children:d})),g.some(w=>w.kind==="style"&&w.style==="Strikethrough")&&(d=i.jsx("s",{children:d}));const k=g.find(w=>w.kind==="url");if(k){const w=/^https?:\/\/t\.co\//i.test(d);d=i.jsx("a",{href:k.href,target:"_blank",rel:"noopener noreferrer",style:O.link,children:w?k.display:d})}const x=g.find(w=>w.kind==="mention");return x&&(d=i.jsx("a",{href:`https://x.com/${x.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:O.link,children:d})),i.jsx("span",{children:typeof d=="string"?Ll(d,O.link):d},u)})}function xm(e,t,n){const r=e.resolved_entities||[];return r.length===0?null:r.map((l,s)=>{var a;switch(l.type){case"divider":return i.jsx("hr",{style:O.bHr},s);case"media":{const o=Nn(l.local_path,l.url,t);return o?i.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",style:{display:"block",cursor:"zoom-in"},onClick:u=>{var c;!u.metaKey&&!u.ctrlKey&&(u.preventDefault(),(c=n==null?void 0:n.onImgClick)==null||c.call(n,o))},children:i.jsx("img",{src:o,style:O.bImg,loading:"lazy",alt:""})},s):null}case"tweet":return l.tweet_id?i.jsxs("a",{href:`https://x.com/i/status/${l.tweet_id}`,target:"_blank",rel:"noopener noreferrer",style:O.bTweet,children:[i.jsx(ld,{}),"View post on X"]},s):null;case"link":return l.url?i.jsx("p",{style:O.bP,children:i.jsx("a",{href:l.url,target:"_blank",rel:"noopener noreferrer",style:O.link,children:l.url})},s):null;case"markdown":{const o=l.markdown??((a=l.data)==null?void 0:a.markdown)??"";return i.jsx("pre",{style:O.bMdPre,children:i.jsx("code",{style:O.bMdCode,children:o})},s)}case"emoji":return l.url?i.jsx("img",{src:l.url,alt:"",style:{height:"1.2em",verticalAlign:"middle",margin:"0 1px"}},s):null;default:return null}})}function _s(e,t,n,r){const l=e.type||"",s=e.text||"",a=e.inline_style_ranges||[],o=e.data||{},u=ym(s,a,o.urls||[],o.mentions||[]);switch(l){case"header-one":return i.jsx("h1",{style:O.bH1,children:u},t);case"header-two":{const c=s.match(/(?:x\.com|twitter\.com)\/i\/status\/(\d+)/);return c?i.jsxs("a",{href:`https://x.com/i/status/${c[1]}`,target:"_blank",rel:"noopener noreferrer",style:O.bTweet,children:[i.jsx(ld,{}),"View post on X"]},t):i.jsx("h2",{style:O.bH2,children:u},t)}case"unstyled":return s.trim()?i.jsx("p",{style:O.bP,children:u},t):i.jsx("span",{style:O.bSpacer},t);case"blockquote":return i.jsx("blockquote",{style:O.bQuote,children:u},t);case"unordered-list-item":case"ordered-list-item":return i.jsx("li",{style:O.bLi,children:u},t);case"atomic":return i.jsx("span",{children:xm(e,n,r)},t);default:return s?i.jsx("p",{style:O.bP,children:u},t):null}}function wm(e,t,n){const r=[];let l=0;for(;ll(null)}),g&&i.jsx("a",{href:g,target:"_blank",rel:"noopener noreferrer",style:{display:"block",cursor:"zoom-in"},onClick:d=>{!d.metaKey&&!d.ctrlKey&&(d.preventDefault(),l(g))},children:i.jsx("img",{src:g,style:O.aCover,alt:"Article cover"})}),i.jsxs("div",{style:O.aMeta,children:[e.title&&i.jsx("div",{style:O.aTweetTitle,children:e.title}),i.jsxs("div",{style:O.aAuthorRow,children:[m?i.jsx("img",{src:m,style:O.aAvatar,alt:a.name||""}):i.jsx("div",{style:O.aAvatarPh}),i.jsxs("div",{children:[i.jsx("div",{style:O.aAuthorName,children:a.name||a.screen_name||"Unknown"}),c&&i.jsx("div",{style:O.aAuthorSub,children:c})]})]})]}),i.jsx("hr",{style:O.aDivider}),i.jsx("div",{style:O.aBody,children:wm(e.blocks||[],n,{onImgClick:l})})]})}function jm({photos:e,onOpen:t}){const n=e.length;if(n===0)return null;if(n===1)return i.jsx("a",{href:e[0].src,target:"_blank",rel:"noopener noreferrer",style:{display:"block"},onClick:l=>{!l.metaKey&&!l.ctrlKey&&(l.preventDefault(),t(0))},children:i.jsx("img",{src:e[0].src,alt:e[0].alt||"",style:O.mediaImg,loading:"lazy"})});const r=n<=2?"180px":"140px";return i.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gridTemplateRows:n===2?r:`${r} ${r}`,gap:"2px"},children:e.map((l,s)=>i.jsx("a",{href:l.src,target:"_blank",rel:"noopener noreferrer",style:{display:"block",overflow:"hidden",gridRow:n===3&&s===0?"span 2":void 0},onClick:a=>{!a.metaKey&&!a.ctrlKey&&(a.preventDefault(),t(s))},children:i.jsx("img",{src:l.src,alt:l.alt||"",loading:"lazy",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})},s))})}function ad({items:e,startIndex:t,onClose:n}){const[r,l]=p.useState(t);p.useEffect(()=>{const a=o=>{(o.key==="Escape"||o.key==="ArrowLeft"||o.key==="ArrowRight")&&(o.stopPropagation(),o.preventDefault()),o.key==="Escape"&&n(),o.key==="ArrowRight"&&l(u=>Math.min(u+1,e.length-1)),o.key==="ArrowLeft"&&l(u=>Math.max(u-1,0))};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[n,e.length]);const s=e[r];return i.jsx("div",{style:O.lightboxBackdrop,onClick:n,children:i.jsxs("div",{style:O.lightboxContent,onClick:a=>a.stopPropagation(),children:[i.jsxs("div",{style:O.lightboxToolbar,children:[e.length>1&&i.jsxs("span",{style:O.lightboxCounter,children:[r+1," / ",e.length]}),i.jsx("a",{href:s.src,target:"_blank",rel:"noopener noreferrer",style:O.lightboxLink,title:"Open in new tab",children:"↗"}),i.jsx("button",{style:O.lightboxBtn,onClick:n,"aria-label":"Close",children:"×"})]}),i.jsx("img",{src:s.src,alt:s.alt||"",style:O.lightboxImg}),e.length>1&&i.jsxs("div",{style:O.lightboxNav,children:[i.jsx("button",{style:O.lightboxNavBtn,onClick:()=>l(a=>Math.max(a-1,0)),disabled:r===0,children:"‹"}),i.jsx("button",{style:O.lightboxNavBtn,onClick:()=>l(a=>Math.min(a+1,e.length-1)),disabled:r===e.length-1,children:"›"})]})]})})}function Oo({tweet:e,isInThread:t,isLast:n,artifactMap:r}){var f,v;const[l,s]=p.useState(null),a=e.author||{},o=e.created_at_secs?rd(e.created_at_secs):"",u=e.entities||{},c=Nn(a.avatar_local_path,a.avatar_url,r),g=t&&!n,m=e.is_quote_status===!0,d=t?O.tweetRowThread:O.tweetRow,k=e.full_text||"",x=((v=(f=e.extended_entities)==null?void 0:f.media)!=null&&v.length?e.extended_entities.media:u.media)||[],w=[],C=[];for(const y of x)if(y.type==="photo"){const j=Nn(y.local_path,y.media_url_https,r);j&&w.push({kind:"photo",src:j,alt:y.alt_text||""})}else if(y.type==="video"||y.type==="animated_gif"){const j=y.local_path&&r[y.local_path]||(()=>{var T,S;return(S=(((T=y.video_info)==null?void 0:T.variants)||[]).filter(b=>b.content_type==="video/mp4").sort((b,I)=>(I.bitrate||0)-(b.bitrate||0))[0])==null?void 0:S.url})();j&&C.push({kind:y.type==="animated_gif"?"gif":"video",src:j})}const h=[];for(const y of x){if(!y.url||!(y.type==="photo"?w.some(T=>T.src===Nn(y.local_path,y.media_url_https,r)):C.length>0))continue;const E=va(y,k,y.url);E&&h.push([E.s,E.e])}return i.jsxs(i.Fragment,{children:[l!==null&&i.jsx(ad,{items:w,startIndex:l,onClose:()=>s(null)}),i.jsxs("div",{style:d,children:[i.jsxs("div",{style:O.leftCol,children:[c?i.jsx("img",{src:c,style:O.avatar,alt:a.name||""}):i.jsx("div",{style:O.avatarPh}),g&&i.jsx("div",{style:O.threadLine})]}),i.jsxs("div",{style:O.rightCol,children:[i.jsxs("div",{style:O.authorRow,children:[i.jsx("span",{style:O.authorName,children:a.name||a.screen_name||"Unknown"}),a.screen_name&&i.jsxs("span",{style:O.authorHandle,children:["@",a.screen_name]}),o&&i.jsxs("span",{style:O.datePart,children:["· ",o]}),m&&i.jsx("span",{style:O.qtBadge,title:"Quote tweet",children:"↻ QT"})]}),i.jsx("div",{style:O.tweetText,children:vm(k,u,h)}),w.length>0&&i.jsx("div",{style:O.mediaGrid,children:i.jsx(jm,{photos:w,onOpen:y=>s(y)})}),C.map((y,j)=>i.jsx("div",{style:O.mediaGrid,children:i.jsx("video",{src:y.src,style:O.mediaVideo,controls:!0,loop:y.kind==="gif",muted:y.kind==="gif",autoPlay:y.kind==="gif"})},j)),(e.retweet_count>0||e.favorite_count>0)&&i.jsxs("div",{style:O.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 Sm({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 d=n.map((x,w)=>({...x,index:w})).filter(x=>x.artifact_role==="raw_tweet_json");if(d.length===0){o("No tweet data found."),s(!1);return}let k=!1;return Yp(e,t,d.map(x=>x.index)).then(async x=>{if(k)return;const w=/https?:\/\/t\.co\/[A-Za-z0-9]+/g,C=j=>{var T;const E=j.full_text||"";return(((T=j.entities)==null?void 0:T.urls)||[]).map(S=>{var b;if(S.fromIndex!=null&&S.toIndex!=null)return[S.fromIndex,S.toIndex];if(((b=S.indices)==null?void 0:b.length)===2)return[S.indices[0],S.indices[1]];if(S.url){const I=E.indexOf(S.url);if(I!==-1)return[I,I+S.url.length]}return null}).filter(Boolean)},h=(j,E,T)=>j.some(([S,b])=>S<=E&&b>=T),f=new Set;for(const j of x){const E=j.full_text||"",T=C(j);let S;for(w.lastIndex=0;(S=w.exec(E))!==null;)h(T,S.index,S.index+S[0].length)||f.add(S[0])}const v=f.size>0?await Zp([...f]).catch(()=>({})):{},y=x.map(j=>{var I;const E=j.full_text||"",T=C(j),S=[];let b;for(w.lastIndex=0;(b=w.exec(E))!==null;){const Q=b[0],te=v[Q];te&&te!==Q&&!h(T,b.index,b.index+Q.length)&&S.push({url:Q,expanded_url:te,display_url:(()=>{try{const G=new URL(te);return G.hostname+(G.pathname.length>1?"/…":"")}catch{return te}})(),fromIndex:b.index,toIndex:b.index+Q.length})}return S.length===0?j:{...j,entities:{...j.entities||{},urls:[...((I=j.entities)==null?void 0:I.urls)||[],...S]}}});k||c(y)}).catch(x=>{k||o(x.message||"Failed to load tweet.")}).finally(()=>{k||s(!1)}),()=>{k=!0}},[e,t,n]),l)return i.jsx("div",{style:O.loading,children:"Loading…"});if(a)return i.jsxs("div",{style:O.error,children:["Error: ",a]});if(u.length===0)return null;const g=mm(e,t,n);if(r==="tweet_thread")return i.jsx("div",{style:O.threadOuter,children:u.map((d,k)=>i.jsx(Oo,{tweet:d,isInThread:!0,isLast:k===u.length-1,artifactMap:g},d.id||k))});const m=u[0];return m.is_article&&m.article?i.jsx(km,{article:m.article,tweetAuthor:m.author,artifactMap:g}):i.jsx("div",{style:O.card,children:i.jsx(Oo,{tweet:m,isInThread:!1,isLast:!0,artifactMap:g})})}const Nm=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv"]),_m=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),Cm=new Set(["jpg","jpeg","png","gif","webp","avif","svg","bmp"]);function od({archiveId:e,entry:t,detail:n}){if(!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:r,artifacts:l}=n,s=r.entry_uid,a=r.entity_kind;if(a==="tweet"||a==="tweet_thread")return i.jsx("div",{className:"preview-tweet-wrap",children:i.jsx(Sm,{archiveId:e,entryUid:s,artifacts:l,entityKind:a})});const o=l.findIndex(m=>m.artifact_role==="primary_media");if(o===-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"}),l.length>0&&i.jsx("ul",{style:{marginTop:"12px",paddingLeft:"20px",fontSize:"0.8rem",color:"var(--muted-2)",fontFamily:"var(--sans)"},children:l.map((m,d)=>i.jsxs("li",{children:[m.artifact_role,": ",m.relpath]},d))})]});const u=l[o],c=`/api/archives/${e}/entries/${s}/artifacts/${o}`,g=u.relpath.split(".").pop().toLowerCase();return Nm.has(g)?i.jsx("div",{className:"preview-panel",children:i.jsx(pm,{src:c})}):_m.has(g)?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:"2rem"},children:"🎵"}),i.jsx("span",{style:{color:"var(--ink)",fontSize:"0.95rem",fontWeight:600},children:r.title||s}),i.jsx("audio",{src:c,controls:!0,style:{marginTop:"8px",width:"100%",maxWidth:"400px"}})]}):g==="pdf"?i.jsx("div",{className:"preview-panel",style:{flex:1,minHeight:0},children:i.jsx(Do,{src:c,type:"pdf",title:r.title,originalUrl:r.original_url})}):g==="html"||g==="htm"?i.jsx("div",{className:"preview-panel",style:{flex:1,minHeight:0},children:i.jsx(Do,{src:c,type:"page",title:r.title,originalUrl:r.original_url})}):Cm.has(g)?i.jsx("div",{className:"preview-panel",style:{height:"100%"},children:i.jsx(hm,{src:c,alt:r.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:l.map((m,d)=>i.jsxs("li",{children:[m.artifact_role,": ",m.relpath]},d))})]})}function Em({archiveId:e,entry:t,detail:n,onClose:r}){var l,s;return p.useEffect(()=>{const a=o=>{o.key==="Escape"&&r()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[r]),i.jsx("div",{className:"preview-modal-backdrop",onClick:r,children:i.jsxs("div",{className:`preview-modal${((l=n==null?void 0:n.summary)==null?void 0:l.entity_kind)==="tweet"||((s=n==null?void 0:n.summary)==null?void 0:s.entity_kind)==="tweet_thread"?"":" preview-modal--full"}`,onClick:a=>a.stopPropagation(),children:[i.jsxs("div",{className:"preview-modal-header",children:[i.jsx("span",{className:"preview-modal-title",children:(t==null?void 0:t.title)||(t==null?void 0:t.entry_uid)||"Preview"}),i.jsx("a",{className:"preview-modal-newtab",href:`/preview/${e}/${t==null?void 0:t.entry_uid}`,target:"_blank",rel:"noopener noreferrer",title:"Open in new tab",children:"↗"}),i.jsx("button",{className:"preview-modal-close",onClick:r,"aria-label":"Close preview",children:"×"})]}),i.jsx("div",{className:"preview-modal-body",children:i.jsx(od,{archiveId:e,entry:t,detail:n})})]})})}function Ao(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 Tm({entry:e,src:t,archiveId:n,onClose:r}){const l=p.useRef(null),[s,a]=p.useState(!1),[o,u]=p.useState(0),[c,g]=p.useState(NaN),[m,d]=p.useState(1);p.useEffect(()=>{!l.current||!t||(l.current.load(),u(0),g(NaN),a(!1))},[t]),p.useEffect(()=>{l.current&&(l.current.volume=m)},[m]);function k(){const f=l.current;f&&(s?f.pause():f.play().catch(()=>{}))}function x(f){const v=l.current;if(!v||!isFinite(c))return;const y=Number(f.target.value);v.currentTime=y,u(y)}function w(f){d(Number(f.target.value))}const C=(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 f;return u(((f=l.current)==null?void 0:f.currentTime)??0)},onLoadedMetadata:()=>{var f;return g(((f=l.current)==null?void 0:f.duration)??NaN)},onDurationChange:()=>{var f;return g(((f=l.current)==null?void 0:f.duration)??NaN)},style:{display:"none"}}),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:ga(h)}}),i.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.85rem",color:"var(--ink)"},title:C,children:C})]}),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:k,"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:Ao(o)}),i.jsx("input",{type:"range",min:0,max:isFinite(c)?c:0,step:.1,value:isFinite(o)?o:0,onChange:x,"aria-label":"Seek",style:{flex:1,minWidth:0,accentColor:"var(--accent)"}}),i.jsx("span",{style:{fontSize:"0.75rem",color:"var(--muted)",whiteSpace:"nowrap",flexShrink:0},children:Ao(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:"✕"})]})]})]})}function Pm({archiveId:e,entryUid:t}){var g,m;const[n,r]=p.useState(null),[l,s]=p.useState(!0),[a,o]=p.useState(null);p.useEffect(()=>{yi(e,t).then(d=>{r(d),s(!1)}).catch(d=>{o((d==null?void 0:d.message)||"Failed to load entry"),s(!1)})},[e,t]);const u=((g=n==null?void 0:n.summary)==null?void 0:g.title)||t,c=(m=n==null?void 0:n.summary)==null?void 0:m.original_url;return i.jsxs("div",{style:{minHeight:"100vh",display:"flex",flexDirection:"column",background:"var(--paper)",fontFamily:"var(--sans)"},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 16px",borderBottom:"1px solid var(--line)",flexShrink:0,background:"var(--paper-2)"},children:[i.jsx("a",{href:"/",style:{color:"var(--accent)",textDecoration:"none",fontSize:"13px",flexShrink:0},children:"← Archive"}),i.jsx("span",{style:{flex:1,fontSize:"14px",fontWeight:600,color:"var(--ink)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u}),c&&i.jsx("a",{href:c,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--muted)",textDecoration:"none",fontSize:"13px",flexShrink:0},children:"Original ↗"})]}),i.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",display:"flex",flexDirection:"column"},children:[l&&i.jsx("div",{style:{padding:"48px",textAlign:"center",color:"var(--muted)",fontSize:"14px"},children:"Loading…"}),a&&i.jsx("div",{style:{padding:"48px",textAlign:"center",color:"var(--alert)",fontSize:"14px"},children:a}),n&&i.jsx(od,{archiveId:e,entry:n.summary,detail:n})]})]})}const Lm=7e3;function Rm({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(bm,{toast:r,onDismiss:t,onIgnoreUblock:n},r.id))}):null}function zm(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 bm({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),Lm);return()=>clearTimeout(u)},[r,e.id,t]);const o=zm(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 Kl=p.createContext(null),Vn=(()=>{const e=window.location.pathname.match(/^\/preview\/([^/]+)\/([^/]+)/);return e?{archiveId:e[1],entryUid:e[2]}:null})(),Dm=["archive","tags","collections","runs","admin","settings"],Im=["profile","tokens","instance","cookies","extensions","storage"];function ln(){const e=window.location.pathname.split("/").filter(Boolean),t=Dm.includes(e[0])?e[0]:"archive",n=t==="settings"&&Im.includes(e[1])?e[1]:"profile",r=new URLSearchParams(window.location.search),l=r.get("q")??"",s=t==="archive"?r.get("tag")??null:null,a=t==="archive"?r.get("entry")??null:null;return{view:t,settingsTab:n,q:l,tag:s,entry:a}}function $m(e,t){return e==="archive"?"/":e==="settings"?`/settings/${t}`:`/${e}`}function Om(){const[e,t]=p.useState("loading"),[n,r]=p.useState(null);p.useEffect(()=>{(async()=>{if(await oh()){t("setup");return}const U=await fh();if(!U){t("login");return}r(U),t("authenticated")})()},[]),p.useEffect(()=>{const D=()=>{r(null),t("login")};return window.addEventListener("auth:expired",D),()=>window.removeEventListener("auth:expired",D)},[]),p.useEffect(()=>{const D=()=>{const{view:U,settingsTab:Z,q:ye,tag:Jl,entry:ql}=ln();h(U),v(Z),j(ye),w(Jl),m(ql),k(null)};return window.addEventListener("popstate",D),()=>window.removeEventListener("popstate",D)},[]);const[l,s]=p.useState([]),[a,o]=p.useState(null),[u,c]=p.useState([]),[g,m]=p.useState(()=>ln().entry),[d,k]=p.useState(null),[x,w]=p.useState(()=>ln().tag),[C,h]=p.useState(()=>ln().view),[f,v]=p.useState(()=>ln().settingsTab),[y,j]=p.useState(()=>ln().q),[E,T]=p.useState(""),[S,b]=p.useState(!1),[I,Q]=p.useState([]),[te,G]=p.useState([]),[ne,ke]=p.useState(()=>sessionStorage.getItem("captureDialogOpen")==="true"),[Re,je]=p.useState([]),R=p.useRef(0),[_,F]=p.useState(()=>sessionStorage.getItem("ublockWarningIgnored")==="true"),[X,M]=p.useState(null),N=p.useRef(0),$=p.useRef(null),B=p.useRef(!1),H=p.useRef(!0),V=(n==null?void 0:n.humanize_slugs)??!1;p.useEffect(()=>{const D=++N.current;M(null),!(!d||!a)&&yi(a,d.entry_uid).then(U=>{D===N.current&&M(U)}).catch(()=>{})},[d,a]),p.useEffect(()=>{sessionStorage.setItem("captureDialogOpen",ne)},[ne]);const le=p.useCallback(async(D,U,Z)=>{if(D){b(!0);try{let ye;U||Z?ye=await Gp(D,U,Z):ye=await qp(D),c(ye),T(ye.length===0?"No results":`${ye.length} result${ye.length===1?"":"s"}`)}catch{c([]),T("Search failed. Try again.")}finally{b(!1)}}},[]);p.useEffect(()=>{e==="authenticated"&&Jp().then(D=>{if(s(D),D.length>0){const U=D[0].id;o(U)}})},[e]),p.useEffect(()=>{if(a){if(H.current){H.current=!1,Promise.all([Ss(a).then(Q),Qr(a).then(G)]);return}w(null),k(null),m(null),Promise.all([le(a,"",null),Ss(a).then(Q),Qr(a).then(G)])}},[a]),p.useEffect(()=>{if(a===null)return;const D=setTimeout(()=>{le(a,y,x)},300);return()=>clearTimeout(D)},[y,a]),p.useEffect(()=>{a!==null&&(x!==null&&h("archive"),le(a,y,x))},[x,a]);const L=p.useCallback(D=>{o(D)},[]),W=p.useCallback(D=>{h(D),D==="tags"&&a&&Qr(a).then(G)},[a]);p.useEffect(()=>{if(Vn)return;const D=$m(C,f);window.location.pathname!==D&&history.pushState(null,"",D+window.location.search)},[C,f]);const q=p.useCallback(D=>{m(D?D.entry_uid:null),k(D)},[]),ae=p.useCallback(D=>{w(D)},[]),z=p.useCallback(()=>{w(null)},[]),K=p.useCallback(()=>{a&&Qr(a).then(G)},[a]),ze=p.useCallback((D,U)=>{x===D?w(U):x!=null&&x.startsWith(D+"/")&&w(U+x.slice(D.length))},[x]),Ce=p.useCallback(D=>{(x===D||x!=null&&x.startsWith(D+"/"))&&w(null)},[x]),ud=p.useCallback((D,U)=>{c(Z=>Z.map(ye=>ye.entry_uid===D?{...ye,title:U}:ye)),k(Z=>Z&&Z.entry_uid===D?{...Z,title:U}:Z),M(Z=>Z&&Z.summary.entry_uid===D?{...Z,summary:{...Z.summary,title:U}}:Z)},[]),cd=p.useCallback(()=>{if(!a||!d)return;const D=++N.current;yi(a,d.entry_uid).then(U=>{D===N.current&&M(U)}).catch(()=>{})},[a,d]),dd=p.useCallback(D=>{c(U=>U.filter(Z=>Z.entry_uid!==D)),k(U=>(U==null?void 0:U.entry_uid)===D?null:U),m(U=>U===D?null:U)},[]);p.useEffect(()=>{if(!g||d)return;const D=u.find(U=>U.entry_uid===g);D&&k(D)},[u,g,d]),p.useEffect(()=>{if(Vn)return;const D=new URLSearchParams;y&&D.set("q",y),C==="archive"&&x&&D.set("tag",x),C==="archive"&&g&&D.set("entry",g);const U=D.toString(),Z=window.location.pathname+(U?"?"+U:"");window.location.pathname+window.location.search!==Z&&history.replaceState(null,"",Z)},[y,x,g,C]),p.useEffect(()=>{const D=U=>{var Z,ye;(U.metaKey||U.ctrlKey)&&U.key==="k"&&(U.preventDefault(),C==="archive"?((Z=$.current)==null||Z.focus(),(ye=$.current)==null||ye.select()):(B.current=!0,h("archive")))};return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[C]),p.useEffect(()=>{C==="archive"&&B.current&&(B.current=!1,requestAnimationFrame(()=>{var D,U;(D=$.current)==null||D.focus(),(U=$.current)==null||U.select()}))},[C]);const fd=p.useCallback(()=>{ke(!0)},[]),pd=p.useCallback(()=>{ke(!1)},[]),hd=p.useCallback(()=>{a&&Promise.all([le(a,y,x),Ss(a).then(Q)])},[a,y,x,le]),md=p.useCallback((D,U,Z="error",ye=null)=>{if(Z==="warning"&&_&&U)return;const Jl=++R.current;je(ql=>[...ql,{id:Jl,text:D,locator:U,type:Z,headline:ye}])},[_]),gd=p.useCallback(D=>{je(U=>U.filter(Z=>Z.id!==D))},[]),vd=p.useCallback(()=>{sessionStorage.setItem("ublockWarningIgnored","true"),F(!0),je(D=>D.filter(U=>!(U.type==="warning"&&U.locator)))},[]),[ya,Xl]=p.useState(null),[In,xa]=p.useState(null),yd=p.useCallback(()=>{d&&Xl(d.entry_uid)},[d]),xd=p.useCallback(()=>Xl(null),[]),wd=p.useCallback((D,U)=>{xa({src:D,entry:U})},[]),kd=p.useCallback(()=>xa(null),[]);return p.useEffect(()=>{Xl(null)},[d]),p.useEffect(()=>(document.body.classList.toggle("has-audio-bar",!!In),()=>document.body.classList.remove("has-audio-bar")),[In]),e==="loading"?i.jsx("div",{className:"auth-loading",children:"Loading\\u2026"}):e==="setup"?i.jsx(Bh,{onComplete:()=>t("login")}):e==="login"?i.jsx(Mh,{onLogin:D=>{r(D),t("authenticated")}}):Vn?i.jsx(Pm,{archiveId:Vn.archiveId,entryUid:Vn.entryUid}):i.jsx(Kl.Provider,{value:{currentUser:n,setCurrentUser:r},children:i.jsxs(i.Fragment,{children:[i.jsx(Uh,{archives:l,archiveId:a,onArchiveChange:L,view:C,onViewChange:W,onCaptureClick:fd}),i.jsxs("main",{className:"app-shell",children:[i.jsxs("div",{className:"workspace",children:[C==="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",{ref:$,className:"search-input",type:"search","aria-label":"Search archive","aria-busy":S,placeholder:"Search titles, URLs, types, tags…",value:y,onChange:D=>j(D.target.value)}),i.jsx("span",{className:"kbd",children:"⌘K"})]}),i.jsxs("span",{className:"result-count",children:[E&&i.jsxs(i.Fragment,{children:[i.jsx("b",{children:E.split(" ")[0]})," ",E.split(" ").slice(1).join(" ")]}),x&&i.jsxs("button",{className:"tag-filter-badge",onClick:z,children:["× ",V?td(x):x]})]})]}),C==="archive"&&i.jsx(Xh,{entries:u,selectedEntryUid:g,onSelectEntry:q,archiveId:a,tagFilter:x,onClearTagFilter:z,searchQuery:y,onSearchChange:j,resultCount:E,searchBusy:S}),C==="runs"&&i.jsx(Gh,{runs:I}),C==="admin"&&i.jsx(Zh,{archives:l}),C==="tags"&&i.jsx(em,{archiveId:a,tagNodes:te,tagFilter:x,onTagFilterSet:ae,onViewChange:W,onTagRenamed:ze,onTagDeleted:Ce,onTagsRefresh:K,humanizeTags:V}),C==="collections"&&i.jsx(nm,{archiveId:a}),C==="settings"&&i.jsx(lm,{tab:f,onTabChange:v,archiveId:a})]}),i.jsx(fm,{archiveId:a,selectedEntry:d,detail:X,onTagFilterSet:ae,tagNodes:te,onTagsRefresh:K,onEntryTitleChange:ud,onEntryDeleted:dd,humanizeTags:V,onDetailRefresh:cd,onOpenPreview:yd,onPlay:wd})]}),ya&&d&&d.entry_uid===ya&&i.jsx(Em,{archiveId:a,entry:d,detail:X,onClose:xd}),In&&i.jsx(Tm,{entry:In.entry,src:In.src,archiveId:a,onClose:kd}),i.jsx(Hh,{open:ne,archiveId:a,onClose:pd,onCaptured:hd,onToast:md}),i.jsx(Rm,{toasts:Re,onDismiss:gd,onIgnoreUblock:vd})]})})}Gc(document.getElementById("root")).render(i.jsx(p.StrictMode,{children:i.jsx(Om,{})}));