diff --git a/crates/archivr-core/src/database.rs b/crates/archivr-core/src/database.rs index 07126a3..d690070 100644 --- a/crates/archivr-core/src/database.rs +++ b/crates/archivr-core/src/database.rs @@ -1692,6 +1692,45 @@ pub fn get_entry_collection_memberships( .map_err(Into::into) } +/// Renames a collection and/or updates its default_visibility_bits. +/// Returns true if updated, false if not found. +/// Refuses to rename the '_default_' collection. +pub fn update_collection( + conn: &Connection, + collection_uid: &str, + new_name: Option<&str>, + new_visibility_bits: Option, +) -> Result { + let coll = get_collection_by_uid(conn, collection_uid)?; + let Some(coll) = coll else { return Ok(false) }; + if coll.slug == "_default_" { + anyhow::bail!("cannot modify the default collection"); + } + let name = new_name.unwrap_or(&coll.name); + let vbits = new_visibility_bits.unwrap_or(coll.default_visibility_bits); + conn.execute( + "UPDATE collections SET name = ?1, default_visibility_bits = ?2 WHERE id = ?3", + params![name, vbits as i64, coll.id], + )?; + Ok(true) +} + +/// Deletes a collection and cascades to collection_entries. +/// Returns true if deleted, false if not found. +/// Refuses to delete the '_default_' collection. +pub fn delete_collection( + conn: &Connection, + collection_uid: &str, +) -> Result { + let coll = get_collection_by_uid(conn, collection_uid)?; + let Some(coll) = coll else { return Ok(false) }; + if coll.slug == "_default_" { + anyhow::bail!("cannot delete the default collection"); + } + conn.execute("DELETE FROM collections WHERE id = ?1", [coll.id])?; + Ok(true) +} + fn run_id_for_item(conn: &Connection, item_id: i64) -> Result { let run_id = conn.query_row( "SELECT run_id FROM archive_run_items WHERE id = ?1", diff --git a/crates/archivr-server/src/routes.rs b/crates/archivr-server/src/routes.rs index 9a27c28..3ae5804 100644 --- a/crates/archivr-server/src/routes.rs +++ b/crates/archivr-server/src/routes.rs @@ -135,7 +135,9 @@ pub fn app(registry: ServerRegistry, auth_db_path: std::path::PathBuf) -> Router .route("/api/archives/:archive_id/collections", get(list_collections_handler).post(create_collection_handler)) .route("/api/archives/:archive_id/collections/:coll_uid", - get(get_collection_handler)) + get(get_collection_handler) + .patch(patch_collection_handler) + .delete(delete_collection_handler)) .route("/api/archives/:archive_id/collections/:coll_uid/entries", post(add_entry_to_collection_handler)) .route("/api/archives/:archive_id/collections/:coll_uid/entries/:entry_uid", @@ -320,6 +322,12 @@ struct UpdateVisibilityBody { visibility_bits: u32, } +#[derive(Debug, serde::Deserialize)] +struct PatchCollectionBody { + name: Option, + default_visibility_bits: Option, +} + async fn list_tags( State(state): State, Path(archive_id): Path, @@ -939,13 +947,41 @@ async fn get_collection_handler( .ok_or(ApiError::not_found("collection not found"))?; let caller_bits = auth_to_caller_bits(&auth); let entries = archive::list_entries_for_collection(&conn, record.id, caller_bits)?; + // Collect per-entry visibility bits from collection_entries + let mut vis_map: std::collections::HashMap = std::collections::HashMap::new(); + { + let mut stmt = conn.prepare( + "SELECT ae.entry_uid, ce.visibility_bits \ + FROM collection_entries ce \ + JOIN archived_entries ae ON ae.id = ce.entry_id \ + WHERE ce.collection_id = ?1", + )?; + let rows = stmt.query_map([record.id], |row| { + Ok((row.get::<_, String>(0)?, row.get::<_, i64>(1)? as u32)) + })?; + for r in rows { + if let Ok((uid, bits)) = r { + vis_map.insert(uid, bits); + } + } + } + let entries_json: Vec = entries.iter().map(|e| { + let vis = vis_map.get(&e.entry_uid).copied().unwrap_or(record.default_visibility_bits); + serde_json::json!({ + "entry_uid": e.entry_uid, + "title": e.title, + "source_kind": e.source_kind, + "archived_at": e.archived_at, + "collection_visibility_bits": vis, + }) + }).collect(); Ok(Json(serde_json::json!({ "collection_uid": record.collection_uid, "name": record.name, "slug": record.slug, "default_visibility_bits": record.default_visibility_bits, "created_at": record.created_at, - "entries": entries, + "entries": entries_json, }))) } @@ -1041,6 +1077,40 @@ async fn list_entry_collections_handler( } } +async fn patch_collection_handler( + State(state): State, + auth: AuthUser, + Path((archive_id, coll_uid)): Path<(String, String)>, + Json(body): Json, +) -> Result { + auth.require_role(ROLE_USER)?; + let mounted = mounted_archive(&state, &archive_id)?; + let conn = database::open_or_initialize(&mounted.archive_path)?; + let name_ref: Option<&str> = body.name.as_deref(); + let updated = database::update_collection(&conn, &coll_uid, name_ref, body.default_visibility_bits)?; + if updated { + Ok(StatusCode::NO_CONTENT) + } else { + Err(ApiError::not_found("collection not found")) + } +} + +async fn delete_collection_handler( + State(state): State, + auth: AuthUser, + Path((archive_id, coll_uid)): Path<(String, String)>, +) -> Result { + auth.require_role(ROLE_USER)?; + let mounted = mounted_archive(&state, &archive_id)?; + let conn = database::open_or_initialize(&mounted.archive_path)?; + let deleted = database::delete_collection(&conn, &coll_uid)?; + if deleted { + Ok(StatusCode::NO_CONTENT) + } else { + Err(ApiError::not_found("collection not found")) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/archivr-server/static/assets/index-C6h0jcH3.js b/crates/archivr-server/static/assets/index-C6h0jcH3.js new file mode 100644 index 0000000..5000950 --- /dev/null +++ b/crates/archivr-server/static/assets/index-C6h0jcH3.js @@ -0,0 +1,40 @@ +(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))r(l);new MutationObserver(l=>{for(const i of l)if(i.type==="childList")for(const s of i.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&r(s)}).observe(document,{childList:!0,subtree:!0});function n(l){const i={};return l.integrity&&(i.integrity=l.integrity),l.referrerPolicy&&(i.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?i.credentials="include":l.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(l){if(l.ep)return;l.ep=!0;const i=n(l);fetch(l.href,i)}})();var nu={exports:{}},fl={},ru={exports:{}},$={};/** + * @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 ur=Symbol.for("react.element"),Cc=Symbol.for("react.portal"),Nc=Symbol.for("react.fragment"),jc=Symbol.for("react.strict_mode"),Ec=Symbol.for("react.profiler"),_c=Symbol.for("react.provider"),Pc=Symbol.for("react.context"),Tc=Symbol.for("react.forward_ref"),zc=Symbol.for("react.suspense"),Lc=Symbol.for("react.memo"),Rc=Symbol.for("react.lazy"),Hs=Symbol.iterator;function Oc(e){return e===null||typeof e!="object"?null:(e=Hs&&e[Hs]||e["@@iterator"],typeof e=="function"?e:null)}var lu={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},iu=Object.assign,su={};function xn(e,t,n){this.props=e,this.context=t,this.refs=su,this.updater=n||lu}xn.prototype.isReactComponent={};xn.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")};xn.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function ou(){}ou.prototype=xn.prototype;function Gi(e,t,n){this.props=e,this.context=t,this.refs=su,this.updater=n||lu}var Ji=Gi.prototype=new ou;Ji.constructor=Gi;iu(Ji,xn.prototype);Ji.isPureReactComponent=!0;var Ws=Array.isArray,uu=Object.prototype.hasOwnProperty,Zi={current:null},au={key:!0,ref:!0,__self:!0,__source:!0};function cu(e,t,n){var r,l={},i=null,s=null;if(t!=null)for(r in t.ref!==void 0&&(s=t.ref),t.key!==void 0&&(i=""+t.key),t)uu.call(t,r)&&!au.hasOwnProperty(r)&&(l[r]=t[r]);var u=arguments.length-2;if(u===1)l.children=n;else if(1>>1,O=E[A];if(0>>1;Al(se,R))Rel(we,se)?(E[A]=we,E[Re]=R,A=Re):(E[A]=se,E[M]=R,A=M);else if(Rel(we,R))E[A]=we,E[Re]=R,A=Re;else break e}}return k}function l(E,k){var R=E.sortIndex-k.sortIndex;return R!==0?R:E.id-k.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var s=Date,u=s.now();e.unstable_now=function(){return s.now()-u}}var a=[],d=[],v=1,m=null,h=3,w=!1,x=!1,S=!1,j=typeof setTimeout=="function"?setTimeout:null,f=typeof clearTimeout=="function"?clearTimeout:null,c=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function p(E){for(var k=n(d);k!==null;){if(k.callback===null)r(d);else if(k.startTime<=E)r(d),k.sortIndex=k.expirationTime,t(a,k);else break;k=n(d)}}function g(E){if(S=!1,p(E),!x)if(n(a)!==null)x=!0,Ae(N);else{var k=n(d);k!==null&&Be(g,k.startTime-E)}}function N(E,k){x=!1,S&&(S=!1,f(L),L=-1),w=!0;var R=h;try{for(p(k),m=n(a);m!==null&&(!(m.expirationTime>k)||E&&!J());){var A=m.callback;if(typeof A=="function"){m.callback=null,h=m.priorityLevel;var O=A(m.expirationTime<=k);k=e.unstable_now(),typeof O=="function"?m.callback=O:m===n(a)&&r(a),p(k)}else r(a);m=n(a)}if(m!==null)var de=!0;else{var M=n(d);M!==null&&Be(g,M.startTime-k),de=!1}return de}finally{m=null,h=R,w=!1}}var T=!1,P=null,L=-1,U=5,D=-1;function J(){return!(e.unstable_now()-DE||125A?(E.sortIndex=R,t(d,E),n(a)===null&&E===n(d)&&(S?(f(L),L=-1):S=!0,Be(g,R-A))):(E.sortIndex=O,t(a,E),x||w||(x=!0,Ae(N))),E},e.unstable_shouldYield=J,e.unstable_wrapCallback=function(E){var k=h;return function(){var R=h;h=k;try{return E.apply(this,arguments)}finally{h=R}}}})(mu);hu.exports=mu;var Wc=hu.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 Qc=y,Te=Wc;function C(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"),ri=Object.prototype.hasOwnProperty,Kc=/^[: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]*$/,Ks={},Ys={};function Yc(e){return ri.call(Ys,e)?!0:ri.call(Ks,e)?!1:Kc.test(e)?Ys[e]=!0:(Ks[e]=!0,!1)}function Xc(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 Gc(e,t,n,r){if(t===null||typeof t>"u"||Xc(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 me(e,t,n,r,l,i,s){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=l,this.mustUseProperty=n,this.propertyName=e,this.type=t,this.sanitizeURL=i,this.removeEmptyString=s}var ie={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){ie[e]=new me(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];ie[t]=new me(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){ie[e]=new me(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){ie[e]=new me(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){ie[e]=new me(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){ie[e]=new me(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){ie[e]=new me(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){ie[e]=new me(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){ie[e]=new me(e,5,!1,e.toLowerCase(),null,!1,!1)});var bi=/[\-:]([a-z])/g;function es(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(bi,es);ie[t]=new me(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(bi,es);ie[t]=new me(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(bi,es);ie[t]=new me(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){ie[e]=new me(e,1,!1,e.toLowerCase(),null,!1,!1)});ie.xlinkHref=new me("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){ie[e]=new me(e,1,!1,e.toLowerCase(),null,!0,!0)});function ts(e,t,n,r){var l=ie.hasOwnProperty(t)?ie[t]:null;(l!==null?l.type!==0:r||!(2u||l[s]!==i[u]){var a=` +`+l[s].replace(" at new "," at ");return e.displayName&&a.includes("")&&(a=a.replace("",e.displayName)),a}while(1<=s&&0<=u);break}}}finally{Ll=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?Ln(e):""}function Jc(e){switch(e.tag){case 5:return Ln(e.type);case 16:return Ln("Lazy");case 13:return Ln("Suspense");case 19:return Ln("SuspenseList");case 0:case 2:case 15:return e=Rl(e.type,!1),e;case 11:return e=Rl(e.type.render,!1),e;case 1:return e=Rl(e.type,!0),e;default:return""}}function oi(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 Gt:return"Fragment";case Xt:return"Portal";case li:return"Profiler";case ns:return"StrictMode";case ii:return"Suspense";case si:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case gu:return(e.displayName||"Context")+".Consumer";case yu:return(e._context.displayName||"Context")+".Provider";case rs:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ls:return t=e.displayName||null,t!==null?t:oi(e.type)||"Memo";case ft:t=e._payload,e=e._init;try{return oi(e(t))}catch{}}return null}function Zc(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 oi(t);case 8:return t===ns?"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 Et(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function xu(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function qc(e){var t=xu(e)?"checked":"value",n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var l=n.get,i=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return l.call(this)},set:function(s){r=""+s,i.call(this,s)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(s){r=""+s},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function mr(e){e._valueTracker||(e._valueTracker=qc(e))}function Su(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=xu(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function Vr(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 ui(e,t){var n=t.checked;return X({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function Gs(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=Et(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 ku(e,t){t=t.checked,t!=null&&ts(e,"checked",t,!1)}function ai(e,t){ku(e,t);var n=Et(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")?ci(e,t.type,n):t.hasOwnProperty("defaultValue")&&ci(e,t.type,Et(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function Js(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 ci(e,t,n){(t!=="number"||Vr(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var Rn=Array.isArray;function on(e,t,n,r){if(e=e.options,t){t={};for(var l=0;l"+t.valueOf().toString()+"",t=vr.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Kn(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var $n={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},bc=["Webkit","ms","Moz","O"];Object.keys($n).forEach(function(e){bc.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),$n[t]=$n[e]})});function Eu(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||$n.hasOwnProperty(e)&&$n[e]?(""+t).trim():t+"px"}function _u(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,l=Eu(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,l):e[n]=l}}var ed=X({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 pi(e,t){if(t){if(ed[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(C(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(C(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(C(61))}if(t.style!=null&&typeof t.style!="object")throw Error(C(62))}}function hi(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 mi=null;function is(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var vi=null,un=null,an=null;function bs(e){if(e=dr(e)){if(typeof vi!="function")throw Error(C(280));var t=e.stateNode;t&&(t=yl(t),vi(e.stateNode,e.type,t))}}function Pu(e){un?an?an.push(e):an=[e]:un=e}function Tu(){if(un){var e=un,t=an;if(an=un=null,bs(e),t)for(e=0;e>>=0,e===0?32:31-(dd(e)/fd|0)|0}var yr=64,gr=4194304;function On(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 Kr(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,l=e.suspendedLanes,i=e.pingedLanes,s=n&268435455;if(s!==0){var u=s&~l;u!==0?r=On(u):(i&=s,i!==0&&(r=On(i)))}else s=n&~l,s!==0?r=On(s):i!==0&&(r=On(i));if(r===0)return 0;if(t!==0&&t!==r&&!(t&l)&&(l=r&-r,i=t&-t,l>=i||l===16&&(i&4194240)!==0))return t;if(r&4&&(r|=n&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0n;n++)t.push(e);return t}function ar(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Ye(t),e[t]=n}function vd(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=In),uo=" ",ao=!1;function Gu(e,t){switch(e){case"keyup":return Wd.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Ju(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Jt=!1;function Kd(e,t){switch(e){case"compositionend":return Ju(t);case"keypress":return t.which!==32?null:(ao=!0,uo);case"textInput":return e=t.data,e===uo&&ao?null:e;default:return null}}function Yd(e,t){if(Jt)return e==="compositionend"||!ps&&Gu(e,t)?(e=Yu(),Or=cs=vt=null,Jt=!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=ho(n)}}function ea(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?ea(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function ta(){for(var e=window,t=Vr();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=Vr(e.document)}return t}function hs(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 nf(e){var t=ta(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&ea(n.ownerDocument.documentElement,n)){if(r!==null&&hs(n)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in n)n.selectionStart=t,n.selectionEnd=Math.min(e,n.value.length);else if(e=(t=n.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var l=n.textContent.length,i=Math.min(r.start,l);r=r.end===void 0?i:Math.min(r.end,l),!e.extend&&i>r&&(l=r,r=i,i=l),l=mo(n,i);var s=mo(n,r);l&&s&&(e.rangeCount!==1||e.anchorNode!==l.node||e.anchorOffset!==l.offset||e.focusNode!==s.node||e.focusOffset!==s.offset)&&(t=t.createRange(),t.setStart(l.node,l.offset),e.removeAllRanges(),i>r?(e.addRange(t),e.extend(s.node,s.offset)):(t.setEnd(s.node,s.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,Zt=null,ki=null,An=null,Ci=!1;function vo(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Ci||Zt==null||Zt!==Vr(r)||(r=Zt,"selectionStart"in r&&hs(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}),An&&qn(An,r)||(An=r,r=Gr(ki,"onSelect"),0en||(e.current=Ti[en],Ti[en]=null,en--)}function V(e,t){en++,Ti[en]=e.current,e.current=t}var _t={},ce=Tt(_t),ke=Tt(!1),At=_t;function hn(e,t){var n=e.type.contextTypes;if(!n)return _t;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var l={},i;for(i in n)l[i]=t[i];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=l),l}function Ce(e){return e=e.childContextTypes,e!=null}function Zr(){W(ke),W(ce)}function Co(e,t,n){if(ce.current!==_t)throw Error(C(168));V(ce,t),V(ke,n)}function ca(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(C(108,Zc(e)||"Unknown",l));return X({},n,r)}function qr(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||_t,At=ce.current,V(ce,e),V(ke,ke.current),!0}function No(e,t,n){var r=e.stateNode;if(!r)throw Error(C(169));n?(e=ca(e,t,At),r.__reactInternalMemoizedMergedChildContext=e,W(ke),W(ce),V(ce,e)):W(ke),V(ke,n)}var nt=null,gl=!1,Kl=!1;function da(e){nt===null?nt=[e]:nt.push(e)}function mf(e){gl=!0,da(e)}function zt(){if(!Kl&&nt!==null){Kl=!0;var e=0,t=B;try{var n=nt;for(B=1;e>=s,l-=s,rt=1<<32-Ye(t)+l|n<L?(U=P,P=null):U=P.sibling;var D=h(f,P,p[L],g);if(D===null){P===null&&(P=U);break}e&&P&&D.alternate===null&&t(f,P),c=i(D,c,L),T===null?N=D:T.sibling=D,T=D,P=U}if(L===p.length)return n(f,P),Q&&Rt(f,L),N;if(P===null){for(;LL?(U=P,P=null):U=P.sibling;var J=h(f,P,D.value,g);if(J===null){P===null&&(P=U);break}e&&P&&J.alternate===null&&t(f,P),c=i(J,c,L),T===null?N=J:T.sibling=J,T=J,P=U}if(D.done)return n(f,P),Q&&Rt(f,L),N;if(P===null){for(;!D.done;L++,D=p.next())D=m(f,D.value,g),D!==null&&(c=i(D,c,L),T===null?N=D:T.sibling=D,T=D);return Q&&Rt(f,L),N}for(P=r(f,P);!D.done;L++,D=p.next())D=w(P,f,L,D.value,g),D!==null&&(e&&D.alternate!==null&&P.delete(D.key===null?L:D.key),c=i(D,c,L),T===null?N=D:T.sibling=D,T=D);return e&&P.forEach(function(je){return t(f,je)}),Q&&Rt(f,L),N}function j(f,c,p,g){if(typeof p=="object"&&p!==null&&p.type===Gt&&p.key===null&&(p=p.props.children),typeof p=="object"&&p!==null){switch(p.$$typeof){case hr:e:{for(var N=p.key,T=c;T!==null;){if(T.key===N){if(N=p.type,N===Gt){if(T.tag===7){n(f,T.sibling),c=l(T,p.props.children),c.return=f,f=c;break e}}else if(T.elementType===N||typeof N=="object"&&N!==null&&N.$$typeof===ft&&_o(N)===T.type){n(f,T.sibling),c=l(T,p.props),c.ref=Pn(f,T,p),c.return=f,f=c;break e}n(f,T);break}else t(f,T);T=T.sibling}p.type===Gt?(c=Ut(p.props.children,f.mode,g,p.key),c.return=f,f=c):(g=Br(p.type,p.key,p.props,null,f.mode,g),g.ref=Pn(f,c,p),g.return=f,f=g)}return s(f);case Xt:e:{for(T=p.key;c!==null;){if(c.key===T)if(c.tag===4&&c.stateNode.containerInfo===p.containerInfo&&c.stateNode.implementation===p.implementation){n(f,c.sibling),c=l(c,p.children||[]),c.return=f,f=c;break e}else{n(f,c);break}else t(f,c);c=c.sibling}c=ei(p,f.mode,g),c.return=f,f=c}return s(f);case ft:return T=p._init,j(f,c,T(p._payload),g)}if(Rn(p))return x(f,c,p,g);if(Cn(p))return S(f,c,p,g);jr(f,p)}return typeof p=="string"&&p!==""||typeof p=="number"?(p=""+p,c!==null&&c.tag===6?(n(f,c.sibling),c=l(c,p),c.return=f,f=c):(n(f,c),c=bl(p,f.mode,g),c.return=f,f=c),s(f)):n(f,c)}return j}var vn=ma(!0),va=ma(!1),tl=Tt(null),nl=null,rn=null,gs=null;function ws(){gs=rn=nl=null}function xs(e){var t=tl.current;W(tl),e._currentValue=t}function Ri(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 dn(e,t){nl=e,gs=rn=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Se=!0),e.firstContext=null)}function Fe(e){var t=e._currentValue;if(gs!==e)if(e={context:e,memoizedValue:t,next:null},rn===null){if(nl===null)throw Error(C(308));rn=e,nl.dependencies={lanes:0,firstContext:e}}else rn=rn.next=e;return t}var Mt=null;function Ss(e){Mt===null?Mt=[e]:Mt.push(e)}function ya(e,t,n,r){var l=t.interleaved;return l===null?(n.next=n,Ss(t)):(n.next=l.next,l.next=n),t.interleaved=n,ut(e,r)}function ut(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 pt=!1;function ks(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function ga(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 it(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function kt(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,F&2){var l=r.pending;return l===null?t.next=t:(t.next=l.next,l.next=t),r.pending=t,ut(e,n)}return l=r.interleaved,l===null?(t.next=t,Ss(r)):(t.next=l.next,l.next=t),r.interleaved=t,ut(e,n)}function Mr(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,os(e,n)}}function Po(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var l=null,i=null;if(n=n.firstBaseUpdate,n!==null){do{var s={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};i===null?l=i=s:i=i.next=s,n=n.next}while(n!==null);i===null?l=i=t:i=i.next=t}else l=i=t;n={baseState:r.baseState,firstBaseUpdate:l,lastBaseUpdate:i,shared:r.shared,effects:r.effects},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}function rl(e,t,n,r){var l=e.updateQueue;pt=!1;var i=l.firstBaseUpdate,s=l.lastBaseUpdate,u=l.shared.pending;if(u!==null){l.shared.pending=null;var a=u,d=a.next;a.next=null,s===null?i=d:s.next=d,s=a;var v=e.alternate;v!==null&&(v=v.updateQueue,u=v.lastBaseUpdate,u!==s&&(u===null?v.firstBaseUpdate=d:u.next=d,v.lastBaseUpdate=a))}if(i!==null){var m=l.baseState;s=0,v=d=a=null,u=i;do{var h=u.lane,w=u.eventTime;if((r&h)===h){v!==null&&(v=v.next={eventTime:w,lane:0,tag:u.tag,payload:u.payload,callback:u.callback,next:null});e:{var x=e,S=u;switch(h=t,w=n,S.tag){case 1:if(x=S.payload,typeof x=="function"){m=x.call(w,m,h);break e}m=x;break e;case 3:x.flags=x.flags&-65537|128;case 0:if(x=S.payload,h=typeof x=="function"?x.call(w,m,h):x,h==null)break e;m=X({},m,h);break e;case 2:pt=!0}}u.callback!==null&&u.lane!==0&&(e.flags|=64,h=l.effects,h===null?l.effects=[u]:h.push(u))}else w={eventTime:w,lane:h,tag:u.tag,payload:u.payload,callback:u.callback,next:null},v===null?(d=v=w,a=m):v=v.next=w,s|=h;if(u=u.next,u===null){if(u=l.shared.pending,u===null)break;h=u,u=h.next,h.next=null,l.lastBaseUpdate=h,l.shared.pending=null}}while(!0);if(v===null&&(a=m),l.baseState=a,l.firstBaseUpdate=d,l.lastBaseUpdate=v,t=l.shared.interleaved,t!==null){l=t;do s|=l.lane,l=l.next;while(l!==t)}else i===null&&(l.shared.lanes=0);Ht|=s,e.lanes=s,e.memoizedState=m}}function To(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=Xl.transition;Xl.transition={};try{e(!1),t()}finally{B=n,Xl.transition=r}}function Ma(){return Ie().memoizedState}function wf(e,t,n){var r=Nt(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},$a(e))Fa(t,n);else if(n=ya(e,t,n,r),n!==null){var l=pe();Xe(n,e,r,l),Ia(n,t,r)}}function xf(e,t,n){var r=Nt(e),l={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if($a(e))Fa(t,l);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=t.lastRenderedReducer,i!==null))try{var s=t.lastRenderedState,u=i(s,n);if(l.hasEagerState=!0,l.eagerState=u,Ge(u,s)){var a=t.interleaved;a===null?(l.next=l,Ss(t)):(l.next=a.next,a.next=l),t.interleaved=l;return}}catch{}finally{}n=ya(e,t,l,r),n!==null&&(l=pe(),Xe(n,e,r,l),Ia(n,t,r))}}function $a(e){var t=e.alternate;return e===Y||t!==null&&t===Y}function Fa(e,t){Bn=il=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function Ia(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,os(e,n)}}var sl={readContext:Fe,useCallback:oe,useContext:oe,useEffect:oe,useImperativeHandle:oe,useInsertionEffect:oe,useLayoutEffect:oe,useMemo:oe,useReducer:oe,useRef:oe,useState:oe,useDebugValue:oe,useDeferredValue:oe,useTransition:oe,useMutableSource:oe,useSyncExternalStore:oe,useId:oe,unstable_isNewReconciler:!1},Sf={readContext:Fe,useCallback:function(e,t){return Ze().memoizedState=[e,t===void 0?null:t],e},useContext:Fe,useEffect:Lo,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,Fr(4194308,4,za.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Fr(4194308,4,e,t)},useInsertionEffect:function(e,t){return Fr(4,2,e,t)},useMemo:function(e,t){var n=Ze();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=Ze();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=wf.bind(null,Y,e),[r.memoizedState,e]},useRef:function(e){var t=Ze();return e={current:e},t.memoizedState=e},useState:zo,useDebugValue:zs,useDeferredValue:function(e){return Ze().memoizedState=e},useTransition:function(){var e=zo(!1),t=e[0];return e=gf.bind(null,e[1]),Ze().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=Y,l=Ze();if(Q){if(n===void 0)throw Error(C(407));n=n()}else{if(n=t(),ne===null)throw Error(C(349));Vt&30||ka(r,t,n)}l.memoizedState=n;var i={value:n,getSnapshot:t};return l.queue=i,Lo(Na.bind(null,r,i,e),[e]),r.flags|=2048,sr(9,Ca.bind(null,r,i,n,t),void 0,null),n},useId:function(){var e=Ze(),t=ne.identifierPrefix;if(Q){var n=lt,r=rt;n=(r&~(1<<32-Ye(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=lr++,0<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=s.createElement(n,{is:r.is}):(e=s.createElement(n),n==="select"&&(s=e,r.multiple?s.multiple=!0:r.size&&(s.size=r.size))):e=s.createElementNS(e,n),e[qe]=t,e[tr]=r,Xa(e,t,!1,!1),t.stateNode=e;e:{switch(s=hi(n,r),n){case"dialog":H("cancel",e),H("close",e),l=r;break;case"iframe":case"object":case"embed":H("load",e),l=r;break;case"video":case"audio":for(l=0;lwn&&(t.flags|=128,r=!0,Tn(i,!1),t.lanes=4194304)}else{if(!r)if(e=ll(s),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Tn(i,!0),i.tail===null&&i.tailMode==="hidden"&&!s.alternate&&!Q)return ue(t),null}else 2*Z()-i.renderingStartTime>wn&&n!==1073741824&&(t.flags|=128,r=!0,Tn(i,!1),t.lanes=4194304);i.isBackwards?(s.sibling=t.child,t.child=s):(n=i.last,n!==null?n.sibling=s:t.child=s,i.last=s)}return i.tail!==null?(t=i.tail,i.rendering=t,i.tail=t.sibling,i.renderingStartTime=Z(),t.sibling=null,n=K.current,V(K,r?n&1|2:n&1),t):(ue(t),null);case 22:case 23:return $s(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?Ee&1073741824&&(ue(t),t.subtreeFlags&6&&(t.flags|=8192)):ue(t),null;case 24:return null;case 25:return null}throw Error(C(156,t.tag))}function Tf(e,t){switch(vs(t),t.tag){case 1:return Ce(t.type)&&Zr(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return yn(),W(ke),W(ce),js(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Ns(t),null;case 13:if(W(K),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(C(340));mn()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return W(K),null;case 4:return yn(),null;case 10:return xs(t.type._context),null;case 22:case 23:return $s(),null;case 24:return null;default:return null}}var _r=!1,ae=!1,zf=typeof WeakSet=="function"?WeakSet:Set,z=null;function ln(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){G(e,t,r)}else n.current=null}function Bi(e,t,n){try{n()}catch(r){G(e,t,r)}}var Vo=!1;function Lf(e,t){if(Ni=Yr,e=ta(),hs(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var l=r.anchorOffset,i=r.focusNode;r=r.focusOffset;try{n.nodeType,i.nodeType}catch{n=null;break e}var s=0,u=-1,a=-1,d=0,v=0,m=e,h=null;t:for(;;){for(var w;m!==n||l!==0&&m.nodeType!==3||(u=s+l),m!==i||r!==0&&m.nodeType!==3||(a=s+r),m.nodeType===3&&(s+=m.nodeValue.length),(w=m.firstChild)!==null;)h=m,m=w;for(;;){if(m===e)break t;if(h===n&&++d===l&&(u=s),h===i&&++v===r&&(a=s),(w=m.nextSibling)!==null)break;m=h,h=m.parentNode}m=w}n=u===-1||a===-1?null:{start:u,end:a}}else n=null}n=n||{start:0,end:0}}else n=null;for(ji={focusedElem:e,selectionRange:n},Yr=!1,z=t;z!==null;)if(t=z,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,z=e;else for(;z!==null;){t=z;try{var x=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(x!==null){var S=x.memoizedProps,j=x.memoizedState,f=t.stateNode,c=f.getSnapshotBeforeUpdate(t.elementType===t.type?S:We(t.type,S),j);f.__reactInternalSnapshotBeforeUpdate=c}break;case 3:var p=t.stateNode.containerInfo;p.nodeType===1?p.textContent="":p.nodeType===9&&p.documentElement&&p.removeChild(p.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(C(163))}}catch(g){G(t,t.return,g)}if(e=t.sibling,e!==null){e.return=t.return,z=e;break}z=t.return}return x=Vo,Vo=!1,x}function Vn(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var l=r=r.next;do{if((l.tag&e)===e){var i=l.destroy;l.destroy=void 0,i!==void 0&&Bi(t,n,i)}l=l.next}while(l!==r)}}function Sl(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function Vi(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function Za(e){var t=e.alternate;t!==null&&(e.alternate=null,Za(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[qe],delete t[tr],delete t[Pi],delete t[pf],delete t[hf])),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 qa(e){return e.tag===5||e.tag===3||e.tag===4}function Ho(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||qa(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 Hi(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=Jr));else if(r!==4&&(e=e.child,e!==null))for(Hi(e,t,n),e=e.sibling;e!==null;)Hi(e,t,n),e=e.sibling}function Wi(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(Wi(e,t,n),e=e.sibling;e!==null;)Wi(e,t,n),e=e.sibling}var re=null,Qe=!1;function dt(e,t,n){for(n=n.child;n!==null;)ba(e,t,n),n=n.sibling}function ba(e,t,n){if(be&&typeof be.onCommitFiberUnmount=="function")try{be.onCommitFiberUnmount(pl,n)}catch{}switch(n.tag){case 5:ae||ln(n,t);case 6:var r=re,l=Qe;re=null,dt(e,t,n),re=r,Qe=l,re!==null&&(Qe?(e=re,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):re.removeChild(n.stateNode));break;case 18:re!==null&&(Qe?(e=re,n=n.stateNode,e.nodeType===8?Ql(e.parentNode,n):e.nodeType===1&&Ql(e,n),Jn(e)):Ql(re,n.stateNode));break;case 4:r=re,l=Qe,re=n.stateNode.containerInfo,Qe=!0,dt(e,t,n),re=r,Qe=l;break;case 0:case 11:case 14:case 15:if(!ae&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){l=r=r.next;do{var i=l,s=i.destroy;i=i.tag,s!==void 0&&(i&2||i&4)&&Bi(n,t,s),l=l.next}while(l!==r)}dt(e,t,n);break;case 1:if(!ae&&(ln(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(u){G(n,t,u)}dt(e,t,n);break;case 21:dt(e,t,n);break;case 22:n.mode&1?(ae=(r=ae)||n.memoizedState!==null,dt(e,t,n),ae=r):dt(e,t,n);break;default:dt(e,t,n)}}function Wo(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new zf),t.forEach(function(r){var l=Af.bind(null,e,r);n.has(r)||(n.add(r),r.then(l,l))})}}function He(e,t){var n=t.deletions;if(n!==null)for(var r=0;rl&&(l=s),r&=~i}if(r=l,r=Z()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Of(r/1960))-r,10e?16:e,yt===null)var r=!1;else{if(e=yt,yt=null,al=0,F&6)throw Error(C(331));var l=F;for(F|=4,z=e.current;z!==null;){var i=z,s=i.child;if(z.flags&16){var u=i.deletions;if(u!==null){for(var a=0;aZ()-Ds?It(e,0):Os|=n),Ne(e,t)}function oc(e,t){t===0&&(e.mode&1?(t=gr,gr<<=1,!(gr&130023424)&&(gr=4194304)):t=1);var n=pe();e=ut(e,t),e!==null&&(ar(e,t,n),Ne(e,n))}function Uf(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),oc(e,n)}function Af(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(C(314))}r!==null&&r.delete(t),oc(e,n)}var uc;uc=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||ke.current)Se=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return Se=!1,_f(e,t,n);Se=!!(e.flags&131072)}else Se=!1,Q&&t.flags&1048576&&fa(t,el,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Ir(e,t),e=t.pendingProps;var l=hn(t,ce.current);dn(t,n),l=_s(null,t,r,e,l,n);var i=Ps();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,Ce(r)?(i=!0,qr(t)):i=!1,t.memoizedState=l.state!==null&&l.state!==void 0?l.state:null,ks(t),l.updater=xl,t.stateNode=l,l._reactInternals=t,Di(t,r,e,n),t=Fi(null,t,r,!0,i,n)):(t.tag=0,Q&&i&&ms(t),fe(null,t,l,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Ir(e,t),e=t.pendingProps,l=r._init,r=l(r._payload),t.type=r,l=t.tag=Vf(r),e=We(r,e),l){case 0:t=$i(null,t,r,e,n);break e;case 1:t=Uo(null,t,r,e,n);break e;case 11:t=Fo(null,t,r,e,n);break e;case 14:t=Io(null,t,r,We(r.type,e),n);break e}throw Error(C(306,r,""))}return t;case 0:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:We(r,l),$i(e,t,r,l,n);case 1:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:We(r,l),Uo(e,t,r,l,n);case 3:e:{if(Qa(t),e===null)throw Error(C(387));r=t.pendingProps,i=t.memoizedState,l=i.element,ga(e,t),rl(t,r,null,n);var s=t.memoizedState;if(r=s.element,i.isDehydrated)if(i={element:r,isDehydrated:!1,cache:s.cache,pendingSuspenseBoundaries:s.pendingSuspenseBoundaries,transitions:s.transitions},t.updateQueue.baseState=i,t.memoizedState=i,t.flags&256){l=gn(Error(C(423)),t),t=Ao(e,t,r,n,l);break e}else if(r!==l){l=gn(Error(C(424)),t),t=Ao(e,t,r,n,l);break e}else for(_e=St(t.stateNode.containerInfo.firstChild),Pe=t,Q=!0,Ke=null,n=va(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(mn(),r===l){t=at(e,t,n);break e}fe(e,t,r,n)}t=t.child}return t;case 5:return wa(t),e===null&&Li(t),r=t.type,l=t.pendingProps,i=e!==null?e.memoizedProps:null,s=l.children,Ei(r,l)?s=null:i!==null&&Ei(r,i)&&(t.flags|=32),Wa(e,t),fe(e,t,s,n),t.child;case 6:return e===null&&Li(t),null;case 13:return Ka(e,t,n);case 4:return Cs(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=vn(t,null,r,n):fe(e,t,r,n),t.child;case 11:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:We(r,l),Fo(e,t,r,l,n);case 7:return fe(e,t,t.pendingProps,n),t.child;case 8:return fe(e,t,t.pendingProps.children,n),t.child;case 12:return fe(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,l=t.pendingProps,i=t.memoizedProps,s=l.value,V(tl,r._currentValue),r._currentValue=s,i!==null)if(Ge(i.value,s)){if(i.children===l.children&&!ke.current){t=at(e,t,n);break e}}else for(i=t.child,i!==null&&(i.return=t);i!==null;){var u=i.dependencies;if(u!==null){s=i.child;for(var a=u.firstContext;a!==null;){if(a.context===r){if(i.tag===1){a=it(-1,n&-n),a.tag=2;var d=i.updateQueue;if(d!==null){d=d.shared;var v=d.pending;v===null?a.next=a:(a.next=v.next,v.next=a),d.pending=a}}i.lanes|=n,a=i.alternate,a!==null&&(a.lanes|=n),Ri(i.return,n,t),u.lanes|=n;break}a=a.next}}else if(i.tag===10)s=i.type===t.type?null:i.child;else if(i.tag===18){if(s=i.return,s===null)throw Error(C(341));s.lanes|=n,u=s.alternate,u!==null&&(u.lanes|=n),Ri(s,n,t),s=i.sibling}else s=i.child;if(s!==null)s.return=i;else for(s=i;s!==null;){if(s===t){s=null;break}if(i=s.sibling,i!==null){i.return=s.return,s=i;break}s=s.return}i=s}fe(e,t,l.children,n),t=t.child}return t;case 9:return l=t.type,r=t.pendingProps.children,dn(t,n),l=Fe(l),r=r(l),t.flags|=1,fe(e,t,r,n),t.child;case 14:return r=t.type,l=We(r,t.pendingProps),l=We(r.type,l),Io(e,t,r,l,n);case 15:return Va(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:We(r,l),Ir(e,t),t.tag=1,Ce(r)?(e=!0,qr(t)):e=!1,dn(t,n),Ua(t,r,l),Di(t,r,l,n),Fi(null,t,r,!0,e,n);case 19:return Ya(e,t,n);case 22:return Ha(e,t,n)}throw Error(C(156,t.tag))};function ac(e,t){return $u(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 Me(e,t,n,r){return new Bf(e,t,n,r)}function Is(e){return e=e.prototype,!(!e||!e.isReactComponent)}function Vf(e){if(typeof e=="function")return Is(e)?1:0;if(e!=null){if(e=e.$$typeof,e===rs)return 11;if(e===ls)return 14}return 2}function jt(e,t){var n=e.alternate;return n===null?(n=Me(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 Br(e,t,n,r,l,i){var s=2;if(r=e,typeof e=="function")Is(e)&&(s=1);else if(typeof e=="string")s=5;else e:switch(e){case Gt:return Ut(n.children,l,i,t);case ns:s=8,l|=8;break;case li:return e=Me(12,n,t,l|2),e.elementType=li,e.lanes=i,e;case ii:return e=Me(13,n,t,l),e.elementType=ii,e.lanes=i,e;case si:return e=Me(19,n,t,l),e.elementType=si,e.lanes=i,e;case wu:return Cl(n,l,i,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case yu:s=10;break e;case gu:s=9;break e;case rs:s=11;break e;case ls:s=14;break e;case ft:s=16,r=null;break e}throw Error(C(130,e==null?e:typeof e,""))}return t=Me(s,n,t,l),t.elementType=e,t.type=r,t.lanes=i,t}function Ut(e,t,n,r){return e=Me(7,e,r,t),e.lanes=n,e}function Cl(e,t,n,r){return e=Me(22,e,r,t),e.elementType=wu,e.lanes=n,e.stateNode={isHidden:!1},e}function bl(e,t,n){return e=Me(6,e,null,t),e.lanes=n,e}function ei(e,t,n){return t=Me(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function Hf(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=Dl(0),this.expirationTimes=Dl(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Dl(0),this.identifierPrefix=r,this.onRecoverableError=l,this.mutableSourceEagerHydrationData=null}function Us(e,t,n,r,l,i,s,u,a){return e=new Hf(e,t,n,u,a),t===1?(t=1,i===!0&&(t|=8)):t=0,i=Me(3,null,null,t),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},ks(i),e}function Wf(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(pc)}catch(e){console.error(e)}}pc(),pu.exports=ze;var Gf=pu.exports,hc,qo=Gf;hc=qo.createRoot,qo.hydrateRoot;async function ve(e){const t=await fetch(e);if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()}async function Jf(){return ve("/api/archives")}async function Zf(e){return ve(`/api/archives/${e}/entries`)}async function qf(e,t,n){const r=new URLSearchParams;return t&&r.set("q",t),n&&r.set("tag",n),ve(`/api/archives/${e}/entries/search?${r}`)}async function bf(e,t){return ve(`/api/archives/${e}/entries/${t}`)}async function ti(e,t){return ve(`/api/archives/${e}/entries/${t}/tags`)}async function ep(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 tp(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 bo(e){return ve(`/api/archives/${e}/runs`)}async function ni(e){return ve(`/api/archives/${e}/tags`)}async function np(e,t){const n=await fetch(`/api/archives/${e}/captures`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({locator:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||`HTTP ${n.status}`)}return n.json()}async function rp(e,t){return ve(`/api/archives/${e}/capture_jobs/${t}`)}async function lp(){return(await(await fetch("/api/auth/setup")).json()).setup_required===!0}async function ip(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 sp(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 op(){await fetch("/api/auth/logout",{method:"POST"})}async function up(){const e=await fetch("/api/auth/me");return e.status===401?null:e.json()}async function ap(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 cp(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 dp(){return ve("/api/auth/tokens")}async function fp(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 pp(e){const t=await fetch(`/api/auth/tokens/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(await t.text())}async function hp(){return ve("/api/admin/instance-settings")}async function mp(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 vp(){return ve("/api/admin/users")}async function yp(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 gp(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 wp(){return ve("/api/admin/roles")}async function xp(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 Sp(e){return ve(`/api/archives/${e}/collections`)}async function kp(e,t,n,r=2){const l=await fetch(`/api/archives/${e}/collections`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:t,slug:n,default_visibility_bits:r})});if(!l.ok){const i=await l.json().catch(()=>({error:l.statusText}));throw new Error(i.error||l.statusText)}return l.json()}async function Cp(e,t){return ve(`/api/archives/${e}/collections/${t}`)}async function Np(e,t,n,r=2){const l=await fetch(`/api/archives/${e}/collections/${t}/entries`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({entry_uid:n,visibility_bits:r})});if(!l.ok){const i=await l.json().catch(()=>({error:l.statusText}));throw new Error(i.error||l.statusText)}}async function jp(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 Ep(e,t,n,r){const l=await fetch(`/api/archives/${e}/collections/${t}/entries/${n}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({visibility_bits:r})});if(!l.ok){const i=await l.json().catch(()=>({error:l.statusText}));throw new Error(i.error||l.statusText)}}async function _p(e,t){return ve(`/api/archives/${e}/entries/${t}/collections`)}async function eu(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 Pp(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)}}const Tp=window.fetch;window.fetch=async(...e)=>{var n;const t=await Tp(...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 zp({onLogin:e}){const[t,n]=y.useState(""),[r,l]=y.useState(""),[i,s]=y.useState(null),[u,a]=y.useState(!1);async function d(v){v.preventDefault(),s(null),a(!0);try{const m=await sp(t,r);e(m)}catch(m){s(m.message)}finally{a(!1)}}return o.jsxs("div",{className:"login-page",children:[o.jsx("h1",{children:"Archivr"}),o.jsxs("form",{onSubmit:d,children:[o.jsxs("label",{children:["Username",o.jsx("input",{type:"text",value:t,onChange:v=>n(v.target.value),autoFocus:!0,required:!0})]}),o.jsxs("label",{children:["Password",o.jsx("input",{type:"password",value:r,onChange:v=>l(v.target.value),required:!0})]}),i&&o.jsx("p",{className:"error",children:i}),o.jsx("button",{type:"submit",disabled:u,children:u?"Logging in…":"Log in"})]})]})}function Lp({onComplete:e}){const[t,n]=y.useState(""),[r,l]=y.useState(""),[i,s]=y.useState(""),[u,a]=y.useState(null),[d,v]=y.useState(!1);async function m(h){if(h.preventDefault(),r!==i){a("Passwords do not match");return}if(r.length<8){a("Password must be at least 8 characters");return}a(null),v(!0);try{await ip(t,r),e()}catch(w){a(w.message)}finally{v(!1)}}return o.jsxs("div",{className:"setup-page",children:[o.jsx("h1",{children:"Welcome to Archivr"}),o.jsx("p",{children:"Create your owner account to get started."}),o.jsxs("form",{onSubmit:m,children:[o.jsxs("label",{children:["Username",o.jsx("input",{type:"text",value:t,onChange:h=>n(h.target.value),autoFocus:!0,required:!0})]}),o.jsxs("label",{children:["Password",o.jsx("input",{type:"password",value:r,onChange:h=>l(h.target.value),required:!0})]}),o.jsxs("label",{children:["Confirm password",o.jsx("input",{type:"password",value:i,onChange:h=>s(h.target.value),required:!0})]}),u&&o.jsx("p",{className:"error",children:u}),o.jsx("button",{type:"submit",disabled:d,children:d?"Creating account…":"Create account"})]})]})}function Rp({archives:e,archiveId:t,onArchiveChange:n,view:r,onViewChange:l,onCaptureClick:i}){const{currentUser:s,setCurrentUser:u}=y.useContext(Pl)??{},[a,d]=y.useState(!1);async function v(){d(!0),await op(),u(null),window.location.reload()}return o.jsxs("header",{className:"topbar",children:[o.jsx("div",{className:"brand",children:"Archivr"}),o.jsx("select",{className:"archive-switcher","aria-label":"Select archive",value:t??"",onChange:m=>n(m.target.value),children:e.map(m=>o.jsx("option",{value:m.id,children:m.label},m.id))}),o.jsx("nav",{className:"nav","aria-label":"Primary",children:["archive","runs","admin","tags","collections","settings"].map(m=>o.jsx("button",{className:`nav-link${r===m?" is-active":""}`,onClick:()=>l(m),children:m.charAt(0).toUpperCase()+m.slice(1)},m))}),o.jsx("button",{className:"capture-button",onClick:i,children:"+ Capture"}),s&&o.jsxs("div",{className:"user-menu",children:[o.jsx("span",{className:"username",children:s.display_name||s.username}),o.jsx("button",{className:"nav-link",onClick:()=>l("settings"),style:{color:"#d7cdbf",fontSize:13},children:"Settings"}),o.jsx("button",{onClick:v,disabled:a,className:"logout-btn",children:a?"Logging out…":"Log out"})]})]})}function Op({open:e,archiveId:t,onClose:n,onCaptured:r}){const l=y.useRef(null),[i,s]=y.useState(""),[u,a]=y.useState(null),[d,v]=y.useState(!1),[m,h]=y.useState(null),w=y.useRef(null);y.useEffect(()=>{const j=l.current;if(!j)return;const f=()=>{clearInterval(w.current),n()};return j.addEventListener("close",f),()=>j.removeEventListener("close",f)},[n]),y.useEffect(()=>{const j=l.current;j&&(e?(s(""),a(null),h(null),v(!1),clearInterval(w.current),j.open||j.showModal()):j.open&&j.close())},[e]);async function x(){if(!i.trim()){a("Enter a locator.");return}v(!0),a(null),h(null);try{const j=await np(t,i.trim());h("running"),w.current=setInterval(async()=>{var f;try{const c=await rp(t,j.job_uid);c.status==="completed"?(clearInterval(w.current),w.current=null,v(!1),h("completed"),(f=l.current)==null||f.close(),r()):c.status==="failed"&&(clearInterval(w.current),w.current=null,v(!1),h("failed"),a(c.error_text||"Capture failed."))}catch(c){clearInterval(w.current),w.current=null,v(!1),a(c.message)}},500)}catch(j){a(j.message),v(!1)}}function S(){return d?m==="running"?"Running…":"Capturing…":"Capture"}return o.jsx("dialog",{ref:l,className:"capture-dialog",children:o.jsxs("div",{className:"capture-dialog-inner",children:[o.jsx("h2",{className:"capture-dialog-title",children:"Capture"}),o.jsx("label",{htmlFor:"capture-locator",className:"capture-label",children:"Locator"}),o.jsx("input",{id:"capture-locator",className:"capture-input",type:"text",placeholder:"tweet:1234567890 or https://...",value:i,onChange:j=>s(j.target.value),onKeyDown:j=>{j.key==="Enter"&&x()},autoComplete:"off"}),u&&o.jsx("div",{className:"capture-error",children:u}),o.jsxs("div",{className:"capture-actions",children:[o.jsx("button",{type:"button",className:"capture-cancel",onClick:()=>{var j;return(j=l.current)==null?void 0:j.close()},children:"Cancel"}),o.jsx("button",{type:"button",className:"capture-submit",onClick:x,disabled:d,children:S()})]})]})})}function mc(e){if(!e)return"0 B";const t=["B","KB","MB","GB"];let n=e,r=0;for(;n>=1024&&rString(r).padStart(2,"0");return`${t.getUTCFullYear()}-${n(t.getUTCMonth()+1)}-${n(t.getUTCDate())} ${n(t.getUTCHours())}:${n(t.getUTCMinutes())}`}const tu={youtube:'',x:'',instagram:'',facebook:'',tiktok:'',reddit:'',snapchat:'',local:'',web:'',other:'?'};function Dp(e){return tu[e]??tu.other}function Mp({entry:e,archiveId:t,isSelected:n,onSelect:r}){const[l,i]=y.useState(!1),u=e.source_kind==="web"&&e.entity_kind==="page"&&e.has_favicon&&t&&!l?o.jsx("img",{src:`/api/archives/${t}/entries/${e.entry_uid}/favicon`,width:"16",height:"16",alt:"",onError:()=>i(!0),style:{objectFit:"contain"}}):o.jsx("span",{dangerouslySetInnerHTML:{__html:Dp(e.source_kind)}});return o.jsxs("div",{className:n?"is-selected":void 0,tabIndex:0,"data-entry-uid":e.entry_uid,onClick:r,onKeyDown:a=>{a.key==="Enter"&&r()},children:[o.jsx("div",{className:"col-added",children:vc(e.archived_at)}),o.jsxs("div",{className:"col-title",children:[o.jsx("span",{className:"source-icon",children:u}),o.jsx("span",{className:"entry-title",children:Ft(e.title)||Ft(e.entry_uid)})]}),o.jsx("div",{className:"col-type",children:o.jsx("span",{className:"type-pill",children:Ft(e.entity_kind)})}),o.jsx("div",{className:"col-size",children:mc(e.total_artifact_bytes)}),o.jsx("div",{className:"url-cell col-url",children:Ft(e.original_url)})]})}function $p({entries:e,selectedEntryUid:t,onSelectEntry:n,archiveId:r}){return o.jsx("section",{id:"archive-view",className:"view is-active",children:o.jsxs("div",{className:"entry-table",children:[o.jsxs("div",{className:"entry-header-row",children:[o.jsx("div",{className:"col-added",children:"Added"}),o.jsx("div",{className:"col-title",children:"Title"}),o.jsx("div",{className:"col-type",children:"Type"}),o.jsx("div",{className:"col-size",children:"Size"}),o.jsx("div",{className:"col-url",children:"Original URL"})]}),o.jsx("div",{id:"entries-body",children:e.map(l=>o.jsx(Mp,{entry:l,archiveId:r,isSelected:l.entry_uid===t,onSelect:()=>n(l)},l.entry_uid))})]})})}function Fp({runs:e}){return o.jsx("section",{id:"runs-view",className:"view is-active",children:o.jsxs("table",{className:"entry-table",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Started"}),o.jsx("th",{children:"Status"}),o.jsx("th",{children:"Requested"}),o.jsx("th",{children:"Completed"}),o.jsx("th",{children:"Failed"})]})}),o.jsx("tbody",{children:e.map((t,n)=>o.jsxs("tr",{children:[o.jsx("td",{children:t.started_at??""}),o.jsx("td",{children:t.status??""}),o.jsx("td",{children:t.requested_count??""}),o.jsx("td",{children:t.completed_count??""}),o.jsx("td",{children:t.failed_count??""})]},n))})]})})}const Ip=4;function Up({archives:e}){const{currentUser:t}=y.useContext(Pl)??{},n=t&&(t.role_bits&Ip)!==0,[r,l]=y.useState("users"),[i,s]=y.useState([]),[u,a]=y.useState([]),[d,v]=y.useState(!1),[m,h]=y.useState(null),[w,x]=y.useState(""),[S,j]=y.useState(""),[f,c]=y.useState(""),[p,g]=y.useState(null),[N,T]=y.useState(!1),[P,L]=y.useState(""),[U,D]=y.useState(""),[J,je]=y.useState(null),[ye,ge]=y.useState(!1),Ue=y.useCallback(async()=>{if(n){v(!0),h(null);try{const[k,R]=await Promise.all([vp(),wp()]);s(k),a(R)}catch(k){h(k.message)}finally{v(!1)}}},[n]);y.useEffect(()=>{Ue()},[Ue]);async function Ae(k){const R=k.status==="active"?"disabled":"active";try{await gp(k.user_uid,R),s(A=>A.map(O=>O.user_uid===k.user_uid?{...O,status:R}:O))}catch(A){h(A.message)}}async function Be(k){if(k.preventDefault(),!w.trim()||!S){g("Username and password required");return}T(!0),g(null);try{await yp(w.trim(),S,f.trim()||void 0),x(""),j(""),c(""),await Ue()}catch(R){g(R.message)}finally{T(!1)}}async function E(k){if(k.preventDefault(),!P.trim()||!U.trim()){je("Slug and name required");return}ge(!0),je(null);try{await xp(P.trim(),U.trim()),L(""),D(""),await Ue()}catch(R){je(R.message)}finally{ge(!1)}}return n?o.jsxs("section",{id:"admin-view",className:"view admin-view is-active",children:[o.jsx("h1",{children:"Admin"}),o.jsxs("div",{className:"admin-tabs",children:[o.jsx("button",{className:`admin-tab${r==="users"?" is-active":""}`,onClick:()=>l("users"),children:"Users"}),o.jsx("button",{className:`admin-tab${r==="roles"?" is-active":""}`,onClick:()=>l("roles"),children:"Roles"}),o.jsx("button",{className:`admin-tab${r==="archives"?" is-active":""}`,onClick:()=>l("archives"),children:"Archives"})]}),m&&o.jsx("div",{className:"capture-error",children:m}),r==="users"&&o.jsxs("div",{className:"admin-section",children:[o.jsx("h2",{children:"Users"}),d?o.jsx("p",{className:"muted",children:"Loading…"}):o.jsxs("table",{className:"admin-table",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Username"}),o.jsx("th",{children:"Email"}),o.jsx("th",{children:"Roles"}),o.jsx("th",{children:"Status"}),o.jsx("th",{children:"Actions"})]})}),o.jsx("tbody",{children:i.map(k=>o.jsxs("tr",{className:k.status==="disabled"?"admin-row-disabled":"",children:[o.jsx("td",{children:k.username}),o.jsx("td",{className:"muted",children:k.email||"—"}),o.jsx("td",{children:k.role_slugs.join(", ")||"—"}),o.jsx("td",{children:o.jsx("span",{className:`status-badge status-${k.status}`,children:k.status})}),o.jsx("td",{children:o.jsx("button",{className:"admin-action-btn",onClick:()=>Ae(k),children:k.status==="active"?"Ban":"Unban"})})]},k.user_uid))})]}),o.jsx("h3",{children:"Create User"}),o.jsxs("form",{className:"admin-form",onSubmit:Be,children:[o.jsx("input",{className:"admin-input",placeholder:"Username",value:w,onChange:k=>x(k.target.value),required:!0}),o.jsx("input",{className:"admin-input",type:"password",placeholder:"Password (min 8 chars)",value:S,onChange:k=>j(k.target.value),required:!0}),o.jsx("input",{className:"admin-input",type:"email",placeholder:"Email (optional)",value:f,onChange:k=>c(k.target.value)}),p&&o.jsx("div",{className:"capture-error",children:p}),o.jsx("button",{className:"capture-submit",type:"submit",disabled:N,children:N?"Creating…":"Create User"})]})]}),r==="roles"&&o.jsxs("div",{className:"admin-section",children:[o.jsx("h2",{children:"Roles"}),d?o.jsx("p",{className:"muted",children:"Loading…"}):o.jsxs("table",{className:"admin-table",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Slug"}),o.jsx("th",{children:"Name"}),o.jsx("th",{children:"Level"}),o.jsx("th",{children:"Bit"}),o.jsx("th",{children:"Built-in"})]})}),o.jsx("tbody",{children:u.map(k=>o.jsxs("tr",{children:[o.jsx("td",{children:o.jsx("code",{children:k.slug})}),o.jsx("td",{children:k.name}),o.jsx("td",{children:k.level}),o.jsx("td",{children:k.bit_position}),o.jsx("td",{children:k.is_builtin?"✓":""})]},k.role_uid))})]}),o.jsx("h3",{children:"Create Custom Role"}),o.jsxs("form",{className:"admin-form",onSubmit:E,children:[o.jsx("input",{className:"admin-input",placeholder:"Slug (e.g. moderator)",value:P,onChange:k=>L(k.target.value),required:!0}),o.jsx("input",{className:"admin-input",placeholder:"Display Name (e.g. Moderator)",value:U,onChange:k=>D(k.target.value),required:!0}),J&&o.jsx("div",{className:"capture-error",children:J}),o.jsx("button",{className:"capture-submit",type:"submit",disabled:ye,children:ye?"Creating…":"Create Role"})]})]}),r==="archives"&&o.jsxs("div",{className:"admin-section",children:[o.jsx("h2",{children:"Mounted Archives"}),o.jsx("div",{className:"admin-list",children:e.map(k=>o.jsxs("div",{className:"admin-archive",children:[o.jsx("strong",{children:k.label}),o.jsx("div",{className:"muted",children:k.archive_path})]},k.id))})]})]}):o.jsxs("section",{id:"admin-view",className:"view admin-view is-active",children:[o.jsx("h1",{children:"Admin"}),o.jsx("p",{className:"muted",children:"You need admin privileges to access this panel."}),o.jsx("h2",{children:"Mounted Archives"}),o.jsx("div",{className:"admin-list",children:e.map(k=>o.jsxs("div",{className:"admin-archive",children:[o.jsx("strong",{children:k.label}),o.jsx("div",{className:"muted",children:k.archive_path})]},k.id))})]})}function yc({node:e,tagFilter:t,onTagFilterSet:n,onViewChange:r}){var s;const l=t===e.tag.full_path;function i(){const u=l?null:e.tag.full_path;n(u),r("archive")}return o.jsxs("li",{children:[o.jsx("button",{className:`tag-node-btn${l?" is-active":""}`,title:e.tag.full_path,onClick:i,children:e.tag.name}),((s=e.children)==null?void 0:s.length)>0&&o.jsx("div",{className:"tag-children",children:o.jsx("ul",{className:"tag-tree-list",children:e.children.map(u=>o.jsx(yc,{node:u,tagFilter:t,onTagFilterSet:n,onViewChange:r},u.tag.tag_uid))})})]})}function Ap({tagNodes:e,tagFilter:t,onTagFilterSet:n,onViewChange:r}){return o.jsx("section",{id:"tags-view",className:"view is-active",children:o.jsx("div",{className:"tag-tree",children:e.length===0?o.jsx("div",{children:"No tags yet."}):o.jsx("ul",{className:"tag-tree-list",children:e.map(l=>o.jsx(yc,{node:l,tagFilter:t,onTagFilterSet:n,onViewChange:r},l.tag.tag_uid))})})})}const Mn=[{value:0,label:"Private"},{value:2,label:"Users only"},{value:3,label:"Public"}],Bp=e=>{var t;return((t=Mn.find(n=>n.value===e))==null?void 0:t.label)??String(e)};function Vp({archiveId:e}){const[t,n]=y.useState([]),[r,l]=y.useState(!1),[i,s]=y.useState(null),[u,a]=y.useState(null),[d,v]=y.useState(null),[m,h]=y.useState(!1),[w,x]=y.useState(null),[S,j]=y.useState(""),[f,c]=y.useState(""),[p,g]=y.useState(2),[N,T]=y.useState(!1),[P,L]=y.useState(null),[U,D]=y.useState(""),[J,je]=y.useState(2),[ye,ge]=y.useState(!1),[Ue,Ae]=y.useState(null),[Be,E]=y.useState(!1),[k,R]=y.useState(""),A=y.useRef(null),O=t.find(_=>_.collection_uid===u)??null,de=(O==null?void 0:O.slug)==="_default_",M=y.useCallback(async()=>{if(e){l(!0),s(null);try{const _=await Sp(e);n(_)}catch(_){s(_.message)}finally{l(!1)}}},[e]),se=y.useCallback(async _=>{if(!_){v(null);return}h(!0),x(null);try{const I=await Cp(e,_);v(I)}catch(I){x(I.message)}finally{h(!1)}},[e]);y.useEffect(()=>{M()},[M]),y.useEffect(()=>{se(u)},[u,se]),y.useEffect(()=>{Be&&A.current&&A.current.focus()},[Be]);async function Re(_){_.preventDefault();const I=S.trim(),Ve=f.trim();if(!(!I||!Ve)){T(!0),L(null);try{const Lt=await kp(e,I,Ve,p);j(""),c(""),g(2),await M(),a(Lt.collection_uid)}catch(Lt){L(Lt.message)}finally{T(!1)}}}async function we(){const _=k.trim();if(!_||!O){E(!1);return}try{await eu(e,O.collection_uid,{name:_}),await M(),v(I=>I&&{...I,name:_})}catch(I){s(I.message)}finally{E(!1)}}async function gc(_){if(O)try{await eu(e,O.collection_uid,{default_visibility_bits:_}),await M(),v(I=>I&&{...I,default_visibility_bits:_})}catch(I){s(I.message)}}async function wc(){if(O&&window.confirm(`Delete collection "${O.name}"? Entries will not be deleted.`))try{await Pp(e,O.collection_uid),a(null),v(null),await M()}catch(_){s(_.message)}}async function xc(_){_.preventDefault();const I=U.trim();if(!(!I||!O)){ge(!0),Ae(null);try{await Np(e,O.collection_uid,I,J),D(""),await se(O.collection_uid)}catch(Ve){Ae(Ve.message)}finally{ge(!1)}}}async function Sc(_){if(O)try{await jp(e,O.collection_uid,_),await se(O.collection_uid)}catch(I){x(I.message)}}async function kc(_,I){if(O)try{await Ep(e,O.collection_uid,_,I),v(Ve=>Ve&&{...Ve,entries:Ve.entries.map(Lt=>Lt.entry_uid===_?{...Lt,collection_visibility_bits:I}:Lt)})}catch(Ve){x(Ve.message)}}return e?o.jsxs("div",{className:"collections-view",children:[o.jsx("h2",{className:"collections-heading",children:"Collections"}),r&&o.jsx("div",{className:"muted",children:"Loading…"}),i&&o.jsxs("div",{className:"collections-error",children:[i," ",o.jsx("button",{onClick:()=>s(null),className:"coll-dismiss",children:"×"})]}),o.jsxs("div",{className:"collections-layout",children:[o.jsxs("div",{className:"collections-sidebar",children:[t.map(_=>o.jsxs("button",{className:`coll-row${u===_.collection_uid?" is-active":""}`,onClick:()=>a(_.collection_uid),children:[o.jsx("span",{className:"coll-row-name",children:_.name}),o.jsx("span",{className:"coll-row-meta",children:Bp(_.default_visibility_bits)})]},_.collection_uid)),t.length===0&&!r&&o.jsx("div",{className:"muted",style:{padding:"8px 12px"},children:"No collections yet."})]}),O?o.jsxs("div",{className:"coll-detail",children:[o.jsxs("div",{className:"coll-detail-header",children:[Be?o.jsx("input",{ref:A,className:"coll-rename-input",value:k,onChange:_=>R(_.target.value),onBlur:we,onKeyDown:_=>{_.key==="Enter"&&we(),_.key==="Escape"&&E(!1)}}):o.jsxs("h3",{className:`coll-detail-name${de?"":" coll-detail-name--editable"}`,title:de?void 0:"Click to rename",onClick:()=>{de||(R(O.name),E(!0))},children:[(d==null?void 0:d.name)??O.name,!de&&o.jsx("span",{className:"coll-edit-hint",children:" ✎"})]}),!de&&o.jsx("button",{className:"coll-delete-btn",onClick:wc,title:"Delete collection",children:"Delete"})]}),o.jsxs("div",{className:"coll-detail-vis",children:[o.jsx("span",{className:"coll-vis-label",children:"Default visibility"}),o.jsx("select",{className:"coll-vis-select",value:(d==null?void 0:d.default_visibility_bits)??O.default_visibility_bits,onChange:_=>gc(Number(_.target.value)),disabled:de,children:Mn.map(_=>o.jsx("option",{value:_.value,children:_.label},_.value))})]}),o.jsxs("div",{className:"coll-entries-section",children:[o.jsx("div",{className:"coll-section-heading",children:"Entries"}),m&&o.jsx("div",{className:"muted",children:"Loading…"}),w&&o.jsx("div",{className:"collections-error",children:w}),!m&&d&&(d.entries.length===0?o.jsx("div",{className:"muted",children:"No entries in this collection."}):o.jsx("ul",{className:"coll-entries-list",children:d.entries.map(_=>o.jsxs("li",{className:"coll-entry-row",children:[o.jsxs("div",{className:"coll-entry-info",children:[o.jsx("span",{className:"coll-entry-title",children:_.title||_.entry_uid}),o.jsx("span",{className:"coll-entry-kind muted",children:_.source_kind})]}),o.jsxs("div",{className:"coll-entry-actions",children:[o.jsx("select",{className:"coll-entry-vis-select",value:_.collection_visibility_bits,onChange:I=>kc(_.entry_uid,Number(I.target.value)),children:Mn.map(I=>o.jsx("option",{value:I.value,children:I.label},I.value))}),!de&&o.jsx("button",{className:"coll-entry-remove",onClick:()=>Sc(_.entry_uid),title:"Remove from collection",children:"×"})]})]},_.entry_uid))}))]}),!de&&o.jsxs("form",{className:"coll-add-entry-form",onSubmit:xc,children:[o.jsx("div",{className:"coll-section-heading",children:"Add entry"}),o.jsxs("div",{className:"coll-add-entry-row",children:[o.jsx("input",{className:"coll-add-entry-input",type:"text",value:U,onChange:_=>D(_.target.value),placeholder:"entry_uid",required:!0}),o.jsx("select",{className:"coll-vis-select",value:J,onChange:_=>je(Number(_.target.value)),children:Mn.map(_=>o.jsx("option",{value:_.value,children:_.label},_.value))}),o.jsx("button",{className:"coll-add-btn",type:"submit",disabled:ye,children:ye?"…":"Add"})]}),Ue&&o.jsx("div",{className:"collections-error",style:{marginTop:4},children:Ue})]})]}):o.jsx("div",{className:"coll-detail coll-detail--empty",children:o.jsx("div",{className:"muted",children:"Select a collection to view details."})})]}),o.jsxs("details",{className:"coll-create-details",style:{marginTop:"1.5rem"},children:[o.jsx("summary",{style:{cursor:"pointer",fontWeight:600},children:"Create collection"}),o.jsxs("form",{onSubmit:Re,style:{marginTop:"0.75rem",display:"flex",flexDirection:"column",gap:"0.5rem",maxWidth:400},children:[o.jsxs("label",{children:["Name",o.jsx("input",{className:"capture-input",type:"text",value:S,onChange:_=>{j(_.target.value),f||c(_.target.value.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},placeholder:"My Collection",required:!0})]}),o.jsxs("label",{children:["Slug",o.jsx("input",{className:"capture-input",type:"text",value:f,onChange:_=>c(_.target.value),placeholder:"my-collection",required:!0})]}),o.jsxs("label",{children:["Default visibility",o.jsx("select",{className:"capture-input",style:{height:42},value:p,onChange:_=>g(Number(_.target.value)),children:Mn.map(_=>o.jsx("option",{value:_.value,children:_.label},_.value))})]}),P&&o.jsx("div",{className:"collections-error",children:P}),o.jsx("button",{className:"capture-submit",type:"submit",disabled:N,style:{alignSelf:"flex-start",padding:"8px 20px"},children:N?"Creating…":"Create"})]})]})]}):o.jsx("div",{className:"view-placeholder",children:"Select an archive."})}const Hp=4;function Wp(){const{currentUser:e,setCurrentUser:t}=y.useContext(Pl)??{},n=e&&(e.role_bits&Hp)!==0,[r,l]=y.useState("profile");return o.jsxs("section",{className:"admin-view",children:[o.jsx("h1",{children:"Settings"}),o.jsx("div",{className:"admin-tabs",style:{display:"flex",gap:12,marginBottom:20},children:["profile","tokens",...n?["instance"]:[]].map(i=>o.jsx("button",{className:`nav-link${r===i?" is-active":""}`,style:{borderBottom:r===i?"2px solid var(--accent)":void 0,color:"var(--ink)"},onClick:()=>l(i),children:i==="profile"?"Profile":i==="tokens"?"API Tokens":"Instance"},i))}),r==="profile"&&o.jsx(Qp,{currentUser:e,setCurrentUser:t}),r==="tokens"&&o.jsx(Kp,{}),r==="instance"&&n&&o.jsx(Yp,{})]})}function Qp({currentUser:e,setCurrentUser:t}){const[n,r]=y.useState((e==null?void 0:e.display_name)??""),[l,i]=y.useState(!1),[s,u]=y.useState(null),[a,d]=y.useState(""),[v,m]=y.useState(""),[h,w]=y.useState(""),[x,S]=y.useState(!1),[j,f]=y.useState(null);async function c(g){g.preventDefault(),i(!0),u(null);try{await ap(n),t(N=>({...N,display_name:n||null})),u({ok:!0,text:"Saved."})}catch(N){u({ok:!1,text:N.message})}finally{i(!1)}}async function p(g){if(g.preventDefault(),v!==h){f({ok:!1,text:"Passwords do not match."});return}S(!0),f(null);try{await cp(a,v),d(""),m(""),w(""),f({ok:!0,text:"Password changed."})}catch(N){f({ok:!1,text:N.message})}finally{S(!1)}}return o.jsxs("div",{style:{maxWidth:480},children:[o.jsxs("div",{className:"admin-section",children:[o.jsx("h2",{style:{fontSize:15,marginBottom:12},children:"Display Name"}),o.jsxs("form",{className:"admin-form",onSubmit:c,children:[o.jsx("input",{className:"admin-input",placeholder:(e==null?void 0:e.username)??"",value:n,onChange:g=>r(g.target.value)}),s&&o.jsx("div",{className:s.ok?"muted":"capture-error",children:s.text}),o.jsx("button",{className:"capture-submit",type:"submit",disabled:l,children:l?"Saving…":"Save"})]})]}),o.jsxs("div",{className:"admin-section",style:{marginTop:28},children:[o.jsx("h2",{style:{fontSize:15,marginBottom:12},children:"Change Password"}),o.jsxs("form",{className:"admin-form",onSubmit:p,children:[o.jsx("input",{className:"admin-input",type:"password",placeholder:"Current password",value:a,onChange:g=>d(g.target.value),required:!0}),o.jsx("input",{className:"admin-input",type:"password",placeholder:"New password",value:v,onChange:g=>m(g.target.value),required:!0}),o.jsx("input",{className:"admin-input",type:"password",placeholder:"Confirm new password",value:h,onChange:g=>w(g.target.value),required:!0}),j&&o.jsx("div",{className:j.ok?"muted":"capture-error",children:j.text}),o.jsx("button",{className:"capture-submit",type:"submit",disabled:x,children:x?"Changing…":"Change Password"})]})]})]})}function Kp(){const[e,t]=y.useState([]),[n,r]=y.useState(!0),[l,i]=y.useState(null),[s,u]=y.useState(""),[a,d]=y.useState(!1),[v,m]=y.useState(null),h=y.useCallback(async()=>{r(!0),i(null);try{t(await dp())}catch(S){i(S.message)}finally{r(!1)}},[]);y.useEffect(()=>{h()},[h]);async function w(S){if(S.preventDefault(),!!s.trim()){d(!0);try{const j=await fp(s.trim());m(j),u(""),h()}catch(j){i(j.message)}finally{d(!1)}}}async function x(S){try{await pp(S),t(j=>j.filter(f=>f.token_uid!==S))}catch(j){i(j.message)}}return o.jsxs("div",{style:{maxWidth:640},children:[o.jsx("h2",{style:{fontSize:15,marginBottom:12},children:"API Tokens"}),v&&o.jsxs("div",{style:{background:"#e8f5e9",border:"1px solid #a5d6a7",padding:"12px 14px",marginBottom:16,fontSize:13},children:[o.jsx("strong",{children:"Token created."})," Copy it now \\u2014 it will not be shown again.",o.jsx("br",{}),o.jsx("code",{style:{wordBreak:"break-all",display:"block",marginTop:6,padding:"6px 8px",background:"#f5f5f5",border:"1px solid #ddd"},children:v.raw_token}),o.jsx("button",{style:{marginTop:8,fontSize:12,border:"1px solid #aaa",background:"none",cursor:"pointer"},onClick:()=>m(null),children:"Dismiss"})]}),o.jsxs("form",{className:"admin-form",onSubmit:w,style:{display:"flex",gap:8,marginBottom:16},children:[o.jsx("input",{className:"admin-input",placeholder:"Token name",value:s,onChange:S=>u(S.target.value),style:{flex:1},required:!0}),o.jsx("button",{className:"capture-submit",type:"submit",disabled:a,children:a?"Creating…":"Create"})]}),l&&o.jsx("div",{className:"capture-error",children:l}),n?o.jsx("div",{className:"muted",children:"Loading\\u2026"}):o.jsxs("div",{className:"admin-list",children:[e.length===0&&o.jsx("div",{className:"muted",children:"No tokens yet."}),e.map(S=>o.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",border:"1px solid var(--line)",background:"var(--paper-3)",padding:"10px 12px"},children:[o.jsxs("div",{children:[o.jsx("strong",{style:{fontSize:14},children:S.name}),o.jsxs("div",{className:"muted",style:{fontSize:12,marginTop:2},children:["Created ",S.created_at.slice(0,10),S.last_used_at&&` · Last used ${S.last_used_at.slice(0,10)}`]})]}),o.jsx("button",{onClick:()=>x(S.token_uid),style:{border:"1px solid var(--line)",background:"none",cursor:"pointer",color:"var(--accent)",fontSize:12,padding:"4px 10px"},children:"Revoke"})]},S.token_uid))]})]})}function Yp(){const[e,t]=y.useState(null),[n,r]=y.useState(!0),[l,i]=y.useState(null),[s,u]=y.useState(!1),[a,d]=y.useState(null);y.useEffect(()=>{(async()=>{try{t(await hp())}catch(m){i(m.message)}finally{r(!1)}})()},[]);async function v(m){m.preventDefault(),u(!0),d(null);try{await mp(e),d({ok:!0,text:"Saved."})}catch(h){d({ok:!1,text:h.message})}finally{u(!1)}}return n?o.jsx("div",{className:"muted",children:"Loading\\u2026"}):l?o.jsx("div",{className:"capture-error",children:l}):e?o.jsxs("div",{style:{maxWidth:480},children:[o.jsx("h2",{style:{fontSize:15,marginBottom:12},children:"Instance Settings"}),o.jsxs("form",{onSubmit:v,children:[o.jsxs("div",{className:"admin-section",children:[[["public_index_enabled","Public index (unauthenticated browsing)"],["public_entry_content_enabled","Public entry content"],["open_registration_enabled","Open registration"]].map(([m,h])=>o.jsxs("label",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:12,cursor:"pointer"},children:[o.jsx("input",{type:"checkbox",checked:!!e[m],onChange:w=>t(x=>({...x,[m]:w.target.checked}))}),h]},m)),o.jsxs("div",{style:{marginBottom:12},children:[o.jsx("label",{style:{display:"block",fontWeight:600,marginBottom:4,fontSize:13},children:"Default entry visibility"}),o.jsxs("select",{className:"admin-input",value:e.default_entry_visibility,onChange:m=>t(h=>({...h,default_entry_visibility:Number(m.target.value)})),children:[o.jsx("option",{value:0,children:"Private (0)"}),o.jsx("option",{value:2,children:"Unlisted (2)"}),o.jsx("option",{value:3,children:"Public (3)"})]})]})]}),a&&o.jsx("div",{className:a.ok?"muted":"capture-error",children:a.text}),o.jsx("button",{className:"capture-submit",type:"submit",disabled:s,children:s?"Saving…":"Save Settings"})]})]}):null}function Xp({archiveId:e,selectedEntry:t,onTagFilterSet:n,tagNodes:r,onTagsRefresh:l}){const[i,s]=y.useState(null),[u,a]=y.useState([]),[d,v]=y.useState(""),[m,h]=y.useState([]),[w,x]=y.useState(""),S=y.useRef(0);y.useEffect(()=>{if(!t||!e){s(null),a([]),h([]);return}const c=++S.current;s(null),a([]),Promise.all([bf(e,t.entry_uid),ti(e,t.entry_uid),_p(e,t.entry_uid)]).then(([p,g,N])=>{c===S.current&&(s(p),a(g),h(N))}).catch(()=>{})},[t,e]);async function j(){const c=d.trim();if(!(!c||!t))try{await ep(e,t.entry_uid,c),v(""),x("");const p=await ti(e,t.entry_uid);a(p),l()}catch(p){x(p.message)}}async function f(c){try{await tp(e,t.entry_uid,c);const p=await ti(e,t.entry_uid);a(p),l()}catch{}}return o.jsxs("aside",{className:"context-rail",children:[o.jsx("div",{className:"rail-title",children:"Context"}),t?i?o.jsxs("div",{className:"rail-body",children:[o.jsx("strong",{className:"rail-entry-title",children:Ft(i.summary.title)||Ft(i.summary.entry_uid)}),o.jsxs("div",{className:"rail-section",children:[i.summary.original_url&&o.jsxs("div",{className:"rail-item",children:[o.jsx("span",{className:"rail-label",children:"Original URL"}),":"," ",o.jsx("a",{href:i.summary.original_url,target:"_blank",rel:"noopener noreferrer",className:"rail-url-link",children:i.summary.original_url})]}),[["Added",vc(i.summary.archived_at)],["Source",i.summary.source_kind],["Type",i.summary.entity_kind],["Visibility",i.summary.visibility],["Structured root",i.structured_root_relpath]].map(([c,p])=>o.jsxs("div",{className:"rail-item",children:[o.jsx("span",{className:"rail-label",children:c}),": ",Ft(p)]},c))]}),i.artifacts.length>0?o.jsxs("div",{className:"rail-section",children:[o.jsxs("div",{className:"rail-section-heading",children:["Artifacts (",i.artifacts.length,")"]}),o.jsx("ul",{className:"artifact-list",children:i.artifacts.map((c,p)=>o.jsx("li",{children:o.jsxs("a",{href:`/api/archives/${e}/entries/${i.summary.entry_uid}/artifacts/${p}`,target:"_blank",rel:"noopener noreferrer",className:"artifact-link",children:[c.artifact_role.replace(/_/g," "),c.byte_size!=null?` (${mc(c.byte_size)})`:""]})},p))})]}):o.jsx("div",{className:"rail-item muted",children:"No artifacts."})]}):o.jsx("div",{className:"rail-body",children:"Loading…"}):o.jsx("div",{className:"rail-body",children:"Select an entry."}),t&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"entry-tags",children:u.length===0?o.jsx("span",{className:"muted",children:"No tags."}):u.map(c=>o.jsxs("span",{className:"tag-pill",title:c.full_path,children:[c.name,o.jsx("button",{className:"remove-tag",title:`Remove tag ${c.full_path}`,onClick:()=>f(c.tag_uid),children:"×"})]},c.tag_uid))}),o.jsxs("div",{className:"assign-tag-form",children:[o.jsx("input",{className:"assign-tag-input",type:"text",placeholder:"/science/cs",autoComplete:"off",value:d,onChange:c=>v(c.target.value),onKeyDown:c=>{c.key==="Enter"&&j()}}),o.jsx("button",{className:"assign-tag-btn",onClick:j,children:"Add tag"}),w&&o.jsx("div",{className:"muted",style:{fontSize:"0.85em",color:"var(--accent)"},children:w})]}),t&&m.length>0&&o.jsxs("div",{className:"rail-section",children:[o.jsx("div",{className:"rail-section-heading",children:"Collections"}),m.map(c=>o.jsxs("div",{className:"rail-item",children:[o.jsx("span",{className:"rail-label",children:c.collection_uid}),":"," ",o.jsx("span",{className:"muted",children:{0:"Private",1:"Public",2:"Users only",3:"Public"}[c.visibility_bits]??`bits:${c.visibility_bits}`})]},c.collection_uid))]})]})]})}const Pl=y.createContext(null);function Gp(){const[e,t]=y.useState("loading"),[n,r]=y.useState(null);y.useEffect(()=>{(async()=>{if(await lp()){t("setup");return}const se=await up();if(!se){t("login");return}r(se),t("authenticated")})()},[]),y.useEffect(()=>{const M=()=>{r(null),t("login")};return window.addEventListener("auth:expired",M),()=>window.removeEventListener("auth:expired",M)},[]);const[l,i]=y.useState([]),[s,u]=y.useState(null),[a,d]=y.useState([]),[v,m]=y.useState(null),[h,w]=y.useState(null),[x,S]=y.useState(null),[j,f]=y.useState("archive"),[c,p]=y.useState(""),[g,N]=y.useState(""),[T,P]=y.useState(!1),[L,U]=y.useState([]),[D,J]=y.useState([]),[je,ye]=y.useState(!1),ge=y.useCallback(async(M,se,Re)=>{if(M){P(!0);try{let we;se||Re?we=await qf(M,se,Re):we=await Zf(M),d(we),N(we.length===0?"No results":`${we.length} result${we.length===1?"":"s"}`)}catch{d([]),N("Search failed. Try again.")}finally{P(!1)}}},[]);y.useEffect(()=>{Jf().then(M=>{if(i(M),M.length>0){const se=M[0].id;u(se)}})},[]),y.useEffect(()=>{s&&(S(null),w(null),m(null),Promise.all([ge(s,"",null),bo(s).then(U),ni(s).then(J)]))},[s]),y.useEffect(()=>{if(s===null)return;const M=setTimeout(()=>{ge(s,c,x)},300);return()=>clearTimeout(M)},[c,s]),y.useEffect(()=>{s!==null&&(f("archive"),ge(s,c,x))},[x,s]);const Ue=y.useCallback(M=>{u(M)},[]),Ae=y.useCallback(M=>{f(M),M==="tags"&&s&&ni(s).then(J)},[s]),Be=y.useCallback(M=>{m(M?M.entry_uid:null),w(M)},[]),E=y.useCallback(M=>{S(M)},[]),k=y.useCallback(()=>{S(null)},[]),R=y.useCallback(()=>{s&&ni(s).then(J)},[s]),A=y.useCallback(()=>{ye(!0)},[]),O=y.useCallback(()=>{ye(!1)},[]),de=y.useCallback(()=>{s&&Promise.all([ge(s,c,x),bo(s).then(U)])},[s,c,x,ge]);return e==="loading"?o.jsx("div",{className:"auth-loading",children:"Loading\\u2026"}):e==="setup"?o.jsx(Lp,{onComplete:()=>t("login")}):e==="login"?o.jsx(zp,{onLogin:M=>{r(M),t("authenticated")}}):o.jsx(Pl.Provider,{value:{currentUser:n,setCurrentUser:r},children:o.jsxs(o.Fragment,{children:[o.jsx(Rp,{archives:l,archiveId:s,onArchiveChange:Ue,view:j,onViewChange:Ae,onCaptureClick:A}),o.jsxs("main",{className:"app-shell",children:[o.jsxs("div",{className:"workspace",children:[j==="archive"&&o.jsxs("div",{className:"search-row",children:[o.jsx("input",{className:"search-input",type:"search","aria-label":"Search archive","aria-busy":T,value:c,onChange:M=>p(M.target.value)}),o.jsxs("div",{className:"result-count",children:[g,x&&o.jsxs("button",{className:"tag-filter-badge",onClick:k,children:["× ",x]})]})]}),j==="archive"&&o.jsx($p,{entries:a,selectedEntryUid:v,onSelectEntry:Be,archiveId:s,tagFilter:x,onClearTagFilter:k,searchQuery:c,onSearchChange:p,resultCount:g,searchBusy:T}),j==="runs"&&o.jsx(Fp,{runs:L}),j==="admin"&&o.jsx(Up,{archives:l}),j==="tags"&&o.jsx(Ap,{tagNodes:D,tagFilter:x,onTagFilterSet:E,onViewChange:Ae}),j==="collections"&&o.jsx(Vp,{archiveId:s}),j==="settings"&&o.jsx(Wp,{})]}),o.jsx(Xp,{archiveId:s,selectedEntry:h,onTagFilterSet:E,tagNodes:D,onTagsRefresh:R})]}),o.jsx(Op,{open:je,archiveId:s,onClose:O,onCaptured:de})]})})}hc(document.getElementById("root")).render(o.jsx(y.StrictMode,{children:o.jsx(Gp,{})})); diff --git a/crates/archivr-server/static/assets/index-D40QFUPh.css b/crates/archivr-server/static/assets/index-D40QFUPh.css new file mode 100644 index 0000000..04f6484 --- /dev/null +++ b/crates/archivr-server/static/assets/index-D40QFUPh.css @@ -0,0 +1 @@ +:root{color-scheme:light;--ink: #20251f;--muted: #666a61;--paper: #f5f0e7;--paper-2: #e9e1d2;--paper-3: #fffaf0;--line: #d2c6b5;--line-soft: #e5dccd;--accent: #8d3f30;--accent-2: #b78342;--link: #245f72;--top: #141d18}*{box-sizing:border-box}body{margin:0;min-height:100vh;background:var(--paper);color:var(--ink);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif}button,input,select{font:inherit}.topbar{height:56px;display:grid;grid-template-columns:auto minmax(180px,250px) 1fr auto;align-items:center;gap:18px;padding:0 18px;background:var(--top);color:#f7eedf;border-bottom:3px solid var(--accent)}.brand{font-family:Georgia,Times New Roman,serif;font-size:28px;line-height:1}.archive-switcher{width:100%;min-width:0;border:1px solid rgba(247,238,223,.35);background:#202b25;color:#f7eedf;padding:7px 9px}.nav{display:flex;gap:16px;justify-content:flex-end;min-width:0}.nav-link{border:0;background:transparent;color:#d7cdbf;cursor:pointer;padding:8px 0}.nav-link.is-active{color:#fffaf0;border-bottom:1px solid #fffaf0}.capture-button{border:0;background:#f7eedf;color:var(--top);padding:9px 12px;cursor:pointer}.app-shell{height:calc(100vh - 56px);display:grid;grid-template-columns:minmax(0,1fr) 320px}.workspace{min-width:0;overflow:auto}.search-row{min-height:76px;display:grid;grid-template-columns:minmax(0,1fr) max-content;gap:18px;align-items:center;padding:14px 16px;background:var(--paper-2);border-bottom:1px solid var(--line)}.search-input{width:100%;height:46px;border:2px solid var(--ink);background:var(--paper-3);color:var(--ink);padding:0 14px;font-size:16px;outline-offset:3px}.result-count{min-width:76px;color:var(--muted);font-size:13px;text-align:right}.view{display:none}.view.is-active{display:block}.entry-table{width:100%;font-size:13px;overflow:auto}.entry-header-row{display:flex;align-items:stretch;position:sticky;top:0;z-index:1;background:#ded5c7;border-bottom:1px solid #cec4b5;color:#5d625e;font-size:11px;text-transform:uppercase}.entry-header-row>div{padding:10px;flex-shrink:0}#entries-body>div{display:flex;align-items:baseline;cursor:default;border-bottom:1px solid var(--line-soft)}#entries-body>div>div{padding:10px;flex-shrink:0;overflow:hidden}#entries-body>div:nth-child(2n){background:#f2ede5}#entries-body>div:nth-child(odd){background:var(--paper-3)}#entries-body>div.is-selected{background:#eee2d2;outline:2px solid var(--accent);outline-offset:-2px}.col-added{width:168px}.col-title{flex:1 1 0;min-width:0;overflow:hidden}.col-type{width:120px}.col-size{width:100px}.col-url{flex:0 0 30%;min-width:0;overflow:hidden}#runs-view .entry-table{border-collapse:collapse;table-layout:auto}#runs-view .entry-table th{position:sticky;top:0;z-index:1;text-align:left;padding:10px;background:#ded5c7;color:#5d625e;border-bottom:1px solid #cec4b5;font-size:11px;text-transform:uppercase}#runs-view .entry-table td{padding:10px;border-bottom:1px solid var(--line-soft);vertical-align:top}#runs-view .entry-table tr:nth-child(2n) td{background:#f2ede5}#runs-view .entry-table tr:nth-child(odd) td{background:var(--paper-3)}.entry-title{color:var(--link);font-weight:750}.source-icon{display:inline-flex;align-items:center;width:1em;height:1em;margin-right:.35em;vertical-align:middle;flex-shrink:0}.source-icon svg{width:100%;height:100%}.url-cell{color:#555b55;word-break:break-all}.type-pill{display:inline-block;padding:2px 6px;background:#d8e3df;color:#275a5f;border:1px solid #bfd0ca}.context-rail{border-left:1px solid var(--line);background:#efe7dc;padding:18px;overflow:auto}.rail-title{color:var(--accent);font-weight:800;margin-bottom:10px;text-transform:uppercase;font-size:12px;letter-spacing:0}.rail-body{color:var(--muted);font-size:14px;line-height:1.6}.rail-body strong{color:var(--ink)}.rail-item{padding:10px 0;border-bottom:1px solid var(--line)}.admin-view{padding:22px}.admin-view h1{margin:0 0 16px;font-size:18px}.admin-list{display:grid;gap:10px;max-width:780px}.admin-archive{border:1px solid var(--line);background:var(--paper-3);padding:12px}.muted{color:var(--muted)}@media (max-width: 900px){.topbar{grid-template-columns:1fr auto;height:auto;min-height:56px;padding:12px}.archive-switcher,.nav{grid-column:1 / -1}.nav{justify-content:flex-start;overflow-x:auto}.app-shell{height:auto;grid-template-columns:1fr}.search-row{grid-template-columns:1fr}.result-count{text-align:left}.context-rail{border-left:0;border-top:1px solid var(--line)}.entry-table{min-width:860px}}.rail-entry-title{display:block;font-size:15px;font-weight:700;color:var(--ink);margin-bottom:12px;line-height:1.4}.rail-section{margin-bottom:18px}.rail-section-heading{font-size:11px;font-weight:800;text-transform:uppercase;letter-spacing:.04em;color:var(--accent);margin-bottom:6px}.rail-label{font-weight:600;color:var(--ink)}.rail-url-link{color:var(--accent);word-break:break-all;font-size:13px}.artifact-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:4px}.artifact-link{display:block;padding:6px 8px;background:var(--paper-3);border:1px solid var(--line);color:var(--accent);text-decoration:none;font-size:13px;border-radius:3px}.artifact-link:hover{background:var(--line);text-decoration:underline}.search-input[aria-busy=true]{cursor:progress}.tag-tree{padding:12px}.tag-tree-list{list-style:none;margin:0;padding:0}.tag-children{padding-left:16px}.tag-node-btn{border:0;background:transparent;color:var(--link);cursor:pointer;padding:3px 0;text-align:left;font-size:13px;display:block;width:100%}.tag-node-btn:hover{text-decoration:underline}.tag-node-btn.is-active{font-weight:600;color:var(--ink)}.entry-tags{display:flex;flex-wrap:wrap;gap:6px;padding:8px 0}.tag-pill{display:inline-flex;align-items:center;gap:4px;background:var(--paper-2);border:1px solid var(--line);border-radius:3px;font-size:12px;padding:2px 6px;color:var(--ink)}.remove-tag{border:0;background:none;cursor:pointer;color:var(--muted);padding:0;font-size:14px;line-height:1}.remove-tag:hover{color:var(--accent)}.assign-tag-form{display:flex;gap:6px;padding:6px 0 8px;border-top:1px solid var(--line-soft);margin-top:4px}.assign-tag-input{flex:1;min-width:0;border:1px solid var(--line);background:var(--paper-3);color:var(--ink);padding:4px 7px;font-size:12px}.assign-tag-btn{border:1px solid var(--line);background:var(--paper-2);color:var(--ink);cursor:pointer;padding:4px 10px;font-size:12px;white-space:nowrap}.assign-tag-btn:hover{background:var(--paper)}.tag-filter-badge{display:inline-flex;align-items:center;gap:4px;background:var(--accent);color:#fff;border:0;border-radius:3px;font-size:12px;padding:2px 8px;cursor:pointer;margin-left:8px}.tag-filter-badge:hover{opacity:.85}.capture-dialog{border:2px solid var(--ink);background:var(--paper);padding:0;min-width:360px;max-width:520px;box-shadow:4px 4px 0 var(--ink)}.capture-dialog::backdrop{background:#00000073}.capture-dialog-inner{padding:28px}.capture-dialog-title{margin:0 0 16px;font-size:18px;font-family:Georgia,Times New Roman,serif}.capture-label{display:block;font-size:13px;font-weight:600;margin-bottom:6px;color:var(--muted);text-transform:uppercase;letter-spacing:.04em}.capture-input{width:100%;height:42px;border:2px solid var(--ink);background:var(--paper-3);color:var(--ink);padding:0 12px;font-size:15px;margin-bottom:10px;outline-offset:3px}.capture-error{color:var(--accent);font-size:13px;margin-bottom:10px;min-height:18px}.capture-actions{display:flex;gap:10px;justify-content:flex-end;margin-top:16px}.capture-cancel{border:1px solid var(--line);background:none;color:var(--ink);padding:8px 18px;cursor:pointer}.capture-cancel:hover{background:var(--paper-2)}.capture-submit{border:0;background:var(--ink);color:var(--paper);padding:8px 20px;cursor:pointer;font-weight:600}.capture-submit:hover{opacity:.85}.capture-submit:disabled{opacity:.45;cursor:default}.collections-view{padding:24px}.collections-heading{margin:0 0 16px;font-size:22px;font-family:Georgia,Times New Roman,serif}.collections-error{color:var(--accent);font-size:13px;margin-bottom:8px}.coll-dismiss{background:none;border:none;cursor:pointer;color:var(--accent);font-size:16px;line-height:1;padding:0 4px}.collections-layout{display:grid;grid-template-columns:220px 1fr;gap:0;border:1px solid var(--line);min-height:340px}.collections-sidebar{border-right:1px solid var(--line);overflow-y:auto}.coll-row{display:flex;flex-direction:column;width:100%;padding:10px 14px;border:none;border-bottom:1px solid var(--line-soft);background:none;cursor:pointer;text-align:left;gap:2px}.coll-row:hover{background:var(--paper-2)}.coll-row.is-active{background:var(--paper-2);border-left:3px solid var(--accent)}.coll-row-name{font-size:14px;font-weight:600;color:var(--ink)}.coll-row-meta{font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.04em}.coll-detail{padding:20px 24px;display:flex;flex-direction:column;gap:16px}.coll-detail--empty{justify-content:center;align-items:center}.coll-detail-header{display:flex;align-items:center;gap:12px}.coll-detail-name{margin:0;font-size:18px;font-family:Georgia,Times New Roman,serif;flex:1}.coll-detail-name--editable{cursor:pointer}.coll-detail-name--editable:hover{color:var(--link)}.coll-edit-hint{font-size:14px;opacity:.5;margin-left:4px}.coll-rename-input{flex:1;font-size:16px;font-family:Georgia,Times New Roman,serif;border:2px solid var(--ink);padding:4px 8px;background:var(--paper-3);color:var(--ink)}.coll-delete-btn{border:1px solid var(--accent);background:none;color:var(--accent);padding:5px 12px;font-size:13px;cursor:pointer}.coll-delete-btn:hover{background:var(--accent);color:var(--paper)}.coll-detail-vis{display:flex;align-items:center;gap:10px}.coll-vis-label{font-size:13px;font-weight:600;color:var(--muted);text-transform:uppercase;letter-spacing:.04em;white-space:nowrap}.coll-vis-select{border:1px solid var(--line);background:var(--paper-3);color:var(--ink);padding:4px 8px;font-size:13px}.coll-section-heading{font-size:11px;font-weight:700;color:var(--muted);text-transform:uppercase;letter-spacing:.06em;margin-bottom:8px}.coll-entries-section{flex:1}.coll-entries-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:2px}.coll-entry-row{display:flex;align-items:center;gap:10px;padding:7px 0;border-bottom:1px solid var(--line-soft)}.coll-entry-info{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}.coll-entry-title{font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.coll-entry-kind{font-size:11px;text-transform:uppercase;letter-spacing:.04em}.coll-entry-actions{display:flex;align-items:center;gap:6px;flex-shrink:0}.coll-entry-vis-select{border:1px solid var(--line);background:var(--paper-3);color:var(--ink);padding:3px 6px;font-size:12px}.coll-entry-remove{border:none;background:none;cursor:pointer;color:var(--muted);font-size:18px;line-height:1;padding:0 4px}.coll-entry-remove:hover{color:var(--accent)}.coll-add-entry-form{border-top:1px solid var(--line-soft);padding-top:12px}.coll-add-entry-row{display:flex;gap:8px;align-items:center}.coll-add-entry-input{flex:1;border:1px solid var(--line);background:var(--paper-3);color:var(--ink);padding:6px 10px;font-size:13px;min-width:0}.coll-add-btn{border:none;background:var(--ink);color:var(--paper);padding:6px 14px;font-size:13px;font-weight:600;cursor:pointer;white-space:nowrap}.coll-add-btn:hover{opacity:.85}.coll-add-btn:disabled{opacity:.45;cursor:default}.coll-create-details summary{font-weight:600;cursor:pointer} diff --git a/crates/archivr-server/static/index.html b/crates/archivr-server/static/index.html index b59d787..5d3d3d6 100644 --- a/crates/archivr-server/static/index.html +++ b/crates/archivr-server/static/index.html @@ -4,8 +4,8 @@ Archivr - - + +
diff --git a/frontend/src/api.js b/frontend/src/api.js index 334fbf6..6b17079 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -285,6 +285,20 @@ export async function listEntryCollections(archiveId, entryUid) { return getJson(`/api/archives/${archiveId}/entries/${entryUid}/collections`); } +export async function updateCollection(archiveId, collUid, patch) { + const res = await fetch(`/api/archives/${archiveId}/collections/${collUid}`, { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(patch), + }) + if (!res.ok) { const e = await res.json().catch(() => ({})); throw new Error(e.error ?? res.statusText) } +} + +export async function deleteCollection(archiveId, collUid) { + const res = await fetch(`/api/archives/${archiveId}/collections/${collUid}`, { method: 'DELETE' }) + if (!res.ok) { const e = await res.json().catch(() => ({})); throw new Error(e.error ?? res.statusText) } +} + // ── 401 interceptor ─────────────────────────────────────────────────────────── const _origFetch = window.fetch; window.fetch = async (...args) => { diff --git a/frontend/src/components/CollectionsView.jsx b/frontend/src/components/CollectionsView.jsx index bd542e7..48e4271 100644 --- a/frontend/src/components/CollectionsView.jsx +++ b/frontend/src/components/CollectionsView.jsx @@ -1,15 +1,25 @@ -import { useState, useEffect, useCallback } from 'react' -import { listCollections, createCollection, getCollection } from '../api.js' +import { useState, useEffect, useCallback, useRef } from 'react' +import { + listCollections, createCollection, getCollection, + addEntryToCollection, removeEntryFromCollection, + updateEntryVisibility, updateCollection, deleteCollection, +} from '../api.js' -const VIS_LABELS = { 0: 'Private', 1: 'Public', 2: 'Users only', 3: 'Public' } +const VIS_OPTIONS = [ + { value: 0, label: 'Private' }, + { value: 2, label: 'Users only' }, + { value: 3, label: 'Public' }, +] +const VIS_LABEL = v => VIS_OPTIONS.find(o => o.value === v)?.label ?? String(v) export default function CollectionsView({ archiveId }) { const [collections, setCollections] = useState([]) const [loading, setLoading] = useState(false) const [error, setError] = useState(null) - const [selectedColl, setSelectedColl] = useState(null) + const [selectedUid, setSelectedUid] = useState(null) const [collDetail, setCollDetail] = useState(null) const [detailLoading, setDetailLoading] = useState(false) + const [detailError, setDetailError] = useState(null) // Create form const [newName, setNewName] = useState('') @@ -18,7 +28,21 @@ export default function CollectionsView({ archiveId }) { const [creating, setCreating] = useState(false) const [createError, setCreateError] = useState(null) - const refresh = useCallback(async () => { + // Add-entry form + const [addUid, setAddUid] = useState('') + const [addVis, setAddVis] = useState(2) + const [adding, setAdding] = useState(false) + const [addError, setAddError] = useState(null) + + // Inline rename state + const [renaming, setRenaming] = useState(false) + const [renameVal, setRenameVal] = useState('') + const renameRef = useRef(null) + + const selected = collections.find(c => c.collection_uid === selectedUid) ?? null + const isDefault = selected?.slug === '_default_' + + const refreshList = useCallback(async () => { if (!archiveId) return setLoading(true) setError(null) @@ -32,16 +56,25 @@ export default function CollectionsView({ archiveId }) { } }, [archiveId]) - useEffect(() => { refresh() }, [refresh]) - - useEffect(() => { - if (!selectedColl) { setCollDetail(null); return } + const refreshDetail = useCallback(async (uid) => { + if (!uid) { setCollDetail(null); return } setDetailLoading(true) - getCollection(archiveId, selectedColl.collection_uid) - .then(d => setCollDetail(d)) - .catch(e => setError(e.message)) - .finally(() => setDetailLoading(false)) - }, [selectedColl, archiveId]) + setDetailError(null) + try { + const d = await getCollection(archiveId, uid) + setCollDetail(d) + } catch (e) { + setDetailError(e.message) + } finally { + setDetailLoading(false) + } + }, [archiveId]) + + useEffect(() => { refreshList() }, [refreshList]) + useEffect(() => { refreshDetail(selectedUid) }, [selectedUid, refreshDetail]) + + // Auto-focus rename input + useEffect(() => { if (renaming && renameRef.current) renameRef.current.focus() }, [renaming]) async function handleCreate(e) { e.preventDefault() @@ -51,11 +84,12 @@ export default function CollectionsView({ archiveId }) { setCreating(true) setCreateError(null) try { - await createCollection(archiveId, name, slug, newVis) + const coll = await createCollection(archiveId, name, slug, newVis) setNewName('') setNewSlug('') setNewVis(2) - await refresh() + await refreshList() + setSelectedUid(coll.collection_uid) } catch (err) { setCreateError(err.message) } finally { @@ -63,71 +97,240 @@ export default function CollectionsView({ archiveId }) { } } + async function handleRenameCommit() { + const name = renameVal.trim() + if (!name || !selected) { setRenaming(false); return } + try { + await updateCollection(archiveId, selected.collection_uid, { name }) + await refreshList() + setCollDetail(d => d ? { ...d, name } : d) + } catch (e) { + setError(e.message) + } finally { + setRenaming(false) + } + } + + async function handleVisChange(newVisVal) { + if (!selected) return + try { + await updateCollection(archiveId, selected.collection_uid, { default_visibility_bits: newVisVal }) + await refreshList() + setCollDetail(d => d ? { ...d, default_visibility_bits: newVisVal } : d) + } catch (e) { + setError(e.message) + } + } + + async function handleDelete() { + if (!selected) return + if (!window.confirm(`Delete collection "${selected.name}"? Entries will not be deleted.`)) return + try { + await deleteCollection(archiveId, selected.collection_uid) + setSelectedUid(null) + setCollDetail(null) + await refreshList() + } catch (e) { + setError(e.message) + } + } + + async function handleAddEntry(e) { + e.preventDefault() + const uid = addUid.trim() + if (!uid || !selected) return + setAdding(true) + setAddError(null) + try { + await addEntryToCollection(archiveId, selected.collection_uid, uid, addVis) + setAddUid('') + await refreshDetail(selected.collection_uid) + } catch (err) { + setAddError(err.message) + } finally { + setAdding(false) + } + } + + async function handleRemoveEntry(entryUid) { + if (!selected) return + try { + await removeEntryFromCollection(archiveId, selected.collection_uid, entryUid) + await refreshDetail(selected.collection_uid) + } catch (e) { + setDetailError(e.message) + } + } + + async function handleEntryVisChange(entryUid, vis) { + if (!selected) return + try { + await updateEntryVisibility(archiveId, selected.collection_uid, entryUid, vis) + setCollDetail(d => d ? { + ...d, + entries: d.entries.map(en => + en.entry_uid === entryUid ? { ...en, collection_visibility_bits: vis } : en + ), + } : d) + } catch (e) { + setDetailError(e.message) + } + } + if (!archiveId) return
Select an archive.
return (
-

Collections

+

Collections

{loading &&
Loading…
} - {error &&
{error}
} + {error &&
{error}
}
-
+ {/* Sidebar */} +
{collections.map(c => ( -
setSelectedColl(c)} + className={`coll-row${selectedUid === c.collection_uid ? ' is-active' : ''}`} + onClick={() => setSelectedUid(c.collection_uid)} > - {c.name} - - {VIS_LABELS[c.default_visibility_bits] ?? c.default_visibility_bits} - -
+ {c.name} + {VIS_LABEL(c.default_visibility_bits)} + ))} {collections.length === 0 && !loading && ( -
No collections yet.
+
No collections yet.
)}
- {selectedColl && ( -
-

{selectedColl.name}

-
- Default visibility: {VIS_LABELS[selectedColl.default_visibility_bits] ?? selectedColl.default_visibility_bits} -
- {detailLoading ? ( -
Loading entries…
- ) : collDetail ? ( - collDetail.entries.length === 0 ? ( -
No entries visible to you in this collection.
+ {/* Detail pane */} + {selected ? ( +
+ {/* Header */} +
+ {renaming ? ( + setRenameVal(e.target.value)} + onBlur={handleRenameCommit} + onKeyDown={e => { + if (e.key === 'Enter') handleRenameCommit() + if (e.key === 'Escape') setRenaming(false) + }} + /> ) : ( -
    - {collDetail.entries.map(entry => ( -
  • - - {entry.title || entry.entry_uid} - - - {entry.source_kind} - -
  • - ))} -
- ) - ) : null} +

{ if (!isDefault) { setRenameVal(selected.name); setRenaming(true) } }} + > + {collDetail?.name ?? selected.name} + {!isDefault && } +

+ )} + {!isDefault && ( + + )} +
+ + {/* Visibility */} +
+ Default visibility + +
+ + {/* Entries */} +
+
Entries
+ {detailLoading &&
Loading…
} + {detailError &&
{detailError}
} + {!detailLoading && collDetail && ( + collDetail.entries.length === 0 ? ( +
No entries in this collection.
+ ) : ( +
    + {collDetail.entries.map(entry => ( +
  • +
    + {entry.title || entry.entry_uid} + {entry.source_kind} +
    +
    + + {!isDefault && ( + + )} +
    +
  • + ))} +
+ ) + )} +
+ + {/* Add entry (non-default only) */} + {!isDefault && ( +
+
Add entry
+
+ setAddUid(e.target.value)} + placeholder="entry_uid" + required + /> + + +
+ {addError &&
{addError}
} +
+ )} +
+ ) : ( +
+
Select a collection to view details.
)}
-
+ {/* Create form */} +
Create collection