(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 o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).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 va={exports:{}},gl={},ya={exports:{}},B={};/** * @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 fr=Symbol.for("react.element"),$c=Symbol.for("react.portal"),Mc=Symbol.for("react.fragment"),Fc=Symbol.for("react.strict_mode"),Ac=Symbol.for("react.profiler"),Ic=Symbol.for("react.provider"),Uc=Symbol.for("react.context"),Bc=Symbol.for("react.forward_ref"),Vc=Symbol.for("react.suspense"),Wc=Symbol.for("react.memo"),Hc=Symbol.for("react.lazy"),no=Symbol.iterator;function Qc(e){return e===null||typeof e!="object"?null:(e=no&&e[no]||e["@@iterator"],typeof e=="function"?e:null)}var wa={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},xa=Object.assign,Sa={};function jn(e,t,n){this.props=e,this.context=t,this.refs=Sa,this.updater=n||wa}jn.prototype.isReactComponent={};jn.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")};jn.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function ka(){}ka.prototype=jn.prototype;function ai(e,t,n){this.props=e,this.context=t,this.refs=Sa,this.updater=n||wa}var ui=ai.prototype=new ka;ui.constructor=ai;xa(ui,jn.prototype);ui.isPureReactComponent=!0;var ro=Array.isArray,ja=Object.prototype.hasOwnProperty,ci={current:null},Na={key:!0,ref:!0,__self:!0,__source:!0};function Ca(e,t,n){var r,l={},s=null,o=null;if(t!=null)for(r in t.ref!==void 0&&(o=t.ref),t.key!==void 0&&(s=""+t.key),t)ja.call(t,r)&&!Na.hasOwnProperty(r)&&(l[r]=t[r]);var a=arguments.length-2;if(a===1)l.children=n;else if(1>>1,A=z[Q];if(0>>1;Ql(Qe,M))Fel(lt,Qe)?(z[Q]=lt,z[Fe]=M,Q=Fe):(z[Q]=Qe,z[ce]=M,Q=ce);else if(Fel(lt,M))z[Q]=lt,z[Fe]=M,Q=Fe;else break e}}return C}function l(z,C){var M=z.sortIndex-C.sortIndex;return M!==0?M:z.id-C.id}if(typeof performance=="object"&&typeof performance.now=="function"){var s=performance;e.unstable_now=function(){return s.now()}}else{var o=Date,a=o.now();e.unstable_now=function(){return o.now()-a}}var u=[],c=[],y=1,g=null,m=3,w=!1,S=!1,j=!1,O=typeof setTimeout=="function"?setTimeout:null,f=typeof clearTimeout=="function"?clearTimeout:null,d=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function h(z){for(var C=n(c);C!==null;){if(C.callback===null)r(c);else if(C.startTime<=z)r(c),C.sortIndex=C.expirationTime,t(u,C);else break;C=n(c)}}function x(z){if(j=!1,h(z),!S)if(n(u)!==null)S=!0,q(k);else{var C=n(c);C!==null&&Me(x,C.startTime-z)}}function k(z,C){S=!1,j&&(j=!1,f(p),p=-1),w=!0;var M=m;try{for(h(C),g=n(u);g!==null&&(!(g.expirationTime>C)||z&&!I());){var Q=g.callback;if(typeof Q=="function"){g.callback=null,m=g.priorityLevel;var A=Q(g.expirationTime<=C);C=e.unstable_now(),typeof A=="function"?g.callback=A:g===n(u)&&r(u),h(C)}else r(u);g=n(u)}if(g!==null)var we=!0;else{var ce=n(c);ce!==null&&Me(x,ce.startTime-C),we=!1}return we}finally{g=null,m=M,w=!1}}var E=!1,L=null,p=-1,N=5,T=-1;function I(){return!(e.unstable_now()-Tz||125Q?(z.sortIndex=M,t(c,z),n(u)===null&&z===n(c)&&(j?(f(p),p=-1):j=!0,Me(x,M-Q))):(z.sortIndex=A,t(u,z),S||w||(S=!0,q(k))),z},e.unstable_shouldYield=I,e.unstable_wrapCallback=function(z){var C=m;return function(){var M=m;m=C;try{return z.apply(this,arguments)}finally{m=M}}}})(La);Pa.exports=La;var nd=Pa.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 rd=v,De=nd;function _(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"),hs=Object.prototype.hasOwnProperty,ld=/^[: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]*$/,so={},io={};function sd(e){return hs.call(io,e)?!0:hs.call(so,e)?!1:ld.test(e)?io[e]=!0:(so[e]=!0,!1)}function id(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 od(e,t,n,r){if(t===null||typeof t>"u"||id(e,t,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function je(e,t,n,r,l,s,o){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=o}var he={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){he[e]=new je(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];he[t]=new je(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){he[e]=new je(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){he[e]=new je(e,2,!1,e,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){he[e]=new je(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){he[e]=new je(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){he[e]=new je(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){he[e]=new je(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){he[e]=new je(e,5,!1,e.toLowerCase(),null,!1,!1)});var fi=/[\-:]([a-z])/g;function pi(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(fi,pi);he[t]=new je(t,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(fi,pi);he[t]=new je(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(fi,pi);he[t]=new je(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){he[e]=new je(e,1,!1,e.toLowerCase(),null,!1,!1)});he.xlinkHref=new je("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){he[e]=new je(e,1,!1,e.toLowerCase(),null,!0,!0)});function hi(e,t,n,r){var l=he.hasOwnProperty(t)?he[t]:null;(l!==null?l.type!==0:r||!(2a||l[o]!==s[a]){var u=` `+l[o].replace(" at new "," at ");return e.displayName&&u.includes("")&&(u=u.replace("",e.displayName)),u}while(1<=o&&0<=a);break}}}finally{Ul=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?$n(e):""}function ad(e){switch(e.tag){case 5:return $n(e.type);case 16:return $n("Lazy");case 13:return $n("Suspense");case 19:return $n("SuspenseList");case 0:case 2:case 15:return e=Bl(e.type,!1),e;case 11:return e=Bl(e.type.render,!1),e;case 1:return e=Bl(e.type,!0),e;default:return""}}function ys(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 Zt:return"Fragment";case qt:return"Portal";case ms:return"Profiler";case mi:return"StrictMode";case gs:return"Suspense";case vs:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Da:return(e.displayName||"Context")+".Consumer";case Ra:return(e._context.displayName||"Context")+".Provider";case gi:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case vi:return t=e.displayName||null,t!==null?t:ys(e.type)||"Memo";case gt:t=e._payload,e=e._init;try{return ys(e(t))}catch{}}return null}function ud(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 ys(t);case 8:return t===mi?"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 Lt(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function $a(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function cd(e){var t=$a(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(o){r=""+o,s.call(this,o)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(o){r=""+o},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function wr(e){e._valueTracker||(e._valueTracker=cd(e))}function Ma(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=$a(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function Kr(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 ws(e,t){var n=t.checked;return te({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function ao(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=Lt(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 Fa(e,t){t=t.checked,t!=null&&hi(e,"checked",t,!1)}function xs(e,t){Fa(e,t);var n=Lt(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")?Ss(e,t.type,n):t.hasOwnProperty("defaultValue")&&Ss(e,t.type,Lt(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function uo(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 Ss(e,t,n){(t!=="number"||Kr(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var Mn=Array.isArray;function cn(e,t,n,r){if(e=e.options,t){t={};for(var l=0;l"+t.valueOf().toString()+"",t=xr.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Xn(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Un={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},dd=["Webkit","ms","Moz","O"];Object.keys(Un).forEach(function(e){dd.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Un[t]=Un[e]})});function Ba(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Un.hasOwnProperty(e)&&Un[e]?(""+t).trim():t+"px"}function Va(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,l=Ba(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,l):e[n]=l}}var fd=te({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 Ns(e,t){if(t){if(fd[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(_(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(_(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(_(61))}if(t.style!=null&&typeof t.style!="object")throw Error(_(62))}}function Cs(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 _s=null;function yi(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Es=null,dn=null,fn=null;function po(e){if(e=mr(e)){if(typeof Es!="function")throw Error(_(280));var t=e.stateNode;t&&(t=Sl(t),Es(e.stateNode,e.type,t))}}function Wa(e){dn?fn?fn.push(e):fn=[e]:dn=e}function Ha(){if(dn){var e=dn,t=fn;if(fn=dn=null,po(e),t)for(e=0;e>>=0,e===0?32:31-(jd(e)/Nd|0)|0}var Sr=64,kr=4194304;function Fn(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 Xr(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,l=e.suspendedLanes,s=e.pingedLanes,o=n&268435455;if(o!==0){var a=o&~l;a!==0?r=Fn(a):(s&=o,s!==0&&(r=Fn(s)))}else o=n&~l,o!==0?r=Fn(o):s!==0&&(r=Fn(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 pr(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Xe(t),e[t]=n}function Td(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=Vn),ko=" ",jo=!1;function cu(e,t){switch(e){case"keyup":return nf.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function du(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var bt=!1;function lf(e,t){switch(e){case"compositionend":return du(t);case"keypress":return t.which!==32?null:(jo=!0,ko);case"textInput":return e=t.data,e===ko&&jo?null:e;default:return null}}function sf(e,t){if(bt)return e==="compositionend"||!_i&&cu(e,t)?(e=au(),Fr=ji=xt=null,bt=!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=Eo(n)}}function mu(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?mu(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function gu(){for(var e=window,t=Kr();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=Kr(e.document)}return t}function Ei(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 mf(e){var t=gu(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&mu(n.ownerDocument.documentElement,n)){if(r!==null&&Ei(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=To(n,s);var o=To(n,r);l&&o&&(e.rangeCount!==1||e.anchorNode!==l.node||e.anchorOffset!==l.offset||e.focusNode!==o.node||e.focusOffset!==o.offset)&&(t=t.createRange(),t.setStart(l.node,l.offset),e.removeAllRanges(),s>r?(e.addRange(t),e.extend(o.node,o.offset)):(t.setEnd(o.node,o.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,en=null,Ds=null,Hn=null,Os=!1;function Po(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Os||en==null||en!==Kr(r)||(r=en,"selectionStart"in r&&Ei(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}),Hn&&nr(Hn,r)||(Hn=r,r=br(Ds,"onSelect"),0rn||(e.current=Us[rn],Us[rn]=null,rn--)}function Y(e,t){rn++,Us[rn]=e.current,e.current=t}var zt={},ye=Dt(zt),_e=Dt(!1),Wt=zt;function vn(e,t){var n=e.type.contextTypes;if(!n)return zt;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 Ee(e){return e=e.childContextTypes,e!=null}function tl(){X(_e),X(ye)}function Mo(e,t,n){if(ye.current!==zt)throw Error(_(168));Y(ye,t),Y(_e,n)}function Cu(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(_(108,ud(e)||"Unknown",l));return te({},n,r)}function nl(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||zt,Wt=ye.current,Y(ye,e),Y(_e,_e.current),!0}function Fo(e,t,n){var r=e.stateNode;if(!r)throw Error(_(169));n?(e=Cu(e,t,Wt),r.__reactInternalMemoizedMergedChildContext=e,X(_e),X(ye),Y(ye,e)):X(_e),Y(_e,n)}var it=null,kl=!1,ts=!1;function _u(e){it===null?it=[e]:it.push(e)}function Ef(e){kl=!0,_u(e)}function Ot(){if(!ts&&it!==null){ts=!0;var e=0,t=J;try{var n=it;for(J=1;e>=o,l-=o,ot=1<<32-Xe(t)+l|n<p?(N=L,L=null):N=L.sibling;var T=m(f,L,h[p],x);if(T===null){L===null&&(L=N);break}e&&L&&T.alternate===null&&t(f,L),d=s(T,d,p),E===null?k=T:E.sibling=T,E=T,L=N}if(p===h.length)return n(f,L),Z&&$t(f,p),k;if(L===null){for(;pp?(N=L,L=null):N=L.sibling;var I=m(f,L,T.value,x);if(I===null){L===null&&(L=N);break}e&&L&&I.alternate===null&&t(f,L),d=s(I,d,p),E===null?k=I:E.sibling=I,E=I,L=N}if(T.done)return n(f,L),Z&&$t(f,p),k;if(L===null){for(;!T.done;p++,T=h.next())T=g(f,T.value,x),T!==null&&(d=s(T,d,p),E===null?k=T:E.sibling=T,E=T);return Z&&$t(f,p),k}for(L=r(f,L);!T.done;p++,T=h.next())T=w(L,f,p,T.value,x),T!==null&&(e&&T.alternate!==null&&L.delete(T.key===null?p:T.key),d=s(T,d,p),E===null?k=T:E.sibling=T,E=T);return e&&L.forEach(function(U){return t(f,U)}),Z&&$t(f,p),k}function O(f,d,h,x){if(typeof h=="object"&&h!==null&&h.type===Zt&&h.key===null&&(h=h.props.children),typeof h=="object"&&h!==null){switch(h.$$typeof){case yr:e:{for(var k=h.key,E=d;E!==null;){if(E.key===k){if(k=h.type,k===Zt){if(E.tag===7){n(f,E.sibling),d=l(E,h.props.children),d.return=f,f=d;break e}}else if(E.elementType===k||typeof k=="object"&&k!==null&&k.$$typeof===gt&&Uo(k)===E.type){n(f,E.sibling),d=l(E,h.props),d.ref=zn(f,E,h),d.return=f,f=d;break e}n(f,E);break}else t(f,E);E=E.sibling}h.type===Zt?(d=Vt(h.props.children,f.mode,x,h.key),d.return=f,f=d):(x=Qr(h.type,h.key,h.props,null,f.mode,x),x.ref=zn(f,d,h),x.return=f,f=x)}return o(f);case qt:e:{for(E=h.key;d!==null;){if(d.key===E)if(d.tag===4&&d.stateNode.containerInfo===h.containerInfo&&d.stateNode.implementation===h.implementation){n(f,d.sibling),d=l(d,h.children||[]),d.return=f,f=d;break e}else{n(f,d);break}else t(f,d);d=d.sibling}d=us(h,f.mode,x),d.return=f,f=d}return o(f);case gt:return E=h._init,O(f,d,E(h._payload),x)}if(Mn(h))return S(f,d,h,x);if(_n(h))return j(f,d,h,x);Pr(f,h)}return typeof h=="string"&&h!==""||typeof h=="number"?(h=""+h,d!==null&&d.tag===6?(n(f,d.sibling),d=l(d,h),d.return=f,f=d):(n(f,d),d=as(h,f.mode,x),d.return=f,f=d),o(f)):n(f,d)}return O}var wn=Lu(!0),zu=Lu(!1),sl=Dt(null),il=null,on=null,zi=null;function Ri(){zi=on=il=null}function Di(e){var t=sl.current;X(sl),e._currentValue=t}function Ws(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 hn(e,t){il=e,zi=on=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Ce=!0),e.firstContext=null)}function We(e){var t=e._currentValue;if(zi!==e)if(e={context:e,memoizedValue:t,next:null},on===null){if(il===null)throw Error(_(308));on=e,il.dependencies={lanes:0,firstContext:e}}else on=on.next=e;return t}var At=null;function Oi(e){At===null?At=[e]:At.push(e)}function Ru(e,t,n,r){var l=t.interleaved;return l===null?(n.next=n,Oi(t)):(n.next=l.next,l.next=n),t.interleaved=n,ft(e,r)}function ft(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 vt=!1;function $i(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Du(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 ut(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function _t(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,W&2){var l=r.pending;return l===null?t.next=t:(t.next=l.next,l.next=t),r.pending=t,ft(e,n)}return l=r.interleaved,l===null?(t.next=t,Oi(r)):(t.next=l.next,l.next=t),r.interleaved=t,ft(e,n)}function Ir(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,xi(e,n)}}function Bo(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 o={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};s===null?l=s=o:s=s.next=o,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 ol(e,t,n,r){var l=e.updateQueue;vt=!1;var s=l.firstBaseUpdate,o=l.lastBaseUpdate,a=l.shared.pending;if(a!==null){l.shared.pending=null;var u=a,c=u.next;u.next=null,o===null?s=c:o.next=c,o=u;var y=e.alternate;y!==null&&(y=y.updateQueue,a=y.lastBaseUpdate,a!==o&&(a===null?y.firstBaseUpdate=c:a.next=c,y.lastBaseUpdate=u))}if(s!==null){var g=l.baseState;o=0,y=c=u=null,a=s;do{var m=a.lane,w=a.eventTime;if((r&m)===m){y!==null&&(y=y.next={eventTime:w,lane:0,tag:a.tag,payload:a.payload,callback:a.callback,next:null});e:{var S=e,j=a;switch(m=t,w=n,j.tag){case 1:if(S=j.payload,typeof S=="function"){g=S.call(w,g,m);break e}g=S;break e;case 3:S.flags=S.flags&-65537|128;case 0:if(S=j.payload,m=typeof S=="function"?S.call(w,g,m):S,m==null)break e;g=te({},g,m);break e;case 2:vt=!0}}a.callback!==null&&a.lane!==0&&(e.flags|=64,m=l.effects,m===null?l.effects=[a]:m.push(a))}else w={eventTime:w,lane:m,tag:a.tag,payload:a.payload,callback:a.callback,next:null},y===null?(c=y=w,u=g):y=y.next=w,o|=m;if(a=a.next,a===null){if(a=l.shared.pending,a===null)break;m=a,a=m.next,m.next=null,l.lastBaseUpdate=m,l.shared.pending=null}}while(!0);if(y===null&&(u=g),l.baseState=u,l.firstBaseUpdate=c,l.lastBaseUpdate=y,t=l.shared.interleaved,t!==null){l=t;do o|=l.lane,l=l.next;while(l!==t)}else s===null&&(l.shared.lanes=0);Kt|=o,e.lanes=o,e.memoizedState=g}}function Vo(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=rs.transition;rs.transition={};try{e(!1),t()}finally{J=n,rs.transition=r}}function Xu(){return He().memoizedState}function zf(e,t,n){var r=Tt(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},qu(e))Zu(t,n);else if(n=Ru(e,t,n,r),n!==null){var l=Se();qe(n,e,r,l),bu(n,t,r)}}function Rf(e,t,n){var r=Tt(e),l={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(qu(e))Zu(t,l);else{var s=e.alternate;if(e.lanes===0&&(s===null||s.lanes===0)&&(s=t.lastRenderedReducer,s!==null))try{var o=t.lastRenderedState,a=s(o,n);if(l.hasEagerState=!0,l.eagerState=a,Ze(a,o)){var u=t.interleaved;u===null?(l.next=l,Oi(t)):(l.next=u.next,u.next=l),t.interleaved=l;return}}catch{}finally{}n=Ru(e,t,l,r),n!==null&&(l=Se(),qe(n,e,r,l),bu(n,t,r))}}function qu(e){var t=e.alternate;return e===ee||t!==null&&t===ee}function Zu(e,t){Qn=ul=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function bu(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,xi(e,n)}}var cl={readContext:We,useCallback:me,useContext:me,useEffect:me,useImperativeHandle:me,useInsertionEffect:me,useLayoutEffect:me,useMemo:me,useReducer:me,useRef:me,useState:me,useDebugValue:me,useDeferredValue:me,useTransition:me,useMutableSource:me,useSyncExternalStore:me,useId:me,unstable_isNewReconciler:!1},Df={readContext:We,useCallback:function(e,t){return et().memoizedState=[e,t===void 0?null:t],e},useContext:We,useEffect:Ho,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,Br(4194308,4,Qu.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Br(4194308,4,e,t)},useInsertionEffect:function(e,t){return Br(4,2,e,t)},useMemo:function(e,t){var n=et();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=et();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=zf.bind(null,ee,e),[r.memoizedState,e]},useRef:function(e){var t=et();return e={current:e},t.memoizedState=e},useState:Wo,useDebugValue:Wi,useDeferredValue:function(e){return et().memoizedState=e},useTransition:function(){var e=Wo(!1),t=e[0];return e=Lf.bind(null,e[1]),et().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=ee,l=et();if(Z){if(n===void 0)throw Error(_(407));n=n()}else{if(n=t(),ae===null)throw Error(_(349));Qt&30||Fu(r,t,n)}l.memoizedState=n;var s={value:n,getSnapshot:t};return l.queue=s,Ho(Iu.bind(null,r,s,e),[e]),r.flags|=2048,cr(9,Au.bind(null,r,s,n,t),void 0,null),n},useId:function(){var e=et(),t=ae.identifierPrefix;if(Z){var n=at,r=ot;n=(r&~(1<<32-Xe(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=ar++,0<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=o.createElement(n,{is:r.is}):(e=o.createElement(n),n==="select"&&(o=e,r.multiple?o.multiple=!0:r.size&&(o.size=r.size))):e=o.createElementNS(e,n),e[tt]=t,e[sr]=r,uc(e,t,!1,!1),t.stateNode=e;e:{switch(o=Cs(n,r),n){case"dialog":G("cancel",e),G("close",e),l=r;break;case"iframe":case"object":case"embed":G("load",e),l=r;break;case"video":case"audio":for(l=0;lkn&&(t.flags|=128,r=!0,Rn(s,!1),t.lanes=4194304)}else{if(!r)if(e=al(o),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Rn(s,!0),s.tail===null&&s.tailMode==="hidden"&&!o.alternate&&!Z)return ge(t),null}else 2*re()-s.renderingStartTime>kn&&n!==1073741824&&(t.flags|=128,r=!0,Rn(s,!1),t.lanes=4194304);s.isBackwards?(o.sibling=t.child,t.child=o):(n=s.last,n!==null?n.sibling=o:t.child=o,s.last=o)}return s.tail!==null?(t=s.tail,s.rendering=t,s.tail=t.sibling,s.renderingStartTime=re(),t.sibling=null,n=b.current,Y(b,r?n&1|2:n&1),t):(ge(t),null);case 22:case 23:return Gi(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?Le&1073741824&&(ge(t),t.subtreeFlags&6&&(t.flags|=8192)):ge(t),null;case 24:return null;case 25:return null}throw Error(_(156,t.tag))}function Bf(e,t){switch(Pi(t),t.tag){case 1:return Ee(t.type)&&tl(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return xn(),X(_e),X(ye),Ai(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Fi(t),null;case 13:if(X(b),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(_(340));yn()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return X(b),null;case 4:return xn(),null;case 10:return Di(t.type._context),null;case 22:case 23:return Gi(),null;case 24:return null;default:return null}}var zr=!1,ve=!1,Vf=typeof WeakSet=="function"?WeakSet:Set,D=null;function an(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){ne(e,t,r)}else n.current=null}function Zs(e,t,n){try{n()}catch(r){ne(e,t,r)}}var ta=!1;function Wf(e,t){if($s=qr,e=gu(),Ei(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 o=0,a=-1,u=-1,c=0,y=0,g=e,m=null;t:for(;;){for(var w;g!==n||l!==0&&g.nodeType!==3||(a=o+l),g!==s||r!==0&&g.nodeType!==3||(u=o+r),g.nodeType===3&&(o+=g.nodeValue.length),(w=g.firstChild)!==null;)m=g,g=w;for(;;){if(g===e)break t;if(m===n&&++c===l&&(a=o),m===s&&++y===r&&(u=o),(w=g.nextSibling)!==null)break;g=m,m=g.parentNode}g=w}n=a===-1||u===-1?null:{start:a,end:u}}else n=null}n=n||{start:0,end:0}}else n=null;for(Ms={focusedElem:e,selectionRange:n},qr=!1,D=t;D!==null;)if(t=D,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,D=e;else for(;D!==null;){t=D;try{var S=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(S!==null){var j=S.memoizedProps,O=S.memoizedState,f=t.stateNode,d=f.getSnapshotBeforeUpdate(t.elementType===t.type?j:Je(t.type,j),O);f.__reactInternalSnapshotBeforeUpdate=d}break;case 3:var h=t.stateNode.containerInfo;h.nodeType===1?h.textContent="":h.nodeType===9&&h.documentElement&&h.removeChild(h.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(_(163))}}catch(x){ne(t,t.return,x)}if(e=t.sibling,e!==null){e.return=t.return,D=e;break}D=t.return}return S=ta,ta=!1,S}function Kn(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&&Zs(t,n,s)}l=l.next}while(l!==r)}}function Cl(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 bs(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 fc(e){var t=e.alternate;t!==null&&(e.alternate=null,fc(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[tt],delete t[sr],delete t[Is],delete t[Cf],delete t[_f])),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 pc(e){return e.tag===5||e.tag===3||e.tag===4}function na(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||pc(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 ei(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=el));else if(r!==4&&(e=e.child,e!==null))for(ei(e,t,n),e=e.sibling;e!==null;)ei(e,t,n),e=e.sibling}function ti(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(ti(e,t,n),e=e.sibling;e!==null;)ti(e,t,n),e=e.sibling}var fe=null,Ye=!1;function mt(e,t,n){for(n=n.child;n!==null;)hc(e,t,n),n=n.sibling}function hc(e,t,n){if(nt&&typeof nt.onCommitFiberUnmount=="function")try{nt.onCommitFiberUnmount(vl,n)}catch{}switch(n.tag){case 5:ve||an(n,t);case 6:var r=fe,l=Ye;fe=null,mt(e,t,n),fe=r,Ye=l,fe!==null&&(Ye?(e=fe,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):fe.removeChild(n.stateNode));break;case 18:fe!==null&&(Ye?(e=fe,n=n.stateNode,e.nodeType===8?es(e.parentNode,n):e.nodeType===1&&es(e,n),er(e)):es(fe,n.stateNode));break;case 4:r=fe,l=Ye,fe=n.stateNode.containerInfo,Ye=!0,mt(e,t,n),fe=r,Ye=l;break;case 0:case 11:case 14:case 15:if(!ve&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){l=r=r.next;do{var s=l,o=s.destroy;s=s.tag,o!==void 0&&(s&2||s&4)&&Zs(n,t,o),l=l.next}while(l!==r)}mt(e,t,n);break;case 1:if(!ve&&(an(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(a){ne(n,t,a)}mt(e,t,n);break;case 21:mt(e,t,n);break;case 22:n.mode&1?(ve=(r=ve)||n.memoizedState!==null,mt(e,t,n),ve=r):mt(e,t,n);break;default:mt(e,t,n)}}function ra(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new Vf),t.forEach(function(r){var l=Zf.bind(null,e,r);n.has(r)||(n.add(r),r.then(l,l))})}}function Ke(e,t){var n=t.deletions;if(n!==null)for(var r=0;rl&&(l=o),r&=~s}if(r=l,r=re()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Qf(r/1960))-r,10e?16:e,St===null)var r=!1;else{if(e=St,St=null,pl=0,W&6)throw Error(_(331));var l=W;for(W|=4,D=e.current;D!==null;){var s=D,o=s.child;if(D.flags&16){var a=s.deletions;if(a!==null){for(var u=0;ure()-Ji?Bt(e,0):Ki|=n),Te(e,t)}function kc(e,t){t===0&&(e.mode&1?(t=kr,kr<<=1,!(kr&130023424)&&(kr=4194304)):t=1);var n=Se();e=ft(e,t),e!==null&&(pr(e,t,n),Te(e,n))}function qf(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),kc(e,n)}function Zf(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(_(314))}r!==null&&r.delete(t),kc(e,n)}var jc;jc=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||_e.current)Ce=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return Ce=!1,If(e,t,n);Ce=!!(e.flags&131072)}else Ce=!1,Z&&t.flags&1048576&&Eu(t,ll,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Vr(e,t),e=t.pendingProps;var l=vn(t,ye.current);hn(t,n),l=Ui(null,t,r,e,l,n);var s=Bi();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,Ee(r)?(s=!0,nl(t)):s=!1,t.memoizedState=l.state!==null&&l.state!==void 0?l.state:null,$i(t),l.updater=Nl,t.stateNode=l,l._reactInternals=t,Qs(t,r,e,n),t=Ys(null,t,r,!0,s,n)):(t.tag=0,Z&&s&&Ti(t),xe(null,t,l,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Vr(e,t),e=t.pendingProps,l=r._init,r=l(r._payload),t.type=r,l=t.tag=ep(r),e=Je(r,e),l){case 0:t=Js(null,t,r,e,n);break e;case 1:t=Zo(null,t,r,e,n);break e;case 11:t=Xo(null,t,r,e,n);break e;case 14:t=qo(null,t,r,Je(r.type,e),n);break e}throw Error(_(306,r,""))}return t;case 0:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Je(r,l),Js(e,t,r,l,n);case 1:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Je(r,l),Zo(e,t,r,l,n);case 3:e:{if(ic(t),e===null)throw Error(_(387));r=t.pendingProps,s=t.memoizedState,l=s.element,Du(e,t),ol(t,r,null,n);var o=t.memoizedState;if(r=o.element,s.isDehydrated)if(s={element:r,isDehydrated:!1,cache:o.cache,pendingSuspenseBoundaries:o.pendingSuspenseBoundaries,transitions:o.transitions},t.updateQueue.baseState=s,t.memoizedState=s,t.flags&256){l=Sn(Error(_(423)),t),t=bo(e,t,r,n,l);break e}else if(r!==l){l=Sn(Error(_(424)),t),t=bo(e,t,r,n,l);break e}else for(ze=Ct(t.stateNode.containerInfo.firstChild),Re=t,Z=!0,Ge=null,n=zu(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(yn(),r===l){t=pt(e,t,n);break e}xe(e,t,r,n)}t=t.child}return t;case 5:return Ou(t),e===null&&Vs(t),r=t.type,l=t.pendingProps,s=e!==null?e.memoizedProps:null,o=l.children,Fs(r,l)?o=null:s!==null&&Fs(r,s)&&(t.flags|=32),sc(e,t),xe(e,t,o,n),t.child;case 6:return e===null&&Vs(t),null;case 13:return oc(e,t,n);case 4:return Mi(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=wn(t,null,r,n):xe(e,t,r,n),t.child;case 11:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Je(r,l),Xo(e,t,r,l,n);case 7:return xe(e,t,t.pendingProps,n),t.child;case 8:return xe(e,t,t.pendingProps.children,n),t.child;case 12:return xe(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,l=t.pendingProps,s=t.memoizedProps,o=l.value,Y(sl,r._currentValue),r._currentValue=o,s!==null)if(Ze(s.value,o)){if(s.children===l.children&&!_e.current){t=pt(e,t,n);break e}}else for(s=t.child,s!==null&&(s.return=t);s!==null;){var a=s.dependencies;if(a!==null){o=s.child;for(var u=a.firstContext;u!==null;){if(u.context===r){if(s.tag===1){u=ut(-1,n&-n),u.tag=2;var c=s.updateQueue;if(c!==null){c=c.shared;var y=c.pending;y===null?u.next=u:(u.next=y.next,y.next=u),c.pending=u}}s.lanes|=n,u=s.alternate,u!==null&&(u.lanes|=n),Ws(s.return,n,t),a.lanes|=n;break}u=u.next}}else if(s.tag===10)o=s.type===t.type?null:s.child;else if(s.tag===18){if(o=s.return,o===null)throw Error(_(341));o.lanes|=n,a=o.alternate,a!==null&&(a.lanes|=n),Ws(o,n,t),o=s.sibling}else o=s.child;if(o!==null)o.return=s;else for(o=s;o!==null;){if(o===t){o=null;break}if(s=o.sibling,s!==null){s.return=o.return,o=s;break}o=o.return}s=o}xe(e,t,l.children,n),t=t.child}return t;case 9:return l=t.type,r=t.pendingProps.children,hn(t,n),l=We(l),r=r(l),t.flags|=1,xe(e,t,r,n),t.child;case 14:return r=t.type,l=Je(r,t.pendingProps),l=Je(r.type,l),qo(e,t,r,l,n);case 15:return rc(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Je(r,l),Vr(e,t),t.tag=1,Ee(r)?(e=!0,nl(t)):e=!1,hn(t,n),ec(t,r,l),Qs(t,r,l,n),Ys(null,t,r,!0,e,n);case 19:return ac(e,t,n);case 22:return lc(e,t,n)}throw Error(_(156,t.tag))};function Nc(e,t){return qa(e,t)}function bf(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 Be(e,t,n,r){return new bf(e,t,n,r)}function qi(e){return e=e.prototype,!(!e||!e.isReactComponent)}function ep(e){if(typeof e=="function")return qi(e)?1:0;if(e!=null){if(e=e.$$typeof,e===gi)return 11;if(e===vi)return 14}return 2}function Pt(e,t){var n=e.alternate;return n===null?(n=Be(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 Qr(e,t,n,r,l,s){var o=2;if(r=e,typeof e=="function")qi(e)&&(o=1);else if(typeof e=="string")o=5;else e:switch(e){case Zt:return Vt(n.children,l,s,t);case mi:o=8,l|=8;break;case ms:return e=Be(12,n,t,l|2),e.elementType=ms,e.lanes=s,e;case gs:return e=Be(13,n,t,l),e.elementType=gs,e.lanes=s,e;case vs:return e=Be(19,n,t,l),e.elementType=vs,e.lanes=s,e;case Oa:return El(n,l,s,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Ra:o=10;break e;case Da:o=9;break e;case gi:o=11;break e;case vi:o=14;break e;case gt:o=16,r=null;break e}throw Error(_(130,e==null?e:typeof e,""))}return t=Be(o,n,t,l),t.elementType=e,t.type=r,t.lanes=s,t}function Vt(e,t,n,r){return e=Be(7,e,r,t),e.lanes=n,e}function El(e,t,n,r){return e=Be(22,e,r,t),e.elementType=Oa,e.lanes=n,e.stateNode={isHidden:!1},e}function as(e,t,n){return e=Be(6,e,null,t),e.lanes=n,e}function us(e,t,n){return t=Be(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function tp(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=Wl(0),this.expirationTimes=Wl(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Wl(0),this.identifierPrefix=r,this.onRecoverableError=l,this.mutableSourceEagerHydrationData=null}function Zi(e,t,n,r,l,s,o,a,u){return e=new tp(e,t,n,a,u),t===1?(t=1,s===!0&&(t|=8)):t=0,s=Be(3,null,null,t),e.current=s,s.stateNode=e,s.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},$i(s),e}function np(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Tc)}catch(e){console.error(e)}}Tc(),Ta.exports=Oe;var op=Ta.exports,Pc,da=op;Pc=da.createRoot,da.hydrateRoot;async function ue(e){const t=await fetch(e);if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()}async function ap(){return ue("/api/archives")}async function up(e){return ue(`/api/archives/${e}/entries`)}async function cp(e,t,n){const r=new URLSearchParams;return t&&r.set("q",t),n&&r.set("tag",n),ue(`/api/archives/${e}/entries/search?${r}`)}async function dp(e,t){return ue(`/api/archives/${e}/entries/${t}`)}async function fp(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 cs(e,t){return ue(`/api/archives/${e}/entries/${t}/tags`)}async function pp(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 hp(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 mp(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 gp(e,t,n){const r=await fetch(`/api/archives/${e}/tags/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n})});if(!r.ok)throw new Error(await r.text());return r.json()}async function vp(e,t){const n=await fetch(`/api/archives/${e}/tags/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(await n.text())}async function fa(e){return ue(`/api/archives/${e}/runs`)}async function ds(e){return ue(`/api/archives/${e}/tags`)}async function yp(e,t,n=null){const r={locator:t};n&&n!=="best"&&(r.quality=n);const l=await fetch(`/api/archives/${e}/captures`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!l.ok){const s=await l.json().catch(()=>({}));throw new Error(s.error||`HTTP ${l.status}`)}return l.json()}async function wp(e,t){return ue(`/api/archives/${e}/captures/probe?locator=${encodeURIComponent(t)}`)}async function xp(e,t){return ue(`/api/archives/${e}/capture_jobs/${t}`)}async function Sp(){return(await(await fetch("/api/auth/setup")).json()).setup_required===!0}async function kp(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 jp(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 Np(){await fetch("/api/auth/logout",{method:"POST"})}async function Cp(){const e=await fetch("/api/auth/me");return e.status===401?null:e.json()}async function _p(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 Ep(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 Tp(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 Pp(){return ue("/api/auth/tokens")}async function Lp(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 zp(e){const t=await fetch(`/api/auth/tokens/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(await t.text())}async function Rp(){return ue("/api/admin/instance-settings")}async function Dp(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 Op(){return ue("/api/admin/users")}async function $p(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 Mp(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 Fp(){return ue("/api/admin/roles")}async function Ap(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 Ip(e){return ue(`/api/archives/${e}/collections`)}async function Up(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 Bp(e,t){return ue(`/api/archives/${e}/collections/${t}`)}async function Vp(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 Wp(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 Hp(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 Qp(e,t){return ue(`/api/archives/${e}/entries/${t}/collections`)}async function pa(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 Kp(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 Jp(e){return ue(`/api/archives/${e}/blob-cleanup`)}async function Yp(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 Gp(){return ue("/api/admin/cookie-rules")}async function Xp(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 qp(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 Zp(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 bp=window.fetch;window.fetch=async(...e)=>{var n;const t=await bp(...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 eh({onLogin:e}){const[t,n]=v.useState(""),[r,l]=v.useState(""),[s,o]=v.useState(null),[a,u]=v.useState(!1);async function c(y){y.preventDefault(),o(null),u(!0);try{const g=await jp(t,r);e(g)}catch(g){o(g.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:y=>n(y.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:y=>l(y.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:a,children:a?"Signing in…":"Sign in"})]})]})})}function th({onComplete:e}){const[t,n]=v.useState(""),[r,l]=v.useState(""),[s,o]=v.useState(""),[a,u]=v.useState(null),[c,y]=v.useState(!1);async function g(m){if(m.preventDefault(),r!==s){u("Passwords do not match");return}if(r.length<8){u("Password must be at least 8 characters");return}u(null),y(!0);try{await kp(t,r),e()}catch(w){u(w.message)}finally{y(!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:g,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:m=>n(m.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:m=>l(m.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:m=>o(m.target.value),required:!0,autoComplete:"new-password"})]}),a&&i.jsx("p",{className:"setup-error",children:a}),i.jsx("button",{className:"setup-submit",type:"submit",disabled:c,children:c?"Creating account…":"Create account"})]})]})})}function nh({archives:e,archiveId:t,onArchiveChange:n,view:r,onViewChange:l,onCaptureClick:s}){const{currentUser:o,setCurrentUser:a}=v.useContext(Rl)??{},[u,c]=v.useState(!1);async function y(){c(!0),await Np(),a(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:g=>n(g.target.value),children:e.map(g=>i.jsx("option",{value:g.id,children:g.label},g.id))})}),i.jsx("nav",{className:"nav","aria-label":"Primary",children:["archive","tags","collections","runs","admin","settings"].map(g=>i.jsx("button",{className:`nav-link${r===g?" is-active":""}`,onClick:()=>l(g),children:g.charAt(0).toUpperCase()+g.slice(1)},g))}),i.jsx("button",{className:"capture-button",onClick:s,children:"Capture"}),o&&i.jsxs("div",{className:"user-menu",children:[i.jsx("span",{className:"user-name",children:o.display_name||o.username}),i.jsx("button",{className:"logout-btn",onClick:y,disabled:u,children:u?"Logging out…":"Log out"})]})]})}let ii=1;function Lc(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 On(e=""){return{id:ii++,locator:e,quality:"best",probeState:"idle",probeQualities:null,probeHasAudio:!1,status:"idle",error:null,jobUid:null,archiveId:null}}function ha(e){return e.some(t=>t.status==="submitting"||t.status==="running")}function rh({open:e,archiveId:t,onClose:n,onCaptured:r,onToast:l}){const s=v.useRef(null),o=v.useRef(!0),a=v.useRef(new Map),u=v.useRef(new Map),c=v.useRef(t);v.useEffect(()=>{c.current=t},[t]);const y=v.useRef(r),g=v.useRef(l);v.useEffect(()=>{y.current=r},[r]),v.useEffect(()=>{g.current=l},[l]);const[m,w]=v.useState(()=>{try{const p=JSON.parse(sessionStorage.getItem("captureItems")||"null");if(Array.isArray(p)&&p.length>0)return p.forEach(N=>{N.id>=ii&&(ii=N.id+1)}),p}catch{}return[On()]});v.useEffect(()=>{sessionStorage.setItem("captureItems",JSON.stringify(m))},[m]),v.useEffect(()=>{["captureDialogLocator","captureDialogError","captureDialogBusy","captureDialogJobStatus","captureDialogJobUid"].forEach(p=>sessionStorage.removeItem(p)),w(p=>p.map(N=>N.status==="submitting"?{...N,status:"idle",error:null}:N)),m.forEach(p=>{p.status==="running"&&p.jobUid&&p.archiveId&&!a.current.has(p.jobUid)&&S(p.id,p.jobUid,p.locator,p.archiveId)})},[]),v.useEffect(()=>{const p=s.current;if(!p)return;const N=()=>{u.current.forEach(T=>clearTimeout(T)),u.current.clear(),n()};return p.addEventListener("close",N),()=>p.removeEventListener("close",N)},[n]),v.useEffect(()=>{const p=s.current;p&&(e?(!o.current&&!ha(m)&&w([On()]),o.current=!1,p.open||p.showModal()):(u.current.forEach(N=>clearTimeout(N)),u.current.clear(),p.open&&p.close()))},[e]),v.useEffect(()=>()=>{a.current.forEach(p=>clearInterval(p)),u.current.forEach(p=>clearTimeout(p))},[]);function S(p,N,T,I){if(a.current.has(N))return;const U=setInterval(async()=>{try{const P=await xp(I,N);if(P.status==="completed")clearInterval(a.current.get(N)),a.current.delete(N),w(F=>F.map(H=>H.id===p?{...H,status:"completed"}:H)),setTimeout(()=>{w(F=>{const H=F.filter(q=>q.id!==p);return H.length===0?[On()]:H})},1400),y.current();else if(P.status==="failed"){clearInterval(a.current.get(N)),a.current.delete(N);const F=P.error_text||"Capture failed.";w(H=>H.map(q=>q.id===p?{...q,status:"failed",error:F}:q)),g.current(F,T)}}catch(P){clearInterval(a.current.get(N)),a.current.delete(N);const F=P.message||"Network error";w(H=>H.map(q=>q.id===p?{...q,status:"failed",error:F}:q)),g.current(F,T)}},500);a.current.set(N,U)}async function j(p){if(!p.locator.trim())return;const N=t,T=p.locator.trim(),I=p.quality||"best";w(U=>U.map(P=>P.id===p.id?{...P,status:"submitting",error:null}:P));try{const U=await yp(N,T,I);w(P=>P.map(F=>F.id===p.id?{...F,status:"running",jobUid:U.job_uid,archiveId:N}:F)),S(p.id,U.job_uid,T,N)}catch(U){const P=U.message||"Submission failed.";w(F=>F.map(H=>H.id===p.id?{...H,status:"failed",error:P}:H)),g.current(P,T)}}function O(){m.filter(N=>N.status==="idle"&&N.locator.trim()).forEach(N=>j(N))}function f(){w(p=>[...p,On()])}function d(p){clearTimeout(u.current.get(p)),u.current.delete(p),w(N=>{const T=N.filter(I=>I.id!==p);return T.length===0?[On()]:T})}function h(p){w(N=>N.map(T=>T.id===p?{...T,status:"idle",error:null}:T))}function x(p,N){if(clearTimeout(u.current.get(p)),w(I=>I.map(U=>U.id===p?{...U,locator:N,probeState:"idle",probeQualities:null,probeHasAudio:!1,quality:"best"}:U)),!Lc(N))return;const T=setTimeout(async()=>{u.current.delete(p),w(I=>I.map(U=>U.id===p?{...U,probeState:"probing"}:U));try{const I=await wp(c.current,N.trim());w(U=>U.map(P=>{if(P.id!==p||P.locator!==N)return P;const F=I.qualities??[],H=I.has_audio??!1,q=F.length===0&&H?"audio":"best";return{...P,probeState:"done",probeQualities:F,probeHasAudio:H,quality:q}}))}catch{w(I=>I.map(U=>U.id===p?{...U,probeState:"idle",probeQualities:null}:U))}},600);u.current.set(p,T)}function k(p,N){w(T=>T.map(I=>I.id===p?{...I,quality:N}:I))}const E=m.filter(p=>p.status==="idle"&&p.locator.trim()).length,L=ha(m);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 p;return(p=s.current)==null?void 0:p.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:m.map((p,N)=>i.jsx(lh,{item:p,autoFocus:N===m.length-1&&p.status==="idle",onLocatorChange:T=>x(p.id,T),onQualityChange:T=>k(p.id,T),onRemove:()=>d(p.id),onReset:()=>h(p.id),onSubmit:O},p.id))}),i.jsxs("button",{type:"button",className:"capture-add-row",onClick:f,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-actions",children:[i.jsx("button",{type:"button",className:"capture-cancel",onClick:()=>{var p;return(p=s.current)==null?void 0:p.close()},children:L?"Close":"Cancel"}),i.jsx("button",{type:"button",className:"capture-submit",onClick:O,disabled:E===0,children:E>1?`Archive ${E}`:"Archive"})]})]})})}function lh({item:e,autoFocus:t,onLocatorChange:n,onQualityChange:r,onRemove:l,onReset:s,onSubmit:o}){const a=v.useRef(null),u=e.status==="submitting"||e.status==="running";v.useEffect(()=>{var y;t&&e.status==="idle"&&((y=a.current)==null||y.focus())},[t]);const c=(()=>{if(e.status==="completed"||u||!Lc(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 y=e.probeQualities??[],g=e.probeHasAudio??!1;return y.length===0&&!g?i.jsx("span",{className:"capture-quality-hint",children:"No media detected"}):y.length===0&&g?i.jsx("select",{className:"capture-quality",value:"audio",onChange:m=>r(m.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:m=>r(m.target.value),"aria-label":"Video quality",children:[i.jsx("option",{value:"best",children:"Best quality"}),y.map(m=>i.jsx("option",{value:m,children:m},m)),g&&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(sh,{status:e.status}),i.jsx("input",{ref:a,className:"capture-input",type:"text",placeholder:"https://… · yt:ID · ytm:ID · tweet:ID · x:ID",value:e.locator,onChange:y=>n(y.target.value),onKeyDown:y=>{y.key==="Enter"&&o()},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 sh({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 oi(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 Ut(e){return ih(e)??""}function zc(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 ma={youtube:'',youtube_music:'',spotify:'',x:'',instagram:'',facebook:'',tiktok:'',reddit:'',snapchat:'',local:'',web:'',other:'?'};function Rc(e){return ma[e]??ma.other}function Dc(e){return e.split("/").map(t=>t?t.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"").join("/")}function oh({entry:e,archiveId:t,isSelected:n,onSelect:r}){const[l,s]=v.useState(!1),a=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:Rc(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:zc(e.archived_at)}),i.jsxs("div",{className:"col-title",children:[i.jsx("span",{className:"source-icon",children:a}),i.jsx("span",{className:"entry-title",children:Ut(e.title)||Ut(e.entry_uid)})]}),i.jsx("div",{className:"col-type",children:i.jsx("span",{className:"type-pill",children:Ut(e.entity_kind)})}),i.jsxs("div",{className:"col-size",children:[i.jsx("span",{className:"size-total",children:oi(e.total_artifact_bytes)}),e.cached_bytes>0&&e.total_artifact_bytes>0&&i.jsxs("span",{className:"size-cached-pct",title:`${oi(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:Ut(e.original_url)})]})}function ah({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(oh,{entry:l,archiveId:r,isSelected:l.entry_uid===t,onSelect:()=>n(l)},l.entry_uid))})]})})}function uh(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 ch({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 dh({runs:e}){const[t,n]=v.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,o=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?o?"Click to hide error":"Click to view error":void 0,children:[i.jsx("td",{children:uh(l.started_at)}),i.jsxs("td",{children:[i.jsx(ch,{status:l.status}),s&&i.jsx("span",{className:"run-expand-hint","aria-hidden":"true",children:o?"▴":"▾"})]}),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&&o&&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 fh=4;function ph({archives:e}){const{currentUser:t}=v.useContext(Rl)??{},n=t&&(t.role_bits&fh)!==0,[r,l]=v.useState("users"),[s,o]=v.useState([]),[a,u]=v.useState([]),[c,y]=v.useState(!1),[g,m]=v.useState(null),[w,S]=v.useState(""),[j,O]=v.useState(""),[f,d]=v.useState(""),[h,x]=v.useState(null),[k,E]=v.useState(!1),[L,p]=v.useState(""),[N,T]=v.useState(""),[I,U]=v.useState(null),[P,F]=v.useState(!1),H=v.useCallback(async()=>{if(n){y(!0),m(null);try{const[C,M]=await Promise.all([Op(),Fp()]);o(C),u(M)}catch(C){m(C.message)}finally{y(!1)}}},[n]);v.useEffect(()=>{H()},[H]);async function q(C){const M=C.status==="active"?"disabled":"active";try{await Mp(C.user_uid,M),o(Q=>Q.map(A=>A.user_uid===C.user_uid?{...A,status:M}:A))}catch(Q){m(Q.message)}}async function Me(C){if(C.preventDefault(),!w.trim()||!j){x("Username and password required");return}E(!0),x(null);try{await $p(w.trim(),j,f.trim()||void 0),S(""),O(""),d(""),await H()}catch(M){x(M.message)}finally{E(!1)}}async function z(C){if(C.preventDefault(),!L.trim()||!N.trim()){U("Slug and name required");return}F(!0),U(null);try{await Ap(L.trim(),N.trim()),p(""),T(""),await H()}catch(M){U(M.message)}finally{F(!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"})]}),g&&i.jsx("div",{className:"form-msg form-msg--err",children:g}),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(C=>i.jsxs("tr",{className:C.status==="disabled"?"admin-row-disabled":"",children:[i.jsx("td",{children:C.username}),i.jsx("td",{className:"muted",children:C.email||"—"}),i.jsx("td",{children:C.role_slugs.join(", ")||"—"}),i.jsx("td",{children:i.jsx("span",{className:`status-badge status-${C.status}`,children:C.status})}),i.jsx("td",{children:i.jsx("button",{className:"admin-action-btn",onClick:()=>q(C),children:C.status==="active"?"Ban":"Unban"})})]},C.user_uid))})]}),i.jsx("h3",{children:"Create User"}),i.jsxs("form",{className:"admin-form",onSubmit:Me,children:[i.jsx("input",{className:"admin-input",placeholder:"Username",value:w,onChange:C=>S(C.target.value),required:!0}),i.jsx("input",{className:"admin-input",type:"password",placeholder:"Password (min 8 chars)",value:j,onChange:C=>O(C.target.value),required:!0}),i.jsx("input",{className:"admin-input",type:"email",placeholder:"Email (optional)",value:f,onChange:C=>d(C.target.value)}),h&&i.jsx("div",{className:"form-msg form-msg--err",children:h}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:k,children:k?"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:a.map(C=>i.jsxs("tr",{children:[i.jsx("td",{children:i.jsx("code",{children:C.slug})}),i.jsx("td",{children:C.name}),i.jsx("td",{children:C.level}),i.jsx("td",{children:C.bit_position}),i.jsx("td",{children:C.is_builtin?"✓":""})]},C.role_uid))})]}),i.jsx("h3",{children:"Create Custom Role"}),i.jsxs("form",{className:"admin-form",onSubmit:z,children:[i.jsx("input",{className:"admin-input",placeholder:"Slug (e.g. moderator)",value:L,onChange:C=>p(C.target.value),required:!0}),i.jsx("input",{className:"admin-input",placeholder:"Display Name (e.g. Moderator)",value:N,onChange:C=>T(C.target.value),required:!0}),I&&i.jsx("div",{className:"form-msg form-msg--err",children:I}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:P,children:P?"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(C=>i.jsxs("div",{className:"admin-archive",children:[i.jsx("strong",{children:C.label}),i.jsx("div",{className:"muted",children:C.archive_path})]},C.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(C=>i.jsxs("div",{className:"admin-archive",children:[i.jsx("strong",{children:C.label}),i.jsx("div",{className:"muted",children:C.archive_path})]},C.id))})]})}function Oc({node:e,archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:o,onTagsRefresh:a,humanizeTags:u}){var x;const c=n===e.tag.full_path,[y,g]=v.useState(!1),[m,w]=v.useState(""),S=v.useRef(!1);function j(){if(y)return;const k=c?null:e.tag.full_path;r(k),l("archive")}function O(k){k.stopPropagation(),w(e.tag.slug),g(!0)}async function f(){const k=m.trim();if(!k||k===e.tag.slug){g(!1);return}try{const E=await gp(t,e.tag.tag_uid,k);s(e.tag.full_path,E.full_path),a()}catch{}finally{g(!1)}}async function d(k){var L;k.stopPropagation();const E=((L=e.children)==null?void 0:L.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 vp(t,e.tag.tag_uid),o(e.tag.full_path),a()}catch{}}const h={archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:o,onTagsRefresh:a,humanizeTags:u};return i.jsxs("li",{children:[i.jsxs("div",{className:"tag-node-row",children:[y?i.jsx("input",{className:"tag-rename-input",autoFocus:!0,value:m,onChange:k=>w(k.target.value),onKeyDown:k=>{k.key==="Enter"&&k.currentTarget.blur(),k.key==="Escape"&&(S.current=!0,k.currentTarget.blur())},onBlur:()=>{S.current?(S.current=!1,g(!1)):f()}}):i.jsxs("button",{className:`tag-node-btn${c?" is-active":""}`,title:e.tag.full_path,onClick:j,onDoubleClick:O,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:k=>{k.stopPropagation(),O(k)},children:i.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),i.jsx("button",{className:"remove tag-node-delete",title:`Delete tag ${e.tag.full_path}`,onClick:d,"aria-label":`Delete tag ${e.tag.full_path}`,children:"×"})]}),((x=e.children)==null?void 0:x.length)>0&&i.jsx("div",{className:"tag-children",children:i.jsx("ul",{className:"tag-tree-list",children:e.children.map(k=>i.jsx(Oc,{node:k,...h},k.tag.tag_uid))})})]})}function hh({archiveId:e,tagNodes:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:o,onTagsRefresh:a,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(Oc,{node:c,archiveId:e,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:o,onTagsRefresh:a,humanizeTags:u},c.tag.tag_uid))})]})})}const In=[{value:0,label:"Private"},{value:2,label:"Users only"},{value:3,label:"Public"}],mh=e=>{var t;return((t=In.find(n=>n.value===e))==null?void 0:t.label)??String(e)};function gh({archiveId:e}){const[t,n]=v.useState([]),[r,l]=v.useState(!1),[s,o]=v.useState(null),[a,u]=v.useState(null),[c,y]=v.useState(null),[g,m]=v.useState(!1),[w,S]=v.useState(null),[j,O]=v.useState(""),[f,d]=v.useState(""),[h,x]=v.useState(2),[k,E]=v.useState(!1),[L,p]=v.useState(null),[N,T]=v.useState(""),[I,U]=v.useState(2),[P,F]=v.useState(!1),[H,q]=v.useState(null),[Me,z]=v.useState(!1),[C,M]=v.useState(""),Q=v.useRef(null),A=t.find(R=>R.collection_uid===a)??null,we=(A==null?void 0:A.slug)==="_default_",ce=v.useCallback(async()=>{if(e){l(!0),o(null);try{const R=await Ip(e);n(R)}catch(R){o(R.message)}finally{l(!1)}}},[e]),Qe=v.useCallback(async R=>{if(!R){y(null);return}m(!0),S(null);try{const V=await Bp(e,R);y(V)}catch(V){S(V.message)}finally{m(!1)}},[e]);v.useEffect(()=>{ce()},[ce]),v.useEffect(()=>{Qe(a)},[a,Qe]),v.useEffect(()=>{Me&&Q.current&&Q.current.focus()},[Me]);async function Fe(R){R.preventDefault();const V=j.trim(),Pe=f.trim();if(!(!V||!Pe)){E(!0),p(null);try{const $=await Up(e,V,Pe,h);O(""),d(""),x(2),await ce(),u($.collection_uid)}catch($){p($.message)}finally{E(!1)}}}async function lt(){const R=C.trim();if(!R||!A){z(!1);return}try{await pa(e,A.collection_uid,{name:R}),await ce(),y(V=>V&&{...V,name:R})}catch(V){o(V.message)}finally{z(!1)}}async function Dl(R){if(A)try{await pa(e,A.collection_uid,{default_visibility_bits:R}),await ce(),y(V=>V&&{...V,default_visibility_bits:R})}catch(V){o(V.message)}}async function Ol(){if(A&&window.confirm(`Delete collection "${A.name}"? Entries will not be deleted.`))try{await Kp(e,A.collection_uid),u(null),y(null),await ce()}catch(R){o(R.message)}}async function $l(R){R.preventDefault();const V=N.trim();if(!(!V||!A)){F(!0),q(null);try{await Vp(e,A.collection_uid,V,I),T(""),await Qe(A.collection_uid)}catch(Pe){q(Pe.message)}finally{F(!1)}}}async function Ml(R){if(A)try{await Wp(e,A.collection_uid,R),await Qe(A.collection_uid)}catch(V){S(V.message)}}async function Fl(R,V){if(A)try{await Hp(e,A.collection_uid,R,V),y(Pe=>Pe&&{...Pe,entries:Pe.entries.map($=>$.entry_uid===R?{...$,collection_visibility_bits:V}:$)})}catch(Pe){S(Pe.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:()=>o(null),className:"coll-dismiss",children:"×"})]}),i.jsxs("div",{className:"collections-layout",children:[i.jsxs("div",{className:"collections-sidebar",children:[t.map(R=>i.jsxs("button",{className:`coll-sidebar-row${a===R.collection_uid?" is-active":""}`,onClick:()=>u(R.collection_uid),children:[i.jsx("span",{className:"coll-row-name",children:R.name}),i.jsx("span",{className:"coll-row-meta",children:mh(R.default_visibility_bits)})]},R.collection_uid)),t.length===0&&!r&&i.jsx("div",{className:"muted",style:{padding:"8px 12px"},children:"No collections yet."})]}),A?i.jsxs("div",{className:"coll-detail",children:[i.jsxs("div",{className:"coll-detail-header",children:[Me?i.jsx("input",{ref:Q,className:"coll-rename-input",value:C,onChange:R=>M(R.target.value),onBlur:lt,onKeyDown:R=>{R.key==="Enter"&<(),R.key==="Escape"&&z(!1)}}):i.jsxs("h3",{className:`coll-detail-name${we?"":" coll-detail-name--editable"}`,title:we?void 0:"Click to rename",onClick:()=>{we||(M(A.name),z(!0))},children:[(c==null?void 0:c.name)??A.name,!we&&i.jsx("span",{className:"coll-edit-hint",children:" ✎"})]}),!we&&i.jsx("button",{className:"coll-delete-btn",onClick:Ol,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)??A.default_visibility_bits,onChange:R=>Dl(Number(R.target.value)),disabled:we,children:In.map(R=>i.jsx("option",{value:R.value,children:R.label},R.value))})]}),i.jsxs("div",{className:"coll-entries-section",children:[i.jsx("div",{className:"coll-section-heading",children:"Entries"}),g&&i.jsx("div",{className:"muted",children:"Loading…"}),w&&i.jsx("div",{className:"collections-error",children:w}),!g&&c&&(c.entries.length===0?i.jsx("div",{className:"muted",children:"No entries in this collection."}):i.jsx("ul",{className:"coll-entries-list",children:c.entries.map(R=>i.jsxs("li",{className:"coll-entry-row",children:[i.jsxs("div",{className:"coll-entry-info",children:[i.jsx("span",{className:"coll-entry-title",children:R.title||R.entry_uid}),i.jsx("span",{className:"coll-entry-kind muted",children:R.source_kind})]}),i.jsxs("div",{className:"coll-entry-actions",children:[i.jsx("select",{className:"coll-entry-vis-select",value:R.collection_visibility_bits,onChange:V=>Fl(R.entry_uid,Number(V.target.value)),children:In.map(V=>i.jsx("option",{value:V.value,children:V.label},V.value))}),!we&&i.jsx("button",{className:"coll-entry-remove",onClick:()=>Ml(R.entry_uid),title:"Remove from collection",children:"×"})]})]},R.entry_uid))}))]}),!we&&i.jsxs("form",{className:"coll-add-entry-form",onSubmit:$l,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:N,onChange:R=>T(R.target.value),placeholder:"entry_uid",required:!0}),i.jsx("select",{className:"coll-vis-select",value:I,onChange:R=>U(Number(R.target.value)),children:In.map(R=>i.jsx("option",{value:R.value,children:R.label},R.value))}),i.jsx("button",{className:"coll-add-btn",type:"submit",disabled:P,children:P?"…":"Add"})]}),H&&i.jsx("div",{className:"collections-error",style:{marginTop:4},children:H})]})]}):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:Fe,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:j,onChange:R=>{O(R.target.value),f||d(R.target.value.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},placeholder:"My Collection",required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"coll-slug",children:"Slug"}),i.jsx("input",{className:"capture-input",id:"coll-slug",type:"text",value:f,onChange:R=>d(R.target.value),placeholder:"my-collection",required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"coll-vis",children:"Default visibility"}),i.jsx("select",{className:"capture-input",id:"coll-vis",style:{height:42},value:h,onChange:R=>x(Number(R.target.value)),children:In.map(R=>i.jsx("option",{value:R.value,children:R.label},R.value))})]}),L&&i.jsx("div",{className:"collections-error",children:L}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:k,children:k?"Creating…":"Create collection"})]})]})]}):i.jsx("div",{className:"view-placeholder",children:"Select an archive."})}const vh=4;function yh({tab:e,onTabChange:t,archiveId:n}){const{currentUser:r,setCurrentUser:l}=v.useContext(Rl)??{},s=r&&(r.role_bits&vh)!==0,o=["profile","tokens",...s?["instance","cookies","storage"]:[]],a={profile:"Profile",tokens:"API Tokens",instance:"Instance",cookies:"Cookies",storage:"Storage"};return i.jsxs("section",{className:"admin-view",children:[i.jsx("h1",{children:"Settings"}),i.jsx("div",{className:"view-tabs",children:o.map(u=>i.jsx("button",{className:`view-tab${e===u?" is-active":""}`,onClick:()=>t(u),children:a[u]},u))}),e==="profile"&&i.jsx(wh,{currentUser:r,setCurrentUser:l}),e==="tokens"&&i.jsx(xh,{}),e==="instance"&&s&&i.jsx(Sh,{}),e==="cookies"&&s&&i.jsx(jh,{}),e==="storage"&&s&&i.jsx(kh,{archiveId:n})]})}function wh({currentUser:e,setCurrentUser:t}){const[n,r]=v.useState((e==null?void 0:e.display_name)??""),[l,s]=v.useState(!1),[o,a]=v.useState(null),[u,c]=v.useState(""),[y,g]=v.useState(""),[m,w]=v.useState(""),[S,j]=v.useState(!1),[O,f]=v.useState(null);async function d(x){x.preventDefault(),s(!0),a(null);try{await _p(n),t(k=>({...k,display_name:n||null})),a({ok:!0,text:"Saved."})}catch(k){a({ok:!1,text:k.message})}finally{s(!1)}}async function h(x){if(x.preventDefault(),y!==m){f({ok:!1,text:"Passwords do not match."});return}j(!0),f(null);try{await Tp(u,y),c(""),g(""),w(""),f({ok:!0,text:"Password changed."})}catch(k){f({ok:!1,text:k.message})}finally{j(!1)}}return i.jsxs("div",{style:{maxWidth:440},children:[i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Display Name"}),i.jsxs("form",{onSubmit:d,children:[i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"display-name",children:"Name shown in the UI"}),i.jsx("input",{className:"field-input",id:"display-name",placeholder:(e==null?void 0:e.username)??"",value:n,onChange:x=>r(x.target.value)})]}),o&&i.jsx("div",{className:`form-msg form-msg--${o.ok?"ok":"err"}`,children:o.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 x=>{const k=x.target.checked;try{await Ep({humanize_slugs:k}),t(E=>({...E,humanize_slugs:k}))}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:h,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:x=>c(x.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:y,onChange:x=>g(x.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:m,onChange:x=>w(x.target.value),required:!0})]}),O&&i.jsx("div",{className:`form-msg form-msg--${O.ok?"ok":"err"}`,children:O.text}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:S,children:S?"Changing…":"Change Password"})]})]})]})}function xh(){const[e,t]=v.useState([]),[n,r]=v.useState(!0),[l,s]=v.useState(null),[o,a]=v.useState(""),[u,c]=v.useState(!1),[y,g]=v.useState(null),m=v.useCallback(async()=>{r(!0),s(null);try{t(await Pp())}catch(j){s(j.message)}finally{r(!1)}},[]);v.useEffect(()=>{m()},[m]);async function w(j){if(j.preventDefault(),!!o.trim()){c(!0);try{const O=await Lp(o.trim());g(O),a(""),m()}catch(O){s(O.message)}finally{c(!1)}}}async function S(j){try{await zp(j),t(O=>O.filter(f=>f.token_uid!==j))}catch(O){s(O.message)}}return i.jsx("div",{style:{maxWidth:600},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"API Tokens"}),y&&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:y.raw_token}),i.jsx("button",{className:"token-dismiss",onClick:()=>g(null),children:"Dismiss"})]}),i.jsxs("form",{className:"token-create-row",onSubmit:w,children:[i.jsx("input",{className:"field-input field-input--flex",placeholder:"Token name",value:o,onChange:j=>a(j.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(j=>i.jsxs("div",{className:"token-row",children:[i.jsxs("div",{className:"token-row-info",children:[i.jsx("strong",{children:j.name}),i.jsxs("div",{className:"muted",children:["Created ",j.created_at.slice(0,10),j.last_used_at&&` · Last used ${j.last_used_at.slice(0,10)}`]})]}),i.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"4px 10px"},onClick:()=>S(j.token_uid),children:"Revoke"})]},j.token_uid))]})]})})}function Sh(){const[e,t]=v.useState(null),[n,r]=v.useState(!0),[l,s]=v.useState(null),[o,a]=v.useState(!1),[u,c]=v.useState(null);v.useEffect(()=>{(async()=>{try{t(await Rp())}catch(g){s(g.message)}finally{r(!1)}})()},[]);async function y(g){g.preventDefault(),a(!0),c(null);try{await Dp(e),c({ok:!0,text:"Saved."})}catch(m){c({ok:!1,text:m.message})}finally{a(!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:y,children:[[["public_index_enabled","Public index (unauthenticated browsing)"],["public_entry_content_enabled","Public entry content"],["open_registration_enabled","Open registration"]].map(([g,m])=>i.jsxs("label",{className:"checkbox-row",children:[i.jsx("input",{type:"checkbox",checked:!!e[g],onChange:w=>t(S=>({...S,[g]:w.target.checked}))}),m]},g)),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:g=>t(m=>({...m,default_entry_visibility:Number(g.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:o,children:o?"Saving…":"Save Settings"})]})]})}):null}function fs(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 kh({archiveId:e}){const[t,n]=v.useState("idle"),[r,l]=v.useState(null),[s,o]=v.useState(null),[a,u]=v.useState(null);function c(){n("idle"),l(null),o(null),u(null)}async function y(){n("scanning"),u(null),l(null);try{const w=await Jp(e);l(w),n("scanned")}catch(w){u(w.message),n("error")}}async function g(){n("deleting"),u(null);try{const w=await Yp(e);o(w),n("done")}catch(w){u(w.message),n("error")}}const m=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:y,children:"Scan for orphaned blobs"}),t==="scanning"&&i.jsx("div",{className:"muted",children:"Scanning…"}),t==="scanned"&&r&&m&&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&&!m&&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:fs(r.total_bytes)})," recoverable."]}),i.jsxs("div",{style:{display:"flex",gap:8},children:[i.jsxs("button",{className:"btn-danger",onClick:g,children:["Delete (",fs(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:fs(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:a}),i.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:c,children:"Try again"})]})]})})}function jh(){const[e,t]=v.useState(null),[n,r]=v.useState(!0),[l,s]=v.useState(null),[o,a]=v.useState("global"),[u,c]=v.useState(""),[y,g]=v.useState("{}"),[m,w]=v.useState(null),[S,j]=v.useState(!1),[O,f]=v.useState({});v.useEffect(()=>{d()},[]);async function d(){r(!0),s(null);try{t(await Gp())}catch(p){s(p.message)}finally{r(!1)}}async function h(p){p.preventDefault();try{JSON.parse(y)}catch{w({ok:!1,text:'cookies must be valid JSON, e.g. {"session": "abc"}'});return}j(!0),w(null);try{await Xp(o==="global"?null:u.trim(),o,y),c(""),g("{}"),a("global"),w({ok:!0,text:"Rule added."}),await d()}catch(N){w({ok:!1,text:N.message})}finally{j(!1)}}async function x(p){try{await Zp(p),await d()}catch(N){s(N.message)}}function k(p){f(N=>({...N,[p.rule_uid]:{cookiesInput:p.cookies_json,saving:!1,msg:null}}))}function E(p){f(N=>{const T={...N};return delete T[p],T})}async function L(p){const N=O[p.rule_uid];try{JSON.parse(N.cookiesInput)}catch{f(T=>({...T,[p.rule_uid]:{...T[p.rule_uid],msg:{ok:!1,text:"Invalid JSON"}}}));return}f(T=>({...T,[p.rule_uid]:{...T[p.rule_uid],saving:!0,msg:null}}));try{await qp(p.rule_uid,{cookies_json:N.cookiesInput}),E(p.rule_uid),await d()}catch(T){f(I=>({...I,[p.rule_uid]:{...I[p.rule_uid],saving:!1,msg:{ok:!1,text:T.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(p=>{const N=O[p.rule_uid],T=p.url_pattern?i.jsxs(i.Fragment,{children:[i.jsxs("span",{className:"muted",children:[p.pattern_kind,":"]})," ",i.jsx("code",{children:p.url_pattern})]}):i.jsx("span",{className:"muted",children:"global (all URLs)"});return i.jsxs("tr",{children:[i.jsx("td",{children:T}),i.jsx("td",{children:N?i.jsxs(i.Fragment,{children:[i.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:12,width:"100%",minHeight:60},value:N.cookiesInput,onChange:I=>f(U=>({...U,[p.rule_uid]:{...U[p.rule_uid],cookiesInput:I.target.value}}))}),N.msg&&i.jsx("div",{className:`form-msg form-msg--${N.msg.ok?"ok":"err"}`,children:N.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:N.saving,onClick:()=>L(p),children:N.saving?"Saving…":"Save"}),i.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>E(p.rule_uid),children:"Cancel"})]})]}):i.jsx("code",{style:{fontSize:12,wordBreak:"break-all"},children:p.cookies_json})}),i.jsx("td",{children:!N&&i.jsxs("div",{style:{display:"flex",gap:6},children:[i.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>k(p),children:"Edit"}),i.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"2px 8px"},onClick:()=>x(p.rule_uid),children:"Del"})]})})]},p.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:h,children:[i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",children:"Pattern type"}),i.jsxs("select",{className:"field-input",value:o,onChange:p=>a(p.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)"})]})]}),o!=="global"&&i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",children:o==="wildcard"?"URL/hostname pattern":"Regex pattern"}),i.jsx("input",{className:"field-input",type:"text",value:u,onChange:p=>c(p.target.value),placeholder:o==="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:y,onChange:p=>g(p.target.value),placeholder:'{"SESSION": "abc123", "token": "xyz"}',required:!0})]}),m&&i.jsx("div",{className:`form-msg form-msg--${m.ok?"ok":"err"}`,children:m.text}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:S,children:S?"Adding…":"Add Rule"})]})]})})}const ga={0:"Private",1:"Public",2:"Users only",3:"Public"},Nh=()=>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 Ch({archiveId:e,selectedEntry:t,onTagFilterSet:n,tagNodes:r,onTagsRefresh:l,onEntryTitleChange:s,onEntryDeleted:o,humanizeTags:a}){const[u,c]=v.useState(null),[y,g]=v.useState([]),[m,w]=v.useState(""),[S,j]=v.useState([]),[O,f]=v.useState(""),d=v.useRef(0),h=v.useRef(!1),[x,k]=v.useState(!1),[E,L]=v.useState("");v.useEffect(()=>{if(!t||!e){c(null),g([]),j([]);return}k(!1),L(""),h.current=!1;const P=++d.current;c(null),g([]),Promise.all([dp(e,t.entry_uid),cs(e,t.entry_uid),Qp(e,t.entry_uid)]).then(([F,H,q])=>{P===d.current&&(c(F),g(H),j(q))}).catch(()=>{})},[t,e]);async function p(){const P=E.trim()||null;try{await fp(e,t.entry_uid,P),c(F=>F&&{...F,summary:{...F.summary,title:P}}),s==null||s(t.entry_uid,P)}catch{}finally{k(!1)}}async function N(){const P=m.trim();if(!(!P||!t))try{await pp(e,t.entry_uid,P),w(""),f("");const F=await cs(e,t.entry_uid);g(F),l()}catch(F){f(F.message)}}async function T(P){try{await hp(e,t.entry_uid,P);const F=await cs(e,t.entry_uid);g(F),l()}catch{}}async function I(){if(!(!t||!e)&&window.confirm("Delete this entry? This cannot be undone."))try{await mp(e,t.entry_uid),o==null||o(t.entry_uid)}catch{}}const U=u?[["Added",zc(u.summary.archived_at)],["Source",u.summary.source_kind],["Type",u.summary.entity_kind],["Visibility",ga[u.summary.visibility]??u.summary.visibility],["Root",u.structured_root_relpath]]:[];return i.jsxs("aside",{className:"context-rail",children:[i.jsx("div",{className:"rail-eyebrow",children:"Context"}),t?u?i.jsxs(i.Fragment,{children:[x?i.jsx("input",{className:"rail-title-input",autoFocus:!0,value:E,onChange:P=>L(P.target.value),onKeyDown:P=>{P.key==="Enter"&&P.currentTarget.blur(),P.key==="Escape"&&(h.current=!0,P.currentTarget.blur())},onBlur:()=>{h.current?k(!1):p(),h.current=!1}}):i.jsxs("h2",{className:"rail-title rail-title--editable",title:"Click to rename",onClick:()=>{L(u.summary.title??""),k(!0)},children:[Ut(u.summary.title)||Ut(u.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"})})]}),u.summary.original_url&&i.jsxs("a",{className:"url-tile",href:u.summary.original_url,target:"_blank",rel:"noopener noreferrer",children:[i.jsx("span",{className:"ico",dangerouslySetInnerHTML:{__html:Rc(u.summary.source_kind)}}),i.jsx("span",{className:"u-text",children:u.summary.original_url}),i.jsx("span",{className:"ext",children:i.jsx(Nh,{})})]}),i.jsx("div",{className:"meta-list",children:U.filter(([,P])=>P!=null&&P!=="").map(([P,F])=>i.jsxs("div",{className:"meta-item",children:[i.jsx("span",{className:"meta-k",children:P}),i.jsx("span",{className:`meta-v${P==="Root"?" mono":""}`,children:Ut(F)})]},P))}),u.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:u.artifacts.length})]}),i.jsx("ul",{className:"artifact-list",children:u.artifacts.map((P,F)=>i.jsx("li",{children:i.jsxs("a",{href:`/api/archives/${e}/entries/${u.summary.entry_uid}/artifacts/${F}`,target:"_blank",rel:"noopener noreferrer",className:"artifact-link",children:[i.jsx("span",{className:"artifact-name",children:P.artifact_role.replace(/_/g," ")}),i.jsx("span",{className:"artifact-size",children:P.byte_size!=null?oi(P.byte_size):"—"})]})},F))})]})]}):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"}),y.length===0?i.jsx("p",{className:"tags-empty",children:"No tags yet."}):i.jsx("div",{className:"tags-wrap",children:y.map(P=>i.jsxs("span",{className:"tag-pill",title:P.full_path,children:[a?Dc(P.full_path):P.full_path,i.jsx("button",{className:"remove",title:`Remove tag ${P.full_path}`,onClick:()=>T(P.tag_uid),children:"×"})]},P.tag_uid))}),O&&i.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:O}),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:m,onChange:P=>w(P.target.value),onKeyDown:P=>{P.key==="Enter"&&N()}}),i.jsx("button",{className:"tag-add-btn",onClick:N,children:"Add"})]})]}),S.length>0&&i.jsxs("div",{className:"rail-section",children:[i.jsx("div",{className:"rail-section-heading",children:"Collections"}),S.map(P=>i.jsxs("div",{className:"coll-row",children:[i.jsx("span",{className:"coll-name",children:P.collection_uid}),i.jsx("span",{className:"vis-badge",children:ga[P.visibility_bits]??`bits:${P.visibility_bits}`})]},P.collection_uid))]}),i.jsx("div",{className:"rail-delete-zone",children:i.jsx("button",{className:"rail-delete-btn",onClick:I,children:"Delete entry"})})]})]})}const _h=7e3;function Eh({toasts:e,onDismiss:t}){return e.length?i.jsx("div",{className:"toast-stack",role:"log","aria-live":"polite","aria-label":"Notifications",children:e.map(n=>i.jsx(Th,{toast:n,onDismiss:t},n.id))}):null}function Th({toast:e,onDismiss:t}){const[n,r]=v.useState(!1);v.useEffect(()=>{if(n)return;const s=setTimeout(()=>t(e.id),_h);return()=>clearTimeout(s)},[n,e.id,t]);const l=e.locator?e.locator.length>48?e.locator.slice(0,45)+"…":e.locator:null;return 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:"Capture failed"}),l&&i.jsx("span",{className:"toast-locator",children:l})]}),i.jsxs("div",{className:"toast-btns",children:[e.errorText&&i.jsx("button",{type:"button",className:"toast-view-btn",onClick:()=>r(s=>!s),children:n?"Hide":"View error"}),i.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})]})]}),n&&e.errorText&&i.jsx("pre",{className:"toast-error-detail",children:e.errorText})]})}const Rl=v.createContext(null),Ph=["archive","tags","collections","runs","admin","settings"],Lh=["profile","tokens","instance","storage"];function ps(){const e=window.location.pathname.split("/").filter(Boolean),t=Ph.includes(e[0])?e[0]:"archive",n=t==="settings"&&Lh.includes(e[1])?e[1]:"profile";return{view:t,settingsTab:n}}function zh(e,t){return e==="archive"?"/":e==="settings"?`/settings/${t}`:`/${e}`}function Rh(){const[e,t]=v.useState("loading"),[n,r]=v.useState(null);v.useEffect(()=>{(async()=>{if(await Sp()){t("setup");return}const K=await Cp();if(!K){t("login");return}r(K),t("authenticated")})()},[]),v.useEffect(()=>{const $=()=>{r(null),t("login")};return window.addEventListener("auth:expired",$),()=>window.removeEventListener("auth:expired",$)},[]),v.useEffect(()=>{const $=()=>{const{view:K,settingsTab:de}=ps();f(K),h(de)};return window.addEventListener("popstate",$),()=>window.removeEventListener("popstate",$)},[]);const[l,s]=v.useState([]),[o,a]=v.useState(null),[u,c]=v.useState([]),[y,g]=v.useState(null),[m,w]=v.useState(null),[S,j]=v.useState(null),[O,f]=v.useState(()=>ps().view),[d,h]=v.useState(()=>ps().settingsTab),[x,k]=v.useState(""),[E,L]=v.useState(""),[p,N]=v.useState(!1),[T,I]=v.useState([]),[U,P]=v.useState([]),[F,H]=v.useState(()=>sessionStorage.getItem("captureDialogOpen")==="true"),[q,Me]=v.useState([]),z=v.useRef(0),C=(n==null?void 0:n.humanize_slugs)??!1;v.useEffect(()=>{sessionStorage.setItem("captureDialogOpen",F)},[F]);const M=v.useCallback(async($,K,de)=>{if($){N(!0);try{let Ae;K||de?Ae=await cp($,K,de):Ae=await up($),c(Ae),L(Ae.length===0?"No results":`${Ae.length} result${Ae.length===1?"":"s"}`)}catch{c([]),L("Search failed. Try again.")}finally{N(!1)}}},[]);v.useEffect(()=>{e==="authenticated"&&ap().then($=>{if(s($),$.length>0){const K=$[0].id;a(K)}})},[e]),v.useEffect(()=>{o&&(j(null),w(null),g(null),Promise.all([M(o,"",null),fa(o).then(I),ds(o).then(P)]))},[o]),v.useEffect(()=>{if(o===null)return;const $=setTimeout(()=>{M(o,x,S)},300);return()=>clearTimeout($)},[x,o]),v.useEffect(()=>{o!==null&&(S!==null&&f("archive"),M(o,x,S))},[S,o]);const Q=v.useCallback($=>{a($)},[]),A=v.useCallback($=>{f($),$==="tags"&&o&&ds(o).then(P)},[o]);v.useEffect(()=>{const $=zh(O,d);window.location.pathname!==$&&history.pushState(null,"",$)},[O,d]);const we=v.useCallback($=>{g($?$.entry_uid:null),w($)},[]),ce=v.useCallback($=>{j($)},[]),Qe=v.useCallback(()=>{j(null)},[]),Fe=v.useCallback(()=>{o&&ds(o).then(P)},[o]),lt=v.useCallback(($,K)=>{S===$?j(K):S!=null&&S.startsWith($+"/")&&j(K+S.slice($.length))},[S]),Dl=v.useCallback($=>{(S===$||S!=null&&S.startsWith($+"/"))&&j(null)},[S]),Ol=v.useCallback(($,K)=>{c(de=>de.map(Ae=>Ae.entry_uid===$?{...Ae,title:K}:Ae)),w(de=>de&&de.entry_uid===$?{...de,title:K}:de)},[]),$l=v.useCallback($=>{c(K=>K.filter(de=>de.entry_uid!==$)),w(K=>(K==null?void 0:K.entry_uid)===$?null:K),g(K=>K===$?null:K)},[]),Ml=v.useCallback(()=>{H(!0)},[]),Fl=v.useCallback(()=>{H(!1)},[]),R=v.useCallback(()=>{o&&Promise.all([M(o,x,S),fa(o).then(I)])},[o,x,S,M]),V=v.useCallback(($,K)=>{const de=++z.current;Me(Ae=>[...Ae,{id:de,errorText:$,locator:K}])},[]),Pe=v.useCallback($=>{Me(K=>K.filter(de=>de.id!==$))},[]);return e==="loading"?i.jsx("div",{className:"auth-loading",children:"Loading\\u2026"}):e==="setup"?i.jsx(th,{onComplete:()=>t("login")}):e==="login"?i.jsx(eh,{onLogin:$=>{r($),t("authenticated")}}):i.jsx(Rl.Provider,{value:{currentUser:n,setCurrentUser:r},children:i.jsxs(i.Fragment,{children:[i.jsx(nh,{archives:l,archiveId:o,onArchiveChange:Q,view:O,onViewChange:A,onCaptureClick:Ml}),i.jsxs("main",{className:"app-shell",children:[i.jsxs("div",{className:"workspace",children:[O==="archive"&&i.jsxs("div",{className:"toolbar",children:[i.jsxs("div",{className:"search-field",children:[i.jsx("span",{className:"ico","aria-hidden":"true",children:i.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[i.jsx("circle",{cx:"11",cy:"11",r:"7"}),i.jsx("line",{x1:"16.5",y1:"16.5",x2:"21",y2:"21"})]})}),i.jsx("input",{className:"search-input",type:"search","aria-label":"Search archive","aria-busy":p,placeholder:"Search titles, URLs, types, tags…",value:x,onChange:$=>k($.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(" ")]}),S&&i.jsxs("button",{className:"tag-filter-badge",onClick:Qe,children:["× ",C?Dc(S):S]})]})]}),O==="archive"&&i.jsx(ah,{entries:u,selectedEntryUid:y,onSelectEntry:we,archiveId:o,tagFilter:S,onClearTagFilter:Qe,searchQuery:x,onSearchChange:k,resultCount:E,searchBusy:p}),O==="runs"&&i.jsx(dh,{runs:T}),O==="admin"&&i.jsx(ph,{archives:l}),O==="tags"&&i.jsx(hh,{archiveId:o,tagNodes:U,tagFilter:S,onTagFilterSet:ce,onViewChange:A,onTagRenamed:lt,onTagDeleted:Dl,onTagsRefresh:Fe,humanizeTags:C}),O==="collections"&&i.jsx(gh,{archiveId:o}),O==="settings"&&i.jsx(yh,{tab:d,onTabChange:h,archiveId:o})]}),i.jsx(Ch,{archiveId:o,selectedEntry:m,onTagFilterSet:ce,tagNodes:U,onTagsRefresh:Fe,onEntryTitleChange:Ol,onEntryDeleted:$l,humanizeTags:C})]}),i.jsx(rh,{open:F,archiveId:o,onClose:Fl,onCaptured:R,onToast:V}),i.jsx(Eh,{toasts:q,onDismiss:Pe})]})})}Pc(document.getElementById("root")).render(i.jsx(v.StrictMode,{children:i.jsx(Rh,{})}));