From 21b11c211f654f824ab81817a786296d57e43f9e Mon Sep 17 00:00:00 2001 From: TheGeneralist <180094941+thegeneralist01@users.noreply.github.com> Date: Mon, 6 Jul 2026 15:34:14 +0200 Subject: [PATCH] feat: YouTube Music audio capture (ytm: shorthand, Spotify detection, stalled job recovery) (#19) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add YouTube Music and Spotify source detection - Add Source variants: YouTubeMusicTrack, YouTubeMusicPlaylist, SpotifyTrack, SpotifyAlbum, SpotifyPlaylist - ytm:ID shorthand → music.youtube.com/watch?v=ID (audio-only, forced in core regardless of caller quality hint) - ytm:playlist/ID and music.youtube.com/playlist URLs detected but fail with 'not yet implemented' via fail_run - Spotify URLs/shorthands detected and fail fast with clear DRM error via fail_run (after run item created, so status is visible in /runs) - source_metadata: youtube_music/music/audio and spotify/music/audio (entity_kind='music' for UI pill, representation_kind='audio' stored) - locator_to_ytdlp_url includes YouTubeMusicTrack for probe endpoint - generate_entry_title: 'Title — Artist' for YTM tracks - Frontend: isVideoSource handles ytm: and music.youtube.com/watch; Spotify returns false (no probe, clear server error on submit) - Placeholder updated to include ytm:ID - SOURCE_ICONS: youtube_music (red disc) and spotify (green waves) - 14 new tests covering all new sources (163 total, all pass) * fix: prevent yt-dlp playlist expansion and stalled run recovery - Add --no-playlist to ytdlp::download and fetch_metadata: URLs with a list= parameter (e.g. music.youtube.com/watch?v=ID&list=RDAMVM…) no longer cause yt-dlp to expand the full playlist and hang; both the metadata probe and the download are now single-item only - Fix fail_stalled_capture_jobs to also recover archive_runs and archive_run_items: capture_jobs.run_uid is NULL at crash time so a join is unreliable; instead fail all archive_runs/items still in_progress directly, then recount failed_count via subquery. Startup recovery now makes the Runs UI reflect the correct failed state after a hard shutdown - Expand fail_stalled_jobs_on_restart test to assert archive_run and archive_run_item rows are also marked failed, not just capture_jobs * fix: use play triangle for youtube_music icon --- crates/archivr-core/src/capture.rs | 274 ++++++++++++++++++ crates/archivr-core/src/database.rs | 64 +++- crates/archivr-core/src/downloader/ytdlp.rs | 11 +- .../{index-bXPw5mQ7.js => index-D2gm2yNL.js} | 2 +- crates/archivr-server/static/index.html | 2 +- frontend/src/components/CaptureDialog.jsx | 14 +- frontend/src/utils.js | 2 + 7 files changed, 362 insertions(+), 7 deletions(-) rename crates/archivr-server/static/assets/{index-bXPw5mQ7.js => index-D2gm2yNL.js} (73%) diff --git a/crates/archivr-core/src/capture.rs b/crates/archivr-core/src/capture.rs index 848906b..5401346 100644 --- a/crates/archivr-core/src/capture.rs +++ b/crates/archivr-core/src/capture.rs @@ -14,6 +14,11 @@ pub enum Source { YouTubeVideo, YouTubePlaylist, YouTubeChannel, + YouTubeMusicTrack, + YouTubeMusicPlaylist, + SpotifyTrack, + SpotifyAlbum, + SpotifyPlaylist, X, Tweet, TweetThread, @@ -72,6 +77,19 @@ fn generate_entry_title(source: Source, meta: &PlatformMetadata) -> String { "Archival of {}", meta.author.as_deref().unwrap_or("Unknown Channel") ), + Source::YouTubeMusicTrack => { + let title = meta.title.as_deref().unwrap_or("Unknown Track"); + match meta.author.as_deref() { + Some(a) => format!("{title} \u{2014} {a}"), + None => title.to_string(), + } + } + Source::YouTubeMusicPlaylist => { + meta.title.clone().unwrap_or_else(|| "YouTube Music Playlist".to_string()) + } + Source::SpotifyTrack | Source::SpotifyAlbum | Source::SpotifyPlaylist => { + meta.title.clone().unwrap_or_else(|| "Spotify Content".to_string()) + } Source::X => format!("X Media by {}", meta.author.as_deref().unwrap_or("unknown")), Source::Tweet => { let excerpt = meta.caption_excerpt().unwrap_or_else(|| "Tweet".to_string()); @@ -124,6 +142,32 @@ fn expand_shorthand_to_url(path: &str, source: &Source) -> String { } } + // YouTube Music shorthands: ytm:ID (track) or ytm:playlist/ID + if matches!(source, Source::YouTubeMusicTrack | Source::YouTubeMusicPlaylist) { + if let Some(after) = path.strip_prefix("ytm:") { + if let Some(id) = after.strip_prefix("playlist/") { + return format!("https://music.youtube.com/playlist?list={id}"); + } + // bare ytm:ID → track + return format!("https://music.youtube.com/watch?v={after}"); + } + } + + // Spotify shorthands: spotify:track:ID, spotify:album:ID, spotify:playlist:ID + if matches!(source, Source::SpotifyTrack | Source::SpotifyAlbum | Source::SpotifyPlaylist) { + if let Some(after) = path.strip_prefix("spotify:") { + if let Some(id) = after.strip_prefix("track:") { + return format!("https://open.spotify.com/track/{id}"); + } + if let Some(id) = after.strip_prefix("album:") { + return format!("https://open.spotify.com/album/{id}"); + } + if let Some(id) = after.strip_prefix("playlist:") { + return format!("https://open.spotify.com/playlist/{id}"); + } + } + } + if *source == Source::X && (path.starts_with("tweet:media:") || path.starts_with("x:media:")) { if let Some(tweet_id) = path.split(':').next_back().and_then(parse_tweet_id) { return format!("https://x.com/i/status/{tweet_id}"); @@ -187,6 +231,27 @@ fn determine_source(path: &str) -> Source { } } + // Shorthand scheme: ytm: + if let Some(after_scheme) = path.strip_prefix("ytm:") { + if after_scheme.starts_with("playlist/") { + return Source::YouTubeMusicPlaylist; + } + // Any other suffix is treated as a track ID + return Source::YouTubeMusicTrack; + } + + // Shorthand scheme: spotify: + if let Some(after_scheme) = path.strip_prefix("spotify:") { + if after_scheme.starts_with("album:") { + return Source::SpotifyAlbum; + } + if after_scheme.starts_with("playlist:") { + return Source::SpotifyPlaylist; + } + // track: or anything else maps to a track + return Source::SpotifyTrack; + } + // Shorthand schemes: tweet:, x:, or twitter: if let Some(after_scheme) = path .strip_prefix("x:") @@ -275,6 +340,37 @@ fn determine_source(path: &str) -> Source { return Source::YouTubeChannel; } + // YouTube Music track URLs: music.youtube.com/watch?v=ID + if path.starts_with("https://music.youtube.com/watch") + || path.starts_with("http://music.youtube.com/watch") + { + return Source::YouTubeMusicTrack; + } + + // YouTube Music playlist URLs: music.youtube.com/playlist?list=ID + if path.starts_with("https://music.youtube.com/playlist") + || path.starts_with("http://music.youtube.com/playlist") + { + return Source::YouTubeMusicPlaylist; + } + + // Spotify URLs: open.spotify.com/{track,album,playlist}/ID + if path.starts_with("https://open.spotify.com/track/") + || path.starts_with("http://open.spotify.com/track/") + { + return Source::SpotifyTrack; + } + if path.starts_with("https://open.spotify.com/album/") + || path.starts_with("http://open.spotify.com/album/") + { + return Source::SpotifyAlbum; + } + if path.starts_with("https://open.spotify.com/playlist/") + || path.starts_with("http://open.spotify.com/playlist/") + { + return Source::SpotifyPlaylist; + } + if path.starts_with("https://x.com/") { return Source::X; } @@ -341,6 +437,7 @@ pub fn locator_to_ytdlp_url(locator: &str) -> Option { let source = determine_source(locator); match source { Source::YouTubeVideo + | Source::YouTubeMusicTrack | Source::X | Source::Instagram | Source::Facebook @@ -426,6 +523,11 @@ fn source_metadata(source: Source) -> (&'static str, &'static str, &'static str) Source::YouTubeVideo => ("youtube", "video", "video"), Source::YouTubePlaylist => ("youtube", "playlist", "container"), Source::YouTubeChannel => ("youtube", "channel", "container"), + Source::YouTubeMusicTrack => ("youtube_music", "music", "audio"), + Source::YouTubeMusicPlaylist => ("youtube_music", "playlist", "container"), + Source::SpotifyTrack => ("spotify", "music", "audio"), + Source::SpotifyAlbum => ("spotify", "album", "container"), + Source::SpotifyPlaylist => ("spotify", "playlist", "container"), Source::X => ("x", "post", "video"), Source::Tweet => ("x", "tweet", "tweet_json"), Source::TweetThread => ("x", "tweet_thread", "tweet_json"), @@ -745,6 +847,27 @@ pub fn perform_capture( )); } + // Sources: Spotify — not downloadable; Spotify audio is DRM-protected. + if matches!(source, Source::SpotifyTrack | Source::SpotifyAlbum | Source::SpotifyPlaylist) { + return Err(fail_run( + &conn, + &run, + &item, + "Spotify downloads are not supported: Spotify audio is DRM-protected and cannot \ + be downloaded by yt-dlp. Archive the equivalent YouTube Music track instead.", + )); + } + + // Sources: YouTube Music Playlist — container expansion not yet implemented. + if source == Source::YouTubeMusicPlaylist { + return Err(fail_run( + &conn, + &run, + &item, + "YouTube Music playlist archiving is not yet implemented.", + )); + } + // Source: generic HTTP/S file URL if source == Source::Url { match downloader::http::download(locator, store_path, ×tamp) { @@ -1002,6 +1125,7 @@ pub fn perform_capture( // because --dump-json is a simulate flag that suppresses the download. let ytdlp_metadata_json: Option = match source { Source::YouTubeVideo + | Source::YouTubeMusicTrack | Source::X | Source::Instagram | Source::Facebook @@ -1042,6 +1166,20 @@ pub fn perform_capture( } } } + Source::YouTubeMusicTrack => { + // Music tracks are always audio-only regardless of the caller's quality hint. + match downloader::ytdlp::download(path.clone(), store_path, ×tamp, Some("audio")) { + Ok(result) => result, + Err(e) => { + return Err(fail_run( + &conn, + &run, + &item, + &format!("Failed to download audio: {e}"), + )); + } + } + } Source::Local => { match downloader::local::save(path.clone(), store_path, ×tamp) { Ok(h) => (h, local_file_extension(&path)), @@ -1412,6 +1550,142 @@ mod tests { } } + #[test] + fn test_youtube_music_sources() { + // --- determine_source --- + let cases = [ + TestCase { + url: "https://music.youtube.com/watch?v=MntbN1DdEP0", + expected: Source::YouTubeMusicTrack, + }, + TestCase { + url: "http://music.youtube.com/watch?v=MntbN1DdEP0", + expected: Source::YouTubeMusicTrack, + }, + TestCase { + url: "https://music.youtube.com/playlist?list=PLtest123", + expected: Source::YouTubeMusicPlaylist, + }, + TestCase { + url: "ytm:MntbN1DdEP0", + expected: Source::YouTubeMusicTrack, + }, + TestCase { + url: "ytm:playlist/PLtest123", + expected: Source::YouTubeMusicPlaylist, + }, + ]; + for case in &cases { + assert_eq!( + determine_source(case.url), + case.expected, + "Failed for URL: {}", + case.url + ); + } + + // --- expand_shorthand_to_url --- + assert_eq!( + expand_shorthand_to_url("ytm:MntbN1DdEP0", &Source::YouTubeMusicTrack), + "https://music.youtube.com/watch?v=MntbN1DdEP0" + ); + assert_eq!( + expand_shorthand_to_url("ytm:playlist/PLtest123", &Source::YouTubeMusicPlaylist), + "https://music.youtube.com/playlist?list=PLtest123" + ); + // Full URL passes through unchanged + assert_eq!( + expand_shorthand_to_url( + "https://music.youtube.com/watch?v=MntbN1DdEP0", + &Source::YouTubeMusicTrack + ), + "https://music.youtube.com/watch?v=MntbN1DdEP0" + ); + + // --- locator_to_ytdlp_url --- + assert_eq!( + locator_to_ytdlp_url("ytm:MntbN1DdEP0"), + Some("https://music.youtube.com/watch?v=MntbN1DdEP0".to_string()) + ); + assert_eq!( + locator_to_ytdlp_url("https://music.youtube.com/watch?v=MntbN1DdEP0"), + Some("https://music.youtube.com/watch?v=MntbN1DdEP0".to_string()) + ); + // Playlist is not exposed to the probe endpoint + assert_eq!(locator_to_ytdlp_url("ytm:playlist/PLtest123"), None); + + // --- source_metadata --- + assert_eq!( + source_metadata(Source::YouTubeMusicTrack), + ("youtube_music", "music", "audio") + ); + assert_eq!( + source_metadata(Source::YouTubeMusicPlaylist), + ("youtube_music", "playlist", "container") + ); + } + + #[test] + fn test_spotify_sources() { + // --- determine_source --- + let cases = [ + TestCase { + url: "https://open.spotify.com/track/4iV5W9uYEdYUVa79Axb7Rh", + expected: Source::SpotifyTrack, + }, + TestCase { + url: "https://open.spotify.com/album/1DFixLWuPkv3KT3TnV35m3", + expected: Source::SpotifyAlbum, + }, + TestCase { + url: "https://open.spotify.com/playlist/37i9dQZF1DXcBWIGoYBM5M", + expected: Source::SpotifyPlaylist, + }, + TestCase { + url: "spotify:track:4iV5W9uYEdYUVa79Axb7Rh", + expected: Source::SpotifyTrack, + }, + TestCase { + url: "spotify:album:1DFixLWuPkv3KT3TnV35m3", + expected: Source::SpotifyAlbum, + }, + TestCase { + url: "spotify:playlist:37i9dQZF1DXcBWIGoYBM5M", + expected: Source::SpotifyPlaylist, + }, + ]; + for case in &cases { + assert_eq!( + determine_source(case.url), + case.expected, + "Failed for URL: {}", + case.url + ); + } + + // --- expand_shorthand_to_url --- + assert_eq!( + expand_shorthand_to_url("spotify:track:4iV5W9uYEdYUVa79Axb7Rh", &Source::SpotifyTrack), + "https://open.spotify.com/track/4iV5W9uYEdYUVa79Axb7Rh" + ); + assert_eq!( + expand_shorthand_to_url("spotify:album:1DFixLWuPkv3KT3TnV35m3", &Source::SpotifyAlbum), + "https://open.spotify.com/album/1DFixLWuPkv3KT3TnV35m3" + ); + assert_eq!( + expand_shorthand_to_url( + "spotify:playlist:37i9dQZF1DXcBWIGoYBM5M", + &Source::SpotifyPlaylist + ), + "https://open.spotify.com/playlist/37i9dQZF1DXcBWIGoYBM5M" + ); + + // --- source_metadata --- + assert_eq!(source_metadata(Source::SpotifyTrack), ("spotify", "music", "audio")); + assert_eq!(source_metadata(Source::SpotifyAlbum), ("spotify", "album", "container")); + assert_eq!(source_metadata(Source::SpotifyPlaylist), ("spotify", "playlist", "container")); + } + #[test] fn test_x_sources() { let x_cases = [ diff --git a/crates/archivr-core/src/database.rs b/crates/archivr-core/src/database.rs index 9e1b6eb..d6c2184 100644 --- a/crates/archivr-core/src/database.rs +++ b/crates/archivr-core/src/database.rs @@ -1082,10 +1082,40 @@ pub fn get_capture_job(conn: &Connection, job_uid: &str) -> Result Result { let now = now_timestamp(); + + // 1. Fail in-progress run items. + conn.execute( + "UPDATE archive_run_items + SET status = 'failed', error_text = 'interrupted by server restart' + WHERE status = 'in_progress'", + [], + )?; + + // 2. Fail in-progress archive runs; recount failed items from the updated rows. + conn.execute( + "UPDATE archive_runs + SET status = 'failed', + finished_at = ?1, + failed_count = ( + SELECT COUNT(*) FROM archive_run_items + WHERE run_id = archive_runs.id AND status = 'failed' + ), + error_summary = 'interrupted by server restart' + WHERE status = 'in_progress'", + [now.clone()], + )?; + + // 3. Fail running capture jobs (the polling layer). let n = conn.execute( "UPDATE capture_jobs SET status = 'failed', error_text = 'interrupted by server restart', @@ -1093,6 +1123,7 @@ pub fn fail_stalled_capture_jobs(conn: &Connection) -> Result { WHERE status = 'running'", [now], )?; + Ok(n) } @@ -2686,13 +2717,40 @@ mod tests { #[test] fn fail_stalled_jobs_on_restart() { let conn = conn(); + + // Simulate an in-progress capture_job (run_uid still NULL — common crash case). let uid = create_capture_job(&conn, "test").unwrap(); update_capture_job_status(&conn, &uid, "running", None, None).unwrap(); + + // Simulate an in-progress archive_run and item with no associated capture_job + // (covers the case where run_uid was never written back before the crash). + let user_id = ensure_default_user(&conn).unwrap(); + let run = create_archive_run(&conn, user_id, 1).unwrap(); + create_archive_run_item(&conn, run.id, None, 0, "https://example.com", None, "web", "file").unwrap(); + let n = fail_stalled_capture_jobs(&conn).unwrap(); - assert_eq!(n, 1); + assert_eq!(n, 1); // one capture_job updated + + // capture_job is failed let job = get_capture_job(&conn, &uid).unwrap().unwrap(); assert_eq!(job.status, "failed"); assert!(job.error_text.as_deref().unwrap().contains("interrupted")); + + // archive_run is failed + let updated_run: String = conn.query_row( + "SELECT status FROM archive_runs WHERE id = ?1", + [run.id], + |r| r.get(0), + ).unwrap(); + assert_eq!(updated_run, "failed"); + + // archive_run_item is failed + let item_status: String = conn.query_row( + "SELECT status FROM archive_run_items WHERE run_id = ?1", + [run.id], + |r| r.get(0), + ).unwrap(); + assert_eq!(item_status, "failed"); } fn make_auth_conn_for_mgmt() -> Connection { diff --git a/crates/archivr-core/src/downloader/ytdlp.rs b/crates/archivr-core/src/downloader/ytdlp.rs index 1b75843..2000cf4 100644 --- a/crates/archivr-core/src/downloader/ytdlp.rs +++ b/crates/archivr-core/src/downloader/ytdlp.rs @@ -109,7 +109,12 @@ pub fn download( let out_template = temp_dir.join(format!("{timestamp}.%(ext)s")); let mut cmd = Command::new(&ytdlp); - cmd.arg(&path).arg("-f").arg(quality_format(quality)); + cmd.arg(&path) + .arg("-f").arg(quality_format(quality)) + // This function is only called for single-item sources; --no-playlist + // prevents yt-dlp from expanding a list= query parameter into a full + // playlist download (e.g. music.youtube.com/watch?v=ID&list=RDAMVM…). + .arg("--no-playlist"); if is_audio { // -x guarantees audio-only even when /best falls back to a combined // A/V format. No --audio-format → native remux only, no re-encode. @@ -166,6 +171,10 @@ pub fn fetch_metadata(path: &str) -> Option { let out = std::process::Command::new(&ytdlp) .arg("--dump-json") + // Same rationale as download(): only called for single-item sources; + // prevents --dump-json from emitting one JSON object per playlist item + // when the URL contains a list= parameter. + .arg("--no-playlist") .arg(path) .output() .ok()?; diff --git a/crates/archivr-server/static/assets/index-bXPw5mQ7.js b/crates/archivr-server/static/assets/index-D2gm2yNL.js similarity index 73% rename from crates/archivr-server/static/assets/index-bXPw5mQ7.js rename to crates/archivr-server/static/assets/index-D2gm2yNL.js index 44da8f2..962bb73 100644 --- a/crates/archivr-server/static/assets/index-bXPw5mQ7.js +++ b/crates/archivr-server/static/assets/index-D2gm2yNL.js @@ -37,4 +37,4 @@ `+l[i].replace(" at new "," at ");return e.displayName&&u.includes("")&&(u=u.replace("",e.displayName)),u}while(1<=i&&0<=a);break}}}finally{Ul=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?$n(e):""}function ad(e){switch(e.tag){case 5:return $n(e.type);case 16:return $n("Lazy");case 13:return $n("Suspense");case 19:return $n("SuspenseList");case 0:case 2:case 15:return e=Bl(e.type,!1),e;case 11:return e=Bl(e.type.render,!1),e;case 1:return e=Bl(e.type,!0),e;default:return""}}function ys(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case qt:return"Fragment";case Zt:return"Portal";case ms:return"Profiler";case mi:return"StrictMode";case vs:return"Suspense";case gs:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Da:return(e.displayName||"Context")+".Consumer";case Ra:return(e._context.displayName||"Context")+".Provider";case vi:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case gi:return t=e.displayName||null,t!==null?t:ys(e.type)||"Memo";case vt:t=e._payload,e=e._init;try{return ys(e(t))}catch{}}return null}function ud(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return ys(t);case 8:return t===mi?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function Lt(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function $a(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function cd(e){var t=$a(e)?"checked":"value",n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var l=n.get,s=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return l.call(this)},set:function(i){r=""+i,s.call(this,i)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(i){r=""+i},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function wr(e){e._valueTracker||(e._valueTracker=cd(e))}function Ma(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=$a(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function Kr(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function ws(e,t){var n=t.checked;return te({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function ao(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=Lt(t.value!=null?t.value:n),e._wrapperState={initialChecked:r,initialValue:n,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function Fa(e,t){t=t.checked,t!=null&&hi(e,"checked",t,!1)}function xs(e,t){Fa(e,t);var n=Lt(t.value),r=t.type;if(n!=null)r==="number"?(n===0&&e.value===""||e.value!=n)&&(e.value=""+n):e.value!==""+n&&(e.value=""+n);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?Ss(e,t.type,n):t.hasOwnProperty("defaultValue")&&Ss(e,t.type,Lt(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function uo(e,t,n){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,n||t===e.value||(e.value=t),e.defaultValue=t}n=e.name,n!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,n!==""&&(e.name=n)}function Ss(e,t,n){(t!=="number"||Kr(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var Mn=Array.isArray;function cn(e,t,n,r){if(e=e.options,t){t={};for(var l=0;l"+t.valueOf().toString()+"",t=xr.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Gn(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Un={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},dd=["Webkit","ms","Moz","O"];Object.keys(Un).forEach(function(e){dd.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Un[t]=Un[e]})});function Ba(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Un.hasOwnProperty(e)&&Un[e]?(""+t).trim():t+"px"}function Va(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,l=Ba(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,l):e[n]=l}}var fd=te({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function Ns(e,t){if(t){if(fd[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(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 Cs(e,t){if(e.indexOf("-")===-1)return typeof t.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var _s=null;function yi(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Es=null,dn=null,fn=null;function po(e){if(e=mr(e)){if(typeof Es!="function")throw Error(C(280));var t=e.stateNode;t&&(t=Sl(t),Es(e.stateNode,e.type,t))}}function Wa(e){dn?fn?fn.push(e):fn=[e]:dn=e}function Ha(){if(dn){var e=dn,t=fn;if(fn=dn=null,po(e),t)for(e=0;e>>=0,e===0?32:31-(jd(e)/Nd|0)|0}var Sr=64,kr=4194304;function Fn(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function Gr(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,l=e.suspendedLanes,s=e.pingedLanes,i=n&268435455;if(i!==0){var a=i&~l;a!==0?r=Fn(a):(s&=i,s!==0&&(r=Fn(s)))}else i=n&~l,i!==0?r=Fn(i):s!==0&&(r=Fn(s));if(r===0)return 0;if(t!==0&&t!==r&&!(t&l)&&(l=r&-r,s=t&-t,l>=s||l===16&&(s&4194240)!==0))return t;if(r&4&&(r|=n&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0n;n++)t.push(e);return t}function pr(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Ge(t),e[t]=n}function Td(e,t){var n=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0=Vn),ko=" ",jo=!1;function cu(e,t){switch(e){case"keyup":return nf.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function du(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var bt=!1;function lf(e,t){switch(e){case"compositionend":return du(t);case"keypress":return t.which!==32?null:(jo=!0,ko);case"textInput":return e=t.data,e===ko&&jo?null:e;default:return null}}function sf(e,t){if(bt)return e==="compositionend"||!_i&&cu(e,t)?(e=au(),Fr=ji=xt=null,bt=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:n,offset:t-e};e=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=Eo(n)}}function mu(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?mu(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function vu(){for(var e=window,t=Kr();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=Kr(e.document)}return t}function Ei(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function mf(e){var t=vu(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&mu(n.ownerDocument.documentElement,n)){if(r!==null&&Ei(n)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in n)n.selectionStart=t,n.selectionEnd=Math.min(e,n.value.length);else if(e=(t=n.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var l=n.textContent.length,s=Math.min(r.start,l);r=r.end===void 0?s:Math.min(r.end,l),!e.extend&&s>r&&(l=r,r=s,s=l),l=To(n,s);var i=To(n,r);l&&i&&(e.rangeCount!==1||e.anchorNode!==l.node||e.anchorOffset!==l.offset||e.focusNode!==i.node||e.focusOffset!==i.offset)&&(t=t.createRange(),t.setStart(l.node,l.offset),e.removeAllRanges(),s>r?(e.addRange(t),e.extend(i.node,i.offset)):(t.setEnd(i.node,i.offset),e.addRange(t)))}}for(t=[],e=n;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n=document.documentMode,en=null,Ds=null,Hn=null,Os=!1;function Po(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Os||en==null||en!==Kr(r)||(r=en,"selectionStart"in r&&Ei(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Hn&&nr(Hn,r)||(Hn=r,r=br(Ds,"onSelect"),0rn||(e.current=Us[rn],Us[rn]=null,rn--)}function J(e,t){rn++,Us[rn]=e.current,e.current=t}var zt={},ye=Dt(zt),_e=Dt(!1),Wt=zt;function gn(e,t){var n=e.type.contextTypes;if(!n)return zt;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var l={},s;for(s in n)l[s]=t[s];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=l),l}function Ee(e){return e=e.childContextTypes,e!=null}function tl(){G(_e),G(ye)}function Mo(e,t,n){if(ye.current!==zt)throw Error(C(168));J(ye,t),J(_e,n)}function Cu(e,t,n){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var l in r)if(!(l in t))throw Error(C(108,ud(e)||"Unknown",l));return te({},n,r)}function nl(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||zt,Wt=ye.current,J(ye,e),J(_e,_e.current),!0}function Fo(e,t,n){var r=e.stateNode;if(!r)throw Error(C(169));n?(e=Cu(e,t,Wt),r.__reactInternalMemoizedMergedChildContext=e,G(_e),G(ye),J(ye,e)):G(_e),J(_e,n)}var it=null,kl=!1,ts=!1;function _u(e){it===null?it=[e]:it.push(e)}function Ef(e){kl=!0,_u(e)}function Ot(){if(!ts&&it!==null){ts=!0;var e=0,t=Y;try{var n=it;for(Y=1;e>=i,l-=i,ot=1<<32-Ge(t)+l|n<y?(T=P,P=null):T=P.sibling;var R=h(f,P,p[y],w);if(R===null){P===null&&(P=T);break}e&&P&&R.alternate===null&&t(f,P),d=s(R,d,y),_===null?k=R:_.sibling=R,_=R,P=T}if(y===p.length)return n(f,P),q&&$t(f,y),k;if(P===null){for(;yy?(T=P,P=null):T=P.sibling;var I=h(f,P,R.value,w);if(I===null){P===null&&(P=T);break}e&&P&&I.alternate===null&&t(f,P),d=s(I,d,y),_===null?k=I:_.sibling=I,_=I,P=T}if(R.done)return n(f,P),q&&$t(f,y),k;if(P===null){for(;!R.done;y++,R=p.next())R=m(f,R.value,w),R!==null&&(d=s(R,d,y),_===null?k=R:_.sibling=R,_=R);return q&&$t(f,y),k}for(P=r(f,P);!R.done;y++,R=p.next())R=x(P,f,y,R.value,w),R!==null&&(e&&R.alternate!==null&&P.delete(R.key===null?y:R.key),d=s(R,d,y),_===null?k=R:_.sibling=R,_=R);return e&&P.forEach(function(U){return t(f,U)}),q&&$t(f,y),k}function O(f,d,p,w){if(typeof p=="object"&&p!==null&&p.type===qt&&p.key===null&&(p=p.props.children),typeof p=="object"&&p!==null){switch(p.$$typeof){case yr:e:{for(var k=p.key,_=d;_!==null;){if(_.key===k){if(k=p.type,k===qt){if(_.tag===7){n(f,_.sibling),d=l(_,p.props.children),d.return=f,f=d;break e}}else if(_.elementType===k||typeof k=="object"&&k!==null&&k.$$typeof===vt&&Uo(k)===_.type){n(f,_.sibling),d=l(_,p.props),d.ref=zn(f,_,p),d.return=f,f=d;break e}n(f,_);break}else t(f,_);_=_.sibling}p.type===qt?(d=Vt(p.props.children,f.mode,w,p.key),d.return=f,f=d):(w=Qr(p.type,p.key,p.props,null,f.mode,w),w.ref=zn(f,d,p),w.return=f,f=w)}return i(f);case Zt:e:{for(_=p.key;d!==null;){if(d.key===_)if(d.tag===4&&d.stateNode.containerInfo===p.containerInfo&&d.stateNode.implementation===p.implementation){n(f,d.sibling),d=l(d,p.children||[]),d.return=f,f=d;break e}else{n(f,d);break}else t(f,d);d=d.sibling}d=us(p,f.mode,w),d.return=f,f=d}return i(f);case vt:return _=p._init,O(f,d,_(p._payload),w)}if(Mn(p))return S(f,d,p,w);if(_n(p))return j(f,d,p,w);Pr(f,p)}return typeof p=="string"&&p!==""||typeof p=="number"?(p=""+p,d!==null&&d.tag===6?(n(f,d.sibling),d=l(d,p),d.return=f,f=d):(n(f,d),d=as(p,f.mode,w),d.return=f,f=d),i(f)):n(f,d)}return O}var wn=Lu(!0),zu=Lu(!1),sl=Dt(null),il=null,on=null,zi=null;function Ri(){zi=on=il=null}function Di(e){var t=sl.current;G(sl),e._currentValue=t}function Ws(e,t,n){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,r!==null&&(r.childLanes|=t)):r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t),e===n)break;e=e.return}}function hn(e,t){il=e,zi=on=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Ce=!0),e.firstContext=null)}function We(e){var t=e._currentValue;if(zi!==e)if(e={context:e,memoizedValue:t,next:null},on===null){if(il===null)throw Error(C(308));on=e,il.dependencies={lanes:0,firstContext:e}}else on=on.next=e;return t}var At=null;function Oi(e){At===null?At=[e]:At.push(e)}function Ru(e,t,n,r){var l=t.interleaved;return l===null?(n.next=n,Oi(t)):(n.next=l.next,l.next=n),t.interleaved=n,ft(e,r)}function ft(e,t){e.lanes|=t;var n=e.alternate;for(n!==null&&(n.lanes|=t),n=e,e=e.return;e!==null;)e.childLanes|=t,n=e.alternate,n!==null&&(n.childLanes|=t),n=e,e=e.return;return n.tag===3?n.stateNode:null}var gt=!1;function $i(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Du(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function ut(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function _t(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,W&2){var l=r.pending;return l===null?t.next=t:(t.next=l.next,l.next=t),r.pending=t,ft(e,n)}return l=r.interleaved,l===null?(t.next=t,Oi(r)):(t.next=l.next,l.next=t),r.interleaved=t,ft(e,n)}function Ir(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,(n&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,xi(e,n)}}function Bo(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var l=null,s=null;if(n=n.firstBaseUpdate,n!==null){do{var i={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};s===null?l=s=i:s=s.next=i,n=n.next}while(n!==null);s===null?l=s=t:s=s.next=t}else l=s=t;n={baseState:r.baseState,firstBaseUpdate:l,lastBaseUpdate:s,shared:r.shared,effects:r.effects},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}function ol(e,t,n,r){var l=e.updateQueue;gt=!1;var s=l.firstBaseUpdate,i=l.lastBaseUpdate,a=l.shared.pending;if(a!==null){l.shared.pending=null;var u=a,c=u.next;u.next=null,i===null?s=c:i.next=c,i=u;var g=e.alternate;g!==null&&(g=g.updateQueue,a=g.lastBaseUpdate,a!==i&&(a===null?g.firstBaseUpdate=c:a.next=c,g.lastBaseUpdate=u))}if(s!==null){var m=l.baseState;i=0,g=c=u=null,a=s;do{var h=a.lane,x=a.eventTime;if((r&h)===h){g!==null&&(g=g.next={eventTime:x,lane:0,tag:a.tag,payload:a.payload,callback:a.callback,next:null});e:{var S=e,j=a;switch(h=t,x=n,j.tag){case 1:if(S=j.payload,typeof S=="function"){m=S.call(x,m,h);break e}m=S;break e;case 3:S.flags=S.flags&-65537|128;case 0:if(S=j.payload,h=typeof S=="function"?S.call(x,m,h):S,h==null)break e;m=te({},m,h);break e;case 2:gt=!0}}a.callback!==null&&a.lane!==0&&(e.flags|=64,h=l.effects,h===null?l.effects=[a]:h.push(a))}else x={eventTime:x,lane:h,tag:a.tag,payload:a.payload,callback:a.callback,next:null},g===null?(c=g=x,u=m):g=g.next=x,i|=h;if(a=a.next,a===null){if(a=l.shared.pending,a===null)break;h=a,a=h.next,h.next=null,l.lastBaseUpdate=h,l.shared.pending=null}}while(!0);if(g===null&&(u=m),l.baseState=u,l.firstBaseUpdate=c,l.lastBaseUpdate=g,t=l.shared.interleaved,t!==null){l=t;do i|=l.lane,l=l.next;while(l!==t)}else s===null&&(l.shared.lanes=0);Kt|=i,e.lanes=i,e.memoizedState=m}}function Vo(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=rs.transition;rs.transition={};try{e(!1),t()}finally{Y=n,rs.transition=r}}function Gu(){return He().memoizedState}function zf(e,t,n){var r=Tt(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},Zu(e))qu(t,n);else if(n=Ru(e,t,n,r),n!==null){var l=Se();Ze(n,e,r,l),bu(n,t,r)}}function Rf(e,t,n){var r=Tt(e),l={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(Zu(e))qu(t,l);else{var s=e.alternate;if(e.lanes===0&&(s===null||s.lanes===0)&&(s=t.lastRenderedReducer,s!==null))try{var i=t.lastRenderedState,a=s(i,n);if(l.hasEagerState=!0,l.eagerState=a,qe(a,i)){var u=t.interleaved;u===null?(l.next=l,Oi(t)):(l.next=u.next,u.next=l),t.interleaved=l;return}}catch{}finally{}n=Ru(e,t,l,r),n!==null&&(l=Se(),Ze(n,e,r,l),bu(n,t,r))}}function Zu(e){var t=e.alternate;return e===ee||t!==null&&t===ee}function qu(e,t){Qn=ul=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function bu(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,xi(e,n)}}var cl={readContext:We,useCallback:me,useContext:me,useEffect:me,useImperativeHandle:me,useInsertionEffect:me,useLayoutEffect:me,useMemo:me,useReducer:me,useRef:me,useState:me,useDebugValue:me,useDeferredValue:me,useTransition:me,useMutableSource:me,useSyncExternalStore:me,useId:me,unstable_isNewReconciler:!1},Df={readContext:We,useCallback:function(e,t){return et().memoizedState=[e,t===void 0?null:t],e},useContext:We,useEffect:Ho,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,Br(4194308,4,Qu.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Br(4194308,4,e,t)},useInsertionEffect:function(e,t){return Br(4,2,e,t)},useMemo:function(e,t){var n=et();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=et();return t=n!==void 0?n(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=zf.bind(null,ee,e),[r.memoizedState,e]},useRef:function(e){var t=et();return e={current:e},t.memoizedState=e},useState:Wo,useDebugValue:Wi,useDeferredValue:function(e){return et().memoizedState=e},useTransition:function(){var e=Wo(!1),t=e[0];return e=Lf.bind(null,e[1]),et().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=ee,l=et();if(q){if(n===void 0)throw Error(C(407));n=n()}else{if(n=t(),ae===null)throw Error(C(349));Qt&30||Fu(r,t,n)}l.memoizedState=n;var s={value:n,getSnapshot:t};return l.queue=s,Ho(Iu.bind(null,r,s,e),[e]),r.flags|=2048,cr(9,Au.bind(null,r,s,n,t),void 0,null),n},useId:function(){var e=et(),t=ae.identifierPrefix;if(q){var n=at,r=ot;n=(r&~(1<<32-Ge(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=ar++,0<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=i.createElement(n,{is:r.is}):(e=i.createElement(n),n==="select"&&(i=e,r.multiple?i.multiple=!0:r.size&&(i.size=r.size))):e=i.createElementNS(e,n),e[tt]=t,e[sr]=r,uc(e,t,!1,!1),t.stateNode=e;e:{switch(i=Cs(n,r),n){case"dialog":X("cancel",e),X("close",e),l=r;break;case"iframe":case"object":case"embed":X("load",e),l=r;break;case"video":case"audio":for(l=0;lkn&&(t.flags|=128,r=!0,Rn(s,!1),t.lanes=4194304)}else{if(!r)if(e=al(i),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Rn(s,!0),s.tail===null&&s.tailMode==="hidden"&&!i.alternate&&!q)return ve(t),null}else 2*re()-s.renderingStartTime>kn&&n!==1073741824&&(t.flags|=128,r=!0,Rn(s,!1),t.lanes=4194304);s.isBackwards?(i.sibling=t.child,t.child=i):(n=s.last,n!==null?n.sibling=i:t.child=i,s.last=i)}return s.tail!==null?(t=s.tail,s.rendering=t,s.tail=t.sibling,s.renderingStartTime=re(),t.sibling=null,n=b.current,J(b,r?n&1|2:n&1),t):(ve(t),null);case 22:case 23:return Xi(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?Le&1073741824&&(ve(t),t.subtreeFlags&6&&(t.flags|=8192)):ve(t),null;case 24:return null;case 25:return null}throw Error(C(156,t.tag))}function Bf(e,t){switch(Pi(t),t.tag){case 1:return Ee(t.type)&&tl(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return xn(),G(_e),G(ye),Ai(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Fi(t),null;case 13:if(G(b),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(C(340));yn()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return G(b),null;case 4:return xn(),null;case 10:return Di(t.type._context),null;case 22:case 23:return Xi(),null;case 24:return null;default:return null}}var zr=!1,ge=!1,Vf=typeof WeakSet=="function"?WeakSet:Set,D=null;function an(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){ne(e,t,r)}else n.current=null}function qs(e,t,n){try{n()}catch(r){ne(e,t,r)}}var ta=!1;function Wf(e,t){if($s=Zr,e=vu(),Ei(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var l=r.anchorOffset,s=r.focusNode;r=r.focusOffset;try{n.nodeType,s.nodeType}catch{n=null;break e}var i=0,a=-1,u=-1,c=0,g=0,m=e,h=null;t:for(;;){for(var x;m!==n||l!==0&&m.nodeType!==3||(a=i+l),m!==s||r!==0&&m.nodeType!==3||(u=i+r),m.nodeType===3&&(i+=m.nodeValue.length),(x=m.firstChild)!==null;)h=m,m=x;for(;;){if(m===e)break t;if(h===n&&++c===l&&(a=i),h===s&&++g===r&&(u=i),(x=m.nextSibling)!==null)break;m=h,h=m.parentNode}m=x}n=a===-1||u===-1?null:{start:a,end:u}}else n=null}n=n||{start:0,end:0}}else n=null;for(Ms={focusedElem:e,selectionRange:n},Zr=!1,D=t;D!==null;)if(t=D,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,D=e;else for(;D!==null;){t=D;try{var S=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(S!==null){var j=S.memoizedProps,O=S.memoizedState,f=t.stateNode,d=f.getSnapshotBeforeUpdate(t.elementType===t.type?j:Ye(t.type,j),O);f.__reactInternalSnapshotBeforeUpdate=d}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(w){ne(t,t.return,w)}if(e=t.sibling,e!==null){e.return=t.return,D=e;break}D=t.return}return S=ta,ta=!1,S}function Kn(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var l=r=r.next;do{if((l.tag&e)===e){var s=l.destroy;l.destroy=void 0,s!==void 0&&qs(t,n,s)}l=l.next}while(l!==r)}}function Cl(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function bs(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function fc(e){var t=e.alternate;t!==null&&(e.alternate=null,fc(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[tt],delete t[sr],delete t[Is],delete t[Cf],delete t[_f])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function pc(e){return e.tag===5||e.tag===3||e.tag===4}function na(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||pc(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function ei(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=el));else if(r!==4&&(e=e.child,e!==null))for(ei(e,t,n),e=e.sibling;e!==null;)ei(e,t,n),e=e.sibling}function ti(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(ti(e,t,n),e=e.sibling;e!==null;)ti(e,t,n),e=e.sibling}var de=null,Je=!1;function mt(e,t,n){for(n=n.child;n!==null;)hc(e,t,n),n=n.sibling}function hc(e,t,n){if(nt&&typeof nt.onCommitFiberUnmount=="function")try{nt.onCommitFiberUnmount(gl,n)}catch{}switch(n.tag){case 5:ge||an(n,t);case 6:var r=de,l=Je;de=null,mt(e,t,n),de=r,Je=l,de!==null&&(Je?(e=de,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):de.removeChild(n.stateNode));break;case 18:de!==null&&(Je?(e=de,n=n.stateNode,e.nodeType===8?es(e.parentNode,n):e.nodeType===1&&es(e,n),er(e)):es(de,n.stateNode));break;case 4:r=de,l=Je,de=n.stateNode.containerInfo,Je=!0,mt(e,t,n),de=r,Je=l;break;case 0:case 11:case 14:case 15:if(!ge&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){l=r=r.next;do{var s=l,i=s.destroy;s=s.tag,i!==void 0&&(s&2||s&4)&&qs(n,t,i),l=l.next}while(l!==r)}mt(e,t,n);break;case 1:if(!ge&&(an(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(a){ne(n,t,a)}mt(e,t,n);break;case 21:mt(e,t,n);break;case 22:n.mode&1?(ge=(r=ge)||n.memoizedState!==null,mt(e,t,n),ge=r):mt(e,t,n);break;default:mt(e,t,n)}}function ra(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new Vf),t.forEach(function(r){var l=qf.bind(null,e,r);n.has(r)||(n.add(r),r.then(l,l))})}}function Ke(e,t){var n=t.deletions;if(n!==null)for(var r=0;rl&&(l=i),r&=~s}if(r=l,r=re()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Qf(r/1960))-r,10e?16:e,St===null)var r=!1;else{if(e=St,St=null,pl=0,W&6)throw Error(C(331));var l=W;for(W|=4,D=e.current;D!==null;){var s=D,i=s.child;if(D.flags&16){var a=s.deletions;if(a!==null){for(var u=0;ure()-Yi?Bt(e,0):Ki|=n),Te(e,t)}function kc(e,t){t===0&&(e.mode&1?(t=kr,kr<<=1,!(kr&130023424)&&(kr=4194304)):t=1);var n=Se();e=ft(e,t),e!==null&&(pr(e,t,n),Te(e,n))}function Zf(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),kc(e,n)}function qf(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),kc(e,n)}var jc;jc=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||_e.current)Ce=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return Ce=!1,If(e,t,n);Ce=!!(e.flags&131072)}else Ce=!1,q&&t.flags&1048576&&Eu(t,ll,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Vr(e,t),e=t.pendingProps;var l=gn(t,ye.current);hn(t,n),l=Ui(null,t,r,e,l,n);var s=Bi();return t.flags|=1,typeof l=="object"&&l!==null&&typeof l.render=="function"&&l.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,Ee(r)?(s=!0,nl(t)):s=!1,t.memoizedState=l.state!==null&&l.state!==void 0?l.state:null,$i(t),l.updater=Nl,t.stateNode=l,l._reactInternals=t,Qs(t,r,e,n),t=Js(null,t,r,!0,s,n)):(t.tag=0,q&&s&&Ti(t),xe(null,t,l,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Vr(e,t),e=t.pendingProps,l=r._init,r=l(r._payload),t.type=r,l=t.tag=ep(r),e=Ye(r,e),l){case 0:t=Ys(null,t,r,e,n);break e;case 1:t=qo(null,t,r,e,n);break e;case 11:t=Go(null,t,r,e,n);break e;case 14:t=Zo(null,t,r,Ye(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:Ye(r,l),Ys(e,t,r,l,n);case 1:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Ye(r,l),qo(e,t,r,l,n);case 3:e:{if(ic(t),e===null)throw Error(C(387));r=t.pendingProps,s=t.memoizedState,l=s.element,Du(e,t),ol(t,r,null,n);var i=t.memoizedState;if(r=i.element,s.isDehydrated)if(s={element:r,isDehydrated:!1,cache:i.cache,pendingSuspenseBoundaries:i.pendingSuspenseBoundaries,transitions:i.transitions},t.updateQueue.baseState=s,t.memoizedState=s,t.flags&256){l=Sn(Error(C(423)),t),t=bo(e,t,r,n,l);break e}else if(r!==l){l=Sn(Error(C(424)),t),t=bo(e,t,r,n,l);break e}else for(ze=Ct(t.stateNode.containerInfo.firstChild),Re=t,q=!0,Xe=null,n=zu(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(yn(),r===l){t=pt(e,t,n);break e}xe(e,t,r,n)}t=t.child}return t;case 5:return Ou(t),e===null&&Vs(t),r=t.type,l=t.pendingProps,s=e!==null?e.memoizedProps:null,i=l.children,Fs(r,l)?i=null:s!==null&&Fs(r,s)&&(t.flags|=32),sc(e,t),xe(e,t,i,n),t.child;case 6:return e===null&&Vs(t),null;case 13:return oc(e,t,n);case 4:return Mi(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=wn(t,null,r,n):xe(e,t,r,n),t.child;case 11:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Ye(r,l),Go(e,t,r,l,n);case 7:return xe(e,t,t.pendingProps,n),t.child;case 8:return xe(e,t,t.pendingProps.children,n),t.child;case 12:return xe(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,l=t.pendingProps,s=t.memoizedProps,i=l.value,J(sl,r._currentValue),r._currentValue=i,s!==null)if(qe(s.value,i)){if(s.children===l.children&&!_e.current){t=pt(e,t,n);break e}}else for(s=t.child,s!==null&&(s.return=t);s!==null;){var a=s.dependencies;if(a!==null){i=s.child;for(var u=a.firstContext;u!==null;){if(u.context===r){if(s.tag===1){u=ut(-1,n&-n),u.tag=2;var c=s.updateQueue;if(c!==null){c=c.shared;var g=c.pending;g===null?u.next=u:(u.next=g.next,g.next=u),c.pending=u}}s.lanes|=n,u=s.alternate,u!==null&&(u.lanes|=n),Ws(s.return,n,t),a.lanes|=n;break}u=u.next}}else if(s.tag===10)i=s.type===t.type?null:s.child;else if(s.tag===18){if(i=s.return,i===null)throw Error(C(341));i.lanes|=n,a=i.alternate,a!==null&&(a.lanes|=n),Ws(i,n,t),i=s.sibling}else i=s.child;if(i!==null)i.return=s;else for(i=s;i!==null;){if(i===t){i=null;break}if(s=i.sibling,s!==null){s.return=i.return,i=s;break}i=i.return}s=i}xe(e,t,l.children,n),t=t.child}return t;case 9:return l=t.type,r=t.pendingProps.children,hn(t,n),l=We(l),r=r(l),t.flags|=1,xe(e,t,r,n),t.child;case 14:return r=t.type,l=Ye(r,t.pendingProps),l=Ye(r.type,l),Zo(e,t,r,l,n);case 15:return rc(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Ye(r,l),Vr(e,t),t.tag=1,Ee(r)?(e=!0,nl(t)):e=!1,hn(t,n),ec(t,r,l),Qs(t,r,l,n),Js(null,t,r,!0,e,n);case 19:return ac(e,t,n);case 22:return lc(e,t,n)}throw Error(C(156,t.tag))};function Nc(e,t){return Za(e,t)}function bf(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Be(e,t,n,r){return new bf(e,t,n,r)}function Zi(e){return e=e.prototype,!(!e||!e.isReactComponent)}function ep(e){if(typeof e=="function")return Zi(e)?1:0;if(e!=null){if(e=e.$$typeof,e===vi)return 11;if(e===gi)return 14}return 2}function Pt(e,t){var n=e.alternate;return n===null?(n=Be(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function Qr(e,t,n,r,l,s){var i=2;if(r=e,typeof e=="function")Zi(e)&&(i=1);else if(typeof e=="string")i=5;else e:switch(e){case qt:return Vt(n.children,l,s,t);case mi:i=8,l|=8;break;case ms:return e=Be(12,n,t,l|2),e.elementType=ms,e.lanes=s,e;case vs:return e=Be(13,n,t,l),e.elementType=vs,e.lanes=s,e;case gs:return e=Be(19,n,t,l),e.elementType=gs,e.lanes=s,e;case Oa:return El(n,l,s,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Ra:i=10;break e;case Da:i=9;break e;case vi:i=11;break e;case gi:i=14;break e;case vt:i=16,r=null;break e}throw Error(C(130,e==null?e:typeof e,""))}return t=Be(i,n,t,l),t.elementType=e,t.type=r,t.lanes=s,t}function Vt(e,t,n,r){return e=Be(7,e,r,t),e.lanes=n,e}function El(e,t,n,r){return e=Be(22,e,r,t),e.elementType=Oa,e.lanes=n,e.stateNode={isHidden:!1},e}function as(e,t,n){return e=Be(6,e,null,t),e.lanes=n,e}function us(e,t,n){return t=Be(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function tp(e,t,n,r,l){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Wl(0),this.expirationTimes=Wl(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Wl(0),this.identifierPrefix=r,this.onRecoverableError=l,this.mutableSourceEagerHydrationData=null}function qi(e,t,n,r,l,s,i,a,u){return e=new tp(e,t,n,a,u),t===1?(t=1,s===!0&&(t|=8)):t=0,s=Be(3,null,null,t),e.current=s,s.stateNode=e,s.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},$i(s),e}function np(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Tc)}catch(e){console.error(e)}}Tc(),Ta.exports=Oe;var op=Ta.exports,Pc,da=op;Pc=da.createRoot,da.hydrateRoot;async function he(e){const t=await fetch(e);if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()}async function ap(){return he("/api/archives")}async function up(e){return he(`/api/archives/${e}/entries`)}async function cp(e,t,n){const r=new URLSearchParams;return t&&r.set("q",t),n&&r.set("tag",n),he(`/api/archives/${e}/entries/search?${r}`)}async function dp(e,t){return he(`/api/archives/${e}/entries/${t}`)}async function fp(e,t,n){const r=await fetch(`/api/archives/${e}/entries/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:n??null})});if(!r.ok)throw new Error(await r.text())}async function cs(e,t){return he(`/api/archives/${e}/entries/${t}/tags`)}async function pp(e,t,n){const r=await fetch(`/api/archives/${e}/entries/${t}/tags`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tag_path:n})});if(!r.ok)throw new Error(`Failed to add tag (${r.status})`)}async function hp(e,t,n){const r=await fetch(`/api/archives/${e}/entries/${t}/tags/${n}`,{method:"DELETE"});if(!r.ok)throw new Error(`Remove failed (${r.status})`)}async function mp(e,t){const n=await fetch(`/api/archives/${e}/entries/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(`Delete failed (${n.status})`)}async function vp(e,t,n){const r=await fetch(`/api/archives/${e}/tags/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n})});if(!r.ok)throw new Error(await r.text());return r.json()}async function gp(e,t){const n=await fetch(`/api/archives/${e}/tags/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(await n.text())}async function fa(e){return he(`/api/archives/${e}/runs`)}async function ds(e){return he(`/api/archives/${e}/tags`)}async function yp(e,t,n=null){const r={locator:t};n&&n!=="best"&&(r.quality=n);const l=await fetch(`/api/archives/${e}/captures`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!l.ok){const s=await l.json().catch(()=>({}));throw new Error(s.error||`HTTP ${l.status}`)}return l.json()}async function wp(e,t){return he(`/api/archives/${e}/captures/probe?locator=${encodeURIComponent(t)}`)}async function xp(e,t){return he(`/api/archives/${e}/capture_jobs/${t}`)}async function Sp(){return(await(await fetch("/api/auth/setup")).json()).setup_required===!0}async function kp(e,t){const n=await fetch("/api/auth/setup",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({username:e,password:t})});if(!n.ok)throw new Error((await n.json()).error||"Setup failed");return n.json()}async function jp(e,t){const n=await fetch("/api/auth/login",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({username:e,password:t})});if(!n.ok)throw new Error((await n.json()).error||"Login failed");return n.json()}async function Np(){await fetch("/api/auth/logout",{method:"POST"})}async function Cp(){const e=await fetch("/api/auth/me");return e.status===401?null:e.json()}async function _p(e){const t=await fetch("/api/auth/me",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({display_name:e})});if(!t.ok)throw new Error(await t.text())}async function Ep(e){const t=await fetch("/api/auth/me",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(await t.text())}async function Tp(e,t){const n=await fetch("/api/auth/me",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({current_password:e,new_password:t})});if(!n.ok){let r=await n.text();try{r=JSON.parse(r).error??r}catch{}throw new Error(r)}}async function Pp(){return he("/api/auth/tokens")}async function Lp(e){const t=await fetch("/api/auth/tokens",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})});if(!t.ok)throw new Error(await t.text());return t.json()}async function zp(e){const t=await fetch(`/api/auth/tokens/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(await t.text())}async function Rp(){return he("/api/admin/instance-settings")}async function Dp(e){const t=await fetch("/api/admin/instance-settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(await t.text())}async function Op(){return he("/api/admin/users")}async function $p(e,t,n){const r=await fetch("/api/admin/users",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,password:t,email:n||void 0})});if(!r.ok){const l=await r.json().catch(()=>({}));throw new Error(l.error||`HTTP ${r.status}`)}return r.json()}async function Mp(e,t){const n=await fetch(`/api/admin/users/${e}/status`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||`HTTP ${n.status}`)}return n.json()}async function Fp(){return he("/api/admin/roles")}async function Ap(e,t){const n=await fetch("/api/admin/roles",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:e,name:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||`HTTP ${n.status}`)}return n.json()}async function Ip(e){return he(`/api/archives/${e}/collections`)}async function Up(e,t,n,r=2){const l=await fetch(`/api/archives/${e}/collections`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:t,slug:n,default_visibility_bits:r})});if(!l.ok){const s=await l.json().catch(()=>({error:l.statusText}));throw new Error(s.error||l.statusText)}return l.json()}async function Bp(e,t){return he(`/api/archives/${e}/collections/${t}`)}async function Vp(e,t,n,r=2){const l=await fetch(`/api/archives/${e}/collections/${t}/entries`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({entry_uid:n,visibility_bits:r})});if(!l.ok){const s=await l.json().catch(()=>({error:l.statusText}));throw new Error(s.error||l.statusText)}}async function Wp(e,t,n){const r=await fetch(`/api/archives/${e}/collections/${t}/entries/${n}`,{method:"DELETE"});if(!r.ok){const l=await r.json().catch(()=>({error:r.statusText}));throw new Error(l.error||r.statusText)}}async function Hp(e,t,n,r){const l=await fetch(`/api/archives/${e}/collections/${t}/entries/${n}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({visibility_bits:r})});if(!l.ok){const s=await l.json().catch(()=>({error:l.statusText}));throw new Error(s.error||l.statusText)}}async function Qp(e,t){return he(`/api/archives/${e}/entries/${t}/collections`)}async function pa(e,t,n){const r=await fetch(`/api/archives/${e}/collections/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!r.ok){const l=await r.json().catch(()=>({}));throw new Error(l.error??r.statusText)}}async function Kp(e,t){const n=await fetch(`/api/archives/${e}/collections/${t}`,{method:"DELETE"});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error??n.statusText)}}async function Yp(e){return he(`/api/archives/${e}/blob-cleanup`)}async function Jp(e){const t=await fetch(`/api/archives/${e}/blob-cleanup`,{method:"DELETE"});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error??t.statusText)}return t.json()}const Xp=window.fetch;window.fetch=async(...e)=>{var n;const t=await Xp(...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 Gp({onLogin:e}){const[t,n]=v.useState(""),[r,l]=v.useState(""),[s,i]=v.useState(null),[a,u]=v.useState(!1);async function c(g){g.preventDefault(),i(null),u(!0);try{const m=await jp(t,r);e(m)}catch(m){i(m.message)}finally{u(!1)}}return o.jsx("div",{className:"login-page",children:o.jsxs("div",{className:"login-card",children:[o.jsx("h1",{className:"login-brand",children:"Archivr"}),o.jsx("p",{className:"login-tagline",children:"Sign in to your archive"}),o.jsxs("form",{onSubmit:c,children:[o.jsxs("div",{className:"login-field",children:[o.jsx("label",{className:"login-label",htmlFor:"login-username",children:"Username"}),o.jsx("input",{className:"login-input",id:"login-username",type:"text",value:t,onChange:g=>n(g.target.value),autoFocus:!0,required:!0,autoComplete:"username"})]}),o.jsxs("div",{className:"login-field",children:[o.jsx("label",{className:"login-label",htmlFor:"login-password",children:"Password"}),o.jsx("input",{className:"login-input",id:"login-password",type:"password",value:r,onChange:g=>l(g.target.value),required:!0,autoComplete:"current-password"})]}),s&&o.jsx("p",{className:"login-error",children:s}),o.jsx("button",{className:"login-submit",type:"submit",disabled:a,children:a?"Signing in…":"Sign in"})]})]})})}function Zp({onComplete:e}){const[t,n]=v.useState(""),[r,l]=v.useState(""),[s,i]=v.useState(""),[a,u]=v.useState(null),[c,g]=v.useState(!1);async function m(h){if(h.preventDefault(),r!==s){u("Passwords do not match");return}if(r.length<8){u("Password must be at least 8 characters");return}u(null),g(!0);try{await kp(t,r),e()}catch(x){u(x.message)}finally{g(!1)}}return o.jsx("div",{className:"setup-page",children:o.jsxs("div",{className:"setup-card",children:[o.jsx("h1",{className:"setup-brand",children:"Archivr"}),o.jsx("p",{className:"setup-tagline",children:"Create your owner account to get started."}),o.jsxs("form",{onSubmit:m,children:[o.jsxs("div",{className:"setup-field",children:[o.jsx("label",{className:"setup-label",htmlFor:"setup-username",children:"Username"}),o.jsx("input",{className:"setup-input",id:"setup-username",type:"text",value:t,onChange:h=>n(h.target.value),autoFocus:!0,required:!0,autoComplete:"username"})]}),o.jsxs("div",{className:"setup-field",children:[o.jsx("label",{className:"setup-label",htmlFor:"setup-password",children:"Password"}),o.jsx("input",{className:"setup-input",id:"setup-password",type:"password",value:r,onChange:h=>l(h.target.value),required:!0,autoComplete:"new-password"})]}),o.jsxs("div",{className:"setup-field",children:[o.jsx("label",{className:"setup-label",htmlFor:"setup-confirm",children:"Confirm password"}),o.jsx("input",{className:"setup-input",id:"setup-confirm",type:"password",value:s,onChange:h=>i(h.target.value),required:!0,autoComplete:"new-password"})]}),a&&o.jsx("p",{className:"setup-error",children:a}),o.jsx("button",{className:"setup-submit",type:"submit",disabled:c,children:c?"Creating account…":"Create account"})]})]})})}function qp({archives:e,archiveId:t,onArchiveChange:n,view:r,onViewChange:l,onCaptureClick:s}){const{currentUser:i,setCurrentUser:a}=v.useContext(Rl)??{},[u,c]=v.useState(!1);async function g(){c(!0),await Np(),a(null),window.location.reload()}return o.jsxs("header",{className:"topbar",children:[o.jsx("div",{className:"brand",children:"Archivr"}),o.jsx("div",{className:"switcher",children:o.jsx("select",{"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","tags","collections","runs","admin","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:s,children:"Capture"}),i&&o.jsxs("div",{className:"user-menu",children:[o.jsx("span",{className:"user-name",children:i.display_name||i.username}),o.jsx("button",{className:"logout-btn",onClick:g,disabled:u,children:u?"Logging out…":"Log out"})]})]})}let ii=1;function Lc(e){const t=e.trim(),n=t.toLowerCase();for(const r of["yt:","youtube:"])if(n.startsWith(r)){const l=n.slice(r.length);return l.startsWith("video/")||l.startsWith("short/")||l.startsWith("shorts/")}for(const r of["x:","twitter:","tweet:"])if(n.startsWith(r))return n.slice(r.length).startsWith("media:");return!!(n.startsWith("instagram:")||n.startsWith("facebook:")||n.startsWith("tiktok:")||n.startsWith("reddit:")||n.startsWith("snapchat:")||(n.startsWith("http://")||n.startsWith("https://"))&&(/^https?:\/\/(?:www\.)?(?:youtu\.be\/[0-9A-Za-z_-]+|youtube\.com\/watch\?v=[0-9A-Za-z_-]+|youtube\.com\/shorts\/[0-9A-Za-z_-]+)/.test(t)||n.startsWith("https://x.com/")||n.startsWith("http://x.com/")||/^https?:\/\/(?:www\.)?instagram\.com\//.test(n)||/^https?:\/\/(?:www\.)?facebook\.com\//.test(n)||n.startsWith("https://fb.watch/")||n.startsWith("http://fb.watch/")||/^https?:\/\/(?:www\.)?tiktok\.com\//.test(n)||/^https?:\/\/(?:www\.)?reddit\.com\//.test(n)||n.startsWith("https://redd.it/")||n.startsWith("http://redd.it/")||/^https?:\/\/(?:www\.)?snapchat\.com\//.test(n)))}function On(e=""){return{id:ii++,locator:e,quality:"best",probeState:"idle",probeQualities:null,probeHasAudio:!1,status:"idle",error:null,jobUid:null,archiveId:null}}function ha(e){return e.some(t=>t.status==="submitting"||t.status==="running")}function bp({open:e,archiveId:t,onClose:n,onCaptured:r,onToast:l}){const s=v.useRef(null),i=v.useRef(!0),a=v.useRef(new Map),u=v.useRef(new Map),c=v.useRef(t);v.useEffect(()=>{c.current=t},[t]);const g=v.useRef(r),m=v.useRef(l);v.useEffect(()=>{g.current=r},[r]),v.useEffect(()=>{m.current=l},[l]);const[h,x]=v.useState(()=>{try{const y=JSON.parse(sessionStorage.getItem("captureItems")||"null");if(Array.isArray(y)&&y.length>0)return y.forEach(T=>{T.id>=ii&&(ii=T.id+1)}),y}catch{}return[On()]});v.useEffect(()=>{sessionStorage.setItem("captureItems",JSON.stringify(h))},[h]),v.useEffect(()=>{["captureDialogLocator","captureDialogError","captureDialogBusy","captureDialogJobStatus","captureDialogJobUid"].forEach(y=>sessionStorage.removeItem(y)),x(y=>y.map(T=>T.status==="submitting"?{...T,status:"idle",error:null}:T)),h.forEach(y=>{y.status==="running"&&y.jobUid&&y.archiveId&&!a.current.has(y.jobUid)&&S(y.id,y.jobUid,y.locator,y.archiveId)})},[]),v.useEffect(()=>{const y=s.current;if(!y)return;const T=()=>{u.current.forEach(R=>clearTimeout(R)),u.current.clear(),n()};return y.addEventListener("close",T),()=>y.removeEventListener("close",T)},[n]),v.useEffect(()=>{const y=s.current;y&&(e?(!i.current&&!ha(h)&&x([On()]),i.current=!1,y.open||y.showModal()):(u.current.forEach(T=>clearTimeout(T)),u.current.clear(),y.open&&y.close()))},[e]),v.useEffect(()=>()=>{a.current.forEach(y=>clearInterval(y)),u.current.forEach(y=>clearTimeout(y))},[]);function S(y,T,R,I){if(a.current.has(T))return;const U=setInterval(async()=>{try{const E=await xp(I,T);if(E.status==="completed")clearInterval(a.current.get(T)),a.current.delete(T),x(F=>F.map(H=>H.id===y?{...H,status:"completed"}:H)),setTimeout(()=>{x(F=>{const H=F.filter(Z=>Z.id!==y);return H.length===0?[On()]:H})},1400),g.current();else if(E.status==="failed"){clearInterval(a.current.get(T)),a.current.delete(T);const F=E.error_text||"Capture failed.";x(H=>H.map(Z=>Z.id===y?{...Z,status:"failed",error:F}:Z)),m.current(F,R)}}catch(E){clearInterval(a.current.get(T)),a.current.delete(T);const F=E.message||"Network error";x(H=>H.map(Z=>Z.id===y?{...Z,status:"failed",error:F}:Z)),m.current(F,R)}},500);a.current.set(T,U)}async function j(y){if(!y.locator.trim())return;const T=t,R=y.locator.trim(),I=y.quality||"best";x(U=>U.map(E=>E.id===y.id?{...E,status:"submitting",error:null}:E));try{const U=await yp(T,R,I);x(E=>E.map(F=>F.id===y.id?{...F,status:"running",jobUid:U.job_uid,archiveId:T}:F)),S(y.id,U.job_uid,R,T)}catch(U){const E=U.message||"Submission failed.";x(F=>F.map(H=>H.id===y.id?{...H,status:"failed",error:E}:H)),m.current(E,R)}}function O(){h.filter(T=>T.status==="idle"&&T.locator.trim()).forEach(T=>j(T))}function f(){x(y=>[...y,On()])}function d(y){clearTimeout(u.current.get(y)),u.current.delete(y),x(T=>{const R=T.filter(I=>I.id!==y);return R.length===0?[On()]:R})}function p(y){x(T=>T.map(R=>R.id===y?{...R,status:"idle",error:null}:R))}function w(y,T){if(clearTimeout(u.current.get(y)),x(I=>I.map(U=>U.id===y?{...U,locator:T,probeState:"idle",probeQualities:null,probeHasAudio:!1,quality:"best"}:U)),!Lc(T))return;const R=setTimeout(async()=>{u.current.delete(y),x(I=>I.map(U=>U.id===y?{...U,probeState:"probing"}:U));try{const I=await wp(c.current,T.trim());x(U=>U.map(E=>{if(E.id!==y||E.locator!==T)return E;const F=I.qualities??[],H=I.has_audio??!1,Z=F.length===0&&H?"audio":"best";return{...E,probeState:"done",probeQualities:F,probeHasAudio:H,quality:Z}}))}catch{x(I=>I.map(U=>U.id===y?{...U,probeState:"idle",probeQualities:null}:U))}},600);u.current.set(y,R)}function k(y,T){x(R=>R.map(I=>I.id===y?{...I,quality:T}:I))}const _=h.filter(y=>y.status==="idle"&&y.locator.trim()).length,P=ha(h);return o.jsx("dialog",{ref:s,className:"capture-dialog",children:o.jsxs("div",{className:"capture-dialog-inner",children:[o.jsxs("div",{className:"capture-dialog-header",children:[o.jsx("h2",{className:"capture-dialog-title",children:"Capture"}),o.jsx("button",{type:"button",className:"capture-dialog-close",onClick:()=>{var y;return(y=s.current)==null?void 0:y.close()},"aria-label":"Close",children:o.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[o.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),o.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),o.jsx("div",{className:"capture-rows",children:h.map((y,T)=>o.jsx(eh,{item:y,autoFocus:T===h.length-1&&y.status==="idle",onLocatorChange:R=>w(y.id,R),onQualityChange:R=>k(y.id,R),onRemove:()=>d(y.id),onReset:()=>p(y.id),onSubmit:O},y.id))}),o.jsxs("button",{type:"button",className:"capture-add-row",onClick:f,children:[o.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[o.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"14"}),o.jsx("line",{x1:"2",y1:"8",x2:"14",y2:"8"})]}),"Add another"]}),o.jsxs("div",{className:"capture-actions",children:[o.jsx("button",{type:"button",className:"capture-cancel",onClick:()=>{var y;return(y=s.current)==null?void 0:y.close()},children:P?"Close":"Cancel"}),o.jsx("button",{type:"button",className:"capture-submit",onClick:O,disabled:_===0,children:_>1?`Archive ${_}`:"Archive"})]})]})})}function eh({item:e,autoFocus:t,onLocatorChange:n,onQualityChange:r,onRemove:l,onReset:s,onSubmit:i}){const a=v.useRef(null),u=e.status==="submitting"||e.status==="running";v.useEffect(()=>{var g;t&&e.status==="idle"&&((g=a.current)==null||g.focus())},[t]);const c=(()=>{if(e.status==="completed"||u||!Lc(e.locator))return null;if(e.probeState==="probing")return o.jsx("span",{className:"capture-quality-probing","aria-label":"Checking available qualities",children:"…"});if(e.probeState==="done"){const g=e.probeQualities??[],m=e.probeHasAudio??!1;return g.length===0&&!m?o.jsx("span",{className:"capture-quality-hint",children:"No media detected"}):g.length===0&&m?o.jsx("select",{className:"capture-quality",value:"audio",onChange:h=>r(h.target.value),"aria-label":"Video quality",children:o.jsx("option",{value:"audio",children:"Audio only"})}):o.jsxs("select",{className:"capture-quality",value:e.quality||"best",onChange:h=>r(h.target.value),"aria-label":"Video quality",children:[o.jsx("option",{value:"best",children:"Best quality"}),g.map(h=>o.jsx("option",{value:h,children:h},h)),m&&o.jsx("option",{value:"audio",children:"Audio only"})]})}return null})();return o.jsxs("div",{className:`capture-row capture-row--${e.status}`,children:[o.jsxs("div",{className:"capture-row-main",children:[o.jsx(th,{status:e.status}),o.jsx("input",{ref:a,className:"capture-input",type:"text",placeholder:"https://… · yt:ID · tweet:ID · x:ID",value:e.locator,onChange:g=>n(g.target.value),onKeyDown:g=>{g.key==="Enter"&&i()},disabled:u||e.status==="completed",autoComplete:"off",spellCheck:!1}),c,e.status==="failed"&&o.jsx("button",{type:"button",className:"capture-row-action",onClick:s,title:"Retry",children:o.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[o.jsx("path",{d:"M13 2.5A7 7 0 1 1 6.5 1"}),o.jsx("polyline",{points:"6.5 1 4 3.5 6.5 6"})]})}),!u&&e.status!=="completed"&&e.status!=="failed"&&o.jsx("button",{type:"button",className:"capture-row-action capture-row-remove",onClick:l,"aria-label":"Remove",children:o.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[o.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),o.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),e.error&&o.jsx("p",{className:"capture-row-error",children:e.error})]})}function th({status:e}){return e==="submitting"||e==="running"?o.jsx("span",{className:"cap-dot cap-dot--running","aria-label":"Running",children:o.jsx("span",{className:"cap-spinner"})}):e==="completed"?o.jsx("span",{className:"cap-dot cap-dot--ok","aria-label":"Done",children:"✓"}):e==="failed"?o.jsx("span",{className:"cap-dot cap-dot--err","aria-label":"Failed",children:"✕"}):o.jsx("span",{className:"cap-dot cap-dot--idle","aria-hidden":"true"})}function oi(e){if(!e)return"0 B";const t=["B","KB","MB","GB"];let n=e,r=0;for(;n>=1024&&r").replace(/"/g,'"').replace(/'/g,"'").replace(/'/g,"'")}function Ut(e){return nh(e)??""}function zc(e){if(!e)return"";const t=new Date(e);if(isNaN(t))return e;const n=r=>String(r).padStart(2,"0");return`${t.getUTCFullYear()}-${n(t.getUTCMonth()+1)}-${n(t.getUTCDate())} ${n(t.getUTCHours())}:${n(t.getUTCMinutes())}`}const ma={youtube:'',x:'',instagram:'',facebook:'',tiktok:'',reddit:'',snapchat:'',local:'',web:'',other:'?'};function Rc(e){return ma[e]??ma.other}function Dc(e){return e.split("/").map(t=>t?t.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"").join("/")}function rh({entry:e,archiveId:t,isSelected:n,onSelect:r}){const[l,s]=v.useState(!1),a=e.source_kind==="web"&&e.entity_kind==="page"&&e.has_favicon&&t&&!l?o.jsx("img",{src:`/api/archives/${t}/entries/${e.entry_uid}/favicon`,width:"16",height:"16",alt:"",onError:()=>s(!0),style:{objectFit:"contain"}}):o.jsx("span",{dangerouslySetInnerHTML:{__html:Rc(e.source_kind)}});return o.jsxs("div",{className:n?"is-selected":void 0,tabIndex:0,"data-entry-uid":e.entry_uid,onClick:r,onKeyDown:u=>{u.key==="Enter"&&r()},children:[o.jsx("div",{className:"col-added",children:zc(e.archived_at)}),o.jsxs("div",{className:"col-title",children:[o.jsx("span",{className:"source-icon",children:a}),o.jsx("span",{className:"entry-title",children:Ut(e.title)||Ut(e.entry_uid)})]}),o.jsx("div",{className:"col-type",children:o.jsx("span",{className:"type-pill",children:Ut(e.entity_kind)})}),o.jsxs("div",{className:"col-size",children:[o.jsx("span",{className:"size-total",children:oi(e.total_artifact_bytes)}),e.cached_bytes>0&&e.total_artifact_bytes>0&&o.jsxs("span",{className:"size-cached-pct",title:`${oi(e.cached_bytes)} already on disk from an earlier entry`,children:[Math.round(e.cached_bytes/e.total_artifact_bytes*100),"% cached"]})]}),o.jsx("div",{className:"url-cell col-url",children:Ut(e.original_url)})]})}function lh({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(rh,{entry:l,archiveId:r,isSelected:l.entry_uid===t,onSelect:()=>n(l)},l.entry_uid))})]})})}function sh(e){if(!e)return"—";try{return new Date(e).toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return e}}function ih({status:e}){const t=e==="completed"?"run-status--completed":e==="failed"?"run-status--failed":e==="in_progress"?"run-status--in-progress":"",n=e?e.replace(/_/g," "):"—";return o.jsx("span",{className:`run-status ${t}`,children:n})}function oh({runs:e}){const[t,n]=v.useState(null);function r(l){n(s=>s===l?null:l)}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.length===0?o.jsx("tr",{children:o.jsx("td",{colSpan:5,style:{color:"var(--muted)",padding:"24px 16px",textAlign:"center"},children:"No runs yet."})}):e.map(l=>{const s=l.status==="failed"&&l.error_summary,i=t===l.run_uid;return[o.jsxs("tr",{className:s?"run-row run-row--failed":"run-row",onClick:s?()=>r(l.run_uid):void 0,title:s?i?"Click to hide error":"Click to view error":void 0,children:[o.jsx("td",{children:sh(l.started_at)}),o.jsxs("td",{children:[o.jsx(ih,{status:l.status}),s&&o.jsx("span",{className:"run-expand-hint","aria-hidden":"true",children:i?"▴":"▾"})]}),o.jsx("td",{children:l.requested_count??"—"}),o.jsx("td",{children:l.completed_count??"—"}),o.jsx("td",{children:l.failed_count??"—"})]},l.run_uid),s&&i&&o.jsx("tr",{className:"run-error-row",children:o.jsx("td",{colSpan:5,children:o.jsx("pre",{className:"run-error-detail",children:l.error_summary})})},`${l.run_uid}-detail`)]})})]})})}const ah=4;function uh({archives:e}){const{currentUser:t}=v.useContext(Rl)??{},n=t&&(t.role_bits&ah)!==0,[r,l]=v.useState("users"),[s,i]=v.useState([]),[a,u]=v.useState([]),[c,g]=v.useState(!1),[m,h]=v.useState(null),[x,S]=v.useState(""),[j,O]=v.useState(""),[f,d]=v.useState(""),[p,w]=v.useState(null),[k,_]=v.useState(!1),[P,y]=v.useState(""),[T,R]=v.useState(""),[I,U]=v.useState(null),[E,F]=v.useState(!1),H=v.useCallback(async()=>{if(n){g(!0),h(null);try{const[N,M]=await Promise.all([Op(),Fp()]);i(N),u(M)}catch(N){h(N.message)}finally{g(!1)}}},[n]);v.useEffect(()=>{H()},[H]);async function Z(N){const M=N.status==="active"?"disabled":"active";try{await Mp(N.user_uid,M),i(Q=>Q.map(A=>A.user_uid===N.user_uid?{...A,status:M}:A))}catch(Q){h(Q.message)}}async function Me(N){if(N.preventDefault(),!x.trim()||!j){w("Username and password required");return}_(!0),w(null);try{await $p(x.trim(),j,f.trim()||void 0),S(""),O(""),d(""),await H()}catch(M){w(M.message)}finally{_(!1)}}async function L(N){if(N.preventDefault(),!P.trim()||!T.trim()){U("Slug and name required");return}F(!0),U(null);try{await Ap(P.trim(),T.trim()),y(""),R(""),await H()}catch(M){U(M.message)}finally{F(!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:"view-tabs",children:[o.jsx("button",{className:`view-tab${r==="users"?" is-active":""}`,onClick:()=>l("users"),children:"Users"}),o.jsx("button",{className:`view-tab${r==="roles"?" is-active":""}`,onClick:()=>l("roles"),children:"Roles"}),o.jsx("button",{className:`view-tab${r==="archives"?" is-active":""}`,onClick:()=>l("archives"),children:"Archives"})]}),m&&o.jsx("div",{className:"form-msg form-msg--err",children:m}),r==="users"&&o.jsxs("div",{className:"admin-section",children:[o.jsx("h2",{children:"Users"}),c?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:s.map(N=>o.jsxs("tr",{className:N.status==="disabled"?"admin-row-disabled":"",children:[o.jsx("td",{children:N.username}),o.jsx("td",{className:"muted",children:N.email||"—"}),o.jsx("td",{children:N.role_slugs.join(", ")||"—"}),o.jsx("td",{children:o.jsx("span",{className:`status-badge status-${N.status}`,children:N.status})}),o.jsx("td",{children:o.jsx("button",{className:"admin-action-btn",onClick:()=>Z(N),children:N.status==="active"?"Ban":"Unban"})})]},N.user_uid))})]}),o.jsx("h3",{children:"Create User"}),o.jsxs("form",{className:"admin-form",onSubmit:Me,children:[o.jsx("input",{className:"admin-input",placeholder:"Username",value:x,onChange:N=>S(N.target.value),required:!0}),o.jsx("input",{className:"admin-input",type:"password",placeholder:"Password (min 8 chars)",value:j,onChange:N=>O(N.target.value),required:!0}),o.jsx("input",{className:"admin-input",type:"email",placeholder:"Email (optional)",value:f,onChange:N=>d(N.target.value)}),p&&o.jsx("div",{className:"form-msg form-msg--err",children:p}),o.jsx("button",{className:"btn-primary",type:"submit",disabled:k,children:k?"Creating…":"Create User"})]})]}),r==="roles"&&o.jsxs("div",{className:"admin-section",children:[o.jsx("h2",{children:"Roles"}),c?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:a.map(N=>o.jsxs("tr",{children:[o.jsx("td",{children:o.jsx("code",{children:N.slug})}),o.jsx("td",{children:N.name}),o.jsx("td",{children:N.level}),o.jsx("td",{children:N.bit_position}),o.jsx("td",{children:N.is_builtin?"✓":""})]},N.role_uid))})]}),o.jsx("h3",{children:"Create Custom Role"}),o.jsxs("form",{className:"admin-form",onSubmit:L,children:[o.jsx("input",{className:"admin-input",placeholder:"Slug (e.g. moderator)",value:P,onChange:N=>y(N.target.value),required:!0}),o.jsx("input",{className:"admin-input",placeholder:"Display Name (e.g. Moderator)",value:T,onChange:N=>R(N.target.value),required:!0}),I&&o.jsx("div",{className:"form-msg form-msg--err",children:I}),o.jsx("button",{className:"btn-primary",type:"submit",disabled:E,children:E?"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(N=>o.jsxs("div",{className:"admin-archive",children:[o.jsx("strong",{children:N.label}),o.jsx("div",{className:"muted",children:N.archive_path})]},N.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(N=>o.jsxs("div",{className:"admin-archive",children:[o.jsx("strong",{children:N.label}),o.jsx("div",{className:"muted",children:N.archive_path})]},N.id))})]})}function Oc({node:e,archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:i,onTagsRefresh:a,humanizeTags:u}){var w;const c=n===e.tag.full_path,[g,m]=v.useState(!1),[h,x]=v.useState(""),S=v.useRef(!1);function j(){if(g)return;const k=c?null:e.tag.full_path;r(k),l("archive")}function O(k){k.stopPropagation(),x(e.tag.slug),m(!0)}async function f(){const k=h.trim();if(!k||k===e.tag.slug){m(!1);return}try{const _=await vp(t,e.tag.tag_uid,k);s(e.tag.full_path,_.full_path),a()}catch{}finally{m(!1)}}async function d(k){var P;k.stopPropagation();const _=((P=e.children)==null?void 0:P.length)>0?`Delete tag "${e.tag.full_path}" and all its child tags? This cannot be undone.`:`Delete tag "${e.tag.full_path}"? This cannot be undone.`;if(window.confirm(_))try{await gp(t,e.tag.tag_uid),i(e.tag.full_path),a()}catch{}}const p={archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:i,onTagsRefresh:a,humanizeTags:u};return o.jsxs("li",{children:[o.jsxs("div",{className:"tag-node-row",children:[g?o.jsx("input",{className:"tag-rename-input",autoFocus:!0,value:h,onChange:k=>x(k.target.value),onKeyDown:k=>{k.key==="Enter"&&k.currentTarget.blur(),k.key==="Escape"&&(S.current=!0,k.currentTarget.blur())},onBlur:()=>{S.current?(S.current=!1,m(!1)):f()}}):o.jsxs("button",{className:`tag-node-btn${c?" is-active":""}`,title:e.tag.full_path,onClick:j,onDoubleClick:O,children:[u?e.tag.name:e.tag.slug,o.jsx("svg",{className:"edit-icon",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",onClick:k=>{k.stopPropagation(),O(k)},children:o.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),o.jsx("button",{className:"remove tag-node-delete",title:`Delete tag ${e.tag.full_path}`,onClick:d,"aria-label":`Delete tag ${e.tag.full_path}`,children:"×"})]}),((w=e.children)==null?void 0:w.length)>0&&o.jsx("div",{className:"tag-children",children:o.jsx("ul",{className:"tag-tree-list",children:e.children.map(k=>o.jsx(Oc,{node:k,...p},k.tag.tag_uid))})})]})}function ch({archiveId:e,tagNodes:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:i,onTagsRefresh:a,humanizeTags:u}){return o.jsx("section",{id:"tags-view",className:"view is-active",children:o.jsxs("div",{className:"tag-tree",children:[o.jsxs("div",{className:"tag-tree-header",children:[o.jsx("span",{className:"tag-tree-title",children:"Tags"}),n&&o.jsxs("span",{className:"tag-tree-active",children:["Filtering: ",n]})]}),t.length===0?o.jsx("p",{className:"muted",style:{padding:"8px 0"},children:"No tags yet."}):o.jsx("ul",{className:"tag-tree-list",children:t.map(c=>o.jsx(Oc,{node:c,archiveId:e,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:i,onTagsRefresh:a,humanizeTags:u},c.tag.tag_uid))})]})})}const In=[{value:0,label:"Private"},{value:2,label:"Users only"},{value:3,label:"Public"}],dh=e=>{var t;return((t=In.find(n=>n.value===e))==null?void 0:t.label)??String(e)};function fh({archiveId:e}){const[t,n]=v.useState([]),[r,l]=v.useState(!1),[s,i]=v.useState(null),[a,u]=v.useState(null),[c,g]=v.useState(null),[m,h]=v.useState(!1),[x,S]=v.useState(null),[j,O]=v.useState(""),[f,d]=v.useState(""),[p,w]=v.useState(2),[k,_]=v.useState(!1),[P,y]=v.useState(null),[T,R]=v.useState(""),[I,U]=v.useState(2),[E,F]=v.useState(!1),[H,Z]=v.useState(null),[Me,L]=v.useState(!1),[N,M]=v.useState(""),Q=v.useRef(null),A=t.find(z=>z.collection_uid===a)??null,we=(A==null?void 0:A.slug)==="_default_",ue=v.useCallback(async()=>{if(e){l(!0),i(null);try{const z=await Ip(e);n(z)}catch(z){i(z.message)}finally{l(!1)}}},[e]),Qe=v.useCallback(async z=>{if(!z){g(null);return}h(!0),S(null);try{const V=await Bp(e,z);g(V)}catch(V){S(V.message)}finally{h(!1)}},[e]);v.useEffect(()=>{ue()},[ue]),v.useEffect(()=>{Qe(a)},[a,Qe]),v.useEffect(()=>{Me&&Q.current&&Q.current.focus()},[Me]);async function Fe(z){z.preventDefault();const V=j.trim(),Pe=f.trim();if(!(!V||!Pe)){_(!0),y(null);try{const $=await Up(e,V,Pe,p);O(""),d(""),w(2),await ue(),u($.collection_uid)}catch($){y($.message)}finally{_(!1)}}}async function lt(){const z=N.trim();if(!z||!A){L(!1);return}try{await pa(e,A.collection_uid,{name:z}),await ue(),g(V=>V&&{...V,name:z})}catch(V){i(V.message)}finally{L(!1)}}async function Dl(z){if(A)try{await pa(e,A.collection_uid,{default_visibility_bits:z}),await ue(),g(V=>V&&{...V,default_visibility_bits:z})}catch(V){i(V.message)}}async function Ol(){if(A&&window.confirm(`Delete collection "${A.name}"? Entries will not be deleted.`))try{await Kp(e,A.collection_uid),u(null),g(null),await ue()}catch(z){i(z.message)}}async function $l(z){z.preventDefault();const V=T.trim();if(!(!V||!A)){F(!0),Z(null);try{await Vp(e,A.collection_uid,V,I),R(""),await Qe(A.collection_uid)}catch(Pe){Z(Pe.message)}finally{F(!1)}}}async function Ml(z){if(A)try{await Wp(e,A.collection_uid,z),await Qe(A.collection_uid)}catch(V){S(V.message)}}async function Fl(z,V){if(A)try{await Hp(e,A.collection_uid,z,V),g(Pe=>Pe&&{...Pe,entries:Pe.entries.map($=>$.entry_uid===z?{...$,collection_visibility_bits:V}:$)})}catch(Pe){S(Pe.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…"}),s&&o.jsxs("div",{className:"collections-error",children:[s," ",o.jsx("button",{onClick:()=>i(null),className:"coll-dismiss",children:"×"})]}),o.jsxs("div",{className:"collections-layout",children:[o.jsxs("div",{className:"collections-sidebar",children:[t.map(z=>o.jsxs("button",{className:`coll-sidebar-row${a===z.collection_uid?" is-active":""}`,onClick:()=>u(z.collection_uid),children:[o.jsx("span",{className:"coll-row-name",children:z.name}),o.jsx("span",{className:"coll-row-meta",children:dh(z.default_visibility_bits)})]},z.collection_uid)),t.length===0&&!r&&o.jsx("div",{className:"muted",style:{padding:"8px 12px"},children:"No collections yet."})]}),A?o.jsxs("div",{className:"coll-detail",children:[o.jsxs("div",{className:"coll-detail-header",children:[Me?o.jsx("input",{ref:Q,className:"coll-rename-input",value:N,onChange:z=>M(z.target.value),onBlur:lt,onKeyDown:z=>{z.key==="Enter"&<(),z.key==="Escape"&&L(!1)}}):o.jsxs("h3",{className:`coll-detail-name${we?"":" coll-detail-name--editable"}`,title:we?void 0:"Click to rename",onClick:()=>{we||(M(A.name),L(!0))},children:[(c==null?void 0:c.name)??A.name,!we&&o.jsx("span",{className:"coll-edit-hint",children:" ✎"})]}),!we&&o.jsx("button",{className:"coll-delete-btn",onClick:Ol,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:(c==null?void 0:c.default_visibility_bits)??A.default_visibility_bits,onChange:z=>Dl(Number(z.target.value)),disabled:we,children:In.map(z=>o.jsx("option",{value:z.value,children:z.label},z.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…"}),x&&o.jsx("div",{className:"collections-error",children:x}),!m&&c&&(c.entries.length===0?o.jsx("div",{className:"muted",children:"No entries in this collection."}):o.jsx("ul",{className:"coll-entries-list",children:c.entries.map(z=>o.jsxs("li",{className:"coll-entry-row",children:[o.jsxs("div",{className:"coll-entry-info",children:[o.jsx("span",{className:"coll-entry-title",children:z.title||z.entry_uid}),o.jsx("span",{className:"coll-entry-kind muted",children:z.source_kind})]}),o.jsxs("div",{className:"coll-entry-actions",children:[o.jsx("select",{className:"coll-entry-vis-select",value:z.collection_visibility_bits,onChange:V=>Fl(z.entry_uid,Number(V.target.value)),children:In.map(V=>o.jsx("option",{value:V.value,children:V.label},V.value))}),!we&&o.jsx("button",{className:"coll-entry-remove",onClick:()=>Ml(z.entry_uid),title:"Remove from collection",children:"×"})]})]},z.entry_uid))}))]}),!we&&o.jsxs("form",{className:"coll-add-entry-form",onSubmit:$l,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:T,onChange:z=>R(z.target.value),placeholder:"entry_uid",required:!0}),o.jsx("select",{className:"coll-vis-select",value:I,onChange:z=>U(Number(z.target.value)),children:In.map(z=>o.jsx("option",{value:z.value,children:z.label},z.value))}),o.jsx("button",{className:"coll-add-btn",type:"submit",disabled:E,children:E?"…":"Add"})]}),H&&o.jsx("div",{className:"collections-error",style:{marginTop:4},children:H})]})]}):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",children:[o.jsx("summary",{children:"+ Create collection"}),o.jsxs("form",{className:"coll-create-form",onSubmit:Fe,children:[o.jsxs("div",{className:"form-field",children:[o.jsx("label",{className:"form-label",htmlFor:"coll-name",children:"Name"}),o.jsx("input",{className:"capture-input",id:"coll-name",type:"text",value:j,onChange:z=>{O(z.target.value),f||d(z.target.value.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},placeholder:"My Collection",required:!0})]}),o.jsxs("div",{className:"form-field",children:[o.jsx("label",{className:"form-label",htmlFor:"coll-slug",children:"Slug"}),o.jsx("input",{className:"capture-input",id:"coll-slug",type:"text",value:f,onChange:z=>d(z.target.value),placeholder:"my-collection",required:!0})]}),o.jsxs("div",{className:"form-field",children:[o.jsx("label",{className:"form-label",htmlFor:"coll-vis",children:"Default visibility"}),o.jsx("select",{className:"capture-input",id:"coll-vis",style:{height:42},value:p,onChange:z=>w(Number(z.target.value)),children:In.map(z=>o.jsx("option",{value:z.value,children:z.label},z.value))})]}),P&&o.jsx("div",{className:"collections-error",children:P}),o.jsx("button",{className:"btn-primary",type:"submit",disabled:k,children:k?"Creating…":"Create collection"})]})]})]}):o.jsx("div",{className:"view-placeholder",children:"Select an archive."})}const ph=4;function hh({tab:e,onTabChange:t,archiveId:n}){const{currentUser:r,setCurrentUser:l}=v.useContext(Rl)??{},s=r&&(r.role_bits&ph)!==0,i=["profile","tokens",...s?["instance","storage"]:[]],a={profile:"Profile",tokens:"API Tokens",instance:"Instance",storage:"Storage"};return o.jsxs("section",{className:"admin-view",children:[o.jsx("h1",{children:"Settings"}),o.jsx("div",{className:"view-tabs",children:i.map(u=>o.jsx("button",{className:`view-tab${e===u?" is-active":""}`,onClick:()=>t(u),children:a[u]},u))}),e==="profile"&&o.jsx(mh,{currentUser:r,setCurrentUser:l}),e==="tokens"&&o.jsx(vh,{}),e==="instance"&&s&&o.jsx(gh,{}),e==="storage"&&s&&o.jsx(yh,{archiveId:n})]})}function mh({currentUser:e,setCurrentUser:t}){const[n,r]=v.useState((e==null?void 0:e.display_name)??""),[l,s]=v.useState(!1),[i,a]=v.useState(null),[u,c]=v.useState(""),[g,m]=v.useState(""),[h,x]=v.useState(""),[S,j]=v.useState(!1),[O,f]=v.useState(null);async function d(w){w.preventDefault(),s(!0),a(null);try{await _p(n),t(k=>({...k,display_name:n||null})),a({ok:!0,text:"Saved."})}catch(k){a({ok:!1,text:k.message})}finally{s(!1)}}async function p(w){if(w.preventDefault(),g!==h){f({ok:!1,text:"Passwords do not match."});return}j(!0),f(null);try{await Tp(u,g),c(""),m(""),x(""),f({ok:!0,text:"Password changed."})}catch(k){f({ok:!1,text:k.message})}finally{j(!1)}}return o.jsxs("div",{style:{maxWidth:440},children:[o.jsxs("div",{className:"form-section",children:[o.jsx("h2",{children:"Display Name"}),o.jsxs("form",{onSubmit:d,children:[o.jsxs("div",{className:"form-field",children:[o.jsx("label",{className:"form-label",htmlFor:"display-name",children:"Name shown in the UI"}),o.jsx("input",{className:"field-input",id:"display-name",placeholder:(e==null?void 0:e.username)??"",value:n,onChange:w=>r(w.target.value)})]}),i&&o.jsx("div",{className:`form-msg form-msg--${i.ok?"ok":"err"}`,children:i.text}),o.jsx("button",{className:"btn-primary",type:"submit",disabled:l,children:l?"Saving…":"Save"})]})]}),o.jsxs("div",{className:"form-section",children:[o.jsx("h2",{children:"Display Preferences"}),o.jsxs("label",{className:"checkbox-row",children:[o.jsx("input",{type:"checkbox",checked:(e==null?void 0:e.humanize_slugs)??!1,onChange:async w=>{const k=w.target.checked;try{await Ep({humanize_slugs:k}),t(_=>({..._,humanize_slugs:k}))}catch{}}}),o.jsx("span",{className:"form-label",style:{margin:0},children:"Humanize tag display"})]}),o.jsx("p",{className:"muted",style:{fontSize:13,margin:"4px 0 0"},children:'When on, tag paths show as "X / Articles" instead of "x/articles".'})]}),o.jsxs("div",{className:"form-section",children:[o.jsx("h2",{children:"Change Password"}),o.jsxs("form",{onSubmit:p,children:[o.jsxs("div",{className:"form-field",children:[o.jsx("label",{className:"form-label",htmlFor:"cur-pw",children:"Current password"}),o.jsx("input",{className:"field-input",id:"cur-pw",type:"password",value:u,onChange:w=>c(w.target.value),required:!0})]}),o.jsxs("div",{className:"form-field",children:[o.jsx("label",{className:"form-label",htmlFor:"new-pw",children:"New password"}),o.jsx("input",{className:"field-input",id:"new-pw",type:"password",value:g,onChange:w=>m(w.target.value),required:!0})]}),o.jsxs("div",{className:"form-field",children:[o.jsx("label",{className:"form-label",htmlFor:"confirm-pw",children:"Confirm new password"}),o.jsx("input",{className:"field-input",id:"confirm-pw",type:"password",value:h,onChange:w=>x(w.target.value),required:!0})]}),O&&o.jsx("div",{className:`form-msg form-msg--${O.ok?"ok":"err"}`,children:O.text}),o.jsx("button",{className:"btn-primary",type:"submit",disabled:S,children:S?"Changing…":"Change Password"})]})]})]})}function vh(){const[e,t]=v.useState([]),[n,r]=v.useState(!0),[l,s]=v.useState(null),[i,a]=v.useState(""),[u,c]=v.useState(!1),[g,m]=v.useState(null),h=v.useCallback(async()=>{r(!0),s(null);try{t(await Pp())}catch(j){s(j.message)}finally{r(!1)}},[]);v.useEffect(()=>{h()},[h]);async function x(j){if(j.preventDefault(),!!i.trim()){c(!0);try{const O=await Lp(i.trim());m(O),a(""),h()}catch(O){s(O.message)}finally{c(!1)}}}async function S(j){try{await zp(j),t(O=>O.filter(f=>f.token_uid!==j))}catch(O){s(O.message)}}return o.jsx("div",{style:{maxWidth:600},children:o.jsxs("div",{className:"form-section",children:[o.jsx("h2",{children:"API Tokens"}),g&&o.jsxs("div",{className:"token-banner",children:[o.jsx("strong",{children:"Token created."})," Copy it now — it won't be shown again.",o.jsx("code",{children:g.raw_token}),o.jsx("button",{className:"token-dismiss",onClick:()=>m(null),children:"Dismiss"})]}),o.jsxs("form",{className:"token-create-row",onSubmit:x,children:[o.jsx("input",{className:"field-input field-input--flex",placeholder:"Token name",value:i,onChange:j=>a(j.target.value),required:!0}),o.jsx("button",{className:"btn-primary",type:"submit",disabled:u,children:u?"Creating…":"Create token"})]}),l&&o.jsx("div",{className:"form-msg form-msg--err",children:l}),n?o.jsx("div",{className:"muted",children:"Loading…"}):o.jsxs("div",{children:[e.length===0&&o.jsx("div",{className:"muted",children:"No tokens yet."}),e.map(j=>o.jsxs("div",{className:"token-row",children:[o.jsxs("div",{className:"token-row-info",children:[o.jsx("strong",{children:j.name}),o.jsxs("div",{className:"muted",children:["Created ",j.created_at.slice(0,10),j.last_used_at&&` · Last used ${j.last_used_at.slice(0,10)}`]})]}),o.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"4px 10px"},onClick:()=>S(j.token_uid),children:"Revoke"})]},j.token_uid))]})]})})}function gh(){const[e,t]=v.useState(null),[n,r]=v.useState(!0),[l,s]=v.useState(null),[i,a]=v.useState(!1),[u,c]=v.useState(null);v.useEffect(()=>{(async()=>{try{t(await Rp())}catch(m){s(m.message)}finally{r(!1)}})()},[]);async function g(m){m.preventDefault(),a(!0),c(null);try{await Dp(e),c({ok:!0,text:"Saved."})}catch(h){c({ok:!1,text:h.message})}finally{a(!1)}}return n?o.jsx("div",{className:"muted",children:"Loading…"}):l?o.jsx("div",{className:"form-msg form-msg--err",children:l}):e?o.jsx("div",{style:{maxWidth:440},children:o.jsxs("div",{className:"form-section",children:[o.jsx("h2",{children:"Instance Settings"}),o.jsxs("form",{onSubmit:g,children:[[["public_index_enabled","Public index (unauthenticated browsing)"],["public_entry_content_enabled","Public entry content"],["open_registration_enabled","Open registration"]].map(([m,h])=>o.jsxs("label",{className:"checkbox-row",children:[o.jsx("input",{type:"checkbox",checked:!!e[m],onChange:x=>t(S=>({...S,[m]:x.target.checked}))}),h]},m)),o.jsxs("div",{className:"form-field",style:{marginTop:4},children:[o.jsx("label",{className:"form-label",children:"Default entry visibility"}),o.jsxs("select",{className:"field-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"}),o.jsx("option",{value:2,children:"Unlisted"}),o.jsx("option",{value:3,children:"Public"})]})]}),u&&o.jsx("div",{className:`form-msg form-msg--${u.ok?"ok":"err"}`,children:u.text}),o.jsx("button",{className:"btn-primary",type:"submit",disabled:i,children:i?"Saving…":"Save Settings"})]})]})}):null}function fs(e){if(e===0)return"0 B";const t=["B","KB","MB","GB","TB"],n=Math.floor(Math.log(e)/Math.log(1024));return`${(e/Math.pow(1024,n)).toFixed(n===0?0:1)} ${t[n]}`}function yh({archiveId:e}){const[t,n]=v.useState("idle"),[r,l]=v.useState(null),[s,i]=v.useState(null),[a,u]=v.useState(null);function c(){n("idle"),l(null),i(null),u(null)}async function g(){n("scanning"),u(null),l(null);try{const x=await Yp(e);l(x),n("scanned")}catch(x){u(x.message),n("error")}}async function m(){n("deleting"),u(null);try{const x=await Jp(e);i(x),n("done")}catch(x){u(x.message),n("error")}}const h=r&&r.deletable_files===0&&r.orphaned_blob_rows===0;return o.jsx("div",{style:{maxWidth:440},children:o.jsxs("div",{className:"form-section",children:[o.jsx("h2",{children:"Orphan Cleanup"}),o.jsxs("p",{className:"muted",style:{marginBottom:16},children:["Scan for blob files and database records that are no longer referenced by any archive entry and safely delete them."," ",o.jsx("strong",{children:"Cleanup is blocked while captures are running."})]}),!e&&o.jsx("div",{className:"muted",children:"No archive selected."}),e&&t==="idle"&&o.jsx("button",{className:"btn-ghost",onClick:g,children:"Scan for orphaned blobs"}),t==="scanning"&&o.jsx("div",{className:"muted",children:"Scanning…"}),t==="scanned"&&r&&h&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"form-msg form-msg--ok",children:"Archive is clean — nothing to remove."}),o.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:c,children:"Done"})]}),t==="scanned"&&r&&!h&&o.jsxs("div",{children:[o.jsxs("div",{style:{marginBottom:14,lineHeight:1.6},children:["Found ",o.jsx("strong",{children:r.deletable_files})," unreferenced file",r.deletable_files!==1?"s":""," ","and ",o.jsx("strong",{children:r.orphaned_blob_rows})," orphaned DB record",r.orphaned_blob_rows!==1?"s":""," ","— ",o.jsx("strong",{children:fs(r.total_bytes)})," recoverable."]}),o.jsxs("div",{style:{display:"flex",gap:8},children:[o.jsxs("button",{className:"btn-danger",onClick:m,children:["Delete (",fs(r.total_bytes),")"]}),o.jsx("button",{className:"btn-ghost",onClick:c,children:"Cancel"})]})]}),t==="deleting"&&o.jsx("div",{className:"muted",children:"Deleting…"}),t==="done"&&s&&o.jsxs("div",{children:[o.jsxs("div",{className:"form-msg form-msg--ok",children:["Freed ",o.jsx("strong",{children:fs(s.freed_bytes)})," ","— removed ",s.deleted_files," file",s.deleted_files!==1?"s":""," ","and ",s.deleted_blob_rows," DB record",s.deleted_blob_rows!==1?"s":"","."]}),s.errors&&s.errors.length>0&&o.jsxs("div",{className:"form-msg form-msg--err",style:{marginTop:6},children:[s.errors.length," file",s.errors.length!==1?"s":""," could not be deleted."]}),o.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:c,children:"Scan again"})]}),t==="error"&&o.jsxs("div",{children:[o.jsx("div",{className:"form-msg form-msg--err",children:a}),o.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:c,children:"Try again"})]})]})})}const va={0:"Private",1:"Public",2:"Users only",3:"Public"},wh=()=>o.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:o.jsx("path",{d:"M7 17 17 7M9 7h8v8"})});function xh({archiveId:e,selectedEntry:t,onTagFilterSet:n,tagNodes:r,onTagsRefresh:l,onEntryTitleChange:s,onEntryDeleted:i,humanizeTags:a}){const[u,c]=v.useState(null),[g,m]=v.useState([]),[h,x]=v.useState(""),[S,j]=v.useState([]),[O,f]=v.useState(""),d=v.useRef(0),p=v.useRef(!1),[w,k]=v.useState(!1),[_,P]=v.useState("");v.useEffect(()=>{if(!t||!e){c(null),m([]),j([]);return}k(!1),P(""),p.current=!1;const E=++d.current;c(null),m([]),Promise.all([dp(e,t.entry_uid),cs(e,t.entry_uid),Qp(e,t.entry_uid)]).then(([F,H,Z])=>{E===d.current&&(c(F),m(H),j(Z))}).catch(()=>{})},[t,e]);async function y(){const E=_.trim()||null;try{await fp(e,t.entry_uid,E),c(F=>F&&{...F,summary:{...F.summary,title:E}}),s==null||s(t.entry_uid,E)}catch{}finally{k(!1)}}async function T(){const E=h.trim();if(!(!E||!t))try{await pp(e,t.entry_uid,E),x(""),f("");const F=await cs(e,t.entry_uid);m(F),l()}catch(F){f(F.message)}}async function R(E){try{await hp(e,t.entry_uid,E);const F=await cs(e,t.entry_uid);m(F),l()}catch{}}async function I(){if(!(!t||!e)&&window.confirm("Delete this entry? This cannot be undone."))try{await mp(e,t.entry_uid),i==null||i(t.entry_uid)}catch{}}const U=u?[["Added",zc(u.summary.archived_at)],["Source",u.summary.source_kind],["Type",u.summary.entity_kind],["Visibility",va[u.summary.visibility]??u.summary.visibility],["Root",u.structured_root_relpath]]:[];return o.jsxs("aside",{className:"context-rail",children:[o.jsx("div",{className:"rail-eyebrow",children:"Context"}),t?u?o.jsxs(o.Fragment,{children:[w?o.jsx("input",{className:"rail-title-input",autoFocus:!0,value:_,onChange:E=>P(E.target.value),onKeyDown:E=>{E.key==="Enter"&&E.currentTarget.blur(),E.key==="Escape"&&(p.current=!0,E.currentTarget.blur())},onBlur:()=>{p.current?k(!1):y(),p.current=!1}}):o.jsxs("h2",{className:"rail-title rail-title--editable",title:"Click to rename",onClick:()=>{P(u.summary.title??""),k(!0)},children:[Ut(u.summary.title)||Ut(u.summary.entry_uid),o.jsx("svg",{className:"edit-icon",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),u.summary.original_url&&o.jsxs("a",{className:"url-tile",href:u.summary.original_url,target:"_blank",rel:"noopener noreferrer",children:[o.jsx("span",{className:"ico",dangerouslySetInnerHTML:{__html:Rc(u.summary.source_kind)}}),o.jsx("span",{className:"u-text",children:u.summary.original_url}),o.jsx("span",{className:"ext",children:o.jsx(wh,{})})]}),o.jsx("div",{className:"meta-list",children:U.filter(([,E])=>E!=null&&E!=="").map(([E,F])=>o.jsxs("div",{className:"meta-item",children:[o.jsx("span",{className:"meta-k",children:E}),o.jsx("span",{className:`meta-v${E==="Root"?" mono":""}`,children:Ut(F)})]},E))}),u.artifacts.length>0&&o.jsxs("div",{className:"rail-section",children:[o.jsxs("div",{className:"rail-section-heading",children:["Artifacts ",o.jsx("span",{className:"num",children:u.artifacts.length})]}),o.jsx("ul",{className:"artifact-list",children:u.artifacts.map((E,F)=>o.jsx("li",{children:o.jsxs("a",{href:`/api/archives/${e}/entries/${u.summary.entry_uid}/artifacts/${F}`,target:"_blank",rel:"noopener noreferrer",className:"artifact-link",children:[o.jsx("span",{className:"artifact-name",children:E.artifact_role.replace(/_/g," ")}),o.jsx("span",{className:"artifact-size",children:E.byte_size!=null?oi(E.byte_size):"—"})]})},F))})]})]}):o.jsx("p",{className:"tags-empty",children:"Loading…"}):o.jsx("p",{className:"tags-empty",children:"Select an entry."}),t&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"rail-section",children:[o.jsx("div",{className:"rail-section-heading",children:"Tags"}),g.length===0?o.jsx("p",{className:"tags-empty",children:"No tags yet."}):o.jsx("div",{className:"tags-wrap",children:g.map(E=>o.jsxs("span",{className:"tag-pill",title:E.full_path,children:[a?Dc(E.full_path):E.full_path,o.jsx("button",{className:"remove",title:`Remove tag ${E.full_path}`,onClick:()=>R(E.tag_uid),children:"×"})]},E.tag_uid))}),O&&o.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:O}),o.jsxs("div",{className:"tag-input-wrap",children:[o.jsx("span",{className:"hash",children:"/"}),o.jsx("input",{className:"tag-input",type:"text",placeholder:"science/cs",autoComplete:"off",value:h,onChange:E=>x(E.target.value),onKeyDown:E=>{E.key==="Enter"&&T()}}),o.jsx("button",{className:"tag-add-btn",onClick:T,children:"Add"})]})]}),S.length>0&&o.jsxs("div",{className:"rail-section",children:[o.jsx("div",{className:"rail-section-heading",children:"Collections"}),S.map(E=>o.jsxs("div",{className:"coll-row",children:[o.jsx("span",{className:"coll-name",children:E.collection_uid}),o.jsx("span",{className:"vis-badge",children:va[E.visibility_bits]??`bits:${E.visibility_bits}`})]},E.collection_uid))]}),o.jsx("div",{className:"rail-delete-zone",children:o.jsx("button",{className:"rail-delete-btn",onClick:I,children:"Delete entry"})})]})]})}const Sh=7e3;function kh({toasts:e,onDismiss:t}){return e.length?o.jsx("div",{className:"toast-stack",role:"log","aria-live":"polite","aria-label":"Notifications",children:e.map(n=>o.jsx(jh,{toast:n,onDismiss:t},n.id))}):null}function jh({toast:e,onDismiss:t}){const[n,r]=v.useState(!1);v.useEffect(()=>{if(n)return;const s=setTimeout(()=>t(e.id),Sh);return()=>clearTimeout(s)},[n,e.id,t]);const l=e.locator?e.locator.length>48?e.locator.slice(0,45)+"…":e.locator:null;return o.jsxs("div",{className:"toast toast--error",role:"alert","aria-atomic":"true",children:[o.jsxs("div",{className:"toast-top",children:[o.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"✕"}),o.jsxs("div",{className:"toast-body",children:[o.jsx("span",{className:"toast-headline",children:"Capture failed"}),l&&o.jsx("span",{className:"toast-locator",children:l})]}),o.jsxs("div",{className:"toast-btns",children:[e.errorText&&o.jsx("button",{type:"button",className:"toast-view-btn",onClick:()=>r(s=>!s),children:n?"Hide":"View error"}),o.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})]})]}),n&&e.errorText&&o.jsx("pre",{className:"toast-error-detail",children:e.errorText})]})}const Rl=v.createContext(null),Nh=["archive","tags","collections","runs","admin","settings"],Ch=["profile","tokens","instance","storage"];function ps(){const e=window.location.pathname.split("/").filter(Boolean),t=Nh.includes(e[0])?e[0]:"archive",n=t==="settings"&&Ch.includes(e[1])?e[1]:"profile";return{view:t,settingsTab:n}}function _h(e,t){return e==="archive"?"/":e==="settings"?`/settings/${t}`:`/${e}`}function Eh(){const[e,t]=v.useState("loading"),[n,r]=v.useState(null);v.useEffect(()=>{(async()=>{if(await Sp()){t("setup");return}const K=await Cp();if(!K){t("login");return}r(K),t("authenticated")})()},[]),v.useEffect(()=>{const $=()=>{r(null),t("login")};return window.addEventListener("auth:expired",$),()=>window.removeEventListener("auth:expired",$)},[]),v.useEffect(()=>{const $=()=>{const{view:K,settingsTab:ce}=ps();f(K),p(ce)};return window.addEventListener("popstate",$),()=>window.removeEventListener("popstate",$)},[]);const[l,s]=v.useState([]),[i,a]=v.useState(null),[u,c]=v.useState([]),[g,m]=v.useState(null),[h,x]=v.useState(null),[S,j]=v.useState(null),[O,f]=v.useState(()=>ps().view),[d,p]=v.useState(()=>ps().settingsTab),[w,k]=v.useState(""),[_,P]=v.useState(""),[y,T]=v.useState(!1),[R,I]=v.useState([]),[U,E]=v.useState([]),[F,H]=v.useState(()=>sessionStorage.getItem("captureDialogOpen")==="true"),[Z,Me]=v.useState([]),L=v.useRef(0),N=(n==null?void 0:n.humanize_slugs)??!1;v.useEffect(()=>{sessionStorage.setItem("captureDialogOpen",F)},[F]);const M=v.useCallback(async($,K,ce)=>{if($){T(!0);try{let Ae;K||ce?Ae=await cp($,K,ce):Ae=await up($),c(Ae),P(Ae.length===0?"No results":`${Ae.length} result${Ae.length===1?"":"s"}`)}catch{c([]),P("Search failed. Try again.")}finally{T(!1)}}},[]);v.useEffect(()=>{e==="authenticated"&&ap().then($=>{if(s($),$.length>0){const K=$[0].id;a(K)}})},[e]),v.useEffect(()=>{i&&(j(null),x(null),m(null),Promise.all([M(i,"",null),fa(i).then(I),ds(i).then(E)]))},[i]),v.useEffect(()=>{if(i===null)return;const $=setTimeout(()=>{M(i,w,S)},300);return()=>clearTimeout($)},[w,i]),v.useEffect(()=>{i!==null&&(S!==null&&f("archive"),M(i,w,S))},[S,i]);const Q=v.useCallback($=>{a($)},[]),A=v.useCallback($=>{f($),$==="tags"&&i&&ds(i).then(E)},[i]);v.useEffect(()=>{const $=_h(O,d);window.location.pathname!==$&&history.pushState(null,"",$)},[O,d]);const we=v.useCallback($=>{m($?$.entry_uid:null),x($)},[]),ue=v.useCallback($=>{j($)},[]),Qe=v.useCallback(()=>{j(null)},[]),Fe=v.useCallback(()=>{i&&ds(i).then(E)},[i]),lt=v.useCallback(($,K)=>{S===$?j(K):S!=null&&S.startsWith($+"/")&&j(K+S.slice($.length))},[S]),Dl=v.useCallback($=>{(S===$||S!=null&&S.startsWith($+"/"))&&j(null)},[S]),Ol=v.useCallback(($,K)=>{c(ce=>ce.map(Ae=>Ae.entry_uid===$?{...Ae,title:K}:Ae)),x(ce=>ce&&ce.entry_uid===$?{...ce,title:K}:ce)},[]),$l=v.useCallback($=>{c(K=>K.filter(ce=>ce.entry_uid!==$)),x(K=>(K==null?void 0:K.entry_uid)===$?null:K),m(K=>K===$?null:K)},[]),Ml=v.useCallback(()=>{H(!0)},[]),Fl=v.useCallback(()=>{H(!1)},[]),z=v.useCallback(()=>{i&&Promise.all([M(i,w,S),fa(i).then(I)])},[i,w,S,M]),V=v.useCallback(($,K)=>{const ce=++L.current;Me(Ae=>[...Ae,{id:ce,errorText:$,locator:K}])},[]),Pe=v.useCallback($=>{Me(K=>K.filter(ce=>ce.id!==$))},[]);return e==="loading"?o.jsx("div",{className:"auth-loading",children:"Loading\\u2026"}):e==="setup"?o.jsx(Zp,{onComplete:()=>t("login")}):e==="login"?o.jsx(Gp,{onLogin:$=>{r($),t("authenticated")}}):o.jsx(Rl.Provider,{value:{currentUser:n,setCurrentUser:r},children:o.jsxs(o.Fragment,{children:[o.jsx(qp,{archives:l,archiveId:i,onArchiveChange:Q,view:O,onViewChange:A,onCaptureClick:Ml}),o.jsxs("main",{className:"app-shell",children:[o.jsxs("div",{className:"workspace",children:[O==="archive"&&o.jsxs("div",{className:"toolbar",children:[o.jsxs("div",{className:"search-field",children:[o.jsx("span",{className:"ico","aria-hidden":"true",children:o.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[o.jsx("circle",{cx:"11",cy:"11",r:"7"}),o.jsx("line",{x1:"16.5",y1:"16.5",x2:"21",y2:"21"})]})}),o.jsx("input",{className:"search-input",type:"search","aria-label":"Search archive","aria-busy":y,placeholder:"Search titles, URLs, types, tags…",value:w,onChange:$=>k($.target.value)}),o.jsx("span",{className:"kbd",children:"⌘K"})]}),o.jsxs("span",{className:"result-count",children:[_&&o.jsxs(o.Fragment,{children:[o.jsx("b",{children:_.split(" ")[0]})," ",_.split(" ").slice(1).join(" ")]}),S&&o.jsxs("button",{className:"tag-filter-badge",onClick:Qe,children:["× ",N?Dc(S):S]})]})]}),O==="archive"&&o.jsx(lh,{entries:u,selectedEntryUid:g,onSelectEntry:we,archiveId:i,tagFilter:S,onClearTagFilter:Qe,searchQuery:w,onSearchChange:k,resultCount:_,searchBusy:y}),O==="runs"&&o.jsx(oh,{runs:R}),O==="admin"&&o.jsx(uh,{archives:l}),O==="tags"&&o.jsx(ch,{archiveId:i,tagNodes:U,tagFilter:S,onTagFilterSet:ue,onViewChange:A,onTagRenamed:lt,onTagDeleted:Dl,onTagsRefresh:Fe,humanizeTags:N}),O==="collections"&&o.jsx(fh,{archiveId:i}),O==="settings"&&o.jsx(hh,{tab:d,onTabChange:p,archiveId:i})]}),o.jsx(xh,{archiveId:i,selectedEntry:h,onTagFilterSet:ue,tagNodes:U,onTagsRefresh:Fe,onEntryTitleChange:Ol,onEntryDeleted:$l,humanizeTags:N})]}),o.jsx(bp,{open:F,archiveId:i,onClose:Fl,onCaptured:z,onToast:V}),o.jsx(kh,{toasts:Z,onDismiss:Pe})]})})}Pc(document.getElementById("root")).render(o.jsx(v.StrictMode,{children:o.jsx(Eh,{})})); +`+s.stack}return{value:e,source:t,stack:l,digest:null}}function is(e,t,n){return{value:e,source:null,stack:n??null,digest:t??null}}function Ks(e,t){try{console.error(t.value)}catch(n){setTimeout(function(){throw n})}}var Mf=typeof WeakMap=="function"?WeakMap:Map;function tc(e,t,n){n=ut(-1,n),n.tag=3,n.payload={element:null};var r=t.value;return n.callback=function(){fl||(fl=!0,ni=r),Ks(e,t)},n}function nc(e,t,n){n=ut(-1,n),n.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var l=t.value;n.payload=function(){return r(l)},n.callback=function(){Ks(e,t)}}var s=e.stateNode;return s!==null&&typeof s.componentDidCatch=="function"&&(n.callback=function(){Ks(e,t),typeof r!="function"&&(Et===null?Et=new Set([this]):Et.add(this));var i=t.stack;this.componentDidCatch(t.value,{componentStack:i!==null?i:""})}),n}function Yo(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new Mf;var l=new Set;r.set(t,l)}else l=r.get(t),l===void 0&&(l=new Set,r.set(t,l));l.has(n)||(l.add(n),e=Gf.bind(null,e,t,n),t.then(e,e))}function Jo(e){do{var t;if((t=e.tag===13)&&(t=e.memoizedState,t=t!==null?t.dehydrated!==null:!0),t)return e;e=e.return}while(e!==null);return null}function Xo(e,t,n,r,l){return e.mode&1?(e.flags|=65536,e.lanes=l,e):(e===t?e.flags|=65536:(e.flags|=128,n.flags|=131072,n.flags&=-52805,n.tag===1&&(n.alternate===null?n.tag=17:(t=ut(-1,1),t.tag=2,_t(n,t,1))),n.lanes|=1),e)}var Ff=ht.ReactCurrentOwner,Ce=!1;function xe(e,t,n,r){t.child=e===null?zu(t,null,n,r):wn(t,e.child,n,r)}function Go(e,t,n,r,l){n=n.render;var s=t.ref;return hn(t,l),r=Ui(e,t,n,r,s,l),n=Bi(),e!==null&&!Ce?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~l,pt(e,t,l)):(q&&n&&Ti(t),t.flags|=1,xe(e,t,r,l),t.child)}function Zo(e,t,n,r,l){if(e===null){var s=n.type;return typeof s=="function"&&!Zi(s)&&s.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(t.tag=15,t.type=s,rc(e,t,s,r,l)):(e=Qr(n.type,null,r,t,t.mode,l),e.ref=t.ref,e.return=t,t.child=e)}if(s=e.child,!(e.lanes&l)){var i=s.memoizedProps;if(n=n.compare,n=n!==null?n:nr,n(i,r)&&e.ref===t.ref)return pt(e,t,l)}return t.flags|=1,e=Pt(s,r),e.ref=t.ref,e.return=t,t.child=e}function rc(e,t,n,r,l){if(e!==null){var s=e.memoizedProps;if(nr(s,r)&&e.ref===t.ref)if(Ce=!1,t.pendingProps=r=s,(e.lanes&l)!==0)e.flags&131072&&(Ce=!0);else return t.lanes=e.lanes,pt(e,t,l)}return Ys(e,t,n,r,l)}function lc(e,t,n){var r=t.pendingProps,l=r.children,s=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(t.mode&1))t.memoizedState={baseLanes:0,cachePool:null,transitions:null},J(un,Le),Le|=n;else{if(!(n&1073741824))return e=s!==null?s.baseLanes|n:n,t.lanes=t.childLanes=1073741824,t.memoizedState={baseLanes:e,cachePool:null,transitions:null},t.updateQueue=null,J(un,Le),Le|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=s!==null?s.baseLanes:n,J(un,Le),Le|=r}else s!==null?(r=s.baseLanes|n,t.memoizedState=null):r=n,J(un,Le),Le|=r;return xe(e,t,l,n),t.child}function sc(e,t){var n=t.ref;(e===null&&n!==null||e!==null&&e.ref!==n)&&(t.flags|=512,t.flags|=2097152)}function Ys(e,t,n,r,l){var s=Ee(n)?Wt:ye.current;return s=gn(t,s),hn(t,l),n=Ui(e,t,n,r,s,l),r=Bi(),e!==null&&!Ce?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~l,pt(e,t,l)):(q&&r&&Ti(t),t.flags|=1,xe(e,t,n,l),t.child)}function qo(e,t,n,r,l){if(Ee(n)){var s=!0;nl(t)}else s=!1;if(hn(t,l),t.stateNode===null)Vr(e,t),ec(t,n,r),Qs(t,n,r,l),r=!0;else if(e===null){var i=t.stateNode,a=t.memoizedProps;i.props=a;var u=i.context,c=n.contextType;typeof c=="object"&&c!==null?c=We(c):(c=Ee(n)?Wt:ye.current,c=gn(t,c));var g=n.getDerivedStateFromProps,m=typeof g=="function"||typeof i.getSnapshotBeforeUpdate=="function";m||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==r||u!==c)&&Ko(t,i,r,c),gt=!1;var h=t.memoizedState;i.state=h,ol(t,r,i,l),u=t.memoizedState,a!==r||h!==u||_e.current||gt?(typeof g=="function"&&(Hs(t,n,g,r),u=t.memoizedState),(a=gt||Qo(t,n,a,r,h,u,c))?(m||typeof i.UNSAFE_componentWillMount!="function"&&typeof i.componentWillMount!="function"||(typeof i.componentWillMount=="function"&&i.componentWillMount(),typeof i.UNSAFE_componentWillMount=="function"&&i.UNSAFE_componentWillMount()),typeof i.componentDidMount=="function"&&(t.flags|=4194308)):(typeof i.componentDidMount=="function"&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=u),i.props=r,i.state=u,i.context=c,r=a):(typeof i.componentDidMount=="function"&&(t.flags|=4194308),r=!1)}else{i=t.stateNode,Du(e,t),a=t.memoizedProps,c=t.type===t.elementType?a:Ye(t.type,a),i.props=c,m=t.pendingProps,h=i.context,u=n.contextType,typeof u=="object"&&u!==null?u=We(u):(u=Ee(n)?Wt:ye.current,u=gn(t,u));var x=n.getDerivedStateFromProps;(g=typeof x=="function"||typeof i.getSnapshotBeforeUpdate=="function")||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==m||h!==u)&&Ko(t,i,r,u),gt=!1,h=t.memoizedState,i.state=h,ol(t,r,i,l);var S=t.memoizedState;a!==m||h!==S||_e.current||gt?(typeof x=="function"&&(Hs(t,n,x,r),S=t.memoizedState),(c=gt||Qo(t,n,c,r,h,S,u)||!1)?(g||typeof i.UNSAFE_componentWillUpdate!="function"&&typeof i.componentWillUpdate!="function"||(typeof i.componentWillUpdate=="function"&&i.componentWillUpdate(r,S,u),typeof i.UNSAFE_componentWillUpdate=="function"&&i.UNSAFE_componentWillUpdate(r,S,u)),typeof i.componentDidUpdate=="function"&&(t.flags|=4),typeof i.getSnapshotBeforeUpdate=="function"&&(t.flags|=1024)):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&h===e.memoizedState||(t.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&h===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=S),i.props=r,i.state=S,i.context=u,r=c):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&h===e.memoizedState||(t.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&h===e.memoizedState||(t.flags|=1024),r=!1)}return Js(e,t,n,r,s,l)}function Js(e,t,n,r,l,s){sc(e,t);var i=(t.flags&128)!==0;if(!r&&!i)return l&&Fo(t,n,!1),pt(e,t,s);r=t.stateNode,Ff.current=t;var a=i&&typeof n.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&i?(t.child=wn(t,e.child,null,s),t.child=wn(t,null,a,s)):xe(e,t,a,s),t.memoizedState=r.state,l&&Fo(t,n,!0),t.child}function ic(e){var t=e.stateNode;t.pendingContext?Mo(e,t.pendingContext,t.pendingContext!==t.context):t.context&&Mo(e,t.context,!1),Mi(e,t.containerInfo)}function bo(e,t,n,r,l){return yn(),Li(l),t.flags|=256,xe(e,t,n,r),t.child}var Xs={dehydrated:null,treeContext:null,retryLane:0};function Gs(e){return{baseLanes:e,cachePool:null,transitions:null}}function oc(e,t,n){var r=t.pendingProps,l=b.current,s=!1,i=(t.flags&128)!==0,a;if((a=i)||(a=e!==null&&e.memoizedState===null?!1:(l&2)!==0),a?(s=!0,t.flags&=-129):(e===null||e.memoizedState!==null)&&(l|=1),J(b,l&1),e===null)return Vs(t),e=t.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(t.mode&1?e.data==="$!"?t.lanes=8:t.lanes=1073741824:t.lanes=1,null):(i=r.children,e=r.fallback,s?(r=t.mode,s=t.child,i={mode:"hidden",children:i},!(r&1)&&s!==null?(s.childLanes=0,s.pendingProps=i):s=El(i,r,0,null),e=Vt(e,r,n,null),s.return=t,e.return=t,s.sibling=e,t.child=s,t.child.memoizedState=Gs(n),t.memoizedState=Xs,e):Hi(t,i));if(l=e.memoizedState,l!==null&&(a=l.dehydrated,a!==null))return Af(e,t,i,r,a,l,n);if(s){s=r.fallback,i=t.mode,l=e.child,a=l.sibling;var u={mode:"hidden",children:r.children};return!(i&1)&&t.child!==l?(r=t.child,r.childLanes=0,r.pendingProps=u,t.deletions=null):(r=Pt(l,u),r.subtreeFlags=l.subtreeFlags&14680064),a!==null?s=Pt(a,s):(s=Vt(s,i,n,null),s.flags|=2),s.return=t,r.return=t,r.sibling=s,t.child=r,r=s,s=t.child,i=e.child.memoizedState,i=i===null?Gs(n):{baseLanes:i.baseLanes|n,cachePool:null,transitions:i.transitions},s.memoizedState=i,s.childLanes=e.childLanes&~n,t.memoizedState=Xs,r}return s=e.child,e=s.sibling,r=Pt(s,{mode:"visible",children:r.children}),!(t.mode&1)&&(r.lanes=n),r.return=t,r.sibling=null,e!==null&&(n=t.deletions,n===null?(t.deletions=[e],t.flags|=16):n.push(e)),t.child=r,t.memoizedState=null,r}function Hi(e,t){return t=El({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function Lr(e,t,n,r){return r!==null&&Li(r),wn(t,e.child,null,n),e=Hi(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function Af(e,t,n,r,l,s,i){if(n)return t.flags&256?(t.flags&=-257,r=is(Error(C(422))),Lr(e,t,i,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(s=r.fallback,l=t.mode,r=El({mode:"visible",children:r.children},l,0,null),s=Vt(s,l,i,null),s.flags|=2,r.return=t,s.return=t,r.sibling=s,t.child=r,t.mode&1&&wn(t,e.child,null,i),t.child.memoizedState=Gs(i),t.memoizedState=Xs,s);if(!(t.mode&1))return Lr(e,t,i,null);if(l.data==="$!"){if(r=l.nextSibling&&l.nextSibling.dataset,r)var a=r.dgst;return r=a,s=Error(C(419)),r=is(s,r,void 0),Lr(e,t,i,r)}if(a=(i&e.childLanes)!==0,Ce||a){if(r=ae,r!==null){switch(i&-i){case 4:l=2;break;case 16:l=8;break;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:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:l=32;break;case 536870912:l=268435456;break;default:l=0}l=l&(r.suspendedLanes|i)?0:l,l!==0&&l!==s.retryLane&&(s.retryLane=l,ft(e,l),Ze(r,e,l,-1))}return Gi(),r=is(Error(C(421))),Lr(e,t,i,r)}return l.data==="$?"?(t.flags|=128,t.child=e.child,t=Zf.bind(null,e),l._reactRetry=t,null):(e=s.treeContext,ze=Ct(l.nextSibling),Re=t,q=!0,Xe=null,e!==null&&(Ie[Ue++]=ot,Ie[Ue++]=at,Ie[Ue++]=Ht,ot=e.id,at=e.overflow,Ht=t),t=Hi(t,r.children),t.flags|=4096,t)}function ea(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),Ws(e.return,t,n)}function os(e,t,n,r,l){var s=e.memoizedState;s===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:l}:(s.isBackwards=t,s.rendering=null,s.renderingStartTime=0,s.last=r,s.tail=n,s.tailMode=l)}function ac(e,t,n){var r=t.pendingProps,l=r.revealOrder,s=r.tail;if(xe(e,t,r.children,n),r=b.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&ea(e,n,t);else if(e.tag===19)ea(e,n,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break e;for(;e.sibling===null;){if(e.return===null||e.return===t)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(J(b,r),!(t.mode&1))t.memoizedState=null;else switch(l){case"forwards":for(n=t.child,l=null;n!==null;)e=n.alternate,e!==null&&al(e)===null&&(l=n),n=n.sibling;n=l,n===null?(l=t.child,t.child=null):(l=n.sibling,n.sibling=null),os(t,!1,l,n,s);break;case"backwards":for(n=null,l=t.child,t.child=null;l!==null;){if(e=l.alternate,e!==null&&al(e)===null){t.child=l;break}e=l.sibling,l.sibling=n,n=l,l=e}os(t,!0,n,null,s);break;case"together":os(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function Vr(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function pt(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),Kt|=t.lanes,!(n&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error(C(153));if(t.child!==null){for(e=t.child,n=Pt(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=Pt(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function If(e,t,n){switch(t.tag){case 3:ic(t),yn();break;case 5:Ou(t);break;case 1:Ee(t.type)&&nl(t);break;case 4:Mi(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,l=t.memoizedProps.value;J(sl,r._currentValue),r._currentValue=l;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(J(b,b.current&1),t.flags|=128,null):n&t.child.childLanes?oc(e,t,n):(J(b,b.current&1),e=pt(e,t,n),e!==null?e.sibling:null);J(b,b.current&1);break;case 19:if(r=(n&t.childLanes)!==0,e.flags&128){if(r)return ac(e,t,n);t.flags|=128}if(l=t.memoizedState,l!==null&&(l.rendering=null,l.tail=null,l.lastEffect=null),J(b,b.current),r)break;return null;case 22:case 23:return t.lanes=0,lc(e,t,n)}return pt(e,t,n)}var uc,Zs,cc,dc;uc=function(e,t){for(var n=t.child;n!==null;){if(n.tag===5||n.tag===6)e.appendChild(n.stateNode);else if(n.tag!==4&&n.child!==null){n.child.return=n,n=n.child;continue}if(n===t)break;for(;n.sibling===null;){if(n.return===null||n.return===t)return;n=n.return}n.sibling.return=n.return,n=n.sibling}};Zs=function(){};cc=function(e,t,n,r){var l=e.memoizedProps;if(l!==r){e=t.stateNode,It(rt.current);var s=null;switch(n){case"input":l=ws(e,l),r=ws(e,r),s=[];break;case"select":l=te({},l,{value:void 0}),r=te({},r,{value:void 0}),s=[];break;case"textarea":l=ks(e,l),r=ks(e,r),s=[];break;default:typeof l.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=el)}Ns(n,r);var i;n=null;for(c in l)if(!r.hasOwnProperty(c)&&l.hasOwnProperty(c)&&l[c]!=null)if(c==="style"){var a=l[c];for(i in a)a.hasOwnProperty(i)&&(n||(n={}),n[i]="")}else c!=="dangerouslySetInnerHTML"&&c!=="children"&&c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&c!=="autoFocus"&&(Xn.hasOwnProperty(c)?s||(s=[]):(s=s||[]).push(c,null));for(c in r){var u=r[c];if(a=l!=null?l[c]:void 0,r.hasOwnProperty(c)&&u!==a&&(u!=null||a!=null))if(c==="style")if(a){for(i in a)!a.hasOwnProperty(i)||u&&u.hasOwnProperty(i)||(n||(n={}),n[i]="");for(i in u)u.hasOwnProperty(i)&&a[i]!==u[i]&&(n||(n={}),n[i]=u[i])}else n||(s||(s=[]),s.push(c,n)),n=u;else c==="dangerouslySetInnerHTML"?(u=u?u.__html:void 0,a=a?a.__html:void 0,u!=null&&a!==u&&(s=s||[]).push(c,u)):c==="children"?typeof u!="string"&&typeof u!="number"||(s=s||[]).push(c,""+u):c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&(Xn.hasOwnProperty(c)?(u!=null&&c==="onScroll"&&X("scroll",e),s||a===u||(s=[])):(s=s||[]).push(c,u))}n&&(s=s||[]).push("style",n);var c=s;(t.updateQueue=c)&&(t.flags|=4)}};dc=function(e,t,n,r){n!==r&&(t.flags|=4)};function Rn(e,t){if(!q)switch(e.tailMode){case"hidden":t=e.tail;for(var n=null;t!==null;)t.alternate!==null&&(n=t),t=t.sibling;n===null?e.tail=null:n.sibling=null;break;case"collapsed":n=e.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function ve(e){var t=e.alternate!==null&&e.alternate.child===e.child,n=0,r=0;if(t)for(var l=e.child;l!==null;)n|=l.lanes|l.childLanes,r|=l.subtreeFlags&14680064,r|=l.flags&14680064,l.return=e,l=l.sibling;else for(l=e.child;l!==null;)n|=l.lanes|l.childLanes,r|=l.subtreeFlags,r|=l.flags,l.return=e,l=l.sibling;return e.subtreeFlags|=r,e.childLanes=n,t}function Uf(e,t,n){var r=t.pendingProps;switch(Pi(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return ve(t),null;case 1:return Ee(t.type)&&tl(),ve(t),null;case 3:return r=t.stateNode,xn(),G(_e),G(ye),Ai(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(Tr(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Xe!==null&&(si(Xe),Xe=null))),Zs(e,t),ve(t),null;case 5:Fi(t);var l=It(or.current);if(n=t.type,e!==null&&t.stateNode!=null)cc(e,t,n,r,l),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error(C(166));return ve(t),null}if(e=It(rt.current),Tr(t)){r=t.stateNode,n=t.type;var s=t.memoizedProps;switch(r[tt]=t,r[sr]=s,e=(t.mode&1)!==0,n){case"dialog":X("cancel",r),X("close",r);break;case"iframe":case"object":case"embed":X("load",r);break;case"video":case"audio":for(l=0;l<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=i.createElement(n,{is:r.is}):(e=i.createElement(n),n==="select"&&(i=e,r.multiple?i.multiple=!0:r.size&&(i.size=r.size))):e=i.createElementNS(e,n),e[tt]=t,e[sr]=r,uc(e,t,!1,!1),t.stateNode=e;e:{switch(i=Cs(n,r),n){case"dialog":X("cancel",e),X("close",e),l=r;break;case"iframe":case"object":case"embed":X("load",e),l=r;break;case"video":case"audio":for(l=0;lkn&&(t.flags|=128,r=!0,Rn(s,!1),t.lanes=4194304)}else{if(!r)if(e=al(i),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Rn(s,!0),s.tail===null&&s.tailMode==="hidden"&&!i.alternate&&!q)return ve(t),null}else 2*re()-s.renderingStartTime>kn&&n!==1073741824&&(t.flags|=128,r=!0,Rn(s,!1),t.lanes=4194304);s.isBackwards?(i.sibling=t.child,t.child=i):(n=s.last,n!==null?n.sibling=i:t.child=i,s.last=i)}return s.tail!==null?(t=s.tail,s.rendering=t,s.tail=t.sibling,s.renderingStartTime=re(),t.sibling=null,n=b.current,J(b,r?n&1|2:n&1),t):(ve(t),null);case 22:case 23:return Xi(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?Le&1073741824&&(ve(t),t.subtreeFlags&6&&(t.flags|=8192)):ve(t),null;case 24:return null;case 25:return null}throw Error(C(156,t.tag))}function Bf(e,t){switch(Pi(t),t.tag){case 1:return Ee(t.type)&&tl(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return xn(),G(_e),G(ye),Ai(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Fi(t),null;case 13:if(G(b),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(C(340));yn()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return G(b),null;case 4:return xn(),null;case 10:return Di(t.type._context),null;case 22:case 23:return Xi(),null;case 24:return null;default:return null}}var zr=!1,ge=!1,Vf=typeof WeakSet=="function"?WeakSet:Set,D=null;function an(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){ne(e,t,r)}else n.current=null}function qs(e,t,n){try{n()}catch(r){ne(e,t,r)}}var ta=!1;function Wf(e,t){if($s=Zr,e=vu(),Ei(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var l=r.anchorOffset,s=r.focusNode;r=r.focusOffset;try{n.nodeType,s.nodeType}catch{n=null;break e}var i=0,a=-1,u=-1,c=0,g=0,m=e,h=null;t:for(;;){for(var x;m!==n||l!==0&&m.nodeType!==3||(a=i+l),m!==s||r!==0&&m.nodeType!==3||(u=i+r),m.nodeType===3&&(i+=m.nodeValue.length),(x=m.firstChild)!==null;)h=m,m=x;for(;;){if(m===e)break t;if(h===n&&++c===l&&(a=i),h===s&&++g===r&&(u=i),(x=m.nextSibling)!==null)break;m=h,h=m.parentNode}m=x}n=a===-1||u===-1?null:{start:a,end:u}}else n=null}n=n||{start:0,end:0}}else n=null;for(Ms={focusedElem:e,selectionRange:n},Zr=!1,D=t;D!==null;)if(t=D,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,D=e;else for(;D!==null;){t=D;try{var S=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(S!==null){var j=S.memoizedProps,O=S.memoizedState,f=t.stateNode,d=f.getSnapshotBeforeUpdate(t.elementType===t.type?j:Ye(t.type,j),O);f.__reactInternalSnapshotBeforeUpdate=d}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(w){ne(t,t.return,w)}if(e=t.sibling,e!==null){e.return=t.return,D=e;break}D=t.return}return S=ta,ta=!1,S}function Kn(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var l=r=r.next;do{if((l.tag&e)===e){var s=l.destroy;l.destroy=void 0,s!==void 0&&qs(t,n,s)}l=l.next}while(l!==r)}}function Cl(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function bs(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function fc(e){var t=e.alternate;t!==null&&(e.alternate=null,fc(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[tt],delete t[sr],delete t[Is],delete t[Cf],delete t[_f])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function pc(e){return e.tag===5||e.tag===3||e.tag===4}function na(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||pc(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function ei(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=el));else if(r!==4&&(e=e.child,e!==null))for(ei(e,t,n),e=e.sibling;e!==null;)ei(e,t,n),e=e.sibling}function ti(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(ti(e,t,n),e=e.sibling;e!==null;)ti(e,t,n),e=e.sibling}var de=null,Je=!1;function mt(e,t,n){for(n=n.child;n!==null;)hc(e,t,n),n=n.sibling}function hc(e,t,n){if(nt&&typeof nt.onCommitFiberUnmount=="function")try{nt.onCommitFiberUnmount(gl,n)}catch{}switch(n.tag){case 5:ge||an(n,t);case 6:var r=de,l=Je;de=null,mt(e,t,n),de=r,Je=l,de!==null&&(Je?(e=de,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):de.removeChild(n.stateNode));break;case 18:de!==null&&(Je?(e=de,n=n.stateNode,e.nodeType===8?es(e.parentNode,n):e.nodeType===1&&es(e,n),er(e)):es(de,n.stateNode));break;case 4:r=de,l=Je,de=n.stateNode.containerInfo,Je=!0,mt(e,t,n),de=r,Je=l;break;case 0:case 11:case 14:case 15:if(!ge&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){l=r=r.next;do{var s=l,i=s.destroy;s=s.tag,i!==void 0&&(s&2||s&4)&&qs(n,t,i),l=l.next}while(l!==r)}mt(e,t,n);break;case 1:if(!ge&&(an(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(a){ne(n,t,a)}mt(e,t,n);break;case 21:mt(e,t,n);break;case 22:n.mode&1?(ge=(r=ge)||n.memoizedState!==null,mt(e,t,n),ge=r):mt(e,t,n);break;default:mt(e,t,n)}}function ra(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new Vf),t.forEach(function(r){var l=qf.bind(null,e,r);n.has(r)||(n.add(r),r.then(l,l))})}}function Ke(e,t){var n=t.deletions;if(n!==null)for(var r=0;rl&&(l=i),r&=~s}if(r=l,r=re()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Qf(r/1960))-r,10e?16:e,St===null)var r=!1;else{if(e=St,St=null,pl=0,W&6)throw Error(C(331));var l=W;for(W|=4,D=e.current;D!==null;){var s=D,i=s.child;if(D.flags&16){var a=s.deletions;if(a!==null){for(var u=0;ure()-Yi?Bt(e,0):Ki|=n),Te(e,t)}function kc(e,t){t===0&&(e.mode&1?(t=kr,kr<<=1,!(kr&130023424)&&(kr=4194304)):t=1);var n=Se();e=ft(e,t),e!==null&&(pr(e,t,n),Te(e,n))}function Zf(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),kc(e,n)}function qf(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),kc(e,n)}var jc;jc=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||_e.current)Ce=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return Ce=!1,If(e,t,n);Ce=!!(e.flags&131072)}else Ce=!1,q&&t.flags&1048576&&Eu(t,ll,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Vr(e,t),e=t.pendingProps;var l=gn(t,ye.current);hn(t,n),l=Ui(null,t,r,e,l,n);var s=Bi();return t.flags|=1,typeof l=="object"&&l!==null&&typeof l.render=="function"&&l.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,Ee(r)?(s=!0,nl(t)):s=!1,t.memoizedState=l.state!==null&&l.state!==void 0?l.state:null,$i(t),l.updater=Nl,t.stateNode=l,l._reactInternals=t,Qs(t,r,e,n),t=Js(null,t,r,!0,s,n)):(t.tag=0,q&&s&&Ti(t),xe(null,t,l,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Vr(e,t),e=t.pendingProps,l=r._init,r=l(r._payload),t.type=r,l=t.tag=ep(r),e=Ye(r,e),l){case 0:t=Ys(null,t,r,e,n);break e;case 1:t=qo(null,t,r,e,n);break e;case 11:t=Go(null,t,r,e,n);break e;case 14:t=Zo(null,t,r,Ye(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:Ye(r,l),Ys(e,t,r,l,n);case 1:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Ye(r,l),qo(e,t,r,l,n);case 3:e:{if(ic(t),e===null)throw Error(C(387));r=t.pendingProps,s=t.memoizedState,l=s.element,Du(e,t),ol(t,r,null,n);var i=t.memoizedState;if(r=i.element,s.isDehydrated)if(s={element:r,isDehydrated:!1,cache:i.cache,pendingSuspenseBoundaries:i.pendingSuspenseBoundaries,transitions:i.transitions},t.updateQueue.baseState=s,t.memoizedState=s,t.flags&256){l=Sn(Error(C(423)),t),t=bo(e,t,r,n,l);break e}else if(r!==l){l=Sn(Error(C(424)),t),t=bo(e,t,r,n,l);break e}else for(ze=Ct(t.stateNode.containerInfo.firstChild),Re=t,q=!0,Xe=null,n=zu(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(yn(),r===l){t=pt(e,t,n);break e}xe(e,t,r,n)}t=t.child}return t;case 5:return Ou(t),e===null&&Vs(t),r=t.type,l=t.pendingProps,s=e!==null?e.memoizedProps:null,i=l.children,Fs(r,l)?i=null:s!==null&&Fs(r,s)&&(t.flags|=32),sc(e,t),xe(e,t,i,n),t.child;case 6:return e===null&&Vs(t),null;case 13:return oc(e,t,n);case 4:return Mi(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=wn(t,null,r,n):xe(e,t,r,n),t.child;case 11:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Ye(r,l),Go(e,t,r,l,n);case 7:return xe(e,t,t.pendingProps,n),t.child;case 8:return xe(e,t,t.pendingProps.children,n),t.child;case 12:return xe(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,l=t.pendingProps,s=t.memoizedProps,i=l.value,J(sl,r._currentValue),r._currentValue=i,s!==null)if(qe(s.value,i)){if(s.children===l.children&&!_e.current){t=pt(e,t,n);break e}}else for(s=t.child,s!==null&&(s.return=t);s!==null;){var a=s.dependencies;if(a!==null){i=s.child;for(var u=a.firstContext;u!==null;){if(u.context===r){if(s.tag===1){u=ut(-1,n&-n),u.tag=2;var c=s.updateQueue;if(c!==null){c=c.shared;var g=c.pending;g===null?u.next=u:(u.next=g.next,g.next=u),c.pending=u}}s.lanes|=n,u=s.alternate,u!==null&&(u.lanes|=n),Ws(s.return,n,t),a.lanes|=n;break}u=u.next}}else if(s.tag===10)i=s.type===t.type?null:s.child;else if(s.tag===18){if(i=s.return,i===null)throw Error(C(341));i.lanes|=n,a=i.alternate,a!==null&&(a.lanes|=n),Ws(i,n,t),i=s.sibling}else i=s.child;if(i!==null)i.return=s;else for(i=s;i!==null;){if(i===t){i=null;break}if(s=i.sibling,s!==null){s.return=i.return,i=s;break}i=i.return}s=i}xe(e,t,l.children,n),t=t.child}return t;case 9:return l=t.type,r=t.pendingProps.children,hn(t,n),l=We(l),r=r(l),t.flags|=1,xe(e,t,r,n),t.child;case 14:return r=t.type,l=Ye(r,t.pendingProps),l=Ye(r.type,l),Zo(e,t,r,l,n);case 15:return rc(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Ye(r,l),Vr(e,t),t.tag=1,Ee(r)?(e=!0,nl(t)):e=!1,hn(t,n),ec(t,r,l),Qs(t,r,l,n),Js(null,t,r,!0,e,n);case 19:return ac(e,t,n);case 22:return lc(e,t,n)}throw Error(C(156,t.tag))};function Nc(e,t){return Za(e,t)}function bf(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Be(e,t,n,r){return new bf(e,t,n,r)}function Zi(e){return e=e.prototype,!(!e||!e.isReactComponent)}function ep(e){if(typeof e=="function")return Zi(e)?1:0;if(e!=null){if(e=e.$$typeof,e===vi)return 11;if(e===gi)return 14}return 2}function Pt(e,t){var n=e.alternate;return n===null?(n=Be(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function Qr(e,t,n,r,l,s){var i=2;if(r=e,typeof e=="function")Zi(e)&&(i=1);else if(typeof e=="string")i=5;else e:switch(e){case qt:return Vt(n.children,l,s,t);case mi:i=8,l|=8;break;case ms:return e=Be(12,n,t,l|2),e.elementType=ms,e.lanes=s,e;case vs:return e=Be(13,n,t,l),e.elementType=vs,e.lanes=s,e;case gs:return e=Be(19,n,t,l),e.elementType=gs,e.lanes=s,e;case Oa:return El(n,l,s,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Ra:i=10;break e;case Da:i=9;break e;case vi:i=11;break e;case gi:i=14;break e;case vt:i=16,r=null;break e}throw Error(C(130,e==null?e:typeof e,""))}return t=Be(i,n,t,l),t.elementType=e,t.type=r,t.lanes=s,t}function Vt(e,t,n,r){return e=Be(7,e,r,t),e.lanes=n,e}function El(e,t,n,r){return e=Be(22,e,r,t),e.elementType=Oa,e.lanes=n,e.stateNode={isHidden:!1},e}function as(e,t,n){return e=Be(6,e,null,t),e.lanes=n,e}function us(e,t,n){return t=Be(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function tp(e,t,n,r,l){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Wl(0),this.expirationTimes=Wl(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Wl(0),this.identifierPrefix=r,this.onRecoverableError=l,this.mutableSourceEagerHydrationData=null}function qi(e,t,n,r,l,s,i,a,u){return e=new tp(e,t,n,a,u),t===1?(t=1,s===!0&&(t|=8)):t=0,s=Be(3,null,null,t),e.current=s,s.stateNode=e,s.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},$i(s),e}function np(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Tc)}catch(e){console.error(e)}}Tc(),Ta.exports=Oe;var op=Ta.exports,Pc,da=op;Pc=da.createRoot,da.hydrateRoot;async function he(e){const t=await fetch(e);if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()}async function ap(){return he("/api/archives")}async function up(e){return he(`/api/archives/${e}/entries`)}async function cp(e,t,n){const r=new URLSearchParams;return t&&r.set("q",t),n&&r.set("tag",n),he(`/api/archives/${e}/entries/search?${r}`)}async function dp(e,t){return he(`/api/archives/${e}/entries/${t}`)}async function fp(e,t,n){const r=await fetch(`/api/archives/${e}/entries/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:n??null})});if(!r.ok)throw new Error(await r.text())}async function cs(e,t){return he(`/api/archives/${e}/entries/${t}/tags`)}async function pp(e,t,n){const r=await fetch(`/api/archives/${e}/entries/${t}/tags`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tag_path:n})});if(!r.ok)throw new Error(`Failed to add tag (${r.status})`)}async function hp(e,t,n){const r=await fetch(`/api/archives/${e}/entries/${t}/tags/${n}`,{method:"DELETE"});if(!r.ok)throw new Error(`Remove failed (${r.status})`)}async function mp(e,t){const n=await fetch(`/api/archives/${e}/entries/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(`Delete failed (${n.status})`)}async function vp(e,t,n){const r=await fetch(`/api/archives/${e}/tags/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n})});if(!r.ok)throw new Error(await r.text());return r.json()}async function gp(e,t){const n=await fetch(`/api/archives/${e}/tags/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(await n.text())}async function fa(e){return he(`/api/archives/${e}/runs`)}async function ds(e){return he(`/api/archives/${e}/tags`)}async function yp(e,t,n=null){const r={locator:t};n&&n!=="best"&&(r.quality=n);const l=await fetch(`/api/archives/${e}/captures`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!l.ok){const s=await l.json().catch(()=>({}));throw new Error(s.error||`HTTP ${l.status}`)}return l.json()}async function wp(e,t){return he(`/api/archives/${e}/captures/probe?locator=${encodeURIComponent(t)}`)}async function xp(e,t){return he(`/api/archives/${e}/capture_jobs/${t}`)}async function Sp(){return(await(await fetch("/api/auth/setup")).json()).setup_required===!0}async function kp(e,t){const n=await fetch("/api/auth/setup",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({username:e,password:t})});if(!n.ok)throw new Error((await n.json()).error||"Setup failed");return n.json()}async function jp(e,t){const n=await fetch("/api/auth/login",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({username:e,password:t})});if(!n.ok)throw new Error((await n.json()).error||"Login failed");return n.json()}async function Np(){await fetch("/api/auth/logout",{method:"POST"})}async function Cp(){const e=await fetch("/api/auth/me");return e.status===401?null:e.json()}async function _p(e){const t=await fetch("/api/auth/me",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({display_name:e})});if(!t.ok)throw new Error(await t.text())}async function Ep(e){const t=await fetch("/api/auth/me",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(await t.text())}async function Tp(e,t){const n=await fetch("/api/auth/me",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({current_password:e,new_password:t})});if(!n.ok){let r=await n.text();try{r=JSON.parse(r).error??r}catch{}throw new Error(r)}}async function Pp(){return he("/api/auth/tokens")}async function Lp(e){const t=await fetch("/api/auth/tokens",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})});if(!t.ok)throw new Error(await t.text());return t.json()}async function zp(e){const t=await fetch(`/api/auth/tokens/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(await t.text())}async function Rp(){return he("/api/admin/instance-settings")}async function Dp(e){const t=await fetch("/api/admin/instance-settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(await t.text())}async function Op(){return he("/api/admin/users")}async function $p(e,t,n){const r=await fetch("/api/admin/users",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,password:t,email:n||void 0})});if(!r.ok){const l=await r.json().catch(()=>({}));throw new Error(l.error||`HTTP ${r.status}`)}return r.json()}async function Mp(e,t){const n=await fetch(`/api/admin/users/${e}/status`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||`HTTP ${n.status}`)}return n.json()}async function Fp(){return he("/api/admin/roles")}async function Ap(e,t){const n=await fetch("/api/admin/roles",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:e,name:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||`HTTP ${n.status}`)}return n.json()}async function Ip(e){return he(`/api/archives/${e}/collections`)}async function Up(e,t,n,r=2){const l=await fetch(`/api/archives/${e}/collections`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:t,slug:n,default_visibility_bits:r})});if(!l.ok){const s=await l.json().catch(()=>({error:l.statusText}));throw new Error(s.error||l.statusText)}return l.json()}async function Bp(e,t){return he(`/api/archives/${e}/collections/${t}`)}async function Vp(e,t,n,r=2){const l=await fetch(`/api/archives/${e}/collections/${t}/entries`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({entry_uid:n,visibility_bits:r})});if(!l.ok){const s=await l.json().catch(()=>({error:l.statusText}));throw new Error(s.error||l.statusText)}}async function Wp(e,t,n){const r=await fetch(`/api/archives/${e}/collections/${t}/entries/${n}`,{method:"DELETE"});if(!r.ok){const l=await r.json().catch(()=>({error:r.statusText}));throw new Error(l.error||r.statusText)}}async function Hp(e,t,n,r){const l=await fetch(`/api/archives/${e}/collections/${t}/entries/${n}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({visibility_bits:r})});if(!l.ok){const s=await l.json().catch(()=>({error:l.statusText}));throw new Error(s.error||l.statusText)}}async function Qp(e,t){return he(`/api/archives/${e}/entries/${t}/collections`)}async function pa(e,t,n){const r=await fetch(`/api/archives/${e}/collections/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!r.ok){const l=await r.json().catch(()=>({}));throw new Error(l.error??r.statusText)}}async function Kp(e,t){const n=await fetch(`/api/archives/${e}/collections/${t}`,{method:"DELETE"});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error??n.statusText)}}async function Yp(e){return he(`/api/archives/${e}/blob-cleanup`)}async function Jp(e){const t=await fetch(`/api/archives/${e}/blob-cleanup`,{method:"DELETE"});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error??t.statusText)}return t.json()}const Xp=window.fetch;window.fetch=async(...e)=>{var n;const t=await Xp(...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 Gp({onLogin:e}){const[t,n]=v.useState(""),[r,l]=v.useState(""),[s,i]=v.useState(null),[a,u]=v.useState(!1);async function c(g){g.preventDefault(),i(null),u(!0);try{const m=await jp(t,r);e(m)}catch(m){i(m.message)}finally{u(!1)}}return o.jsx("div",{className:"login-page",children:o.jsxs("div",{className:"login-card",children:[o.jsx("h1",{className:"login-brand",children:"Archivr"}),o.jsx("p",{className:"login-tagline",children:"Sign in to your archive"}),o.jsxs("form",{onSubmit:c,children:[o.jsxs("div",{className:"login-field",children:[o.jsx("label",{className:"login-label",htmlFor:"login-username",children:"Username"}),o.jsx("input",{className:"login-input",id:"login-username",type:"text",value:t,onChange:g=>n(g.target.value),autoFocus:!0,required:!0,autoComplete:"username"})]}),o.jsxs("div",{className:"login-field",children:[o.jsx("label",{className:"login-label",htmlFor:"login-password",children:"Password"}),o.jsx("input",{className:"login-input",id:"login-password",type:"password",value:r,onChange:g=>l(g.target.value),required:!0,autoComplete:"current-password"})]}),s&&o.jsx("p",{className:"login-error",children:s}),o.jsx("button",{className:"login-submit",type:"submit",disabled:a,children:a?"Signing in…":"Sign in"})]})]})})}function Zp({onComplete:e}){const[t,n]=v.useState(""),[r,l]=v.useState(""),[s,i]=v.useState(""),[a,u]=v.useState(null),[c,g]=v.useState(!1);async function m(h){if(h.preventDefault(),r!==s){u("Passwords do not match");return}if(r.length<8){u("Password must be at least 8 characters");return}u(null),g(!0);try{await kp(t,r),e()}catch(x){u(x.message)}finally{g(!1)}}return o.jsx("div",{className:"setup-page",children:o.jsxs("div",{className:"setup-card",children:[o.jsx("h1",{className:"setup-brand",children:"Archivr"}),o.jsx("p",{className:"setup-tagline",children:"Create your owner account to get started."}),o.jsxs("form",{onSubmit:m,children:[o.jsxs("div",{className:"setup-field",children:[o.jsx("label",{className:"setup-label",htmlFor:"setup-username",children:"Username"}),o.jsx("input",{className:"setup-input",id:"setup-username",type:"text",value:t,onChange:h=>n(h.target.value),autoFocus:!0,required:!0,autoComplete:"username"})]}),o.jsxs("div",{className:"setup-field",children:[o.jsx("label",{className:"setup-label",htmlFor:"setup-password",children:"Password"}),o.jsx("input",{className:"setup-input",id:"setup-password",type:"password",value:r,onChange:h=>l(h.target.value),required:!0,autoComplete:"new-password"})]}),o.jsxs("div",{className:"setup-field",children:[o.jsx("label",{className:"setup-label",htmlFor:"setup-confirm",children:"Confirm password"}),o.jsx("input",{className:"setup-input",id:"setup-confirm",type:"password",value:s,onChange:h=>i(h.target.value),required:!0,autoComplete:"new-password"})]}),a&&o.jsx("p",{className:"setup-error",children:a}),o.jsx("button",{className:"setup-submit",type:"submit",disabled:c,children:c?"Creating account…":"Create account"})]})]})})}function qp({archives:e,archiveId:t,onArchiveChange:n,view:r,onViewChange:l,onCaptureClick:s}){const{currentUser:i,setCurrentUser:a}=v.useContext(Rl)??{},[u,c]=v.useState(!1);async function g(){c(!0),await Np(),a(null),window.location.reload()}return o.jsxs("header",{className:"topbar",children:[o.jsx("div",{className:"brand",children:"Archivr"}),o.jsx("div",{className:"switcher",children:o.jsx("select",{"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","tags","collections","runs","admin","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:s,children:"Capture"}),i&&o.jsxs("div",{className:"user-menu",children:[o.jsx("span",{className:"user-name",children:i.display_name||i.username}),o.jsx("button",{className:"logout-btn",onClick:g,disabled:u,children:u?"Logging out…":"Log out"})]})]})}let ii=1;function Lc(e){const t=e.trim(),n=t.toLowerCase();for(const r of["yt:","youtube:"])if(n.startsWith(r)){const l=n.slice(r.length);return l.startsWith("video/")||l.startsWith("short/")||l.startsWith("shorts/")}if(n.startsWith("ytm:"))return!n.slice(4).startsWith("playlist/");for(const r of["x:","twitter:","tweet:"])if(n.startsWith(r))return n.slice(r.length).startsWith("media:");if(n.startsWith("spotify:"))return!1;if(n.startsWith("instagram:")||n.startsWith("facebook:")||n.startsWith("tiktok:")||n.startsWith("reddit:")||n.startsWith("snapchat:"))return!0;if(n.startsWith("http://")||n.startsWith("https://")){if(/^https?:\/\/music\.youtube\.com\/watch/.test(n)||/^https?:\/\/(?:www\.)?(?:youtu\.be\/[0-9A-Za-z_-]+|youtube\.com\/watch\?v=[0-9A-Za-z_-]+|youtube\.com\/shorts\/[0-9A-Za-z_-]+)/.test(t)||n.startsWith("https://x.com/")||n.startsWith("http://x.com/")||/^https?:\/\/(?:www\.)?instagram\.com\//.test(n)||/^https?:\/\/(?:www\.)?facebook\.com\//.test(n)||n.startsWith("https://fb.watch/")||n.startsWith("http://fb.watch/")||/^https?:\/\/(?:www\.)?tiktok\.com\//.test(n)||/^https?:\/\/(?:www\.)?reddit\.com\//.test(n)||n.startsWith("https://redd.it/")||n.startsWith("http://redd.it/")||/^https?:\/\/(?:www\.)?snapchat\.com\//.test(n))return!0;if(n.startsWith("https://open.spotify.com/")||n.startsWith("http://open.spotify.com/"))return!1}return!1}function On(e=""){return{id:ii++,locator:e,quality:"best",probeState:"idle",probeQualities:null,probeHasAudio:!1,status:"idle",error:null,jobUid:null,archiveId:null}}function ha(e){return e.some(t=>t.status==="submitting"||t.status==="running")}function bp({open:e,archiveId:t,onClose:n,onCaptured:r,onToast:l}){const s=v.useRef(null),i=v.useRef(!0),a=v.useRef(new Map),u=v.useRef(new Map),c=v.useRef(t);v.useEffect(()=>{c.current=t},[t]);const g=v.useRef(r),m=v.useRef(l);v.useEffect(()=>{g.current=r},[r]),v.useEffect(()=>{m.current=l},[l]);const[h,x]=v.useState(()=>{try{const y=JSON.parse(sessionStorage.getItem("captureItems")||"null");if(Array.isArray(y)&&y.length>0)return y.forEach(T=>{T.id>=ii&&(ii=T.id+1)}),y}catch{}return[On()]});v.useEffect(()=>{sessionStorage.setItem("captureItems",JSON.stringify(h))},[h]),v.useEffect(()=>{["captureDialogLocator","captureDialogError","captureDialogBusy","captureDialogJobStatus","captureDialogJobUid"].forEach(y=>sessionStorage.removeItem(y)),x(y=>y.map(T=>T.status==="submitting"?{...T,status:"idle",error:null}:T)),h.forEach(y=>{y.status==="running"&&y.jobUid&&y.archiveId&&!a.current.has(y.jobUid)&&S(y.id,y.jobUid,y.locator,y.archiveId)})},[]),v.useEffect(()=>{const y=s.current;if(!y)return;const T=()=>{u.current.forEach(R=>clearTimeout(R)),u.current.clear(),n()};return y.addEventListener("close",T),()=>y.removeEventListener("close",T)},[n]),v.useEffect(()=>{const y=s.current;y&&(e?(!i.current&&!ha(h)&&x([On()]),i.current=!1,y.open||y.showModal()):(u.current.forEach(T=>clearTimeout(T)),u.current.clear(),y.open&&y.close()))},[e]),v.useEffect(()=>()=>{a.current.forEach(y=>clearInterval(y)),u.current.forEach(y=>clearTimeout(y))},[]);function S(y,T,R,I){if(a.current.has(T))return;const U=setInterval(async()=>{try{const E=await xp(I,T);if(E.status==="completed")clearInterval(a.current.get(T)),a.current.delete(T),x(F=>F.map(H=>H.id===y?{...H,status:"completed"}:H)),setTimeout(()=>{x(F=>{const H=F.filter(Z=>Z.id!==y);return H.length===0?[On()]:H})},1400),g.current();else if(E.status==="failed"){clearInterval(a.current.get(T)),a.current.delete(T);const F=E.error_text||"Capture failed.";x(H=>H.map(Z=>Z.id===y?{...Z,status:"failed",error:F}:Z)),m.current(F,R)}}catch(E){clearInterval(a.current.get(T)),a.current.delete(T);const F=E.message||"Network error";x(H=>H.map(Z=>Z.id===y?{...Z,status:"failed",error:F}:Z)),m.current(F,R)}},500);a.current.set(T,U)}async function j(y){if(!y.locator.trim())return;const T=t,R=y.locator.trim(),I=y.quality||"best";x(U=>U.map(E=>E.id===y.id?{...E,status:"submitting",error:null}:E));try{const U=await yp(T,R,I);x(E=>E.map(F=>F.id===y.id?{...F,status:"running",jobUid:U.job_uid,archiveId:T}:F)),S(y.id,U.job_uid,R,T)}catch(U){const E=U.message||"Submission failed.";x(F=>F.map(H=>H.id===y.id?{...H,status:"failed",error:E}:H)),m.current(E,R)}}function O(){h.filter(T=>T.status==="idle"&&T.locator.trim()).forEach(T=>j(T))}function f(){x(y=>[...y,On()])}function d(y){clearTimeout(u.current.get(y)),u.current.delete(y),x(T=>{const R=T.filter(I=>I.id!==y);return R.length===0?[On()]:R})}function p(y){x(T=>T.map(R=>R.id===y?{...R,status:"idle",error:null}:R))}function w(y,T){if(clearTimeout(u.current.get(y)),x(I=>I.map(U=>U.id===y?{...U,locator:T,probeState:"idle",probeQualities:null,probeHasAudio:!1,quality:"best"}:U)),!Lc(T))return;const R=setTimeout(async()=>{u.current.delete(y),x(I=>I.map(U=>U.id===y?{...U,probeState:"probing"}:U));try{const I=await wp(c.current,T.trim());x(U=>U.map(E=>{if(E.id!==y||E.locator!==T)return E;const F=I.qualities??[],H=I.has_audio??!1,Z=F.length===0&&H?"audio":"best";return{...E,probeState:"done",probeQualities:F,probeHasAudio:H,quality:Z}}))}catch{x(I=>I.map(U=>U.id===y?{...U,probeState:"idle",probeQualities:null}:U))}},600);u.current.set(y,R)}function k(y,T){x(R=>R.map(I=>I.id===y?{...I,quality:T}:I))}const _=h.filter(y=>y.status==="idle"&&y.locator.trim()).length,P=ha(h);return o.jsx("dialog",{ref:s,className:"capture-dialog",children:o.jsxs("div",{className:"capture-dialog-inner",children:[o.jsxs("div",{className:"capture-dialog-header",children:[o.jsx("h2",{className:"capture-dialog-title",children:"Capture"}),o.jsx("button",{type:"button",className:"capture-dialog-close",onClick:()=>{var y;return(y=s.current)==null?void 0:y.close()},"aria-label":"Close",children:o.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[o.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),o.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),o.jsx("div",{className:"capture-rows",children:h.map((y,T)=>o.jsx(eh,{item:y,autoFocus:T===h.length-1&&y.status==="idle",onLocatorChange:R=>w(y.id,R),onQualityChange:R=>k(y.id,R),onRemove:()=>d(y.id),onReset:()=>p(y.id),onSubmit:O},y.id))}),o.jsxs("button",{type:"button",className:"capture-add-row",onClick:f,children:[o.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[o.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"14"}),o.jsx("line",{x1:"2",y1:"8",x2:"14",y2:"8"})]}),"Add another"]}),o.jsxs("div",{className:"capture-actions",children:[o.jsx("button",{type:"button",className:"capture-cancel",onClick:()=>{var y;return(y=s.current)==null?void 0:y.close()},children:P?"Close":"Cancel"}),o.jsx("button",{type:"button",className:"capture-submit",onClick:O,disabled:_===0,children:_>1?`Archive ${_}`:"Archive"})]})]})})}function eh({item:e,autoFocus:t,onLocatorChange:n,onQualityChange:r,onRemove:l,onReset:s,onSubmit:i}){const a=v.useRef(null),u=e.status==="submitting"||e.status==="running";v.useEffect(()=>{var g;t&&e.status==="idle"&&((g=a.current)==null||g.focus())},[t]);const c=(()=>{if(e.status==="completed"||u||!Lc(e.locator))return null;if(e.probeState==="probing")return o.jsx("span",{className:"capture-quality-probing","aria-label":"Checking available qualities",children:"…"});if(e.probeState==="done"){const g=e.probeQualities??[],m=e.probeHasAudio??!1;return g.length===0&&!m?o.jsx("span",{className:"capture-quality-hint",children:"No media detected"}):g.length===0&&m?o.jsx("select",{className:"capture-quality",value:"audio",onChange:h=>r(h.target.value),"aria-label":"Video quality",children:o.jsx("option",{value:"audio",children:"Audio only"})}):o.jsxs("select",{className:"capture-quality",value:e.quality||"best",onChange:h=>r(h.target.value),"aria-label":"Video quality",children:[o.jsx("option",{value:"best",children:"Best quality"}),g.map(h=>o.jsx("option",{value:h,children:h},h)),m&&o.jsx("option",{value:"audio",children:"Audio only"})]})}return null})();return o.jsxs("div",{className:`capture-row capture-row--${e.status}`,children:[o.jsxs("div",{className:"capture-row-main",children:[o.jsx(th,{status:e.status}),o.jsx("input",{ref:a,className:"capture-input",type:"text",placeholder:"https://… · yt:ID · ytm:ID · tweet:ID · x:ID",value:e.locator,onChange:g=>n(g.target.value),onKeyDown:g=>{g.key==="Enter"&&i()},disabled:u||e.status==="completed",autoComplete:"off",spellCheck:!1}),c,e.status==="failed"&&o.jsx("button",{type:"button",className:"capture-row-action",onClick:s,title:"Retry",children:o.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[o.jsx("path",{d:"M13 2.5A7 7 0 1 1 6.5 1"}),o.jsx("polyline",{points:"6.5 1 4 3.5 6.5 6"})]})}),!u&&e.status!=="completed"&&e.status!=="failed"&&o.jsx("button",{type:"button",className:"capture-row-action capture-row-remove",onClick:l,"aria-label":"Remove",children:o.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[o.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),o.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),e.error&&o.jsx("p",{className:"capture-row-error",children:e.error})]})}function th({status:e}){return e==="submitting"||e==="running"?o.jsx("span",{className:"cap-dot cap-dot--running","aria-label":"Running",children:o.jsx("span",{className:"cap-spinner"})}):e==="completed"?o.jsx("span",{className:"cap-dot cap-dot--ok","aria-label":"Done",children:"✓"}):e==="failed"?o.jsx("span",{className:"cap-dot cap-dot--err","aria-label":"Failed",children:"✕"}):o.jsx("span",{className:"cap-dot cap-dot--idle","aria-hidden":"true"})}function oi(e){if(!e)return"0 B";const t=["B","KB","MB","GB"];let n=e,r=0;for(;n>=1024&&r").replace(/"/g,'"').replace(/'/g,"'").replace(/'/g,"'")}function Ut(e){return nh(e)??""}function zc(e){if(!e)return"";const t=new Date(e);if(isNaN(t))return e;const n=r=>String(r).padStart(2,"0");return`${t.getUTCFullYear()}-${n(t.getUTCMonth()+1)}-${n(t.getUTCDate())} ${n(t.getUTCHours())}:${n(t.getUTCMinutes())}`}const ma={youtube:'',youtube_music:'',spotify:'',x:'',instagram:'',facebook:'',tiktok:'',reddit:'',snapchat:'',local:'',web:'',other:'?'};function Rc(e){return ma[e]??ma.other}function Dc(e){return e.split("/").map(t=>t?t.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"").join("/")}function rh({entry:e,archiveId:t,isSelected:n,onSelect:r}){const[l,s]=v.useState(!1),a=e.source_kind==="web"&&e.entity_kind==="page"&&e.has_favicon&&t&&!l?o.jsx("img",{src:`/api/archives/${t}/entries/${e.entry_uid}/favicon`,width:"16",height:"16",alt:"",onError:()=>s(!0),style:{objectFit:"contain"}}):o.jsx("span",{dangerouslySetInnerHTML:{__html:Rc(e.source_kind)}});return o.jsxs("div",{className:n?"is-selected":void 0,tabIndex:0,"data-entry-uid":e.entry_uid,onClick:r,onKeyDown:u=>{u.key==="Enter"&&r()},children:[o.jsx("div",{className:"col-added",children:zc(e.archived_at)}),o.jsxs("div",{className:"col-title",children:[o.jsx("span",{className:"source-icon",children:a}),o.jsx("span",{className:"entry-title",children:Ut(e.title)||Ut(e.entry_uid)})]}),o.jsx("div",{className:"col-type",children:o.jsx("span",{className:"type-pill",children:Ut(e.entity_kind)})}),o.jsxs("div",{className:"col-size",children:[o.jsx("span",{className:"size-total",children:oi(e.total_artifact_bytes)}),e.cached_bytes>0&&e.total_artifact_bytes>0&&o.jsxs("span",{className:"size-cached-pct",title:`${oi(e.cached_bytes)} already on disk from an earlier entry`,children:[Math.round(e.cached_bytes/e.total_artifact_bytes*100),"% cached"]})]}),o.jsx("div",{className:"url-cell col-url",children:Ut(e.original_url)})]})}function lh({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(rh,{entry:l,archiveId:r,isSelected:l.entry_uid===t,onSelect:()=>n(l)},l.entry_uid))})]})})}function sh(e){if(!e)return"—";try{return new Date(e).toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return e}}function ih({status:e}){const t=e==="completed"?"run-status--completed":e==="failed"?"run-status--failed":e==="in_progress"?"run-status--in-progress":"",n=e?e.replace(/_/g," "):"—";return o.jsx("span",{className:`run-status ${t}`,children:n})}function oh({runs:e}){const[t,n]=v.useState(null);function r(l){n(s=>s===l?null:l)}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.length===0?o.jsx("tr",{children:o.jsx("td",{colSpan:5,style:{color:"var(--muted)",padding:"24px 16px",textAlign:"center"},children:"No runs yet."})}):e.map(l=>{const s=l.status==="failed"&&l.error_summary,i=t===l.run_uid;return[o.jsxs("tr",{className:s?"run-row run-row--failed":"run-row",onClick:s?()=>r(l.run_uid):void 0,title:s?i?"Click to hide error":"Click to view error":void 0,children:[o.jsx("td",{children:sh(l.started_at)}),o.jsxs("td",{children:[o.jsx(ih,{status:l.status}),s&&o.jsx("span",{className:"run-expand-hint","aria-hidden":"true",children:i?"▴":"▾"})]}),o.jsx("td",{children:l.requested_count??"—"}),o.jsx("td",{children:l.completed_count??"—"}),o.jsx("td",{children:l.failed_count??"—"})]},l.run_uid),s&&i&&o.jsx("tr",{className:"run-error-row",children:o.jsx("td",{colSpan:5,children:o.jsx("pre",{className:"run-error-detail",children:l.error_summary})})},`${l.run_uid}-detail`)]})})]})})}const ah=4;function uh({archives:e}){const{currentUser:t}=v.useContext(Rl)??{},n=t&&(t.role_bits&ah)!==0,[r,l]=v.useState("users"),[s,i]=v.useState([]),[a,u]=v.useState([]),[c,g]=v.useState(!1),[m,h]=v.useState(null),[x,S]=v.useState(""),[j,O]=v.useState(""),[f,d]=v.useState(""),[p,w]=v.useState(null),[k,_]=v.useState(!1),[P,y]=v.useState(""),[T,R]=v.useState(""),[I,U]=v.useState(null),[E,F]=v.useState(!1),H=v.useCallback(async()=>{if(n){g(!0),h(null);try{const[N,M]=await Promise.all([Op(),Fp()]);i(N),u(M)}catch(N){h(N.message)}finally{g(!1)}}},[n]);v.useEffect(()=>{H()},[H]);async function Z(N){const M=N.status==="active"?"disabled":"active";try{await Mp(N.user_uid,M),i(Q=>Q.map(A=>A.user_uid===N.user_uid?{...A,status:M}:A))}catch(Q){h(Q.message)}}async function Me(N){if(N.preventDefault(),!x.trim()||!j){w("Username and password required");return}_(!0),w(null);try{await $p(x.trim(),j,f.trim()||void 0),S(""),O(""),d(""),await H()}catch(M){w(M.message)}finally{_(!1)}}async function L(N){if(N.preventDefault(),!P.trim()||!T.trim()){U("Slug and name required");return}F(!0),U(null);try{await Ap(P.trim(),T.trim()),y(""),R(""),await H()}catch(M){U(M.message)}finally{F(!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:"view-tabs",children:[o.jsx("button",{className:`view-tab${r==="users"?" is-active":""}`,onClick:()=>l("users"),children:"Users"}),o.jsx("button",{className:`view-tab${r==="roles"?" is-active":""}`,onClick:()=>l("roles"),children:"Roles"}),o.jsx("button",{className:`view-tab${r==="archives"?" is-active":""}`,onClick:()=>l("archives"),children:"Archives"})]}),m&&o.jsx("div",{className:"form-msg form-msg--err",children:m}),r==="users"&&o.jsxs("div",{className:"admin-section",children:[o.jsx("h2",{children:"Users"}),c?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:s.map(N=>o.jsxs("tr",{className:N.status==="disabled"?"admin-row-disabled":"",children:[o.jsx("td",{children:N.username}),o.jsx("td",{className:"muted",children:N.email||"—"}),o.jsx("td",{children:N.role_slugs.join(", ")||"—"}),o.jsx("td",{children:o.jsx("span",{className:`status-badge status-${N.status}`,children:N.status})}),o.jsx("td",{children:o.jsx("button",{className:"admin-action-btn",onClick:()=>Z(N),children:N.status==="active"?"Ban":"Unban"})})]},N.user_uid))})]}),o.jsx("h3",{children:"Create User"}),o.jsxs("form",{className:"admin-form",onSubmit:Me,children:[o.jsx("input",{className:"admin-input",placeholder:"Username",value:x,onChange:N=>S(N.target.value),required:!0}),o.jsx("input",{className:"admin-input",type:"password",placeholder:"Password (min 8 chars)",value:j,onChange:N=>O(N.target.value),required:!0}),o.jsx("input",{className:"admin-input",type:"email",placeholder:"Email (optional)",value:f,onChange:N=>d(N.target.value)}),p&&o.jsx("div",{className:"form-msg form-msg--err",children:p}),o.jsx("button",{className:"btn-primary",type:"submit",disabled:k,children:k?"Creating…":"Create User"})]})]}),r==="roles"&&o.jsxs("div",{className:"admin-section",children:[o.jsx("h2",{children:"Roles"}),c?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:a.map(N=>o.jsxs("tr",{children:[o.jsx("td",{children:o.jsx("code",{children:N.slug})}),o.jsx("td",{children:N.name}),o.jsx("td",{children:N.level}),o.jsx("td",{children:N.bit_position}),o.jsx("td",{children:N.is_builtin?"✓":""})]},N.role_uid))})]}),o.jsx("h3",{children:"Create Custom Role"}),o.jsxs("form",{className:"admin-form",onSubmit:L,children:[o.jsx("input",{className:"admin-input",placeholder:"Slug (e.g. moderator)",value:P,onChange:N=>y(N.target.value),required:!0}),o.jsx("input",{className:"admin-input",placeholder:"Display Name (e.g. Moderator)",value:T,onChange:N=>R(N.target.value),required:!0}),I&&o.jsx("div",{className:"form-msg form-msg--err",children:I}),o.jsx("button",{className:"btn-primary",type:"submit",disabled:E,children:E?"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(N=>o.jsxs("div",{className:"admin-archive",children:[o.jsx("strong",{children:N.label}),o.jsx("div",{className:"muted",children:N.archive_path})]},N.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(N=>o.jsxs("div",{className:"admin-archive",children:[o.jsx("strong",{children:N.label}),o.jsx("div",{className:"muted",children:N.archive_path})]},N.id))})]})}function Oc({node:e,archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:i,onTagsRefresh:a,humanizeTags:u}){var w;const c=n===e.tag.full_path,[g,m]=v.useState(!1),[h,x]=v.useState(""),S=v.useRef(!1);function j(){if(g)return;const k=c?null:e.tag.full_path;r(k),l("archive")}function O(k){k.stopPropagation(),x(e.tag.slug),m(!0)}async function f(){const k=h.trim();if(!k||k===e.tag.slug){m(!1);return}try{const _=await vp(t,e.tag.tag_uid,k);s(e.tag.full_path,_.full_path),a()}catch{}finally{m(!1)}}async function d(k){var P;k.stopPropagation();const _=((P=e.children)==null?void 0:P.length)>0?`Delete tag "${e.tag.full_path}" and all its child tags? This cannot be undone.`:`Delete tag "${e.tag.full_path}"? This cannot be undone.`;if(window.confirm(_))try{await gp(t,e.tag.tag_uid),i(e.tag.full_path),a()}catch{}}const p={archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:i,onTagsRefresh:a,humanizeTags:u};return o.jsxs("li",{children:[o.jsxs("div",{className:"tag-node-row",children:[g?o.jsx("input",{className:"tag-rename-input",autoFocus:!0,value:h,onChange:k=>x(k.target.value),onKeyDown:k=>{k.key==="Enter"&&k.currentTarget.blur(),k.key==="Escape"&&(S.current=!0,k.currentTarget.blur())},onBlur:()=>{S.current?(S.current=!1,m(!1)):f()}}):o.jsxs("button",{className:`tag-node-btn${c?" is-active":""}`,title:e.tag.full_path,onClick:j,onDoubleClick:O,children:[u?e.tag.name:e.tag.slug,o.jsx("svg",{className:"edit-icon",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",onClick:k=>{k.stopPropagation(),O(k)},children:o.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),o.jsx("button",{className:"remove tag-node-delete",title:`Delete tag ${e.tag.full_path}`,onClick:d,"aria-label":`Delete tag ${e.tag.full_path}`,children:"×"})]}),((w=e.children)==null?void 0:w.length)>0&&o.jsx("div",{className:"tag-children",children:o.jsx("ul",{className:"tag-tree-list",children:e.children.map(k=>o.jsx(Oc,{node:k,...p},k.tag.tag_uid))})})]})}function ch({archiveId:e,tagNodes:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:i,onTagsRefresh:a,humanizeTags:u}){return o.jsx("section",{id:"tags-view",className:"view is-active",children:o.jsxs("div",{className:"tag-tree",children:[o.jsxs("div",{className:"tag-tree-header",children:[o.jsx("span",{className:"tag-tree-title",children:"Tags"}),n&&o.jsxs("span",{className:"tag-tree-active",children:["Filtering: ",n]})]}),t.length===0?o.jsx("p",{className:"muted",style:{padding:"8px 0"},children:"No tags yet."}):o.jsx("ul",{className:"tag-tree-list",children:t.map(c=>o.jsx(Oc,{node:c,archiveId:e,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:i,onTagsRefresh:a,humanizeTags:u},c.tag.tag_uid))})]})})}const In=[{value:0,label:"Private"},{value:2,label:"Users only"},{value:3,label:"Public"}],dh=e=>{var t;return((t=In.find(n=>n.value===e))==null?void 0:t.label)??String(e)};function fh({archiveId:e}){const[t,n]=v.useState([]),[r,l]=v.useState(!1),[s,i]=v.useState(null),[a,u]=v.useState(null),[c,g]=v.useState(null),[m,h]=v.useState(!1),[x,S]=v.useState(null),[j,O]=v.useState(""),[f,d]=v.useState(""),[p,w]=v.useState(2),[k,_]=v.useState(!1),[P,y]=v.useState(null),[T,R]=v.useState(""),[I,U]=v.useState(2),[E,F]=v.useState(!1),[H,Z]=v.useState(null),[Me,L]=v.useState(!1),[N,M]=v.useState(""),Q=v.useRef(null),A=t.find(z=>z.collection_uid===a)??null,we=(A==null?void 0:A.slug)==="_default_",ue=v.useCallback(async()=>{if(e){l(!0),i(null);try{const z=await Ip(e);n(z)}catch(z){i(z.message)}finally{l(!1)}}},[e]),Qe=v.useCallback(async z=>{if(!z){g(null);return}h(!0),S(null);try{const V=await Bp(e,z);g(V)}catch(V){S(V.message)}finally{h(!1)}},[e]);v.useEffect(()=>{ue()},[ue]),v.useEffect(()=>{Qe(a)},[a,Qe]),v.useEffect(()=>{Me&&Q.current&&Q.current.focus()},[Me]);async function Fe(z){z.preventDefault();const V=j.trim(),Pe=f.trim();if(!(!V||!Pe)){_(!0),y(null);try{const $=await Up(e,V,Pe,p);O(""),d(""),w(2),await ue(),u($.collection_uid)}catch($){y($.message)}finally{_(!1)}}}async function lt(){const z=N.trim();if(!z||!A){L(!1);return}try{await pa(e,A.collection_uid,{name:z}),await ue(),g(V=>V&&{...V,name:z})}catch(V){i(V.message)}finally{L(!1)}}async function Dl(z){if(A)try{await pa(e,A.collection_uid,{default_visibility_bits:z}),await ue(),g(V=>V&&{...V,default_visibility_bits:z})}catch(V){i(V.message)}}async function Ol(){if(A&&window.confirm(`Delete collection "${A.name}"? Entries will not be deleted.`))try{await Kp(e,A.collection_uid),u(null),g(null),await ue()}catch(z){i(z.message)}}async function $l(z){z.preventDefault();const V=T.trim();if(!(!V||!A)){F(!0),Z(null);try{await Vp(e,A.collection_uid,V,I),R(""),await Qe(A.collection_uid)}catch(Pe){Z(Pe.message)}finally{F(!1)}}}async function Ml(z){if(A)try{await Wp(e,A.collection_uid,z),await Qe(A.collection_uid)}catch(V){S(V.message)}}async function Fl(z,V){if(A)try{await Hp(e,A.collection_uid,z,V),g(Pe=>Pe&&{...Pe,entries:Pe.entries.map($=>$.entry_uid===z?{...$,collection_visibility_bits:V}:$)})}catch(Pe){S(Pe.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…"}),s&&o.jsxs("div",{className:"collections-error",children:[s," ",o.jsx("button",{onClick:()=>i(null),className:"coll-dismiss",children:"×"})]}),o.jsxs("div",{className:"collections-layout",children:[o.jsxs("div",{className:"collections-sidebar",children:[t.map(z=>o.jsxs("button",{className:`coll-sidebar-row${a===z.collection_uid?" is-active":""}`,onClick:()=>u(z.collection_uid),children:[o.jsx("span",{className:"coll-row-name",children:z.name}),o.jsx("span",{className:"coll-row-meta",children:dh(z.default_visibility_bits)})]},z.collection_uid)),t.length===0&&!r&&o.jsx("div",{className:"muted",style:{padding:"8px 12px"},children:"No collections yet."})]}),A?o.jsxs("div",{className:"coll-detail",children:[o.jsxs("div",{className:"coll-detail-header",children:[Me?o.jsx("input",{ref:Q,className:"coll-rename-input",value:N,onChange:z=>M(z.target.value),onBlur:lt,onKeyDown:z=>{z.key==="Enter"&<(),z.key==="Escape"&&L(!1)}}):o.jsxs("h3",{className:`coll-detail-name${we?"":" coll-detail-name--editable"}`,title:we?void 0:"Click to rename",onClick:()=>{we||(M(A.name),L(!0))},children:[(c==null?void 0:c.name)??A.name,!we&&o.jsx("span",{className:"coll-edit-hint",children:" ✎"})]}),!we&&o.jsx("button",{className:"coll-delete-btn",onClick:Ol,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:(c==null?void 0:c.default_visibility_bits)??A.default_visibility_bits,onChange:z=>Dl(Number(z.target.value)),disabled:we,children:In.map(z=>o.jsx("option",{value:z.value,children:z.label},z.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…"}),x&&o.jsx("div",{className:"collections-error",children:x}),!m&&c&&(c.entries.length===0?o.jsx("div",{className:"muted",children:"No entries in this collection."}):o.jsx("ul",{className:"coll-entries-list",children:c.entries.map(z=>o.jsxs("li",{className:"coll-entry-row",children:[o.jsxs("div",{className:"coll-entry-info",children:[o.jsx("span",{className:"coll-entry-title",children:z.title||z.entry_uid}),o.jsx("span",{className:"coll-entry-kind muted",children:z.source_kind})]}),o.jsxs("div",{className:"coll-entry-actions",children:[o.jsx("select",{className:"coll-entry-vis-select",value:z.collection_visibility_bits,onChange:V=>Fl(z.entry_uid,Number(V.target.value)),children:In.map(V=>o.jsx("option",{value:V.value,children:V.label},V.value))}),!we&&o.jsx("button",{className:"coll-entry-remove",onClick:()=>Ml(z.entry_uid),title:"Remove from collection",children:"×"})]})]},z.entry_uid))}))]}),!we&&o.jsxs("form",{className:"coll-add-entry-form",onSubmit:$l,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:T,onChange:z=>R(z.target.value),placeholder:"entry_uid",required:!0}),o.jsx("select",{className:"coll-vis-select",value:I,onChange:z=>U(Number(z.target.value)),children:In.map(z=>o.jsx("option",{value:z.value,children:z.label},z.value))}),o.jsx("button",{className:"coll-add-btn",type:"submit",disabled:E,children:E?"…":"Add"})]}),H&&o.jsx("div",{className:"collections-error",style:{marginTop:4},children:H})]})]}):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",children:[o.jsx("summary",{children:"+ Create collection"}),o.jsxs("form",{className:"coll-create-form",onSubmit:Fe,children:[o.jsxs("div",{className:"form-field",children:[o.jsx("label",{className:"form-label",htmlFor:"coll-name",children:"Name"}),o.jsx("input",{className:"capture-input",id:"coll-name",type:"text",value:j,onChange:z=>{O(z.target.value),f||d(z.target.value.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},placeholder:"My Collection",required:!0})]}),o.jsxs("div",{className:"form-field",children:[o.jsx("label",{className:"form-label",htmlFor:"coll-slug",children:"Slug"}),o.jsx("input",{className:"capture-input",id:"coll-slug",type:"text",value:f,onChange:z=>d(z.target.value),placeholder:"my-collection",required:!0})]}),o.jsxs("div",{className:"form-field",children:[o.jsx("label",{className:"form-label",htmlFor:"coll-vis",children:"Default visibility"}),o.jsx("select",{className:"capture-input",id:"coll-vis",style:{height:42},value:p,onChange:z=>w(Number(z.target.value)),children:In.map(z=>o.jsx("option",{value:z.value,children:z.label},z.value))})]}),P&&o.jsx("div",{className:"collections-error",children:P}),o.jsx("button",{className:"btn-primary",type:"submit",disabled:k,children:k?"Creating…":"Create collection"})]})]})]}):o.jsx("div",{className:"view-placeholder",children:"Select an archive."})}const ph=4;function hh({tab:e,onTabChange:t,archiveId:n}){const{currentUser:r,setCurrentUser:l}=v.useContext(Rl)??{},s=r&&(r.role_bits&ph)!==0,i=["profile","tokens",...s?["instance","storage"]:[]],a={profile:"Profile",tokens:"API Tokens",instance:"Instance",storage:"Storage"};return o.jsxs("section",{className:"admin-view",children:[o.jsx("h1",{children:"Settings"}),o.jsx("div",{className:"view-tabs",children:i.map(u=>o.jsx("button",{className:`view-tab${e===u?" is-active":""}`,onClick:()=>t(u),children:a[u]},u))}),e==="profile"&&o.jsx(mh,{currentUser:r,setCurrentUser:l}),e==="tokens"&&o.jsx(vh,{}),e==="instance"&&s&&o.jsx(gh,{}),e==="storage"&&s&&o.jsx(yh,{archiveId:n})]})}function mh({currentUser:e,setCurrentUser:t}){const[n,r]=v.useState((e==null?void 0:e.display_name)??""),[l,s]=v.useState(!1),[i,a]=v.useState(null),[u,c]=v.useState(""),[g,m]=v.useState(""),[h,x]=v.useState(""),[S,j]=v.useState(!1),[O,f]=v.useState(null);async function d(w){w.preventDefault(),s(!0),a(null);try{await _p(n),t(k=>({...k,display_name:n||null})),a({ok:!0,text:"Saved."})}catch(k){a({ok:!1,text:k.message})}finally{s(!1)}}async function p(w){if(w.preventDefault(),g!==h){f({ok:!1,text:"Passwords do not match."});return}j(!0),f(null);try{await Tp(u,g),c(""),m(""),x(""),f({ok:!0,text:"Password changed."})}catch(k){f({ok:!1,text:k.message})}finally{j(!1)}}return o.jsxs("div",{style:{maxWidth:440},children:[o.jsxs("div",{className:"form-section",children:[o.jsx("h2",{children:"Display Name"}),o.jsxs("form",{onSubmit:d,children:[o.jsxs("div",{className:"form-field",children:[o.jsx("label",{className:"form-label",htmlFor:"display-name",children:"Name shown in the UI"}),o.jsx("input",{className:"field-input",id:"display-name",placeholder:(e==null?void 0:e.username)??"",value:n,onChange:w=>r(w.target.value)})]}),i&&o.jsx("div",{className:`form-msg form-msg--${i.ok?"ok":"err"}`,children:i.text}),o.jsx("button",{className:"btn-primary",type:"submit",disabled:l,children:l?"Saving…":"Save"})]})]}),o.jsxs("div",{className:"form-section",children:[o.jsx("h2",{children:"Display Preferences"}),o.jsxs("label",{className:"checkbox-row",children:[o.jsx("input",{type:"checkbox",checked:(e==null?void 0:e.humanize_slugs)??!1,onChange:async w=>{const k=w.target.checked;try{await Ep({humanize_slugs:k}),t(_=>({..._,humanize_slugs:k}))}catch{}}}),o.jsx("span",{className:"form-label",style:{margin:0},children:"Humanize tag display"})]}),o.jsx("p",{className:"muted",style:{fontSize:13,margin:"4px 0 0"},children:'When on, tag paths show as "X / Articles" instead of "x/articles".'})]}),o.jsxs("div",{className:"form-section",children:[o.jsx("h2",{children:"Change Password"}),o.jsxs("form",{onSubmit:p,children:[o.jsxs("div",{className:"form-field",children:[o.jsx("label",{className:"form-label",htmlFor:"cur-pw",children:"Current password"}),o.jsx("input",{className:"field-input",id:"cur-pw",type:"password",value:u,onChange:w=>c(w.target.value),required:!0})]}),o.jsxs("div",{className:"form-field",children:[o.jsx("label",{className:"form-label",htmlFor:"new-pw",children:"New password"}),o.jsx("input",{className:"field-input",id:"new-pw",type:"password",value:g,onChange:w=>m(w.target.value),required:!0})]}),o.jsxs("div",{className:"form-field",children:[o.jsx("label",{className:"form-label",htmlFor:"confirm-pw",children:"Confirm new password"}),o.jsx("input",{className:"field-input",id:"confirm-pw",type:"password",value:h,onChange:w=>x(w.target.value),required:!0})]}),O&&o.jsx("div",{className:`form-msg form-msg--${O.ok?"ok":"err"}`,children:O.text}),o.jsx("button",{className:"btn-primary",type:"submit",disabled:S,children:S?"Changing…":"Change Password"})]})]})]})}function vh(){const[e,t]=v.useState([]),[n,r]=v.useState(!0),[l,s]=v.useState(null),[i,a]=v.useState(""),[u,c]=v.useState(!1),[g,m]=v.useState(null),h=v.useCallback(async()=>{r(!0),s(null);try{t(await Pp())}catch(j){s(j.message)}finally{r(!1)}},[]);v.useEffect(()=>{h()},[h]);async function x(j){if(j.preventDefault(),!!i.trim()){c(!0);try{const O=await Lp(i.trim());m(O),a(""),h()}catch(O){s(O.message)}finally{c(!1)}}}async function S(j){try{await zp(j),t(O=>O.filter(f=>f.token_uid!==j))}catch(O){s(O.message)}}return o.jsx("div",{style:{maxWidth:600},children:o.jsxs("div",{className:"form-section",children:[o.jsx("h2",{children:"API Tokens"}),g&&o.jsxs("div",{className:"token-banner",children:[o.jsx("strong",{children:"Token created."})," Copy it now — it won't be shown again.",o.jsx("code",{children:g.raw_token}),o.jsx("button",{className:"token-dismiss",onClick:()=>m(null),children:"Dismiss"})]}),o.jsxs("form",{className:"token-create-row",onSubmit:x,children:[o.jsx("input",{className:"field-input field-input--flex",placeholder:"Token name",value:i,onChange:j=>a(j.target.value),required:!0}),o.jsx("button",{className:"btn-primary",type:"submit",disabled:u,children:u?"Creating…":"Create token"})]}),l&&o.jsx("div",{className:"form-msg form-msg--err",children:l}),n?o.jsx("div",{className:"muted",children:"Loading…"}):o.jsxs("div",{children:[e.length===0&&o.jsx("div",{className:"muted",children:"No tokens yet."}),e.map(j=>o.jsxs("div",{className:"token-row",children:[o.jsxs("div",{className:"token-row-info",children:[o.jsx("strong",{children:j.name}),o.jsxs("div",{className:"muted",children:["Created ",j.created_at.slice(0,10),j.last_used_at&&` · Last used ${j.last_used_at.slice(0,10)}`]})]}),o.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"4px 10px"},onClick:()=>S(j.token_uid),children:"Revoke"})]},j.token_uid))]})]})})}function gh(){const[e,t]=v.useState(null),[n,r]=v.useState(!0),[l,s]=v.useState(null),[i,a]=v.useState(!1),[u,c]=v.useState(null);v.useEffect(()=>{(async()=>{try{t(await Rp())}catch(m){s(m.message)}finally{r(!1)}})()},[]);async function g(m){m.preventDefault(),a(!0),c(null);try{await Dp(e),c({ok:!0,text:"Saved."})}catch(h){c({ok:!1,text:h.message})}finally{a(!1)}}return n?o.jsx("div",{className:"muted",children:"Loading…"}):l?o.jsx("div",{className:"form-msg form-msg--err",children:l}):e?o.jsx("div",{style:{maxWidth:440},children:o.jsxs("div",{className:"form-section",children:[o.jsx("h2",{children:"Instance Settings"}),o.jsxs("form",{onSubmit:g,children:[[["public_index_enabled","Public index (unauthenticated browsing)"],["public_entry_content_enabled","Public entry content"],["open_registration_enabled","Open registration"]].map(([m,h])=>o.jsxs("label",{className:"checkbox-row",children:[o.jsx("input",{type:"checkbox",checked:!!e[m],onChange:x=>t(S=>({...S,[m]:x.target.checked}))}),h]},m)),o.jsxs("div",{className:"form-field",style:{marginTop:4},children:[o.jsx("label",{className:"form-label",children:"Default entry visibility"}),o.jsxs("select",{className:"field-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"}),o.jsx("option",{value:2,children:"Unlisted"}),o.jsx("option",{value:3,children:"Public"})]})]}),u&&o.jsx("div",{className:`form-msg form-msg--${u.ok?"ok":"err"}`,children:u.text}),o.jsx("button",{className:"btn-primary",type:"submit",disabled:i,children:i?"Saving…":"Save Settings"})]})]})}):null}function fs(e){if(e===0)return"0 B";const t=["B","KB","MB","GB","TB"],n=Math.floor(Math.log(e)/Math.log(1024));return`${(e/Math.pow(1024,n)).toFixed(n===0?0:1)} ${t[n]}`}function yh({archiveId:e}){const[t,n]=v.useState("idle"),[r,l]=v.useState(null),[s,i]=v.useState(null),[a,u]=v.useState(null);function c(){n("idle"),l(null),i(null),u(null)}async function g(){n("scanning"),u(null),l(null);try{const x=await Yp(e);l(x),n("scanned")}catch(x){u(x.message),n("error")}}async function m(){n("deleting"),u(null);try{const x=await Jp(e);i(x),n("done")}catch(x){u(x.message),n("error")}}const h=r&&r.deletable_files===0&&r.orphaned_blob_rows===0;return o.jsx("div",{style:{maxWidth:440},children:o.jsxs("div",{className:"form-section",children:[o.jsx("h2",{children:"Orphan Cleanup"}),o.jsxs("p",{className:"muted",style:{marginBottom:16},children:["Scan for blob files and database records that are no longer referenced by any archive entry and safely delete them."," ",o.jsx("strong",{children:"Cleanup is blocked while captures are running."})]}),!e&&o.jsx("div",{className:"muted",children:"No archive selected."}),e&&t==="idle"&&o.jsx("button",{className:"btn-ghost",onClick:g,children:"Scan for orphaned blobs"}),t==="scanning"&&o.jsx("div",{className:"muted",children:"Scanning…"}),t==="scanned"&&r&&h&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"form-msg form-msg--ok",children:"Archive is clean — nothing to remove."}),o.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:c,children:"Done"})]}),t==="scanned"&&r&&!h&&o.jsxs("div",{children:[o.jsxs("div",{style:{marginBottom:14,lineHeight:1.6},children:["Found ",o.jsx("strong",{children:r.deletable_files})," unreferenced file",r.deletable_files!==1?"s":""," ","and ",o.jsx("strong",{children:r.orphaned_blob_rows})," orphaned DB record",r.orphaned_blob_rows!==1?"s":""," ","— ",o.jsx("strong",{children:fs(r.total_bytes)})," recoverable."]}),o.jsxs("div",{style:{display:"flex",gap:8},children:[o.jsxs("button",{className:"btn-danger",onClick:m,children:["Delete (",fs(r.total_bytes),")"]}),o.jsx("button",{className:"btn-ghost",onClick:c,children:"Cancel"})]})]}),t==="deleting"&&o.jsx("div",{className:"muted",children:"Deleting…"}),t==="done"&&s&&o.jsxs("div",{children:[o.jsxs("div",{className:"form-msg form-msg--ok",children:["Freed ",o.jsx("strong",{children:fs(s.freed_bytes)})," ","— removed ",s.deleted_files," file",s.deleted_files!==1?"s":""," ","and ",s.deleted_blob_rows," DB record",s.deleted_blob_rows!==1?"s":"","."]}),s.errors&&s.errors.length>0&&o.jsxs("div",{className:"form-msg form-msg--err",style:{marginTop:6},children:[s.errors.length," file",s.errors.length!==1?"s":""," could not be deleted."]}),o.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:c,children:"Scan again"})]}),t==="error"&&o.jsxs("div",{children:[o.jsx("div",{className:"form-msg form-msg--err",children:a}),o.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:c,children:"Try again"})]})]})})}const va={0:"Private",1:"Public",2:"Users only",3:"Public"},wh=()=>o.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:o.jsx("path",{d:"M7 17 17 7M9 7h8v8"})});function xh({archiveId:e,selectedEntry:t,onTagFilterSet:n,tagNodes:r,onTagsRefresh:l,onEntryTitleChange:s,onEntryDeleted:i,humanizeTags:a}){const[u,c]=v.useState(null),[g,m]=v.useState([]),[h,x]=v.useState(""),[S,j]=v.useState([]),[O,f]=v.useState(""),d=v.useRef(0),p=v.useRef(!1),[w,k]=v.useState(!1),[_,P]=v.useState("");v.useEffect(()=>{if(!t||!e){c(null),m([]),j([]);return}k(!1),P(""),p.current=!1;const E=++d.current;c(null),m([]),Promise.all([dp(e,t.entry_uid),cs(e,t.entry_uid),Qp(e,t.entry_uid)]).then(([F,H,Z])=>{E===d.current&&(c(F),m(H),j(Z))}).catch(()=>{})},[t,e]);async function y(){const E=_.trim()||null;try{await fp(e,t.entry_uid,E),c(F=>F&&{...F,summary:{...F.summary,title:E}}),s==null||s(t.entry_uid,E)}catch{}finally{k(!1)}}async function T(){const E=h.trim();if(!(!E||!t))try{await pp(e,t.entry_uid,E),x(""),f("");const F=await cs(e,t.entry_uid);m(F),l()}catch(F){f(F.message)}}async function R(E){try{await hp(e,t.entry_uid,E);const F=await cs(e,t.entry_uid);m(F),l()}catch{}}async function I(){if(!(!t||!e)&&window.confirm("Delete this entry? This cannot be undone."))try{await mp(e,t.entry_uid),i==null||i(t.entry_uid)}catch{}}const U=u?[["Added",zc(u.summary.archived_at)],["Source",u.summary.source_kind],["Type",u.summary.entity_kind],["Visibility",va[u.summary.visibility]??u.summary.visibility],["Root",u.structured_root_relpath]]:[];return o.jsxs("aside",{className:"context-rail",children:[o.jsx("div",{className:"rail-eyebrow",children:"Context"}),t?u?o.jsxs(o.Fragment,{children:[w?o.jsx("input",{className:"rail-title-input",autoFocus:!0,value:_,onChange:E=>P(E.target.value),onKeyDown:E=>{E.key==="Enter"&&E.currentTarget.blur(),E.key==="Escape"&&(p.current=!0,E.currentTarget.blur())},onBlur:()=>{p.current?k(!1):y(),p.current=!1}}):o.jsxs("h2",{className:"rail-title rail-title--editable",title:"Click to rename",onClick:()=>{P(u.summary.title??""),k(!0)},children:[Ut(u.summary.title)||Ut(u.summary.entry_uid),o.jsx("svg",{className:"edit-icon",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:o.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),u.summary.original_url&&o.jsxs("a",{className:"url-tile",href:u.summary.original_url,target:"_blank",rel:"noopener noreferrer",children:[o.jsx("span",{className:"ico",dangerouslySetInnerHTML:{__html:Rc(u.summary.source_kind)}}),o.jsx("span",{className:"u-text",children:u.summary.original_url}),o.jsx("span",{className:"ext",children:o.jsx(wh,{})})]}),o.jsx("div",{className:"meta-list",children:U.filter(([,E])=>E!=null&&E!=="").map(([E,F])=>o.jsxs("div",{className:"meta-item",children:[o.jsx("span",{className:"meta-k",children:E}),o.jsx("span",{className:`meta-v${E==="Root"?" mono":""}`,children:Ut(F)})]},E))}),u.artifacts.length>0&&o.jsxs("div",{className:"rail-section",children:[o.jsxs("div",{className:"rail-section-heading",children:["Artifacts ",o.jsx("span",{className:"num",children:u.artifacts.length})]}),o.jsx("ul",{className:"artifact-list",children:u.artifacts.map((E,F)=>o.jsx("li",{children:o.jsxs("a",{href:`/api/archives/${e}/entries/${u.summary.entry_uid}/artifacts/${F}`,target:"_blank",rel:"noopener noreferrer",className:"artifact-link",children:[o.jsx("span",{className:"artifact-name",children:E.artifact_role.replace(/_/g," ")}),o.jsx("span",{className:"artifact-size",children:E.byte_size!=null?oi(E.byte_size):"—"})]})},F))})]})]}):o.jsx("p",{className:"tags-empty",children:"Loading…"}):o.jsx("p",{className:"tags-empty",children:"Select an entry."}),t&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"rail-section",children:[o.jsx("div",{className:"rail-section-heading",children:"Tags"}),g.length===0?o.jsx("p",{className:"tags-empty",children:"No tags yet."}):o.jsx("div",{className:"tags-wrap",children:g.map(E=>o.jsxs("span",{className:"tag-pill",title:E.full_path,children:[a?Dc(E.full_path):E.full_path,o.jsx("button",{className:"remove",title:`Remove tag ${E.full_path}`,onClick:()=>R(E.tag_uid),children:"×"})]},E.tag_uid))}),O&&o.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:O}),o.jsxs("div",{className:"tag-input-wrap",children:[o.jsx("span",{className:"hash",children:"/"}),o.jsx("input",{className:"tag-input",type:"text",placeholder:"science/cs",autoComplete:"off",value:h,onChange:E=>x(E.target.value),onKeyDown:E=>{E.key==="Enter"&&T()}}),o.jsx("button",{className:"tag-add-btn",onClick:T,children:"Add"})]})]}),S.length>0&&o.jsxs("div",{className:"rail-section",children:[o.jsx("div",{className:"rail-section-heading",children:"Collections"}),S.map(E=>o.jsxs("div",{className:"coll-row",children:[o.jsx("span",{className:"coll-name",children:E.collection_uid}),o.jsx("span",{className:"vis-badge",children:va[E.visibility_bits]??`bits:${E.visibility_bits}`})]},E.collection_uid))]}),o.jsx("div",{className:"rail-delete-zone",children:o.jsx("button",{className:"rail-delete-btn",onClick:I,children:"Delete entry"})})]})]})}const Sh=7e3;function kh({toasts:e,onDismiss:t}){return e.length?o.jsx("div",{className:"toast-stack",role:"log","aria-live":"polite","aria-label":"Notifications",children:e.map(n=>o.jsx(jh,{toast:n,onDismiss:t},n.id))}):null}function jh({toast:e,onDismiss:t}){const[n,r]=v.useState(!1);v.useEffect(()=>{if(n)return;const s=setTimeout(()=>t(e.id),Sh);return()=>clearTimeout(s)},[n,e.id,t]);const l=e.locator?e.locator.length>48?e.locator.slice(0,45)+"…":e.locator:null;return o.jsxs("div",{className:"toast toast--error",role:"alert","aria-atomic":"true",children:[o.jsxs("div",{className:"toast-top",children:[o.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"✕"}),o.jsxs("div",{className:"toast-body",children:[o.jsx("span",{className:"toast-headline",children:"Capture failed"}),l&&o.jsx("span",{className:"toast-locator",children:l})]}),o.jsxs("div",{className:"toast-btns",children:[e.errorText&&o.jsx("button",{type:"button",className:"toast-view-btn",onClick:()=>r(s=>!s),children:n?"Hide":"View error"}),o.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})]})]}),n&&e.errorText&&o.jsx("pre",{className:"toast-error-detail",children:e.errorText})]})}const Rl=v.createContext(null),Nh=["archive","tags","collections","runs","admin","settings"],Ch=["profile","tokens","instance","storage"];function ps(){const e=window.location.pathname.split("/").filter(Boolean),t=Nh.includes(e[0])?e[0]:"archive",n=t==="settings"&&Ch.includes(e[1])?e[1]:"profile";return{view:t,settingsTab:n}}function _h(e,t){return e==="archive"?"/":e==="settings"?`/settings/${t}`:`/${e}`}function Eh(){const[e,t]=v.useState("loading"),[n,r]=v.useState(null);v.useEffect(()=>{(async()=>{if(await Sp()){t("setup");return}const K=await Cp();if(!K){t("login");return}r(K),t("authenticated")})()},[]),v.useEffect(()=>{const $=()=>{r(null),t("login")};return window.addEventListener("auth:expired",$),()=>window.removeEventListener("auth:expired",$)},[]),v.useEffect(()=>{const $=()=>{const{view:K,settingsTab:ce}=ps();f(K),p(ce)};return window.addEventListener("popstate",$),()=>window.removeEventListener("popstate",$)},[]);const[l,s]=v.useState([]),[i,a]=v.useState(null),[u,c]=v.useState([]),[g,m]=v.useState(null),[h,x]=v.useState(null),[S,j]=v.useState(null),[O,f]=v.useState(()=>ps().view),[d,p]=v.useState(()=>ps().settingsTab),[w,k]=v.useState(""),[_,P]=v.useState(""),[y,T]=v.useState(!1),[R,I]=v.useState([]),[U,E]=v.useState([]),[F,H]=v.useState(()=>sessionStorage.getItem("captureDialogOpen")==="true"),[Z,Me]=v.useState([]),L=v.useRef(0),N=(n==null?void 0:n.humanize_slugs)??!1;v.useEffect(()=>{sessionStorage.setItem("captureDialogOpen",F)},[F]);const M=v.useCallback(async($,K,ce)=>{if($){T(!0);try{let Ae;K||ce?Ae=await cp($,K,ce):Ae=await up($),c(Ae),P(Ae.length===0?"No results":`${Ae.length} result${Ae.length===1?"":"s"}`)}catch{c([]),P("Search failed. Try again.")}finally{T(!1)}}},[]);v.useEffect(()=>{e==="authenticated"&&ap().then($=>{if(s($),$.length>0){const K=$[0].id;a(K)}})},[e]),v.useEffect(()=>{i&&(j(null),x(null),m(null),Promise.all([M(i,"",null),fa(i).then(I),ds(i).then(E)]))},[i]),v.useEffect(()=>{if(i===null)return;const $=setTimeout(()=>{M(i,w,S)},300);return()=>clearTimeout($)},[w,i]),v.useEffect(()=>{i!==null&&(S!==null&&f("archive"),M(i,w,S))},[S,i]);const Q=v.useCallback($=>{a($)},[]),A=v.useCallback($=>{f($),$==="tags"&&i&&ds(i).then(E)},[i]);v.useEffect(()=>{const $=_h(O,d);window.location.pathname!==$&&history.pushState(null,"",$)},[O,d]);const we=v.useCallback($=>{m($?$.entry_uid:null),x($)},[]),ue=v.useCallback($=>{j($)},[]),Qe=v.useCallback(()=>{j(null)},[]),Fe=v.useCallback(()=>{i&&ds(i).then(E)},[i]),lt=v.useCallback(($,K)=>{S===$?j(K):S!=null&&S.startsWith($+"/")&&j(K+S.slice($.length))},[S]),Dl=v.useCallback($=>{(S===$||S!=null&&S.startsWith($+"/"))&&j(null)},[S]),Ol=v.useCallback(($,K)=>{c(ce=>ce.map(Ae=>Ae.entry_uid===$?{...Ae,title:K}:Ae)),x(ce=>ce&&ce.entry_uid===$?{...ce,title:K}:ce)},[]),$l=v.useCallback($=>{c(K=>K.filter(ce=>ce.entry_uid!==$)),x(K=>(K==null?void 0:K.entry_uid)===$?null:K),m(K=>K===$?null:K)},[]),Ml=v.useCallback(()=>{H(!0)},[]),Fl=v.useCallback(()=>{H(!1)},[]),z=v.useCallback(()=>{i&&Promise.all([M(i,w,S),fa(i).then(I)])},[i,w,S,M]),V=v.useCallback(($,K)=>{const ce=++L.current;Me(Ae=>[...Ae,{id:ce,errorText:$,locator:K}])},[]),Pe=v.useCallback($=>{Me(K=>K.filter(ce=>ce.id!==$))},[]);return e==="loading"?o.jsx("div",{className:"auth-loading",children:"Loading\\u2026"}):e==="setup"?o.jsx(Zp,{onComplete:()=>t("login")}):e==="login"?o.jsx(Gp,{onLogin:$=>{r($),t("authenticated")}}):o.jsx(Rl.Provider,{value:{currentUser:n,setCurrentUser:r},children:o.jsxs(o.Fragment,{children:[o.jsx(qp,{archives:l,archiveId:i,onArchiveChange:Q,view:O,onViewChange:A,onCaptureClick:Ml}),o.jsxs("main",{className:"app-shell",children:[o.jsxs("div",{className:"workspace",children:[O==="archive"&&o.jsxs("div",{className:"toolbar",children:[o.jsxs("div",{className:"search-field",children:[o.jsx("span",{className:"ico","aria-hidden":"true",children:o.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[o.jsx("circle",{cx:"11",cy:"11",r:"7"}),o.jsx("line",{x1:"16.5",y1:"16.5",x2:"21",y2:"21"})]})}),o.jsx("input",{className:"search-input",type:"search","aria-label":"Search archive","aria-busy":y,placeholder:"Search titles, URLs, types, tags…",value:w,onChange:$=>k($.target.value)}),o.jsx("span",{className:"kbd",children:"⌘K"})]}),o.jsxs("span",{className:"result-count",children:[_&&o.jsxs(o.Fragment,{children:[o.jsx("b",{children:_.split(" ")[0]})," ",_.split(" ").slice(1).join(" ")]}),S&&o.jsxs("button",{className:"tag-filter-badge",onClick:Qe,children:["× ",N?Dc(S):S]})]})]}),O==="archive"&&o.jsx(lh,{entries:u,selectedEntryUid:g,onSelectEntry:we,archiveId:i,tagFilter:S,onClearTagFilter:Qe,searchQuery:w,onSearchChange:k,resultCount:_,searchBusy:y}),O==="runs"&&o.jsx(oh,{runs:R}),O==="admin"&&o.jsx(uh,{archives:l}),O==="tags"&&o.jsx(ch,{archiveId:i,tagNodes:U,tagFilter:S,onTagFilterSet:ue,onViewChange:A,onTagRenamed:lt,onTagDeleted:Dl,onTagsRefresh:Fe,humanizeTags:N}),O==="collections"&&o.jsx(fh,{archiveId:i}),O==="settings"&&o.jsx(hh,{tab:d,onTabChange:p,archiveId:i})]}),o.jsx(xh,{archiveId:i,selectedEntry:h,onTagFilterSet:ue,tagNodes:U,onTagsRefresh:Fe,onEntryTitleChange:Ol,onEntryDeleted:$l,humanizeTags:N})]}),o.jsx(bp,{open:F,archiveId:i,onClose:Fl,onCaptured:z,onToast:V}),o.jsx(kh,{toasts:Z,onDismiss:Pe})]})})}Pc(document.getElementById("root")).render(o.jsx(v.StrictMode,{children:o.jsx(Eh,{})})); diff --git a/crates/archivr-server/static/index.html b/crates/archivr-server/static/index.html index ffd1971..4ba3b8d 100644 --- a/crates/archivr-server/static/index.html +++ b/crates/archivr-server/static/index.html @@ -4,7 +4,7 @@ Archivr - + diff --git a/frontend/src/components/CaptureDialog.jsx b/frontend/src/components/CaptureDialog.jsx index 5b2d9e0..3472664 100644 --- a/frontend/src/components/CaptureDialog.jsx +++ b/frontend/src/components/CaptureDialog.jsx @@ -18,6 +18,11 @@ function isVideoSource(locator) { } } + // ytm: shorthand — track only; playlist is not yet implemented + if (ll.startsWith('ytm:')) { + return !ll.slice(4).startsWith('playlist/') + } + // x: / twitter: / tweet: shorthands — only x:media:ID routes to yt-dlp (Source::X) for (const scheme of ['x:', 'twitter:', 'tweet:']) { if (ll.startsWith(scheme)) { @@ -25,6 +30,9 @@ function isVideoSource(locator) { } } + // spotify: shorthands — all will fail with a clear error; no probe needed + if (ll.startsWith('spotify:')) return false + // Other platform shorthands — all go to yt-dlp if (ll.startsWith('instagram:') || ll.startsWith('facebook:') || ll.startsWith('tiktok:') || ll.startsWith('reddit:') || @@ -32,6 +40,8 @@ function isVideoSource(locator) { // HTTP/HTTPS URLs — match the same regexes and prefix checks as determine_source if (ll.startsWith('http://') || ll.startsWith('https://')) { + // YouTube Music track (watch) — before generic YouTube check + if (/^https?:\/\/music\.youtube\.com\/watch/.test(ll)) return true // YouTube video (watch, youtu.be, shorts) — not playlist or channel if (/^https?:\/\/(?:www\.)?(?:youtu\.be\/[0-9A-Za-z_-]+|youtube\.com\/watch\?v=[0-9A-Za-z_-]+|youtube\.com\/shorts\/[0-9A-Za-z_-]+)/.test(l)) return true // x.com → Source::X → yt-dlp (note: twitter.com URLs fall through to Source::Url, not yt-dlp) @@ -46,6 +56,8 @@ function isVideoSource(locator) { if (/^https?:\/\/(?:www\.)?reddit\.com\//.test(ll) || ll.startsWith('https://redd.it/') || ll.startsWith('http://redd.it/')) return true // Snapchat if (/^https?:\/\/(?:www\.)?snapchat\.com\//.test(ll)) return true + // Spotify — all will fail with a clear error; no probe needed + if (ll.startsWith('https://open.spotify.com/') || ll.startsWith('http://open.spotify.com/')) return false } return false @@ -402,7 +414,7 @@ function CaptureRow({ item, autoFocus, onLocatorChange, onQualityChange, onRemov ref={inputRef} className="capture-input" type="text" - placeholder="https://… · yt:ID · tweet:ID · x:ID" + placeholder="https://… · yt:ID · ytm:ID · tweet:ID · x:ID" value={item.locator} onChange={e => onLocatorChange(e.target.value)} onKeyDown={e => { if (e.key === 'Enter') onSubmit() }} diff --git a/frontend/src/utils.js b/frontend/src/utils.js index 56b0265..6463665 100644 --- a/frontend/src/utils.js +++ b/frontend/src/utils.js @@ -35,6 +35,8 @@ export function formatTimestamp(value) { export const SOURCE_ICONS = { youtube: ``, + youtube_music: ``, + spotify: ``, x: ``, instagram: ``, facebook: ``,