agentic-drive 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.13.0
4
+
5
+ - Add the trusted host `claimResourceRef` helper. Commit app ownership and a reference atomically. Release on direct trash or removal and reclaim on restore. Report ownership conflicts as `REF_CONFLICT`. Require identity 0.12.0.
6
+
3
7
  ## 0.12.0
4
8
 
5
9
  - Add typed embedded navigation with `DriveLocation`, `location`, and `onNavigate`.
package/README.md CHANGED
@@ -134,6 +134,39 @@ try {
134
134
  - A browser page needs the Worker on its own origin for now: the Worker sends no CORS headers.
135
135
  - Share with a subject: `share("/pub", { kind: "human", id: "u2" }, "viewer")`.
136
136
 
137
+ ### Atomic app resource ownership
138
+
139
+ Trusted hosts can call `drive.claimResourceRef(ctx, path, ref, ownership, opts)`.
140
+ Use the same Store for Drive and identity sharing. Check app access first. This
141
+ host-only helper is not exposed by HTTP, CLI, or MCP.
142
+
143
+ ```ts
144
+ const item = await drive.claimResourceRef(ctx, "/Plan", "docs:plan", {
145
+ resourceId: "plan", type: "doc", subject: { kind: "human", id: "ana" },
146
+ });
147
+ await drive.trash(ctx, item.id);
148
+ await drive.restore(ctx, item.id);
149
+ ```
150
+
151
+ The same claim at the same path returns the existing reference, including when
152
+ calls run at the same time. Options accept `parents` to create missing folders.
153
+ Resource ids use 1 to 128 letters, digits, underscores, or hyphens. Resource types
154
+ start with a lowercase letter and use lowercase letters, digits, underscores, or
155
+ hyphens. The reference, resource, and owner grant commit in one transaction. A conflict
156
+ throws `DriveError` with code `REF_CONFLICT` (HTTP status 409). A failed path or
157
+ owner grant leaves no reference or claim. One subject can hold several references.
158
+ Direct trash releases one claim. Restore reacquires it and can conflict with a
159
+ new owner. Trashing a folder only hides its children; their claims stay until
160
+ those references are trashed or removed. Hard removal releases live claims.
161
+ If identity erase has removed an old claim, local trash and removal still succeed.
162
+ They keep any claim that another subject now holds. Call `erasePerson` as part of
163
+ account erase. It clears the subject from claimed references in other drives,
164
+ even when another person made the reference. Restore then restores the item
165
+ without recreating the erased subject's ownership.
166
+ Existing resources must already grant the subject ownership. The identity
167
+ lifecycle keeps existing shares and resources when it releases a claim.
168
+ This helper needs `agentic-identity` 0.12.0 or later.
169
+
137
170
  ### Other exports
138
171
 
139
172
  The root export, `agentic-drive`, also exports these names. The package typings give the type of each one.
@@ -189,7 +222,7 @@ checks), `upload`, `sniffMime`, `DEFAULT_MAX_BYTES` (upload helpers), `buildExpo
189
222
  (account plug-in). See Other exports and Features for behavior and limits.
190
223
 
191
224
  Root types: `ActivityAction`, `ActivityEntry`, `Action`, `Actor`, `ActorKind`,
192
- `Can`, `Ctx`, `Drive`, `DriveDeps`, `ErrorCode`, `Node`, `OnConflict`,
225
+ `Can`, `Ctx`, `Drive`, `DriveDeps`, `ErrorCode`, `Node`, `OnConflict`, `ResourceOwnership`,
193
226
  `UploadOptions`, `SearchQuery`, `BackfillOptions`, `BackfillResult`,
194
227
  `DriveAccount`, and `DriveAccountDeps`. They describe activity, callers, drive
195
228
  operations, uploads, migrations, and account operations.
package/dist/account.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as Actor, D as Drive, C as Ctx } from './drive-9cZ_9xU4.js';
1
+ import { A as Actor, D as Drive, C as Ctx } from './drive-BncyFxBL.js';
2
2
  import 'agentic-identity';
3
3
 
4
4
  interface DriveAccountDeps {
package/dist/account.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  driveAccount
3
- } from "./chunk-ECVUDAHL.js";
4
- import "./chunk-DB4F5EWD.js";
3
+ } from "./chunk-OHDNQ23Q.js";
4
+ import "./chunk-FTIWCBCI.js";
5
5
  export {
6
6
  driveAccount
7
7
  };
@@ -1,6 +1,6 @@
1
1
  // src/version.ts
2
2
  import { createRequire } from "module";
3
- var VERSION = true ? "0.12.0" : readPackageVersion();
3
+ var VERSION = true ? "0.13.0" : readPackageVersion();
4
4
 
5
5
  export {
6
6
  VERSION
@@ -1,5 +1,5 @@
1
1
  // src/drive.ts
2
- import { EraseRefusedError, isMachineMade, StoreConflictError, MAX_FOLDER_DEPTH, PRINCIPAL_KINDS, ROLES, SUBJECT_KINDS, hasScope } from "agentic-identity";
2
+ import { ResourceClaimConflictError, EraseRefusedError, isMachineMade, StoreConflictError, MAX_FOLDER_DEPTH, PRINCIPAL_KINDS, ROLES, SUBJECT_KINDS, hasScope } from "agentic-identity";
3
3
  var ROOT_ID = "root";
4
4
  var NODES = "drive_nodes";
5
5
  var NAMES = "drive_names";
@@ -7,6 +7,7 @@ var ACTIVITY = "drive_activity";
7
7
  var ACTOR_KINDS = PRINCIPAL_KINDS;
8
8
  var DECIDED = /* @__PURE__ */ Symbol("decided");
9
9
  var ERROR_STATUS = Object.freeze({
10
+ REF_CONFLICT: 409,
10
11
  CROSS_DRIVE: 409,
11
12
  INVALID_SHARE: 400,
12
13
  TOO_MANY_ITEMS: 409,
@@ -354,7 +355,7 @@ function createDrive(deps) {
354
355
  if (node.kind !== "folder") throw new DriveError("NOT_A_FOLDER", `${node.name} is not a folder`);
355
356
  return node;
356
357
  }
357
- async function insert(ops, w, ctx, parent, rawName, fields, onConflict) {
358
+ async function insert(ops, w, ctx, parent, rawName, fields, onConflict, fixedId) {
358
359
  let { name, key } = parseName(rawName);
359
360
  const empty = w.fresh.has(parent.id);
360
361
  if (!empty) await need(ctx, "write", parent);
@@ -370,7 +371,7 @@ function createDrive(deps) {
370
371
  name = await freeName(ops, parent.owner, parent.id, name);
371
372
  key = parseName(name).key;
372
373
  }
373
- const id = newId();
374
+ const id = fixedId ?? newId();
374
375
  if (sharing) {
375
376
  const depth = await depthOf(ops, w, parent) + 1;
376
377
  if (depth > MAX_ITEM_DEPTH) throw new DriveError("TOO_DEEP", `an item can sit at most ${MAX_ITEM_DEPTH} folders deep`);
@@ -506,13 +507,31 @@ function createDrive(deps) {
506
507
  throw error;
507
508
  }
508
509
  }
509
- async function transactAs(ctx, fn) {
510
+ async function transactAs(ctx, fn, lifecycle) {
511
+ const run = async (mutate) => {
512
+ if (!lifecycle) return transact(mutate);
513
+ if (!sharing) throw new DriveError("INVALID_SHARE", "sharing is not set up");
514
+ const { ownership: o, id, release } = lifecycle;
515
+ let result;
516
+ try {
517
+ await sharing[release ? "releaseResourceClaim" : "claimResource"](o.resourceId, o.subject, id, async (tx, claims) => {
518
+ result = await mutate(tx);
519
+ if (!release) claims.ensureOwner(o.type);
520
+ });
521
+ } catch (error) {
522
+ if (release && error instanceof ResourceClaimConflictError) return transact(mutate);
523
+ if (error instanceof ResourceClaimConflictError) throw new DriveError("REF_CONFLICT", "the app resource has a conflicting owner or reference");
524
+ if (error instanceof StoreConflictError) throw new DriveError("BUSY", "the drive changed at the same time. Try again.");
525
+ throw error;
526
+ }
527
+ return result;
528
+ };
510
529
  const answers = /* @__PURE__ */ new Map();
511
530
  let runs = 0;
512
531
  let asked = false;
513
532
  for (; ; ) {
514
533
  try {
515
- return await transact((tx) => {
534
+ return await run((tx) => {
516
535
  if (++runs > 2 * MAX_ASKS) throw new DriveError("BUSY", "the drive changed at the same time. Try again.");
517
536
  if (runs > 1 && !asked) answers.clear();
518
537
  asked = false;
@@ -641,7 +660,17 @@ function createDrive(deps) {
641
660
  for (let i = 0; i < rows.length; i += size) {
642
661
  const chunk = rows.slice(i, i + size);
643
662
  for (const node of chunk) if (node.blobKey) await blobs.delete(node.blobKey);
644
- for (const node of chunk) await finishResource(principal, node.id);
663
+ for (const node of chunk) {
664
+ const current = await store.get(NODES, node.id);
665
+ if (current?.resourceOwnership && !current.trashed) await transactAs({ owner: node.owner, actor: node.updatedBy }, async (tx) => {
666
+ const held = await tx.get(NODES, node.id);
667
+ if (held) {
668
+ const { resourceOwnership: _released, resourceOwnerId: _id, resourceOwnerKind: _kind, ...rest } = held;
669
+ await tx.put(NODES, node.id, rest);
670
+ }
671
+ }, { ownership: current.resourceOwnership, id: node.id, release: true });
672
+ await finishResource(principal, node.id);
673
+ }
645
674
  for (const node of chunk) for (const entry of await allWhere(store, ACTIVITY, { itemId: node.id, owner: node.owner })) await store.delete(ACTIVITY, entry.id);
646
675
  await transact(async (tx) => {
647
676
  const held = [];
@@ -801,8 +830,9 @@ function createDrive(deps) {
801
830
  },
802
831
  /** Hides an item and, for a folder, everything under it. Nothing else changes. */
803
832
  async trash(ctx, loc) {
833
+ const probe = await resolve(store, ctx, loc);
804
834
  return transactAs(ctx, async (tx, ctx2) => {
805
- const node = await resolve(tx, ctx2, loc);
835
+ const node = await resolve(tx, ctx2, probe.id);
806
836
  if (node.id === ROOT_ID) throw new DriveError("IS_ROOT", "cannot trash the root");
807
837
  await need(ctx2, "write", node);
808
838
  const claim = await claimId(node.owner, node.parentId, node.nameKey);
@@ -814,7 +844,7 @@ function createDrive(deps) {
814
844
  await tx.put(ACTIVITY, entry.id, entry);
815
845
  if (held?.nodeId === node.id) await tx.delete(NAMES, claim);
816
846
  return trashed;
817
- });
847
+ }, probe.resourceOwnership ? { ownership: probe.resourceOwnership, id: probe.id, release: true } : void 0);
818
848
  },
819
849
  /** Items trashed on their own, newest first. */
820
850
  async listTrash(ctx) {
@@ -835,6 +865,7 @@ function createDrive(deps) {
835
865
  },
836
866
  /** Puts a trashed item back. It needs a live parent folder. */
837
867
  async restore(ctx, id, opts = {}) {
868
+ const ownership = (await fetch(store, ctx, id))?.resourceOwnership;
838
869
  let height = 0;
839
870
  if (sharing && opts.parentId !== void 0) {
840
871
  const probe = await fetch(store, ctx, id);
@@ -844,6 +875,10 @@ function createDrive(deps) {
844
875
  return transactAs(ctx, async (tx, ctx2) => {
845
876
  const node = await fetch(tx, ctx2, id);
846
877
  if (!node || node.id === ROOT_ID) throw new DriveError("NOT_FOUND", `no item ${id}`);
878
+ const current = node.resourceOwnership;
879
+ if (Boolean(current) !== Boolean(ownership) || current?.resourceId !== ownership?.resourceId || current?.type !== ownership?.type || current?.subject?.id !== ownership?.subject?.id || current?.subject?.kind !== ownership?.subject?.kind) {
880
+ throw new DriveError("BUSY", "the reference ownership changed at the same time. Try again.");
881
+ }
847
882
  if (!node.trashed) throw new DriveError("NOT_TRASHED", `${node.name} is not in the trash`);
848
883
  await need(ctx2, "write", node);
849
884
  const parent = opts.parentId === void 0 ? await rawNode(tx, node.parentId, node.owner, ctx2.actor) : await rawNode(tx, opts.parentId, ctx2.owner, ctx2.actor);
@@ -870,7 +905,7 @@ function createDrive(deps) {
870
905
  await tx.put(NAMES, await claimId(parent.owner, parent.id, key), { nodeId: restored.id, owner: parent.owner, parentId: parent.id });
871
906
  if (sharing && parent.id !== node.parentId) await tx.put("resources", restored.id, await resourceDoc(restored, parent));
872
907
  return restored;
873
- });
908
+ }, ownership ? { ownership, id } : void 0);
874
909
  },
875
910
  /** Live items that match every field given, sorted by path. */
876
911
  async search(ctx, q = {}) {
@@ -1021,6 +1056,48 @@ function createDrive(deps) {
1021
1056
  await store.put(ACTIVITY, ...logDoc(ctx, node, "share", { subjectKind: subject.kind, subjectId: subject.id, role: claim.role }));
1022
1057
  return node;
1023
1058
  },
1059
+ /** Trusted host only. Check app access before calling. Own the app resource and create its reference atomically. */
1060
+ async claimResourceRef(ctx, path, ref, ownership, opts = {}) {
1061
+ if (!REF.test(ref)) throw new DriveError("INVALID_REF", "a reference looks like docs:<id>");
1062
+ if (!ownership || typeof ownership !== "object" || typeof ownership.resourceId !== "string" || !/^[A-Za-z0-9_-]{1,128}$/.test(ownership.resourceId) || typeof ownership.type !== "string" || !/^[a-z][a-z0-9_-]*$/.test(ownership.type)) {
1063
+ throw new DriveError("INVALID_REF", "ownership needs a safe resource id and a lowercase resource type");
1064
+ }
1065
+ const subject = parseSubject(ownership.subject);
1066
+ const claim = { ...ownership, subject };
1067
+ for (let attempt = 0; ; attempt++) {
1068
+ let existing = null;
1069
+ try {
1070
+ existing = await resolve(store, ctx, path);
1071
+ } catch (error) {
1072
+ if (!(error instanceof DriveError) || error.code !== "NOT_FOUND") throw error;
1073
+ }
1074
+ const id = existing?.id ?? newId();
1075
+ if (typeof id !== "string" || !/^[A-Za-z0-9_-]{1,128}$/.test(id)) throw new DriveError("INVALID_REF", "the reference needs a safe id");
1076
+ try {
1077
+ return await transactAs(ctx, async (tx, ctx2) => {
1078
+ const w = batch();
1079
+ const { parent, name } = await parentAndName(tx, w, ctx2, path, opts.parents ?? false);
1080
+ const slot = await claimed(tx, parent.owner, parent.id, parseName(name).key);
1081
+ if (slot.node?.id === id) {
1082
+ await need(ctx2, "write", slot.node);
1083
+ const held = slot.node.resourceOwnership;
1084
+ if (slot.node.ref !== ref || !held || held.resourceId !== claim.resourceId || held.type !== claim.type || !held.subject || held.subject.id !== subject.id || held.subject.kind !== subject.kind) {
1085
+ throw new DriveError("REF_CONFLICT", "this path has a conflicting reference");
1086
+ }
1087
+ return slot.node;
1088
+ }
1089
+ if (existing) throw new DriveError("BUSY", "the reference moved at the same time. Try again.");
1090
+ const { node } = await insert(tx, w, ctx2, parent, name, { kind: "ref", ref }, "fail", id);
1091
+ const owned = { ...node, resourceOwnership: claim, resourceOwnerId: subject.id, resourceOwnerKind: subject.kind };
1092
+ w.put(NODES, id, owned);
1093
+ await w.apply(tx);
1094
+ return owned;
1095
+ }, { ownership: claim, id });
1096
+ } catch (error) {
1097
+ if (attempt >= 2 || !(error instanceof DriveError) || error.code !== "NAME_TAKEN") throw error;
1098
+ }
1099
+ }
1100
+ },
1024
1101
  /** An app deleted a document. Its references in this drive go to the trash. Returns how many. */
1025
1102
  async forgetDocument(ctx, ref) {
1026
1103
  if (!REF.test(ref)) throw new DriveError("INVALID_REF", `a reference looks like "docs:<id>", got ${JSON.stringify(ref)}`);
@@ -1121,6 +1198,18 @@ function createDrive(deps) {
1121
1198
  let invites = 0;
1122
1199
  for (const [actor, kind] of heldBy(subjectOf(ctx), ownedAgents)) grants += await sweep(await ofDrive(await allWhere(store, "grants", { subjectId: actor, subjectKind: kind })), "grants");
1123
1200
  for (const actor of actors) invites += await sweep(await ofDrive(await allWhere(store, "invites", { createdBy: actor })), "invites");
1201
+ for (const [actor, kind] of heldBy(subjectOf(ctx), ownedAgents)) {
1202
+ for (const { data } of await allWhere(store, NODES, { resourceOwnerId: actor, resourceOwnerKind: kind })) {
1203
+ const node = data;
1204
+ if (!node.resourceOwnership) continue;
1205
+ await transactAs(ctx, async (tx) => {
1206
+ const current = await tx.get(NODES, node.id);
1207
+ if (current?.resourceOwnerId !== actor || current.resourceOwnerKind !== kind) return;
1208
+ const { resourceOwnership: _claim, resourceOwnerId: _id, resourceOwnerKind: _kind, ...rest } = current;
1209
+ await tx.put(NODES, node.id, rest);
1210
+ }, { ownership: node.resourceOwnership, id: node.id, release: true });
1211
+ }
1212
+ }
1124
1213
  const todo = await madeBy(store, actors);
1125
1214
  for (let i = 0; i < todo.length; i += CHUNK) {
1126
1215
  await transact(async (tx) => {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DriveError,
3
3
  safeMime
4
- } from "./chunk-DB4F5EWD.js";
4
+ } from "./chunk-FTIWCBCI.js";
5
5
 
6
6
  // src/upload.ts
7
7
  var DEFAULT_MAX_BYTES = 25 * 1024 * 1024;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DriveError,
3
3
  publicNode
4
- } from "./chunk-DB4F5EWD.js";
4
+ } from "./chunk-FTIWCBCI.js";
5
5
 
6
6
  // src/account.ts
7
7
  var plain = (value) => JSON.parse(JSON.stringify(value));
@@ -11,6 +11,7 @@ var DriveApiError = class extends Error {
11
11
  };
12
12
  var BASE = "/api/v1/drive";
13
13
  var CODES = {
14
+ REF_CONFLICT: true,
14
15
  NOT_FOUND: true,
15
16
  NAME_TAKEN: true,
16
17
  BLOB_EXISTS: true,
package/dist/cli.js CHANGED
@@ -4,11 +4,11 @@ import {
4
4
  } from "./chunk-AB2RTTHJ.js";
5
5
  import {
6
6
  VERSION
7
- } from "./chunk-J2EPNUYS.js";
7
+ } from "./chunk-6TPC3BUW.js";
8
8
  import {
9
9
  buildExport,
10
10
  upload
11
- } from "./chunk-HJXRMOUY.js";
11
+ } from "./chunk-NPJG2MYP.js";
12
12
  import {
13
13
  AuthError,
14
14
  DriveError,
@@ -22,7 +22,7 @@ import {
22
22
  resolveToken,
23
23
  revokeKey,
24
24
  revokePrincipal
25
- } from "./chunk-DB4F5EWD.js";
25
+ } from "./chunk-FTIWCBCI.js";
26
26
 
27
27
  // src/cli.ts
28
28
  import { createReadStream, realpathSync, writeFileSync } from "fs";
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { i as ErrorCode, N as Node, d as ActivityEntry, S as SearchQuery } from './drive-9cZ_9xU4.js';
2
- export { c as ActivityAction } from './drive-9cZ_9xU4.js';
1
+ import { i as ErrorCode, N as Node, d as ActivityEntry, S as SearchQuery } from './drive-BncyFxBL.js';
2
+ export { c as ActivityAction } from './drive-BncyFxBL.js';
3
3
  import 'agentic-identity';
4
4
 
5
5
  type Role = "viewer" | "commenter" | "editor" | "owner";
package/dist/client.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DriveApiError,
3
3
  createClient
4
- } from "./chunk-SEHT5Q5L.js";
4
+ } from "./chunk-TGOARFYZ.js";
5
5
  export {
6
6
  DriveApiError,
7
7
  createClient
@@ -1,5 +1,5 @@
1
1
  import * as agentic_identity from 'agentic-identity';
2
- import { PrincipalKind, Store, Blobs, PrincipalContext, createSharing, Subject, Role, SubjectKind } from 'agentic-identity';
2
+ import { PrincipalKind, Store, Blobs, PrincipalContext, Subject, SubjectKind, createSharing, Role } from 'agentic-identity';
3
3
 
4
4
  declare const ROOT_ID = "root";
5
5
  declare const ACTOR_KINDS: readonly ["human", "agent_of_human", "agent_of_agent", "agent", "user_token"];
@@ -38,7 +38,17 @@ type Action = "read" | "write" | "delete";
38
38
  type Sharing = ReturnType<typeof createSharing>;
39
39
  /** The seam for access. With `sharing`, the default is a role check through agentic-identity. */
40
40
  type Can = (ctx: Ctx, action: Action, node: Node) => boolean | Promise<boolean>;
41
+ type ResourceOwnership = {
42
+ resourceId: string;
43
+ subject: Subject;
44
+ type: string;
45
+ };
41
46
  type Node = {
47
+ /** Trusted host claim. Kept in trash so restore can reacquire it. */
48
+ resourceOwnership?: ResourceOwnership;
49
+ /** Indexed subject fields let account erase find claims in other drives. */
50
+ resourceOwnerId?: string;
51
+ resourceOwnerKind?: SubjectKind;
42
52
  id: string;
43
53
  owner: string;
44
54
  parentId: string;
@@ -63,7 +73,7 @@ type Node = {
63
73
  /** Set while a purge deletes the item. Nothing can see or change it then. */
64
74
  purging: boolean;
65
75
  };
66
- type ErrorCode = "NOT_FOUND" | "NAME_TAKEN" | "BLOB_EXISTS" | "INVALID_NAME" | "INVALID_PATH" | "INVALID_REF" | "NOT_A_FOLDER" | "NOT_A_FILE" | "MOVE_INTO_SELF" | "TOO_DEEP" | "PARENT_GONE" | "TRASHED" | "NOT_TRASHED" | "IS_ROOT" | "FORBIDDEN" | "BLOB_MISSING" | "TOO_LARGE" | "INVALID_EXPIRY" | "BUSY" | "CROSS_DRIVE" | "INVALID_SHARE" | "TOO_MANY_ITEMS";
76
+ type ErrorCode = "REF_CONFLICT" | "NOT_FOUND" | "NAME_TAKEN" | "BLOB_EXISTS" | "INVALID_NAME" | "INVALID_PATH" | "INVALID_REF" | "NOT_A_FOLDER" | "NOT_A_FILE" | "MOVE_INTO_SELF" | "TOO_DEEP" | "PARENT_GONE" | "TRASHED" | "NOT_TRASHED" | "IS_ROOT" | "FORBIDDEN" | "BLOB_MISSING" | "TOO_LARGE" | "INVALID_EXPIRY" | "BUSY" | "CROSS_DRIVE" | "INVALID_SHARE" | "TOO_MANY_ITEMS";
67
77
  /** The HTTP status of each error code. A host that serves the drive reuses it. */
68
78
  declare const ERROR_STATUS: Readonly<Record<ErrorCode, 400 | 403 | 404 | 409 | 413 | 500>>;
69
79
  declare class DriveError extends Error {
@@ -234,6 +244,10 @@ declare function createDrive(deps: DriveDeps): {
234
244
  parents?: boolean;
235
245
  onConflict?: OnConflict;
236
246
  }): Promise<Node>;
247
+ /** Trusted host only. Check app access before calling. Own the app resource and create its reference atomically. */
248
+ claimResourceRef(ctx: Ctx, path: string, ref: string, ownership: ResourceOwnership, opts?: {
249
+ parents?: boolean;
250
+ }): Promise<Node>;
237
251
  /** An app deleted a document. Its references in this drive go to the trash. Returns how many. */
238
252
  forgetDocument(ctx: Ctx, ref: string): Promise<{
239
253
  trashed: number;
@@ -380,4 +394,4 @@ declare function createDrive(deps: DriveDeps): {
380
394
  }>;
381
395
  };
382
396
 
383
- export { type Actor as A, type Ctx as C, type Drive as D, ERROR_STATUS as E, type Node as N, type OnConflict as O, ROOT_ID as R, type SearchQuery as S, ACTOR_KINDS as a, type Action as b, type ActivityAction as c, type ActivityEntry as d, type ActorKind as e, type Can as f, type DriveDeps as g, DriveError as h, type ErrorCode as i, createDrive as j, parseSubject as k, parseName as p, subjectKindOf as s };
397
+ export { type Actor as A, type Ctx as C, type Drive as D, ERROR_STATUS as E, type Node as N, type OnConflict as O, type ResourceOwnership as R, type SearchQuery as S, ACTOR_KINDS as a, type Action as b, type ActivityAction as c, type ActivityEntry as d, type ActorKind as e, type Can as f, type DriveDeps as g, DriveError as h, type ErrorCode as i, ROOT_ID as j, createDrive as k, parseSubject as l, parseName as p, subjectKindOf as s };
package/dist/embed.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { Item } from './client.js';
3
- import './drive-9cZ_9xU4.js';
3
+ import './drive-BncyFxBL.js';
4
4
  import 'agentic-identity';
5
5
 
6
6
  /** Return true to handle a reference open; false or void keeps the download action. */
package/dist/embed.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DriveApiError,
3
3
  createClient
4
- } from "./chunk-SEHT5Q5L.js";
4
+ } from "./chunk-TGOARFYZ.js";
5
5
 
6
6
  // ui/embed.tsx
7
7
  import { useEffect as useEffect3, useRef as useRef3, useState as useState3 } from "react";
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { O as OnConflict, D as Drive, C as Ctx, N as Node, A as Actor } from './drive-9cZ_9xU4.js';
2
- export { a as ACTOR_KINDS, b as Action, c as ActivityAction, d as ActivityEntry, e as ActorKind, f as Can, g as DriveDeps, h as DriveError, E as ERROR_STATUS, i as ErrorCode, R as ROOT_ID, S as SearchQuery, j as createDrive, p as parseName, k as parseSubject, s as subjectKindOf } from './drive-9cZ_9xU4.js';
1
+ import { O as OnConflict, D as Drive, C as Ctx, N as Node, R as ResourceOwnership, A as Actor } from './drive-BncyFxBL.js';
2
+ export { a as ACTOR_KINDS, b as Action, c as ActivityAction, d as ActivityEntry, e as ActorKind, f as Can, g as DriveDeps, h as DriveError, E as ERROR_STATUS, i as ErrorCode, j as ROOT_ID, S as SearchQuery, k as createDrive, p as parseName, l as parseSubject, s as subjectKindOf } from './drive-BncyFxBL.js';
3
+ import * as agentic_identity from 'agentic-identity';
3
4
  import { Store, Blobs, Doc } from 'agentic-identity';
4
5
  export { B as BackfillOptions, a as BackfillResult, b as backfillAuthorIds, c as backfillResources } from './migrate-B79gRPMu.js';
5
6
  export { DriveAccount, DriveAccountDeps, driveAccount } from './account.js';
@@ -76,6 +77,9 @@ declare function revokeKey(store: Store, token: string): Promise<void>;
76
77
  /** A node as the CLI and MCP print it: no storage keys. `machineMade` is true when the creator is not a human principal. */
77
78
  declare function publicNode(node: Node, path?: string): {
78
79
  machineMade: boolean;
80
+ resourceOwnership?: ResourceOwnership;
81
+ resourceOwnerId?: string;
82
+ resourceOwnerKind?: agentic_identity.SubjectKind;
79
83
  id: string;
80
84
  owner: string;
81
85
  parentId: string;
@@ -95,6 +99,9 @@ declare function publicNode(node: Node, path?: string): {
95
99
  trashedAt: number | null;
96
100
  } | {
97
101
  machineMade: boolean;
102
+ resourceOwnership?: ResourceOwnership;
103
+ resourceOwnerId?: string;
104
+ resourceOwnerKind?: agentic_identity.SubjectKind;
98
105
  id: string;
99
106
  owner: string;
100
107
  parentId: string;
@@ -115,4 +122,4 @@ declare function publicNode(node: Node, path?: string): {
115
122
  path: string;
116
123
  };
117
124
 
118
- export { Actor, AuthError, Ctx, DEFAULT_MAX_BYTES, Drive, Node, OnConflict, type UploadOptions, VERSION, addPrincipal, buildExport, importLegacyLocal, issueKey, openLocal, publicNode, readZip, resolveToken, revokeKey, revokePrincipal, sniffMime, upload, writeZip };
125
+ export { Actor, AuthError, Ctx, DEFAULT_MAX_BYTES, Drive, Node, OnConflict, ResourceOwnership, type UploadOptions, VERSION, addPrincipal, buildExport, importLegacyLocal, issueKey, openLocal, publicNode, readZip, resolveToken, revokeKey, revokePrincipal, sniffMime, upload, writeZip };
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  driveAccount
3
- } from "./chunk-ECVUDAHL.js";
3
+ } from "./chunk-OHDNQ23Q.js";
4
4
  import {
5
5
  importLegacyLocal
6
6
  } from "./chunk-AB2RTTHJ.js";
7
7
  import {
8
8
  VERSION
9
- } from "./chunk-J2EPNUYS.js";
9
+ } from "./chunk-6TPC3BUW.js";
10
10
  import {
11
11
  DEFAULT_MAX_BYTES,
12
12
  buildExport,
@@ -14,7 +14,7 @@ import {
14
14
  sniffMime,
15
15
  upload,
16
16
  writeZip
17
- } from "./chunk-HJXRMOUY.js";
17
+ } from "./chunk-NPJG2MYP.js";
18
18
  import {
19
19
  ACTOR_KINDS,
20
20
  AuthError,
@@ -34,7 +34,7 @@ import {
34
34
  revokeKey,
35
35
  revokePrincipal,
36
36
  subjectKindOf
37
- } from "./chunk-DB4F5EWD.js";
37
+ } from "./chunk-FTIWCBCI.js";
38
38
  export {
39
39
  ACTOR_KINDS,
40
40
  AuthError,
package/dist/mcp.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import { D as Drive, C as Ctx } from './drive-9cZ_9xU4.js';
2
+ import { D as Drive, C as Ctx } from './drive-BncyFxBL.js';
3
3
  import { Store } from 'agentic-identity';
4
4
 
5
5
  declare function createMcpServer(drive: Drive, ctx: Ctx, exportDir: string, store: Store): McpServer;
package/dist/mcp.js CHANGED
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  VERSION
3
- } from "./chunk-J2EPNUYS.js";
3
+ } from "./chunk-6TPC3BUW.js";
4
4
  import {
5
5
  buildExport,
6
6
  upload
7
- } from "./chunk-HJXRMOUY.js";
7
+ } from "./chunk-NPJG2MYP.js";
8
8
  import {
9
9
  ACTOR_KINDS,
10
10
  DriveError,
11
11
  inviteIdentity,
12
12
  publicNode
13
- } from "./chunk-DB4F5EWD.js";
13
+ } from "./chunk-FTIWCBCI.js";
14
14
 
15
15
  // src/mcp.ts
16
16
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
package/dist/worker.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Hono } from 'hono';
2
2
  import { D1Like, R2Like } from 'agentic-identity/cloudflare';
3
3
  import { Store, Blobs } from 'agentic-identity';
4
- import { C as Ctx, D as Drive } from './drive-9cZ_9xU4.js';
5
- export { E as ERROR_STATUS, i as ErrorCode, N as Node } from './drive-9cZ_9xU4.js';
4
+ import { C as Ctx, D as Drive } from './drive-BncyFxBL.js';
5
+ export { E as ERROR_STATUS, i as ErrorCode, N as Node } from './drive-BncyFxBL.js';
6
6
  export { B as BackfillOptions, a as BackfillResult, b as backfillAuthorIds, c as backfillResources } from './migrate-B79gRPMu.js';
7
7
 
8
8
  /**
package/dist/worker.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  DEFAULT_MAX_BYTES,
3
3
  buildExport,
4
4
  upload
5
- } from "./chunk-HJXRMOUY.js";
5
+ } from "./chunk-NPJG2MYP.js";
6
6
  import {
7
7
  DEFAULT_URL_SECONDS,
8
8
  DriveError,
@@ -14,7 +14,7 @@ import {
14
14
  inviteIdentity,
15
15
  publicNode,
16
16
  safeMime
17
- } from "./chunk-DB4F5EWD.js";
17
+ } from "./chunk-FTIWCBCI.js";
18
18
 
19
19
  // src/worker.ts
20
20
  import { Hono } from "hono";
package/llms.txt CHANGED
@@ -39,7 +39,7 @@ checks), `upload`, `sniffMime`, `DEFAULT_MAX_BYTES` (upload helpers), `buildExpo
39
39
  (account plug-in). See README for behavior and limits.
40
40
 
41
41
  Root types: `ActivityAction`, `ActivityEntry`, `Action`, `Actor`, `ActorKind`,
42
- `Can`, `Ctx`, `Drive`, `DriveDeps`, `ErrorCode`, `Node`, `OnConflict`,
42
+ `Can`, `Ctx`, `Drive`, `DriveDeps`, `ErrorCode`, `Node`, `OnConflict`, `ResourceOwnership`,
43
43
  `UploadOptions`, `SearchQuery`, `BackfillOptions`, `BackfillResult`,
44
44
  `DriveAccount`, and `DriveAccountDeps`. They describe activity, callers, drive
45
45
  operations, uploads, migrations, and account operations.
@@ -142,3 +142,5 @@ cancels pending downloads. Explicit file locations return to the parent with
142
142
  replace true on success; an error leaves that explicit location selected.
143
143
  Root returns use "/". A direct location assignment does not notify the host,
144
144
  but a completed download does. Apply popstate with setLocation or React props.
145
+
146
+ Trusted hosts use drive.claimResourceRef(ctx, path, ref, { resourceId, type, subject }, opts) for atomic app ownership. Check app access first. Repeated claims at the same path return the same reference. REF_CONFLICT means ownership or reference conflict. Direct trash releases the claim; restore reacquires it. Folder trash keeps child claims. This helper is not an unchecked HTTP, CLI, or MCP action.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentic-drive",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Store, sort, and share files and folders.",
5
5
  "keywords": [
6
6
  "drive",
@@ -79,7 +79,7 @@
79
79
  "dependencies": {
80
80
  "@modelcontextprotocol/sdk": "^1.12.0",
81
81
  "agentic-design": ">=0.8.0 <1.0.0",
82
- "agentic-identity": ">=0.9.0 <1.0.0",
82
+ "agentic-identity": ">=0.12.0 <1.0.0",
83
83
  "hono": "^4.13.14",
84
84
  "zod": "^4.6.6"
85
85
  },
@@ -46,4 +46,4 @@ Error generating stack: `+a.message+`
46
46
  `)},Hp=function(){var l=parseInt(document.body.getAttribute(_i)||"0",10);return isFinite(l)?l:0},V_=function(){g.useEffect(function(){return document.body.setAttribute(_i,(Hp()+1).toString()),function(){var l=Hp()-1;l<=0?document.body.removeAttribute(_i):document.body.setAttribute(_i,l.toString())}},[])},q_=function(l){var r=l.noRelative,c=l.noImportant,o=l.gapMode,s=o===void 0?"margin":o;V_();var f=g.useMemo(function(){return B_(s)},[s]);return g.createElement(G_,{styles:Y_(f,!r,s,c?"":"!important")})},Ud=!1;if(typeof window<"u")try{zr=Object.defineProperty({},"passive",{get:function(){return Ud=!0,!0}}),window.addEventListener("test",zr,zr),window.removeEventListener("test",zr,zr)}catch{Ud=!1}var zr,Si=Ud?{passive:!1}:!1,I_=function(l){return l.tagName==="TEXTAREA"},_b=function(l,r){if(!(l instanceof Element))return!1;var c=window.getComputedStyle(l);return c[r]!=="hidden"&&!(c.overflowY===c.overflowX&&!I_(l)&&c[r]==="visible")},X_=function(l){return _b(l,"overflowY")},P_=function(l){return _b(l,"overflowX")},Bp=function(l,r){var c=r.ownerDocument,o=r;do{typeof ShadowRoot<"u"&&o instanceof ShadowRoot&&(o=o.host);var s=wb(l,o);if(s){var f=Ob(l,o),h=f[1],v=f[2];if(h>v)return!0}o=o.parentNode}while(o&&o!==c.body);return!1},Q_=function(l){var r=l.scrollTop,c=l.scrollHeight,o=l.clientHeight;return[r,c,o]},K_=function(l){var r=l.scrollLeft,c=l.scrollWidth,o=l.clientWidth;return[r,c,o]},wb=function(l,r){return l==="v"?X_(r):P_(r)},Ob=function(l,r){return l==="v"?Q_(r):K_(r)},Z_=function(l,r){return l==="h"&&r==="rtl"?-1:1},F_=function(l,r,c,o,s){var f=Z_(l,window.getComputedStyle(r).direction),h=f*o,v=c.target,S=r.contains(v),p=!1,E=h>0,y=0,x=0;do{if(!v)break;var O=Ob(l,v),j=O[0],A=O[1],w=O[2],D=A-w-f*j;(j||D)&&wb(l,v)&&(y+=D,x+=j);var T=v.parentNode;v=T&&T.nodeType===Node.DOCUMENT_FRAGMENT_NODE?T.host:T}while(!S&&v!==document.body||S&&(r.contains(v)||r===v));return(E&&Math.abs(y)<1||!E&&Math.abs(x)<1)&&(p=!0),p},Ao=function(l){return"changedTouches"in l?[l.changedTouches[0].clientX,l.changedTouches[0].clientY]:[0,0]},Gp=function(l){return[l.deltaX,l.deltaY]},Yp=function(l){return l&&"current"in l?l.current:l},k_=function(l,r){return l[0]===r[0]&&l[1]===r[1]},J_=function(l){return`
47
47
  .block-interactivity-`.concat(l,` {pointer-events: none;}
48
48
  .allow-interactivity-`).concat(l,` {pointer-events: all;}
49
- `)},$_=0,Ei=[];function W_(l){var r=g.useRef([]),c=g.useRef([0,0]),o=g.useRef(),s=g.useState($_++)[0],f=g.useState(Cb)[0],h=g.useRef(l);g.useEffect(function(){h.current=l},[l]),g.useEffect(function(){if(l.inert){document.body.classList.add("block-interactivity-".concat(s));var A=S_([l.lockRef.current],(l.shards||[]).map(Yp)).filter(Boolean);return A.forEach(function(w){return w.classList.add("allow-interactivity-".concat(s))}),function(){document.body.classList.remove("block-interactivity-".concat(s)),A.forEach(function(w){return w.classList.remove("allow-interactivity-".concat(s))})}}},[l.inert,l.lockRef.current,l.shards]);var v=g.useCallback(function(A,w){if("touches"in A&&A.touches.length===2||A.type==="wheel"&&A.ctrlKey)return!h.current.allowPinchZoom;var D=Ao(A),T=c.current,C="deltaX"in A?A.deltaX:T[0]-D[0],B="deltaY"in A?A.deltaY:T[1]-D[1],z,L=A.target,q=Math.abs(C)>Math.abs(B)?"h":"v";if("touches"in A&&q==="h"&&L.type==="range")return!1;var Z=window.getSelection(),$=Z&&Z.anchorNode,te=$?$===L||$.contains(L):!1;if(te)return!1;var re=Bp(q,L);if(!re)return!0;if(re?z=q:(z=q==="v"?"h":"v",re=Bp(q,L)),!re)return!1;if(!o.current&&"changedTouches"in A&&(C||B)&&(o.current=z),!z)return!0;var le=o.current||z;return F_(le,w,A,le==="h"?C:B)},[]),S=g.useCallback(function(A){var w=A;if(!(!Ei.length||Ei[Ei.length-1]!==f)){var D="deltaY"in w?Gp(w):Ao(w),T=r.current.filter(function(z){return z.name===w.type&&(z.target===w.target||w.target===z.shadowParent)&&k_(z.delta,D)})[0];if(T&&T.should){w.cancelable&&w.preventDefault();return}if(!T){var C=(h.current.shards||[]).map(Yp).filter(Boolean).filter(function(z){return z.contains(w.target)}),B=C.length>0?v(w,C[0]):!h.current.noIsolation;B&&w.cancelable&&w.preventDefault()}}},[]),p=g.useCallback(function(A,w,D,T){var C={name:A,delta:w,target:D,should:T,shadowParent:ew(D)};r.current.push(C),setTimeout(function(){r.current=r.current.filter(function(B){return B!==C})},1)},[]),E=g.useCallback(function(A){c.current=Ao(A),o.current=void 0},[]),y=g.useCallback(function(A){p(A.type,Gp(A),A.target,v(A,l.lockRef.current))},[]),x=g.useCallback(function(A){p(A.type,Ao(A),A.target,v(A,l.lockRef.current))},[]);g.useEffect(function(){return Ei.push(f),l.setCallbacks({onScrollCapture:y,onWheelCapture:y,onTouchMoveCapture:x}),document.addEventListener("wheel",S,Si),document.addEventListener("touchmove",S,Si),document.addEventListener("touchstart",E,Si),function(){Ei=Ei.filter(function(A){return A!==f}),document.removeEventListener("wheel",S,Si),document.removeEventListener("touchmove",S,Si),document.removeEventListener("touchstart",E,Si)}},[]);var O=l.removeScrollBar,j=l.inert;return g.createElement(g.Fragment,null,j?g.createElement(f,{styles:J_(s)}):null,O?g.createElement(q_,{noRelative:l.noRelative,gapMode:l.gapMode}):null)}function ew(l){for(var r=null;l!==null;)l instanceof ShadowRoot&&(r=l.host,l=l.host),l=l.parentNode;return r}var tw=R_(xb,W_),Ab=g.forwardRef(function(l,r){return g.createElement(sc,Un({},l,{ref:r,sideCar:tw}))});Ab.classNames=sc.classNames;var Rb=Ab,nw=function(l){if(typeof document>"u")return null;var r=Array.isArray(l)?l[0]:l;return r.ownerDocument.body},Ti=new WeakMap,Ro=new WeakMap,No={},hd=0,Nb=function(l){return l&&(l.host||Nb(l.parentNode))},aw=function(l,r){return r.map(function(c){if(l.contains(c))return c;var o=Nb(c);return o&&l.contains(o)?o:(console.error("aria-hidden",c,"in not contained inside",l,". Doing nothing"),null)}).filter(function(c){return!!c})},lw=function(l,r,c,o){var s=aw(r,Array.isArray(l)?l:[l]);No[c]||(No[c]=new WeakMap);var f=No[c],h=[],v=new Set,S=new Set(s),p=function(y){!y||v.has(y)||(v.add(y),p(y.parentNode))};s.forEach(p);var E=function(y){!y||S.has(y)||Array.prototype.forEach.call(y.children,function(x){if(v.has(x))E(x);else try{var O=x.getAttribute(o),j=O!==null&&O!=="false",A=(Ti.get(x)||0)+1,w=(f.get(x)||0)+1;Ti.set(x,A),f.set(x,w),h.push(x),A===1&&j&&Ro.set(x,!0),w===1&&x.setAttribute(c,"true"),j||x.setAttribute(o,"true")}catch(D){console.error("aria-hidden: cannot operate on ",x,D)}})};return E(r),v.clear(),hd++,function(){h.forEach(function(y){var x=Ti.get(y)-1,O=f.get(y)-1;Ti.set(y,x),f.set(y,O),x||(Ro.has(y)||y.removeAttribute(o),Ro.delete(y)),O||y.removeAttribute(c)}),hd--,hd||(Ti=new WeakMap,Ti=new WeakMap,Ro=new WeakMap,No={})}},Db=function(l,r,c){c===void 0&&(c="data-aria-hidden");var o=Array.from(Array.isArray(l)?l:[l]),s=nw(l);return s?(o.push.apply(o,Array.from(s.querySelectorAll("[aria-live], script"))),lw(o,s,c,"aria-hidden")):function(){return null}},iw=Object.defineProperty,Bt=(l,r)=>iw(l,"name",{value:r,configurable:!0}),dm="Dialog",[jb,gR]=Ht(dm),[rw,En]=jb(dm),uw=Bt(l=>{const{__scopeDialog:r,children:c,open:o,defaultOpen:s,onOpenChange:f,modal:h=!0}=l,v=g.useRef(null),S=g.useRef(null),{nodes:p,registry:E}=Jd(),[y,x]=_l({prop:o,defaultProp:s??!1,onChange:f,caller:dm}),[O,j]=g.useState(0),[A,w]=g.useState(0);return m.jsx(rw,{scope:r,triggerRef:v,contentRef:S,contentId:la(),titleId:la(),descriptionId:la(),titlePresent:O>0,descriptionPresent:A>0,setTitleCount:j,setDescriptionCount:w,open:y,onOpenChange:x,onOpenToggle:g.useCallback(()=>x(D=>!D),[x]),modal:h,branchNodes:p,branchRegistry:E,children:c})},"Dialog"),ow="DialogTrigger",cw=g.forwardRef(Bt(function(r,c){const{__scopeDialog:o,...s}=r,f=En(ow,o),h=Ie(c,f.triggerRef);return m.jsx(De.button,{type:"button","aria-haspopup":"dialog","aria-expanded":f.open,"aria-controls":f.open?f.contentId:void 0,"data-state":fc(f.open),...s,ref:h,onClick:he(r.onClick,f.onOpenToggle)})},"DialogTrigger")),Mb="DialogPortal",[sw,zb]=jb(Mb,{forceMount:void 0}),fw=Bt(l=>{const{__scopeDialog:r,forceMount:c,children:o,container:s}=l,f=En(Mb,r);return m.jsx(sw,{scope:r,forceMount:c,children:g.Children.map(o,h=>m.jsx(sa,{present:c||f.open,children:m.jsx(uc,{asChild:!0,container:s,children:h})}))})},"DialogPortal"),Ld="DialogOverlay",dw=g.forwardRef(Bt(function(r,c){const o=zb(Ld,r.__scopeDialog),{forceMount:s=o.forceMount,...f}=r,h=En(Ld,r.__scopeDialog);return h.modal?m.jsx(sa,{present:s||h.open,children:m.jsx(hw,{...f,ref:c})}):null},"DialogOverlay")),mw=qa("DialogOverlay.RemoveScroll"),hw=g.forwardRef(Bt(function(r,c){const{__scopeDialog:o,...s}=r,f=En(Ld,o),h=T0(),v=Ie(c,h);return m.jsx(Rb,{as:mw,allowPinchZoom:!0,shards:g.useMemo(()=>[f.contentRef,...f.branchNodes.map(S=>({current:S}))],[f.contentRef,f.branchNodes]),children:m.jsx(De.div,{"data-state":fc(f.open),...s,ref:v,style:{pointerEvents:"auto",...s.style}})})},"DialogOverlayImpl")),Vr="DialogContent",vw=g.forwardRef(Bt(function(r,c){const o=zb(Vr,r.__scopeDialog),{forceMount:s=o.forceMount,...f}=r,h=En(Vr,r.__scopeDialog);return m.jsx(sa,{present:s||h.open,children:h.modal?m.jsx(gw,{...f,ref:c}):m.jsx(yw,{...f,ref:c})})},"DialogContent")),gw=g.forwardRef(Bt(function(r,c){const o=En(Vr,r.__scopeDialog),s=g.useRef(null),f=Ie(c,o.contentRef,s);return g.useEffect(()=>{const h=s.current;if(h)return Db(h)},[]),m.jsx(Ub,{...r,ref:f,trapFocus:o.open,disableOutsidePointerEvents:o.open,onCloseAutoFocus:he(r.onCloseAutoFocus,h=>{h.preventDefault(),o.triggerRef.current?.focus()}),onPointerDownOutside:he(r.onPointerDownOutside,h=>{const v=h.detail.originalEvent,S=v.button===0&&v.ctrlKey===!0;(v.button===2||S)&&h.preventDefault()}),onFocusOutside:he(r.onFocusOutside,h=>h.preventDefault())})},"DialogContentModal")),yw=g.forwardRef(Bt(function(r,c){const o=En(Vr,r.__scopeDialog),s=g.useRef(!1),f=g.useRef(!1);return m.jsx(Ub,{...r,ref:c,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:h=>{r.onCloseAutoFocus?.(h),h.defaultPrevented||(s.current||o.triggerRef.current?.focus(),h.preventDefault()),s.current=!1,f.current=!1},onInteractOutside:h=>{r.onInteractOutside?.(h),h.defaultPrevented||(s.current=!0,h.detail.originalEvent.type==="pointerdown"&&(f.current=!0));const v=h.target;o.triggerRef.current?.contains(v)&&h.preventDefault(),h.detail.originalEvent.type==="focusin"&&f.current&&h.preventDefault()}})},"DialogContentNonModal")),Ub=g.forwardRef(Bt(function(r,c){const{__scopeDialog:o,trapFocus:s,onOpenAutoFocus:f,onCloseAutoFocus:h,"aria-describedby":v,children:S,...p}=r,E=En(Vr,o);return cc(),m.jsx(kd,{registry:E.branchRegistry,children:m.jsx(_0,{asChild:!0,loop:!0,trapped:s,branches:E.branchNodes,onMountAutoFocus:f,onUnmountAutoFocus:h,children:m.jsx(ec,{role:"dialog",id:E.contentId,"aria-labelledby":E.titlePresent?E.titleId:void 0,"aria-describedby":E.descriptionPresent?Hb(v,E.descriptionId):v,"data-state":fc(E.open),...p,ref:c,deferPointerDownOutside:!0,onDismiss:()=>E.onOpenChange(!1),children:S})})})},"DialogContentImpl")),pw=g.forwardRef(Bt(function(r,c){const{__scopeDialog:o,...s}=r,f=En("DialogTitle",o),{setTitleCount:h}=f;return xt(()=>(h(v=>v+1),()=>h(v=>v-1)),[h]),m.jsx(De.h2,{id:f.titleId,...s,ref:c})},"DialogTitle")),bw=g.forwardRef(Bt(function(r,c){const{__scopeDialog:o,...s}=r,f=En("DialogDescription",o),{setDescriptionCount:h}=f;return xt(()=>(h(v=>v+1),()=>h(v=>v-1)),[h]),m.jsx(De.p,{id:f.descriptionId,...s,ref:c})},"DialogDescription")),Sw="DialogClose",Lb=g.forwardRef(Bt(function(r,c){const{__scopeDialog:o,...s}=r,f=En(Sw,o);return m.jsx(De.button,{type:"button",...s,ref:c,onClick:he(r.onClick,()=>f.onOpenChange(!1))})},"DialogClose"));function Hb(...l){const r=new Set;for(const c of l)if(typeof c=="string")for(const o of String(c).trim().split(/\s+/))o&&r.add(o);return r.size>0?Array.from(r).join(" "):void 0}Bt(Hb,"concatAriaDescribedby");function fc(l){return l?"open":"closed"}Bt(fc,"getState");var Ew=Object.defineProperty,ut=(l,r)=>Ew(l,"name",{value:r,configurable:!0});function dc(l){const r=l+"CollectionProvider",[c,o]=Ht(r),[s,f]=c(r,{collectionRef:{current:null},itemMap:new Map}),h=ut(A=>{const{scope:w,children:D}=A,T=g.useRef(null),C=g.useRef(new Map).current;return m.jsx(s,{scope:w,itemMap:C,collectionRef:T,children:D})},"CollectionProvider");h.displayName=r;const v=l+"CollectionSlot",S=qa(v),p=g.forwardRef((A,w)=>{const{scope:D,children:T}=A,C=f(v,D),B=Ie(w,C.collectionRef);return m.jsx(S,{ref:B,children:T})});p.displayName=v;const E=l+"CollectionItemSlot",y="data-radix-collection-item",x=qa(E),O=g.forwardRef((A,w)=>{const{scope:D,children:T,...C}=A,B=g.useRef(null),z=Ie(w,B),L=f(E,D);return g.useEffect(()=>(L.itemMap.set(B,{ref:B,...C}),()=>{L.itemMap.delete(B)})),m.jsx(x,{[y]:"",ref:z,children:T})});O.displayName=E;function j(A){const w=f(l+"CollectionConsumer",A);return g.useCallback(()=>{const T=w.collectionRef.current;if(!T)return[];const C=Array.from(T.querySelectorAll(`[${y}]`));return Array.from(w.itemMap.values()).sort((L,q)=>C.indexOf(L.ref.current)-C.indexOf(q.ref.current))},[w.collectionRef,w.itemMap])}return ut(j,"useCollection"),[{Provider:h,Slot:p,ItemSlot:O},j,o]}ut(dc,"createCollection");var Vp=new WeakMap,$e,$t,Do=($t=class extends Map{constructor(c){super(c);ap(this,$e);Wf(this,$e,[...super.keys()]),Vp.set(this,!0)}set(c,o){return Vp.get(this)&&!this.has(c)&&Et(this,$e).push(c),super.set(c,o),this}insert(c,o,s){const f=this.has(o),h=f?this.size:this.size+1,v=mm(c),S=v>=0?Math.min(v,h-1):Math.max(h+v,0);if(f?Et(this,$e).indexOf(o)===S:S===this.size)return this.set(o,s),this;const p=Et(this,$e).filter(y=>y!==o);p.splice(S,0,o);const E=p.map(y=>[y,y===o?s:this.get(y)]);this.clear();for(const[y,x]of E)this.set(y,x);return this}with(c,o,s){const f=new $t(this);return f.insert(c,o,s),f}before(c){const o=Et(this,$e).indexOf(c)-1;if(!(o<0))return this.entryAt(o)}setBefore(c,o,s){const f=Et(this,$e).indexOf(c);if(f===-1)return this;const h=Et(this,$e).indexOf(o),v=h!==-1&&h<f?f-1:f;return this.insert(v,o,s)}after(c){let o=Et(this,$e).indexOf(c);if(o=o===-1||o===this.size-1?-1:o+1,o!==-1)return this.entryAt(o)}setAfter(c,o,s){const f=Et(this,$e).indexOf(c);if(f===-1)return this;const h=Et(this,$e).indexOf(o),v=h!==-1&&h<=f?f:f+1;return this.insert(v,o,s)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return Wf(this,$e,[]),super.clear()}delete(c){const o=super.delete(c);return o&&Et(this,$e).splice(Et(this,$e).indexOf(c),1),o}deleteAt(c){const o=this.keyAt(c);return o!==void 0?this.delete(o):!1}at(c){const o=Go(Et(this,$e),c);if(o!==void 0)return this.get(o)}entryAt(c){const o=Go(Et(this,$e),c);if(o!==void 0)return[o,this.get(o)]}indexOf(c){return Et(this,$e).indexOf(c)}keyAt(c){return Go(Et(this,$e),c)}from(c,o){const s=this.indexOf(c);if(s===-1)return;let f=s+o;return f<0&&(f=0),f>=this.size&&(f=this.size-1),this.at(f)}keyFrom(c,o){const s=this.indexOf(c);if(s===-1)return;let f=s+o;return f<0&&(f=0),f>=this.size&&(f=this.size-1),this.keyAt(f)}find(c,o){let s=0;for(const f of this){if(Reflect.apply(c,o,[f,s,this]))return f;s++}}findIndex(c,o){let s=0;for(const f of this){if(Reflect.apply(c,o,[f,s,this]))return s;s++}return-1}filter(c,o){const s=[];let f=0;for(const h of this)Reflect.apply(c,o,[h,f,this])&&s.push(h),f++;return new $t(s)}map(c,o){const s=[];let f=0;for(const h of this)s.push([h[0],Reflect.apply(c,o,[h,f,this])]),f++;return new $t(s)}reduce(...c){const[o,s]=c,f=c.length>1;if(!f&&this.size===0)throw new TypeError("Reduce of empty OrderedDict with no initial value");let h=0,v=s;for(const S of this)h===0&&!f?v=S:v=Reflect.apply(o,this,[v,S,h,this]),h++;return v}reduceRight(...c){const[o,s]=c,f=c.length>1;if(!f&&this.size===0)throw new TypeError("Reduce of empty OrderedDict with no initial value");let h=s;for(let v=this.size-1;v>=0;v--){const S=this.entryAt(v);v===this.size-1&&!f?h=S:h=Reflect.apply(o,this,[h,S,v,this])}return h}sort(c){if(typeof c!="function")throw new TypeError("OrderedDict.sort requires a compare function");const o=[...this.entries()].sort(c);this.clear();for(const[s,f]of o)this.set(s,f);return this}toSorted(c){if(typeof c!="function")throw new TypeError("OrderedDict.toSorted requires a compare function");const o=[...this.entries()].sort(c);return new $t(o)}toReversed(){const c=new $t;for(let o=this.size-1;o>=0;o--){const s=this.keyAt(o),f=this.get(s);c.set(s,f)}return c}toSpliced(...c){const o=[...this.entries()];return o.splice(...c),new $t(o)}slice(c,o){const s=new $t;for(const f of Et(this,$e).slice(c,o))s.set(f,this.get(f));return s}every(c,o){let s=0;for(const f of this){if(!Reflect.apply(c,o,[f,s,this]))return!1;s++}return!0}some(c,o){let s=0;for(const f of this){if(Reflect.apply(c,o,[f,s,this]))return!0;s++}return!1}},$e=new WeakMap,ut($t,"OrderedDict"),$t);function Go(l,r){if("at"in Array.prototype)return Array.prototype.at.call(l,r);const c=Bb(l,r);return c===-1?void 0:l[c]}ut(Go,"at");function Bb(l,r){const c=l.length,o=mm(r),s=o>=0?o:c+o;return s<0||s>=c?-1:s}ut(Bb,"toSafeIndex");function mm(l){return l!==l||l===0?0:Math.trunc(l)}ut(mm,"toSafeInteger");function Tw(l){const r=l+"CollectionProvider",[c,o]=Ht(r),[s,f]=c(r);s.displayName=l+"CollectionStableContextProvider";const[h,v]=c(r);h.displayName=l+"CollectionStatefulContextProvider";const S=ut(({state:L,...q})=>L?m.jsx(E,{...q,state:L}):m.jsx(p,{...q}),"CollectionProvider");S.displayName=r;const p=ut(L=>{const q=T();return m.jsx(E,{...L,state:q})},"CollectionInit");p.displayName=l+"CollectionInit";const E=ut(L=>{const{scope:q,children:Z,state:$}=L,te=g.useRef(null),[re,le]=g.useState(null),ae=Ie(te,le),[se,J]=$,Y=g.useRef(new Do),k=g.useCallback(()=>{const K=Y.current;return Vb(K)||K.sort(Yo),K},[]);return g.useEffect(()=>{if(!re)return;const K=qb(()=>{J(ne=>{const W=ne.toSorted(Yo);return W.some(([Be],Pe)=>ne.keyAt(Pe)!==Be)?W:ne})});return K.observe(re,{childList:!0,subtree:!0}),()=>{K.disconnect()}},[re,J]),m.jsx(s,{scope:q,collectionElementRef:ae,collectionElementRefObject:te,getCollection:k,setCollection:J,registryRef:Y,children:m.jsx(h,{scope:q,collectionElement:re,collection:se,children:Z})})},"CollectionProviderImpl");E.displayName=l+"CollectionProviderImpl";const y=l+"CollectionSlot",x=qa(y),O=g.forwardRef((L,q)=>{const{scope:Z,children:$}=L,te=f(y,Z),re=Ie(q,te.collectionElementRef);return m.jsx(x,{ref:re,children:$})});O.displayName=y;const j=l+"CollectionItemSlot",A="data-radix-collection-item",w=qa(j),D=g.forwardRef((L,q)=>{const{scope:Z,children:$,...te}=L,re=g.useRef(null),le=f(j,Z),{setCollection:ae,registryRef:se}=le,J=g.useRef(te);Gb(J.current,te)||(J.current=te);const Y=J.current,k=g.useCallback(W=>{const fe=se.current;W?fe.set(W,{...J.current,element:W}):re.current&&fe.delete(re.current)},[se]),K=Ie(q,k,re);xt(()=>{const W=re.current,fe=se.current;W&&fe.has(W)&&fe.set(W,{...Y,element:W})},[Y,se]);const ne=g.useRef(null);return g.useEffect(()=>{const W=re.current,fe=ne.current;(fe?.element??null)===W&&(!W||fe?.itemData===Y)||(ne.current=W?{element:W,itemData:Y}:null,ae(Be=>{const Pe=new Do(Be);return fe&&fe.element!==W&&Pe.delete(fe.element),W&&Pe.set(W,{...Y,element:W}),Pe.sort(Yo)}))}),g.useEffect(()=>()=>{const W=ne.current;ne.current=null,W&&ae(fe=>{if(!fe.has(W.element))return fe;const Be=new Do(fe);return Be.delete(W.element),Be})},[ae]),m.jsx(w,{[A]:"",ref:K,children:$})});D.displayName=j;function T(){return g.useState(new Do)}ut(T,"useInitCollection");function C(L){const{collection:q}=v(l+"CollectionConsumer",L);return q}ut(C,"useCollection");function B(L){const{getCollection:q}=f(l+"CollectionConsumer",L);return q}return ut(B,"useGetCollection"),[{Provider:S,Slot:O,ItemSlot:D},{createCollectionScope:o,useCollection:C,useGetCollection:B,useInitCollection:T}]}ut(Tw,"createCollection");function Gb(l,r){if(l===r)return!0;if(typeof l!="object"||typeof r!="object"||l==null||r==null)return!1;const c=Object.keys(l),o=Object.keys(r);if(c.length!==o.length)return!1;for(const s of c)if(!Object.prototype.hasOwnProperty.call(r,s)||l[s]!==r[s])return!1;return!0}ut(Gb,"shallowEqual");function Yb(l,r){return!!(r.compareDocumentPosition(l)&Node.DOCUMENT_POSITION_PRECEDING)}ut(Yb,"isElementPreceding");function Vb(l){let r;for(const c of l.keys()){if(r){const o=r.compareDocumentPosition(c);if(!(o&Node.DOCUMENT_POSITION_DISCONNECTED)&&o&Node.DOCUMENT_POSITION_PRECEDING)return!1}r=c}return!0}ut(Vb,"isInDocumentOrder");function Yo(l,r){return!l[1].element||!r[1].element?0:Yb(l[1].element,r[1].element)?-1:1}ut(Yo,"sortByDocumentPosition");function qb(l){return new MutationObserver(c=>{for(const o of c)if(o.type==="childList"){l();return}})}ut(qb,"getChildListObserver");var xw=Object.defineProperty,Cw=(l,r)=>xw(l,"name",{value:r,configurable:!0}),_w={LTR:"ltr"},ww=g.createContext(void 0);function Kr(l){const r=g.useContext(ww);return l||r||_w.LTR}Cw(Kr,"useDirection");var Ow=Object.defineProperty,hm=(l,r)=>Ow(l,"name",{value:r,configurable:!0}),vd=!1;function Ib(){const[l,r]=g.useState(vd);return g.useEffect(()=>{vd||(vd=!0,r(!0))},[]),l}hm(Ib,"useIsHydrated");var Xb=Pa[" useSyncExternalStore ".trim().toString()];function Pb(){return()=>{}}hm(Pb,"subscribe");function Qb(){return Xb(Pb,()=>!0,()=>!1)}hm(Qb,"useIsHydratedModern");var Aw=typeof Xb=="function"?Qb:Ib,Rw=Object.defineProperty,wl=(l,r)=>Rw(l,"name",{value:r,configurable:!0}),gd="rovingFocusGroup.onEntryFocus",Nw={bubbles:!1,cancelable:!0},mc="RovingFocusGroup",[Hd,Kb,Dw]=dc(mc),[jw,Ka]=Ht(mc,[Dw]),qp={Vertical:"vertical",Horizontal:"horizontal"},Mw={RTL:"rtl"},[zw,Uw]=jw(mc),vm=g.forwardRef(wl(function(r,c){return m.jsx(Hd.Provider,{scope:r.__scopeRovingFocusGroup,children:m.jsx(Hd.Slot,{scope:r.__scopeRovingFocusGroup,children:m.jsx(Lw,{...r,ref:c})})})},"RovingFocusGroup")),Lw=g.forwardRef(wl(function(r,c){const{__scopeRovingFocusGroup:o,orientation:s,loop:f=!1,dir:h,currentTabStopId:v,defaultCurrentTabStopId:S,onCurrentTabStopIdChange:p,onEntryFocus:E,preventScrollOnEntryFocus:y=!1,...x}=r,O=g.useRef(null),j=Ie(c,O),A=Kr(h),[w,D]=_l({prop:v,defaultProp:S??null,onChange:p,caller:mc}),[T,C]=g.useState(!1),B=Wt(E),z=Kb(o),L=g.useRef(!1),[q,Z]=g.useState(0);return g.useEffect(()=>{const $=O.current;if($)return $.addEventListener(gd,B),()=>$.removeEventListener(gd,B)},[B]),m.jsx(zw,{scope:o,orientation:s,dir:A,loop:f,currentTabStopId:w,onItemFocus:g.useCallback($=>D($),[D]),onItemShiftTab:g.useCallback(()=>C(!0),[]),onFocusableItemAdd:g.useCallback(()=>Z($=>$+1),[]),onFocusableItemRemove:g.useCallback(()=>Z($=>$-1),[]),children:m.jsx(De.div,{tabIndex:T||q===0?-1:0,"data-orientation":s,...x,ref:j,style:{outline:"none",...r.style},onMouseDown:he(r.onMouseDown,()=>{L.current=!0}),onFocus:he(r.onFocus,$=>{const te=!L.current;if($.target===$.currentTarget&&te&&!T){const re=new CustomEvent(gd,Nw);if($.currentTarget.dispatchEvent(re),!re.defaultPrevented){const le=z().filter(k=>k.focusable),ae=le.find(k=>k.active),se=le.find(k=>k.id===w),Y=[ae,se,...le].filter(Boolean).map(k=>k.ref.current);ym(Y,y)}}L.current=!1}),onBlur:he(r.onBlur,()=>C(!1))})})},"RovingFocusGroupImpl")),Hw="RovingFocusGroupItem",gm=g.forwardRef(wl(function(r,c){const{__scopeRovingFocusGroup:o,focusable:s=!0,active:f=!1,tabStopId:h,children:v,...S}=r,p=la(),E=h||p,y=Uw(Hw,o),x=y.currentTabStopId===E,O=Kb(o),{onFocusableItemAdd:j,onFocusableItemRemove:A,currentTabStopId:w}=y,D=Aw();return xt(()=>{if(!(!D||!s))return j(),()=>A()},[D,s,j,A]),g.useEffect(()=>{if(!(D||!s))return j(),()=>A()},[D,s,j,A]),m.jsx(Hd.ItemSlot,{scope:o,id:E,focusable:s,active:f,children:m.jsx(De.span,{tabIndex:x?0:-1,"data-orientation":y.orientation,...S,ref:c,onMouseDown:he(r.onMouseDown,T=>{s?y.onItemFocus(E):T.preventDefault()}),onFocus:he(r.onFocus,()=>y.onItemFocus(E)),onKeyDown:he(r.onKeyDown,T=>{if(T.key==="Tab"&&T.shiftKey){y.onItemShiftTab();return}if(T.target!==T.currentTarget)return;const C=Fb(T,y.orientation,y.dir);if(C!==void 0){if(T.metaKey||T.ctrlKey||T.altKey||T.shiftKey)return;T.preventDefault();let z=O().filter(L=>L.focusable).map(L=>L.ref.current);if(C==="last")z.reverse();else if(C==="prev"||C==="next"){C==="prev"&&z.reverse();const L=z.indexOf(T.currentTarget);z=y.loop?kb(z,L+1):z.slice(L+1)}setTimeout(()=>ym(z))}}),children:typeof v=="function"?v({isCurrentTabStop:x,hasTabStop:w!=null}):v})})},"RovingFocusGroupItem")),Bw={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Zb(l,r){return r!==Mw.RTL?l:l==="ArrowLeft"?"ArrowRight":l==="ArrowRight"?"ArrowLeft":l}wl(Zb,"getDirectionAwareKey");function Fb(l,r,c){const o=Zb(l.key,c);if(!(r===qp.Vertical&&["ArrowLeft","ArrowRight"].includes(o))&&!(r===qp.Horizontal&&["ArrowUp","ArrowDown"].includes(o)))return Bw[o]}wl(Fb,"getFocusIntent");function ym(l,r=!1){const c=document.activeElement;for(const o of l)if(o===c||(o.focus({preventScroll:r}),document.activeElement!==c))return}wl(ym,"focusFirst");function kb(l,r){return l.map((c,o)=>l[(r+o)%l.length])}wl(kb,"wrapArray");var Gw=Object.defineProperty,qe=(l,r)=>Gw(l,"name",{value:r,configurable:!0}),Yw=["Enter"," "],Vw=["ArrowDown","PageUp","Home"],Jb=["ArrowUp","PageDown","End"],qw=[...Vw,...Jb],hc="Menu",[Bd,Iw,Xw]=dc(hc),[Ol,$b]=Ht(hc,[Xw,Mi,Ka]),pm=Mi(),Wb=Ka(),[Pw,Zr]=Ol(hc),[Qw,bm]=Ol(hc),Kw=qe(l=>{const{__scopeMenu:r,open:c=!1,children:o,dir:s,onOpenChange:f,modal:h=!0}=l,v=pm(r),[S,p]=g.useState(null),E=g.useRef(!1),y=Wt(f),x=Kr(s);return g.useEffect(()=>{const O=qe(()=>{E.current=!0,document.addEventListener("pointerdown",j,{capture:!0,once:!0}),document.addEventListener("pointermove",j,{capture:!0,once:!0})},"handleKeyDown"),j=qe(()=>E.current=!1,"handlePointer");return document.addEventListener("keydown",O,{capture:!0}),()=>{document.removeEventListener("keydown",O,{capture:!0}),document.removeEventListener("pointerdown",j,{capture:!0}),document.removeEventListener("pointermove",j,{capture:!0})}},[]),g.useEffect(()=>{if(!c)return;const O=qe(()=>y(!1),"handleBlur");return window.addEventListener("blur",O),()=>window.removeEventListener("blur",O)},[c,y]),m.jsx(Z0,{...v,children:m.jsx(Pw,{scope:r,open:c,onOpenChange:y,content:S,onContentChange:p,children:m.jsx(Qw,{scope:r,onClose:g.useCallback(()=>y(!1),[y]),isUsingKeyboardRef:E,dir:x,modal:h,children:o})})})},"Menu"),Zw=g.forwardRef(qe(function(r,c){const{__scopeMenu:o,...s}=r,f=pm(o);return m.jsx(F0,{...f,...s,ref:c})},"MenuAnchor")),eS="MenuPortal",[Fw,kw]=Ol(eS,{forceMount:void 0}),Jw=qe(l=>{const{__scopeMenu:r,forceMount:c,children:o,container:s}=l,f=Zr(eS,r);return m.jsx(Fw,{scope:r,forceMount:c,children:m.jsx(sa,{present:c||f.open,children:m.jsx(uc,{asChild:!0,container:s,children:o})})})},"MenuPortal"),Va="MenuContent",[$w,tS]=Ol(Va),Ww=g.forwardRef(qe(function(r,c){const o=kw(Va,r.__scopeMenu),{forceMount:s=o.forceMount,...f}=r,h=Zr(Va,r.__scopeMenu),v=bm(Va,r.__scopeMenu);return m.jsx(Bd.Provider,{scope:r.__scopeMenu,children:m.jsx(sa,{present:s||h.open,children:m.jsx(Bd.Slot,{scope:r.__scopeMenu,children:v.modal?m.jsx(eO,{...f,ref:c}):m.jsx(tO,{...f,ref:c})})})})},"MenuContent")),eO=g.forwardRef(qe(function(r,c){const o=Zr(Va,r.__scopeMenu),s=g.useRef(null),f=Ie(c,s);return g.useEffect(()=>{const h=s.current;if(h)return Db(h)},[]),m.jsx(nS,{...r,ref:f,trapFocus:o.open,disableOutsidePointerEvents:o.open,disableOutsideScroll:!0,onFocusOutside:he(r.onFocusOutside,h=>h.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>o.onOpenChange(!1)})},"MenuRootContentModal")),tO=g.forwardRef(qe(function(r,c){const o=Zr(Va,r.__scopeMenu);return m.jsx(nS,{...r,ref:c,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>o.onOpenChange(!1)})},"MenuRootContentNonModal")),nO=qa("MenuContent.ScrollLock"),nS=g.forwardRef(qe(function(r,c){const{__scopeMenu:o,loop:s=!1,trapFocus:f,onOpenAutoFocus:h,onCloseAutoFocus:v,disableOutsidePointerEvents:S,onEntryFocus:p,onEscapeKeyDown:E,onPointerDownOutside:y,onFocusOutside:x,onInteractOutside:O,onDismiss:j,disableOutsideScroll:A,...w}=r,D=Zr(Va,o),T=bm(Va,o),C=pm(o),B=Wb(o),z=Iw(o),[L,q]=g.useState(null),Z=g.useRef(null),[$,te]=g.useState(null);$d($);const{nodes:re,registry:le}=Jd(),ae=!!(f||A),se=Ie(c,Z,D.onContentChange,te),J=g.useRef(0),Y=g.useRef(""),k=g.useRef(0),K=g.useRef(null),ne=g.useRef("right"),W=g.useRef(0),fe=g.useMemo(()=>A?[Z,...re.map(F=>({current:F}))]:[],[Z,re,A]),Be=A?Rb:g.Fragment,Pe=A?{as:nO,allowPinchZoom:!0,shards:fe}:void 0,N=qe(F=>{const oe=Y.current+F,ye=z().filter(Ke=>!Ke.disabled),pe=document.activeElement,Te=ye.find(Ke=>Ke.ref.current===pe)?.textValue,ue=ye.map(Ke=>Ke.textValue),me=uS(ue,oe,Te),mt=ye.find(Ke=>Ke.textValue===me)?.ref.current;function Gt(Ke){Y.current=Ke,window.clearTimeout(J.current),Ke!==""&&(J.current=window.setTimeout(()=>Gt(""),1e3))}qe(Gt,"updateSearch"),Gt(oe),mt&&setTimeout(()=>mt.focus())},"handleTypeaheadSearch");g.useEffect(()=>()=>window.clearTimeout(J.current),[]),cc();const I=g.useCallback(F=>ne.current===K.current?.side&&cS(F,K.current?.area),[]);return m.jsx($w,{scope:o,searchRef:Y,onItemEnter:g.useCallback(F=>{I(F)&&F.preventDefault()},[I]),onItemLeave:g.useCallback(F=>{I(F)||(Z.current?.focus(),q(null))},[I]),onTriggerLeave:g.useCallback(F=>{I(F)&&F.preventDefault()},[I]),pointerGraceTimerRef:k,onPointerGraceIntentChange:g.useCallback(F=>{K.current=F},[]),children:m.jsx(kd,{registry:ae?le:null,children:m.jsx(Be,{...Pe,children:m.jsx(_0,{asChild:!0,trapped:f,branches:re,onMountAutoFocus:he(h,F=>{F.preventDefault(),Z.current?.focus({preventScroll:!0})}),onUnmountAutoFocus:v,children:m.jsx(ec,{asChild:!0,disableOutsidePointerEvents:S,onEscapeKeyDown:E,onPointerDownOutside:y,onFocusOutside:x,onInteractOutside:O,onDismiss:j,children:m.jsx(vm,{asChild:!0,...B,dir:T.dir,orientation:"vertical",loop:s,currentTabStopId:L,onCurrentTabStopIdChange:q,onEntryFocus:he(p,F=>{T.isUsingKeyboardRef.current||F.preventDefault()}),preventScrollOnEntryFocus:!0,children:m.jsx(J0,{role:"menu","aria-orientation":"vertical","data-state":aS(D.open),"data-radix-menu-content":"",dir:T.dir,...C,...w,ref:se,style:{outline:"none",...w.style},onKeyDown:he(w.onKeyDown,F=>{const ye=F.target.closest("[data-radix-menu-content]")===F.currentTarget,pe=F.ctrlKey||F.altKey||F.metaKey,Te=F.key.length===1;ye&&(F.key==="Tab"&&F.preventDefault(),!pe&&Te&&N(F.key));const ue=Z.current;if(F.target!==ue||!qw.includes(F.key))return;F.preventDefault();const mt=z().filter(Gt=>!Gt.disabled).map(Gt=>Gt.ref.current);Jb.includes(F.key)&&mt.reverse(),iS(mt)}),onBlur:he(r.onBlur,F=>{F.currentTarget.contains(F.target)||(window.clearTimeout(J.current),Y.current="")}),onPointerMove:he(r.onPointerMove,Fo(F=>{const oe=F.target,ye=W.current!==F.clientX;if(F.currentTarget.contains(oe)&&ye){const pe=F.clientX>W.current?"right":"left";ne.current=pe,W.current=F.clientX}}))})})})})})})})},"MenuContentImpl")),Gd="MenuItem",Ip="menu.itemSelect",aO=g.forwardRef(qe(function(r,c){const{disabled:o=!1,onSelect:s,...f}=r,h=g.useRef(null),v=bm(Gd,r.__scopeMenu),S=tS(Gd,r.__scopeMenu),p=Ie(c,h),E=g.useRef(!1),y=qe(()=>{const x=h.current;if(!o&&x){const O=new CustomEvent(Ip,{bubbles:!0,cancelable:!0});x.addEventListener(Ip,j=>s?.(j),{once:!0}),Wo(x,O),O.defaultPrevented?E.current=!1:v.onClose()}},"handleSelect");return m.jsx(lO,{...f,ref:p,disabled:o,onClick:he(r.onClick,y),onPointerDown:x=>{r.onPointerDown?.(x),E.current=!0},onPointerUp:he(r.onPointerUp,x=>{E.current||x.currentTarget?.click()}),onKeyDown:he(r.onKeyDown,x=>{o||x.target!==x.currentTarget||S.searchRef.current!==""&&x.key===" "||Yw.includes(x.key)&&(x.currentTarget.click(),x.preventDefault())})})},"MenuItem")),lO=g.forwardRef(qe(function(r,c){const{__scopeMenu:o,disabled:s=!1,textValue:f,...h}=r,v=tS(Gd,o),S=Wb(o),p=g.useRef(null),E=Ie(c,p),[y,x]=g.useState(!1),[O,j]=g.useState("");return g.useEffect(()=>{const A=p.current;A&&j((A.textContent??"").trim())},[h.children]),m.jsx(Bd.ItemSlot,{scope:o,disabled:s,textValue:f??O,children:m.jsx(gm,{asChild:!0,...S,focusable:!s,children:m.jsx(De.div,{role:"menuitem","data-highlighted":y?"":void 0,"aria-disabled":s||void 0,"data-disabled":s?"":void 0,...h,ref:E,onPointerMove:he(r.onPointerMove,Fo(A=>{s?v.onItemLeave(A):(v.onItemEnter(A),A.defaultPrevented||A.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:he(r.onPointerLeave,Fo(A=>v.onItemLeave(A))),onFocus:he(r.onFocus,()=>x(!0)),onBlur:he(r.onBlur,()=>x(!1))})})})},"MenuItemImpl")),iO="MenuRadioGroup",[yR,pR]=Ol(iO,{value:void 0,onValueChange:qe(()=>{},"onValueChange")}),rO="MenuItemIndicator",[bR,SR]=Ol(rO,{checked:!1}),uO=g.forwardRef(qe(function(r,c){const{__scopeMenu:o,...s}=r;return m.jsx(De.div,{role:"separator","aria-orientation":"horizontal",...s,ref:c})},"MenuSeparator")),oO="MenuSub",[ER,TR]=Ol(oO);function aS(l){return l?"open":"closed"}qe(aS,"getOpenState");function lS(l){return l==="indeterminate"}qe(lS,"isIndeterminate");function cO(l){return lS(l)?"indeterminate":l?"checked":"unchecked"}qe(cO,"getCheckedState");function iS(l){const r=document.activeElement;for(const c of l)if(c===r||(c.focus(),document.activeElement!==r))return}qe(iS,"focusFirst");function rS(l,r){return l.map((c,o)=>l[(r+o)%l.length])}qe(rS,"wrapArray");function uS(l,r,c){const s=r.length>1&&Array.from(r).every(p=>p===r[0])?r[0]:r,f=c?l.indexOf(c):-1;let h=rS(l,Math.max(f,0));s.length===1&&(h=h.filter(p=>p!==c));const S=h.find(p=>p.toLowerCase().startsWith(s.toLowerCase()));return S!==c?S:void 0}qe(uS,"getNextMatch");function oS(l,r){const{x:c,y:o}=l;let s=!1;for(let f=0,h=r.length-1;f<r.length;h=f++){const v=r[f],S=r[h],p=v.x,E=v.y,y=S.x,x=S.y;E>o!=x>o&&c<(y-p)*(o-E)/(x-E)+p&&(s=!s)}return s}qe(oS,"isPointInPolygon");function cS(l,r){if(!r)return!1;const c={x:l.clientX,y:l.clientY};return oS(c,r)}qe(cS,"isPointerInGraceArea");function Fo(l){return r=>r.pointerType==="mouse"?l(r):void 0}qe(Fo,"whenMouse");var sO=Object.defineProperty,zi=(l,r)=>sO(l,"name",{value:r,configurable:!0}),Sm="DropdownMenu",[fO,xR]=Ht(Sm,[$b]),Ui=$b(),[dO,sS]=fO(Sm),mO=zi(l=>{const{__scopeDropdownMenu:r,children:c,dir:o,open:s,defaultOpen:f,onOpenChange:h,modal:v=!0}=l,S=Ui(r),p=g.useRef(null),[E,y]=_l({prop:s,defaultProp:f??!1,onChange:h,caller:Sm});return m.jsx(dO,{scope:r,triggerId:la(),triggerRef:p,contentId:la(),open:E,onOpenChange:y,onOpenToggle:g.useCallback(()=>y(x=>!x),[y]),modal:v,children:m.jsx(Kw,{...S,open:E,onOpenChange:y,dir:o,modal:v,children:c})})},"DropdownMenu"),hO="DropdownMenuTrigger",vO=g.forwardRef(zi(function(r,c){const{__scopeDropdownMenu:o,disabled:s=!1,...f}=r,h=sS(hO,o),v=Ui(o),S=Ie(c,h.triggerRef);return m.jsx(Zw,{asChild:!0,...v,children:m.jsx(De.button,{type:"button",id:h.triggerId,"aria-haspopup":"menu","aria-expanded":h.open,"aria-controls":h.open?h.contentId:void 0,"data-state":h.open?"open":"closed","data-disabled":s?"":void 0,disabled:s,...f,ref:S,onPointerDown:he(r.onPointerDown,p=>{!s&&p.button===0&&p.ctrlKey===!1&&(h.onOpenToggle(),h.open||p.preventDefault())}),onKeyDown:he(r.onKeyDown,p=>{s||(["Enter"," "].includes(p.key)&&h.onOpenToggle(),p.key==="ArrowDown"&&h.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(p.key)&&p.preventDefault())})})})},"DropdownMenuTrigger")),gO=zi(l=>{const{__scopeDropdownMenu:r,...c}=l,o=Ui(r);return m.jsx(Jw,{...o,...c})},"DropdownMenuPortal"),yO="DropdownMenuContent",pO=g.forwardRef(zi(function(r,c){const{__scopeDropdownMenu:o,...s}=r,f=sS(yO,o),h=Ui(o),v=g.useRef(!1);return m.jsx(Ww,{id:f.contentId,"aria-labelledby":f.triggerId,...h,...s,ref:c,onCloseAutoFocus:he(r.onCloseAutoFocus,S=>{v.current||f.triggerRef.current?.focus(),v.current=!1,S.preventDefault()}),onInteractOutside:he(r.onInteractOutside,S=>{const p=S.detail.originalEvent,E=p.button===0&&p.ctrlKey===!0,y=p.button===2||E;(!f.modal||y)&&(v.current=!0)}),style:{...r.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuContent")),bO=g.forwardRef(zi(function(r,c){const{__scopeDropdownMenu:o,...s}=r,f=Ui(o);return m.jsx(aO,{...f,...s,ref:c})},"DropdownMenuItem")),SO=g.forwardRef(zi(function(r,c){const{__scopeDropdownMenu:o,...s}=r,f=Ui(o);return m.jsx(uO,{...f,...s,ref:c})},"DropdownMenuSeparator")),EO=Object.defineProperty,Li=(l,r)=>EO(l,"name",{value:r,configurable:!0}),fS={Automatic:"automatic",Manual:"manual"},Em="Tabs",[TO,CR]=Ht(Em,[Ka]),dS=Ka(),[xO,Tm]=TO(Em),CO=g.forwardRef(Li(function(r,c){const{__scopeTabs:o,value:s,onValueChange:f,defaultValue:h,orientation:v="horizontal",dir:S,activationMode:p=fS.Automatic,...E}=r,y=Kr(S),[x,O]=_l({prop:s,onChange:f,defaultProp:h??"",caller:Em});return m.jsx(xO,{scope:o,baseId:la(),value:x,onValueChange:O,orientation:v,dir:y,activationMode:p,children:m.jsx(De.div,{dir:y,"data-orientation":v,...E,ref:c})})},"Tabs")),_O="TabsList",wO=g.forwardRef(Li(function(r,c){const{__scopeTabs:o,loop:s=!0,...f}=r,h=Tm(_O,o),v=dS(o);return m.jsx(vm,{asChild:!0,...v,orientation:h.orientation,dir:h.dir,loop:s,children:m.jsx(De.div,{role:"tablist","aria-orientation":h.orientation,...f,ref:c})})},"TabsList")),OO="TabsTrigger",AO=g.forwardRef(Li(function(r,c){const{__scopeTabs:o,value:s,disabled:f=!1,...h}=r,v=Tm(OO,o),S=dS(o),p=xm(v.baseId,s),E=Cm(v.baseId,s),y=s===v.value;return m.jsx(gm,{asChild:!0,...S,focusable:!f,active:y,children:m.jsx(De.button,{type:"button",role:"tab","aria-selected":y,"aria-controls":E,"data-state":y?"active":"inactive","data-disabled":f?"":void 0,disabled:f,id:p,...h,ref:c,onMouseDown:he(r.onMouseDown,x=>{!f&&x.button===0&&x.ctrlKey===!1?(x.currentTarget.focus(),v.onValueChange(s)):x.preventDefault()}),onKeyDown:he(r.onKeyDown,x=>{f||x.target!==x.currentTarget||[" ","Enter"].includes(x.key)&&v.onValueChange(s)}),onFocus:he(r.onFocus,()=>{const x=v.activationMode!==fS.Manual;!y&&!f&&x&&v.onValueChange(s)})})})},"TabsTrigger")),RO="TabsContent",NO=g.forwardRef(Li(function(r,c){const{__scopeTabs:o,value:s,forceMount:f,children:h,...v}=r,S=Tm(RO,o),p=xm(S.baseId,s),E=Cm(S.baseId,s),y=s===S.value,x=g.useRef(y);return g.useEffect(()=>{const O=requestAnimationFrame(()=>x.current=!1);return()=>cancelAnimationFrame(O)},[]),m.jsx(sa,{present:f||y,children:({present:O})=>m.jsx(De.div,{"data-state":y?"active":"inactive","data-orientation":S.orientation,role:"tabpanel","aria-labelledby":p,hidden:!O,id:E,tabIndex:0,...v,ref:c,style:{...r.style,animationDuration:x.current?"0s":void 0},children:O&&h})})},"TabsContent"));function xm(l,r){return`${l}-trigger-${r}`}Li(xm,"makeTriggerId");function Cm(l,r){return`${l}-content-${r}`}Li(Cm,"makeContentId");var DO=Object.defineProperty,He=(l,r)=>DO(l,"name",{value:r,configurable:!0}),Xp=Pa[" startTransition ".trim().toString()]||(()=>{}),mS="ToastProvider",[_m,hS,jO]=dc("Toast"),Yd={Left:"left",Right:"right"},Pp={Foreground:"foreground"},[vS,_R]=Ht("Toast",[jO]),[MO,vc]=vS(mS);function Vo(l){typeof Xp=="function"?Xp(l):l()}He(Vo,"scheduleUpdate");var zO=He(l=>{const{__scopeToast:r,label:c="Notification",duration:o=5e3,swipeDirection:s=Yd.Right,swipeThreshold:f=50,announcerContainer:h,children:v}=l,[S,p]=g.useState(null),[E,y]=g.useState(0),x=g.useRef(!1),O=g.useCallback(w=>{Vo(()=>p(w))},[]),j=g.useCallback(()=>{Vo(()=>y(w=>w+1))},[]),A=g.useCallback(()=>{Vo(()=>y(w=>w-1))},[]);return c.trim()||console.error(`Invalid prop \`label\` supplied to \`${mS}\`. Expected non-empty \`string\`.`),m.jsx(_m.Provider,{scope:r,children:m.jsx(MO,{scope:r,label:c,duration:o,swipeDirection:s,swipeThreshold:f,toastCount:E,viewport:S,onViewportChange:O,onToastAdd:j,onToastRemove:A,isClosePausedRef:x,announcerContainer:h,children:v})})},"ToastProvider"),UO="ToastViewport",LO=["F8"],Vd="toast.viewportPause",qd="toast.viewportResume",HO=g.forwardRef(He(function(r,c){const{__scopeToast:o,hotkey:s=LO,label:f="Notifications ({hotkey})",...h}=r,v=vc(UO,o),S=hS(o),p=g.useRef(null),E=g.useRef(null),y=g.useRef(null),x=g.useRef(null),O=Ie(c,x,v.onViewportChange),j=s.join("+").replace(/Key/g,"").replace(/Digit/g,""),A=v.toastCount>0;g.useEffect(()=>{const D=He(T=>{s.length!==0&&s.every(B=>T[B]||T.code===B)&&x.current?.focus()},"handleKeyDown");return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[s]),g.useEffect(()=>{const D=p.current,T=x.current;if(A&&D&&T){const C=He(()=>{if(!v.isClosePausedRef.current){const q=new CustomEvent(Vd);T.dispatchEvent(q),v.isClosePausedRef.current=!0}},"handlePause"),B=He(()=>{if(v.isClosePausedRef.current){const q=new CustomEvent(qd);T.dispatchEvent(q),v.isClosePausedRef.current=!1}},"handleResume"),z=He(q=>{!D.contains(q.relatedTarget)&&B()},"handleFocusOutResume"),L=He(()=>{D.contains(document.activeElement)||B()},"handlePointerLeaveResume");return D.addEventListener("focusin",C),D.addEventListener("focusout",z),D.addEventListener("pointermove",C),D.addEventListener("pointerleave",L),window.addEventListener("blur",C),window.addEventListener("focus",B),()=>{D.removeEventListener("focusin",C),D.removeEventListener("focusout",z),D.removeEventListener("pointermove",C),D.removeEventListener("pointerleave",L),window.removeEventListener("blur",C),window.removeEventListener("focus",B)}}},[A,v.isClosePausedRef]);const w=g.useCallback(({tabbingDirection:D})=>{const C=S().map(B=>{const z=B.ref.current,L=[z,...pS(z)];return D==="forwards"?L:L.reverse()});return(D==="forwards"?C.reverse():C).flat()},[S]);return g.useEffect(()=>{const D=x.current;if(D){const T=He(C=>{const B=C.altKey||C.ctrlKey||C.metaKey;if(C.key==="Tab"&&!B){const L=document.activeElement,q=C.shiftKey;if(C.target===D&&q){E.current?.focus();return}const te=w({tabbingDirection:q?"backwards":"forwards"}),re=te.findIndex(le=>le===L);qo(te.slice(re+1))?C.preventDefault():q?E.current?.focus():y.current?.focus()}},"handleKeyDown");return D.addEventListener("keydown",T),()=>D.removeEventListener("keydown",T)}},[S,w]),m.jsxs(y1,{ref:p,role:"region","aria-label":f.replace("{hotkey}",j),tabIndex:-1,style:{pointerEvents:A?void 0:"none"},children:[A&&m.jsx(Qp,{ref:E,onFocusFromOutsideViewport:()=>{const D=w({tabbingDirection:"forwards"});qo(D)}}),m.jsx(_m.Slot,{scope:o,children:m.jsx(De.ol,{tabIndex:-1,...h,ref:O})}),A&&m.jsx(Qp,{ref:y,onFocusFromOutsideViewport:()=>{const D=w({tabbingDirection:"backwards"});qo(D)}})]})},"ToastViewport")),BO="ToastFocusProxy",Qp=g.forwardRef(He(function(r,c){const{__scopeToast:o,onFocusFromOutsideViewport:s,...f}=r,h=vc(BO,o);return m.jsx(rm,{tabIndex:0,...f,ref:c,style:{position:"fixed"},onFocus:v=>{const S=v.relatedTarget;!h.viewport?.contains(S)&&s()}})},"ToastFocusProxy")),gc="Toast",GO="toast.swipeStart",YO="toast.swipeMove",VO="toast.swipeCancel",qO="toast.swipeEnd",IO=g.forwardRef(He(function(r,c){const{forceMount:o,open:s,defaultOpen:f,onOpenChange:h,...v}=r,[S,p]=_l({prop:s,defaultProp:f??!0,onChange:h,caller:gc});return m.jsx(sa,{present:o||S,children:m.jsx(QO,{open:S,...v,ref:c,onClose:()=>p(!1),onPause:Wt(r.onPause),onResume:Wt(r.onResume),onSwipeStart:he(r.onSwipeStart,E=>{E.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:he(r.onSwipeMove,E=>{const{x:y,y:x}=E.detail.delta;E.currentTarget.setAttribute("data-swipe","move"),E.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${y}px`),E.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${x}px`)}),onSwipeCancel:he(r.onSwipeCancel,E=>{E.currentTarget.setAttribute("data-swipe","cancel"),E.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),E.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),E.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),E.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:he(r.onSwipeEnd,E=>{const{x:y,y:x}=E.detail.delta;E.currentTarget.setAttribute("data-swipe","end"),E.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),E.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),E.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${y}px`),E.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${x}px`),p(!1)})})})},"Toast")),[XO,PO]=vS(gc,{onClose(){}}),QO=g.forwardRef(He(function(r,c){const{__scopeToast:o,type:s=Pp.Foreground,duration:f,open:h,onClose:v,onEscapeKeyDown:S,onPause:p,onResume:E,onSwipeStart:y,onSwipeMove:x,onSwipeCancel:O,onSwipeEnd:j,...A}=r,w=vc(gc,o),D=hS(o),[T,C]=g.useState(null),B=Ie(c,C),z=g.useRef(null),L=g.useRef(null),q=f||w.duration,Z=g.useRef(0),$=g.useRef(q),te=g.useRef(0),{onToastAdd:re,onToastRemove:le}=w,ae=Wt(()=>{T?.contains(document.activeElement)&&w.viewport?.focus(),v()}),se=g.useCallback(Y=>{!Y||Y===1/0||(window.clearTimeout(te.current),Z.current=new Date().getTime(),te.current=window.setTimeout(ae,Y))},[ae]);g.useEffect(()=>{const Y=w.viewport;if(Y){const k=He(()=>{se($.current),E?.()},"handleResume"),K=He(()=>{const ne=new Date().getTime()-Z.current;$.current=$.current-ne,window.clearTimeout(te.current),p?.()},"handlePause");return Y.addEventListener(Vd,K),Y.addEventListener(qd,k),()=>{Y.removeEventListener(Vd,K),Y.removeEventListener(qd,k)}}},[w.viewport,q,p,E,se]),g.useEffect(()=>{$.current=q,h&&!w.isClosePausedRef.current&&se(q)},[h,q,w.isClosePausedRef,se]),g.useEffect(()=>()=>{window.clearTimeout(te.current)},[]),g.useEffect(()=>(re(),()=>le()),[re,le]);const J=g.useMemo(()=>T?wm(T):null,[T]);return w.viewport?m.jsxs(m.Fragment,{children:[J&&m.jsx(KO,{__scopeToast:o,role:"status","aria-live":s===Pp.Foreground?"assertive":"polite",children:J}),m.jsx(XO,{scope:o,onClose:ae,children:$o.createPortal(m.jsx(_m.ItemSlot,{scope:o,children:m.jsx(ec,{asChild:!0,onEscapeKeyDown:he(S,Y=>{D().some(K=>K.ref.current?.contains(Y.target))||ae()}),children:m.jsx(De.li,{tabIndex:0,"data-state":h?"open":"closed","data-swipe-direction":w.swipeDirection,...A,ref:B,style:{userSelect:"none",touchAction:"none",...r.style},onKeyDown:he(r.onKeyDown,Y=>{Y.key==="Escape"&&(S?.(Y.nativeEvent),Y.nativeEvent.defaultPrevented||ae())}),onPointerDown:he(r.onPointerDown,Y=>{Y.button===0&&(z.current={x:Y.clientX,y:Y.clientY})}),onPointerMove:he(r.onPointerMove,Y=>{if(!z.current)return;const k=Y.clientX-z.current.x,K=Y.clientY-z.current.y,ne=!!L.current,W=["left","right"].includes(w.swipeDirection),fe=["left","up"].includes(w.swipeDirection)?Math.min:Math.max,Be=W?fe(0,k):0,Pe=W?0:fe(0,K),N=Y.pointerType==="touch"?10:2,I={x:Be,y:Pe},F={originalEvent:Y,delta:I};ne?(L.current=I,Ur(YO,x,F,{discrete:!1})):Kp(I,w.swipeDirection,N)?(L.current=I,Ur(GO,y,F,{discrete:!1}),Y.target.setPointerCapture(Y.pointerId)):(Math.abs(k)>N||Math.abs(K)>N)&&(z.current=null)}),onPointerUp:he(r.onPointerUp,Y=>{const k=L.current,K=Y.target;if(K.hasPointerCapture(Y.pointerId)&&K.releasePointerCapture(Y.pointerId),L.current=null,z.current=null,k){const ne=Y.currentTarget,W={originalEvent:Y,delta:k};Kp(k,w.swipeDirection,w.swipeThreshold)?Ur(qO,j,W,{discrete:!0}):Ur(VO,O,W,{discrete:!0}),ne.addEventListener("click",fe=>fe.preventDefault(),{once:!0})}})})})}),w.viewport)})]}):null},"ToastImpl")),KO=He(l=>{const{__scopeToast:r,children:c,...o}=l,s=vc(gc,r),[f,h]=g.useState(!1),[v,S]=g.useState(!1);return gS(()=>h(!0)),g.useEffect(()=>{const p=window.setTimeout(()=>S(!0),1e3);return()=>window.clearTimeout(p)},[]),v?null:m.jsx(uc,{asChild:!0,container:s.announcerContainer||void 0,children:m.jsx(rm,{...o,children:f&&m.jsxs(m.Fragment,{children:[s.label," ",c]})})})},"ToastAnnounce"),ZO=g.forwardRef(He(function(r,c){const{__scopeToast:o,...s}=r;return m.jsx(De.div,{...s,ref:c})},"ToastTitle")),FO=g.forwardRef(He(function(r,c){const{__scopeToast:o,...s}=r;return m.jsx(De.div,{...s,ref:c})},"ToastDescription")),kO="ToastClose",JO=g.forwardRef(He(function(r,c){const{__scopeToast:o,...s}=r,f=PO(kO,o);return m.jsx($O,{asChild:!0,children:m.jsx(De.button,{type:"button",...s,ref:c,onClick:he(r.onClick,f.onClose)})})},"ToastClose")),$O=g.forwardRef(He(function(r,c){const{__scopeToast:o,altText:s,...f}=r;return m.jsx(De.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":s||void 0,...f,ref:c})},"ToastAnnounceExclude"));function wm(l){const r=[];return Array.from(l.childNodes).forEach(o=>{if(o.nodeType===o.TEXT_NODE&&o.textContent&&r.push(o.textContent),yS(o)){const s=o.ariaHidden||o.hidden||o.style.display==="none",f=o.dataset.radixToastAnnounceExclude==="";if(!s)if(f){const h=o.dataset.radixToastAnnounceAlt;h&&r.push(h)}else r.push(...wm(o))}}),r}He(wm,"getAnnounceTextContent");function Ur(l,r,c,{discrete:o}){const s=c.originalEvent.currentTarget,f=new CustomEvent(l,{bubbles:!0,cancelable:!0,detail:c});r&&s.addEventListener(l,r,{once:!0}),o?Wo(s,f):s.dispatchEvent(f)}He(Ur,"handleAndDispatchCustomEvent");var Kp=He((l,r,c=0)=>{const o=Math.abs(l.x),s=Math.abs(l.y),f=o>s;return r===Yd.Left||r===Yd.Right?f&&o>c:!f&&s>c},"isDeltaInDirection");function gS(l=()=>{}){const r=Wt(l);xt(()=>{let c=0,o=0;return c=window.requestAnimationFrame(()=>o=window.requestAnimationFrame(r)),()=>{window.cancelAnimationFrame(c),window.cancelAnimationFrame(o)}},[r])}He(gS,"useNextFrame");function yS(l){return l.nodeType===l.ELEMENT_NODE}He(yS,"isHTMLElement");function pS(l){const r=[],c=document.createTreeWalker(l,NodeFilter.SHOW_ELEMENT,{acceptNode:He(o=>{const s=o.tagName==="INPUT"&&o.type==="hidden";return o.disabled||o.hidden||s?NodeFilter.FILTER_SKIP:o.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;c.nextNode();)r.push(c.currentNode);return r}He(pS,"getTabbableCandidates");function qo(l){const r=document.activeElement;return l.some(c=>c===r?!0:(c.focus(),document.activeElement!==r))}He(qo,"focusFirst");function Om({open:l,onOpenChange:r,trigger:c,title:o,description:s,children:f,footer:h}){if(o.trim()==="")throw new Error("A dialog needs a non-empty title.");const v=g.useRef(null),S=g.useRef(!1);if(l&&!S.current&&typeof document<"u"){const p=document.activeElement,E=p?.closest('[role="menu"]')?.getAttribute("aria-labelledby");v.current=E&&document.getElementById(E)||p}return S.current=!!l,m.jsxs(uw,{open:l,onOpenChange:r,children:[c&&m.jsx(cw,{asChild:!0,children:c}),m.jsxs(fw,{children:[m.jsx(dw,{className:"agd-overlay"}),m.jsxs(vw,{className:"agd-dialog",...s?{}:{"aria-describedby":void 0},onCloseAutoFocus:p=>{!c&&v.current instanceof HTMLElement&&v.current.isConnected&&(p.preventDefault(),v.current.focus())},onOpenAutoFocus:p=>{const E=p.currentTarget.querySelector("[data-autofocus]");E&&(p.preventDefault(),E.focus())},children:[m.jsx(pw,{className:"agd-dialog__title",children:o}),m.jsx(Lb,{asChild:!0,children:m.jsx(Tl,{label:"Close",icon:m.jsx(yb,{}),size:"sm",className:"agd-dialog__close",tooltip:!1})}),s&&m.jsx(bw,{className:"agd-dialog__description",children:s}),f&&m.jsx("div",{className:"agd-dialog__body",children:f}),h&&m.jsx("div",{className:"agd-dialog__footer",children:h})]})]})]})}var bS=Lb;function WO({trigger:l,items:r,align:c="end"}){for(const s of r)if(s!=="separator"&&s.label.trim()==="")throw new Error("A menu item needs a non-empty label.");const o=g.isValidElement(l)&&l.type===Tl?g.cloneElement(l,{tooltip:!1}):l;return m.jsxs(mO,{modal:!1,children:[m.jsx(vO,{asChild:!0,children:o}),m.jsx(gO,{children:m.jsx(pO,{className:"agd-menu",align:c,sideOffset:6,children:r.map((s,f)=>s==="separator"?m.jsx(SO,{className:"agd-menu__separator"},`sep-${f}`):m.jsxs(bO,{className:s.danger?"agd-menu__item agd-menu__item--danger":"agd-menu__item",disabled:s.disabled,onSelect:s.onSelect,children:[s.icon,m.jsx("span",{children:s.label}),s.shortcut&&m.jsx("kbd",{className:"agd-menu__shortcut",children:s.shortcut})]},`${f}-${s.label}`))})})]})}function eA({label:l,tabs:r,value:c,defaultValue:o,onValueChange:s}){if(l.trim()==="")throw new Error("Tabs need a non-empty label.");const[f,h]=g.useState(o??r[0]?.value),v=c??f,S=r.some(p=>p.value===v)?v:r[0]?.value;return m.jsxs(CO,{className:"agd-tabs",value:v,onValueChange:p=>{h(p),s?.(p)},children:[m.jsx(wO,{className:"agd-tabs__list","aria-label":l,tabIndex:-1,children:r.map(p=>m.jsx(AO,{value:p.value,className:"agd-tabs__trigger",tabIndex:p.value===S?0:-1,children:p.label},p.value))}),r.map(p=>m.jsx(NO,{value:p.value,className:"agd-tabs__panel",children:p.content},p.value))]})}var SS=g.createContext(null),Zp={info:f_,success:c_,warning:pb,danger:h_},tA={info:"Notice",success:"Success",warning:"Warning",danger:"Error"};function nA({children:l}){const[r,c]=g.useState([]),o=g.useCallback(f=>{if(typeof f.title!="string"||f.title.trim()==="")throw new Error("A toast needs a non-empty title.");const h=f.tone===void 0?"info":Object.hasOwn(Zp,f.tone)?f.tone:"danger";c(v=>[...v,{...f,tone:h,id:Date.now()+Math.random()}])},[]),s=f=>c(h=>h.filter(v=>v.id!==f));return m.jsx(SS.Provider,{value:o,children:m.jsxs(zO,{swipeDirection:"right",children:[l,r.map(({id:f,title:h,description:v,tone:S="info"})=>{const p=Zp[S];return m.jsxs(IO,{className:`agd-toast agd-toast--${S}`,type:S==="danger"?"foreground":"background",duration:S==="danger"?1/0:8e3,onOpenChange:E=>!E&&s(f),children:[m.jsx(p,{className:"agd-toast__icon"}),m.jsxs("div",{children:[m.jsxs(ZO,{className:"agd-toast__title",children:[m.jsxs("span",{className:"agd-sr-only",children:[tA[S],": "]}),h]}),v&&m.jsx(FO,{className:"agd-toast__description",children:v})]}),m.jsx(JO,{asChild:!0,children:m.jsx(Tl,{label:"Dismiss",icon:m.jsx(yb,{}),size:"sm",tooltip:!1})})]},f)}),m.jsx(HO,{className:"agd-toast-viewport",label:"Notifications ({hotkey})"})]})})}function yc(){const l=g.useContext(SS);if(!l)throw new Error("useToast needs a ToastProvider above it.");return l}var ES="(max-width: 47.99rem)",aA=l=>{const r=window.matchMedia(ES);return r.addEventListener("change",l),()=>r.removeEventListener("change",l)};function lA({brand:l,sidebar:r,title:c,topbar:o,secondary:s,panel:f,panelLabel:h,children:v}){const S=f!=null&&f!==!1;if(S&&(h??"").trim()==="")throw new Error("A side panel needs a non-empty label.");const p=s!=null&&s!==!1,[E,y]=g.useState(!1),x=g.useRef(null),O=g.useRef(null),j=g.useRef(null),A=g.useRef(!1),[w,D]=g.useState(!1),T=g.useRef(null),C=g.useId(),B=g.useId(),z=g.useId(),L=g.useSyncExternalStore(aA,()=>window.matchMedia(ES).matches,()=>!1),q=g.useRef(L),Z=g.useRef(null),$=g.useRef(null);if(L!==q.current){const ae=document.activeElement,se=Z.current;$.current=Z.current??ae,Z.current=null,q.current=L,A.current=!1,y(L&&(!!se||!!x.current?.contains(ae))),D(L&&!!j.current?.contains(ae))}g.useLayoutEffect(()=>{const ae=$.current;$.current=null,ae instanceof HTMLElement&&ae.isConnected&&ae!==document.activeElement&&ae!==document.body&&ae.focus()},[L]),g.useEffect(()=>{E&&A.current&&x.current?.querySelector("a, [href]")?.focus()},[E]);const te=ae=>{if(ae.key!=="Escape")return;const se=ae.target;if(w&&(j.current?.contains(se)||T.current?.contains(se))&&!se.closest?.('[role="menu"], [role="dialog"]')){D(!1),T.current?.focus();return}E&&(!x.current?.contains(se)&&!O.current?.contains(se)||(y(!1),O.current?.focus()))},re=m.jsxs("header",{className:"agd-shell__topbar",children:[m.jsx("p",{className:"agd-shell__brand",children:l}),m.jsx(Tl,{ref:O,className:"agd-shell__menu",label:"Navigation",icon:m.jsx(d_,{}),"aria-expanded":E,"aria-controls":C,onClick:()=>{A.current=!E,y(ae=>!ae)}}),c!=null&&c!==!1&&m.jsx("div",{className:"agd-shell__title",children:c}),m.jsx("div",{className:"agd-shell__actions",children:o}),p&&m.jsxs(m.Fragment,{children:[m.jsx(Tl,{ref:T,className:"agd-shell__more",label:"More options",icon:m.jsx(bb,{}),"aria-expanded":w,"aria-controls":B,onClick:()=>D(ae=>!ae)}),m.jsx("div",{id:B,ref:j,className:"agd-shell__secondary","data-open":w,children:s})]})]},"topbar"),le=m.jsx("div",{id:C,ref:x,className:"agd-shell__sidebar","data-open":E,onBlur:ae=>{!q.current&&!ae.relatedTarget&&x.current&&getComputedStyle(x.current).display==="none"&&(Z.current=ae.target)},onFocus:()=>{Z.current=null},children:r},"sidebar");return m.jsxs("div",{className:"agd-shell","data-panel":S?"":void 0,onKeyDown:te,children:[m.jsx("a",{className:"agd-skip-link",href:`#${z}`,children:"Skip to content"}),L?[re,le]:[le,re],m.jsx("main",{id:z,className:"agd-shell__content",tabIndex:-1,children:v}),S&&m.jsx("aside",{className:"agd-shell__panel","aria-label":h,children:f})]})}function iA({label:l,items:r,linkComponent:c="a",renderLink:o}){return m.jsx("nav",{"aria-label":l,children:m.jsx("ul",{className:"agd-sidebar-nav",children:r.map(s=>{const f={className:"agd-sidebar-nav__link",href:s.href,"aria-current":s.current?"page":void 0,children:m.jsxs(m.Fragment,{children:[s.icon,s.label]})};return m.jsx("li",{children:o?o(f,s):m.jsx(c,{...f})},s.href)})})})}var rA=Object.defineProperty,uA=(l,r)=>rA(l,"name",{value:r,configurable:!0}),oA={Horizontal:"horizontal",Vertical:"vertical"},cA=Object.values(oA);function sA(l){return cA.includes(l)}uA(sA,"isValidOrientation");var Am="ToggleGroup",[TS,xS]=Ht(Am,[Ka]);Ka();var[wR,OR]=TS(Am),[AR,RR]=TS(Am),fA=Object.defineProperty,CS=(l,r)=>fA(l,"name",{value:r,configurable:!0}),_S="Toolbar",[dA,NR]=Ht(_S,[Ka,xS]),wS=Ka();xS();var[mA,DR]=dA(_S),hA=g.forwardRef(CS(function(r,c){const{__scopeToolbar:o,orientation:s="horizontal",dir:f,loop:h=!0,...v}=r,S=wS(o),p=Kr(f);return m.jsx(mA,{scope:o,orientation:s,dir:p,children:m.jsx(vm,{asChild:!0,...S,orientation:s,dir:p,loop:h,children:m.jsx(De.div,{role:"toolbar","aria-orientation":s,dir:p,...v,ref:c})})})},"Toolbar")),vA=g.forwardRef(CS(function(r,c){const{__scopeToolbar:o,...s}=r,f=wS(o);return m.jsx(gm,{asChild:!0,...f,focusable:!r.disabled,children:m.jsx(De.button,{type:"button",...s,ref:c})})},"ToolbarButton"));function gA({label:l,children:r,dir:c}){const o=c??(typeof document<"u"&&document.documentElement.dir==="rtl"?"rtl":"ltr");return m.jsx(hA,{className:"agd-toolbar","aria-label":l,dir:o,children:r})}var jo=g.forwardRef(function({pressed:r,...c},o){return m.jsx(vA,{asChild:!0,children:m.jsx(Tl,{ref:o,size:"sm","aria-pressed":r,...c})})}),yA=40,pA=/^[\p{L}\p{M}\p{N}\p{P}\p{S}\p{Zs}\u200C\u200D]*$/u,bA=/(?![\p{Default_Ignorable_Code_Point}\u2800])[\p{L}\p{N}\p{P}\p{S}]/u,Fp="[\\p{Script=Arabic}\\p{Script=Devanagari}\\p{Script=Bengali}\\p{Script=Gujarati}\\p{Script=Gurmukhi}\\p{Script=Tamil}\\p{Script=Telugu}\\p{Script=Kannada}\\p{Script=Malayalam}\\p{Script=Sinhala}\\p{Extended_Pictographic}\\p{Emoji_Modifier}]",SA=new RegExp(`(?<=${Fp}\\p{M}*)[\\u200C\\u200D](?=${Fp})`,"gu"),EA=/[\p{Default_Ignorable_Code_Point}\u2800]/u,TA=/^[\p{M}\u200C-\u200F]/u,xA=new RegExp("\\p{M}{5,}","u");function Rm(l){return Nm(l,yA)}function Nm(l,r){if(typeof l!="string"||l.length>r)return null;const c=l.replace(SA,"");return/[\u200C-\u200F]/.test(c)||!pA.test(l)||!bA.test(l)||xA.test(c)||EA.test(c)||TA.test(l)||new RegExp("^\\s|\\s$|\\s{2,}|(?! )\\p{Zs}|[\\u200C-\\u200F]$|[\\u200C-\\u200F]{2,}","u").test(l)?null:l}var kp={active:"",away:"Away",paused:"Paused"},qr=l=>l.kind==="person"?"person":"agent",OS=l=>typeof l.status=="string"&&Object.hasOwn(kp,l.status)?kp[l.status]:"";function Oi(l){return Rm(l.name)??(qr(l)==="agent"?"Unnamed agent":"Unnamed person")}function CA(l){const r=l.trim().split(/\s+/).filter(Boolean);return(r.length>1?[r[0],r[r.length-1]]:[r[0]??""]).map(o=>Array.from(o).find(s=>/[\p{L}\p{N}]/u.test(s))?.toUpperCase()??"").join("")}function _A({entry:l,label:r}){return m.jsx("span",{className:Gn("agd-avatar",`agd-avatar--${qr(l)}`),role:r?"img":void 0,"aria-label":r,"aria-hidden":r?void 0:!0,children:qr(l)==="agent"?m.jsx(m_,{"aria-hidden":"true"}):CA(Oi(l))})}function wA(l){const r=qr(l)==="agent",c=l.actingFor===void 0?null:Rm(l.actingFor)??"Unnamed person";return[Oi(l),r?"agent":"person",r&&`acting for ${c??"an unknown person"}`,OS(l).toLowerCase()].filter(Boolean).join(", ")}function Ai({entry:l,className:r}){const c=Oi(l),o=OS(l),s=qr(l)==="agent",f=l.actingFor===void 0?null:Rm(l.actingFor)??"Unnamed person";return m.jsxs("span",{className:Gn("agd-chip",r),children:[m.jsx(_A,{entry:l}),m.jsx("span",{className:"agd-chip__name",title:c,"aria-hidden":"true",children:c}),s&&m.jsx("span",{className:"agd-pill","aria-hidden":"true",title:f?`An agent acting for ${f}.`:"An agent, not a person.",children:"Agent"}),s&&m.jsxs("span",{className:"agd-chip__meta","aria-hidden":"true",children:["for ",f??"unknown"]}),o&&m.jsx("span",{className:"agd-chip__meta","aria-hidden":"true",children:o}),m.jsx("span",{className:"agd-sr-only",children:wA(l)})]})}function Ri({title:l,description:r,action:c}){return m.jsxs("div",{className:"agd-empty",children:[m.jsx("h2",{className:"agd-empty__title",children:l}),r&&m.jsx("p",{className:"agd-empty__description",children:r}),c]})}var AS=200,yd=[{key:"name",label:"Name"},{key:"owner",label:"Owner"},{key:"modified",label:"Modified"}],Lr=l=>Nm(l.name,AS)??"Untitled",Id=l=>l instanceof Date&&!Number.isNaN(l.getTime());function OA(l,{key:r,direction:c},o){const s=new Intl.Collator(o,{numeric:!0,sensitivity:"base"}),f=c==="ascending"?1:-1;return[...l].sort((h,v)=>{if(r==="modified"){const[S,p]=[Id(h.modified),Id(v.modified)];if(S!==p)return S?-1:1;if(S&&p&&h.modified.getTime()!==v.modified.getTime())return f*(h.modified.getTime()-v.modified.getTime())}else if(r==="owner"){const S=s.compare(Oi(h.owner),Oi(v.owner));if(S!==0)return f*S}else{const S=s.compare(Lr(h),Lr(v));if(S!==0)return f*S}return s.compare(Lr(h),Lr(v))})}function Jp(l,r){return Id(l)?m.jsx("time",{dateTime:l.toISOString(),children:l.toLocaleDateString(r,{day:"numeric",month:"short",year:"numeric"})}):m.jsx("span",{children:"Date unknown"})}var $p=({item:l})=>{const r=Lr(l);return m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"agd-file-row__icon","aria-hidden":"true",children:l.kind==="folder"?m.jsx(wi,{}):m.jsx(Yr,{})}),m.jsx("a",{className:"agd-file-row__name",href:l.href,title:r,children:r})]})};function AA(l){return"items"in l?m.jsx(RA,{...l}):m.jsx("ul",{className:"agd-files","aria-label":l.label,children:l.children})}function RA({label:l,items:r,view:c="table",defaultSort:o={key:"name",direction:"ascending"},sort:s,onSortChange:f,loading:h=!1,empty:v,locale:S="en"}){const[p,E]=g.useState(o),y=s??p,x=g.useMemo(()=>s?r:OA(r,y,S),[r,y,s,S]),[O,j]=g.useState(""),A=g.useRef(y);g.useEffect(()=>{A.current.key===y.key&&A.current.direction===y.direction||(A.current=y,j(`Sorted by ${yd.find(z=>z.key===y.key)?.label.toLowerCase()}, ${y.direction}`))},[y]);const w=g.useRef(h);g.useEffect(()=>{w.current&&!h&&j(`${r.length} ${r.length===1?"file":"files"}`),w.current=h},[h,r.length]);const D=z=>{E(z),f?.(z)},T=z=>D({key:z,direction:y.key===z&&y.direction==="ascending"?"descending":"ascending"}),C=m.jsx("p",{className:"agd-sr-only",role:"status",children:h?"Loading files":O}),B=!h&&x.length===0?v??m.jsx(Ri,{title:"No files",description:"Nothing is here yet."}):c==="grid"?m.jsxs("div",{className:"agd-filegrid-wrap",children:[m.jsx(xl,{label:"Sort by",value:`${y.key}:${y.direction}`,onChange:z=>{const[L,q]=z.target.value.split(":");D({key:L,direction:q})},children:yd.flatMap(z=>[m.jsxs("option",{value:`${z.key}:ascending`,children:[z.label,", ",z.key==="modified"?"oldest first":"A to Z"]},`${z.key}:ascending`),m.jsxs("option",{value:`${z.key}:descending`,children:[z.label,", ",z.key==="modified"?"newest first":"Z to A"]},`${z.key}:descending`)])}),m.jsx("ul",{className:"agd-filegrid","aria-label":l,"aria-busy":h||void 0,children:h?[0,1,2,3].map(z=>m.jsx("li",{className:"agd-filegrid__item agd-skeleton","aria-hidden":"true"},z)):x.map(z=>m.jsxs("li",{className:"agd-filegrid__item",children:[m.jsx("span",{className:"agd-filegrid__head",children:m.jsx($p,{item:z})}),m.jsx(Ai,{entry:z.owner}),m.jsx("span",{className:"agd-file-row__time",children:Jp(z.modified,S)}),z.actions&&m.jsx("span",{className:"agd-file-row__actions",children:z.actions})]},z.id))})]}):m.jsx("div",{className:"agd-filetable-wrap",children:m.jsxs("table",{className:"agd-filetable",role:"table","aria-busy":h||void 0,children:[m.jsx("caption",{className:"agd-sr-only",children:l}),m.jsx("thead",{role:"rowgroup",children:m.jsxs("tr",{role:"row",children:[yd.map(z=>{const L=y.key===z.key;return m.jsx("th",{role:"columnheader",scope:"col","aria-sort":L?y.direction:void 0,children:m.jsxs("button",{type:"button",className:"agd-filetable__sort",onClick:()=>T(z.key),children:[z.label,m.jsx("span",{className:"agd-filetable__arrow","aria-hidden":"true",children:L?y.direction==="ascending"?"↑":"↓":""})]})},z.key)}),m.jsx("th",{role:"columnheader",scope:"col",children:m.jsx("span",{className:"agd-sr-only",children:"Actions"})})]})}),m.jsx("tbody",{role:"rowgroup",children:h?[0,1,2,3].map(z=>m.jsx("tr",{role:"row","aria-hidden":"true",children:[0,1,2,3].map(L=>m.jsx("td",{role:"cell",children:m.jsx("span",{className:"agd-skeleton"})},L))},z)):x.map(z=>m.jsxs("tr",{role:"row",children:[m.jsx("td",{role:"cell",children:m.jsx("span",{className:"agd-filetable__name",children:m.jsx($p,{item:z})})}),m.jsx("td",{role:"cell",children:m.jsx(Ai,{entry:z.owner})}),m.jsx("td",{role:"cell",children:m.jsx("span",{className:"agd-file-row__time",children:Jp(z.modified,S)})}),m.jsx("td",{role:"cell",children:m.jsx("span",{className:"agd-file-row__actions",children:z.actions})})]},z.id))})]})});return m.jsxs(m.Fragment,{children:[C,B]})}function NA({name:l,href:r,kind:c="file",modified:o,editedBy:s,actions:f}){const h=Nm(l,AS)??"Untitled",v=o instanceof Date&&!Number.isNaN(o.getTime());return m.jsxs("li",{className:"agd-file-row",children:[m.jsx("span",{className:"agd-file-row__icon","aria-hidden":"true",children:c==="folder"?m.jsx(wi,{}):m.jsx(Yr,{})}),m.jsx("a",{className:"agd-file-row__name",href:r,title:h,children:h}),m.jsxs("span",{className:"agd-file-row__meta",children:["Edited by ",m.jsx(Ai,{entry:s})]}),v?m.jsx("time",{className:"agd-file-row__time",dateTime:o.toISOString(),children:o.toLocaleDateString("en",{day:"numeric",month:"short",year:"numeric"})}):m.jsx("span",{className:"agd-file-row__time",children:"Date unknown"}),f&&m.jsx("span",{className:"agd-file-row__actions",children:f})]})}var Io={editor:"Can edit",commenter:"Can comment",viewer:"Can view"},RS=["editor","commenter","viewer"],NS=l=>l==="agent"?["commenter","viewer"]:RS,Wp={never:"Never","1d":"In 1 day","7d":"In 7 days","30d":"In 30 days"};function DA(l,r){const c=l.kind==="person"?"person":"agent",o=NS(c),s=o.map(f=>({role:f,allowed:!0}));return o.includes(r)?s:[{role:r,allowed:!1},...s]}function jA({people:l,onInvite:r,onChangeRole:c,onRemove:o}){const[s,f]=g.useState(""),[h,v]=g.useState("viewer"),[S,p]=g.useState(),[E,y]=g.useState(""),x=g.useRef(null),O=hp(s)?.kind??"person",j=NS(O),A=j.includes(h)?h:"viewer";return m.jsxs("div",{className:"agd-share",children:[m.jsxs("form",{className:"agd-share__invite",noValidate:!0,onSubmit:w=>{w.preventDefault();const D=hp(s);if(!D){y(""),p("Enter an email like ada@example.org, or an agent handle like @claude.");return}const T=C=>C?.replace(/^@/,"").toLowerCase()===D.to.replace(/^@/,"").toLowerCase();if(l.some(C=>T(C.invitedAs)||T(C.entry.id)||T(C.entry.name))){y(""),p(`${D.to} already has access. Change their role in the list below.`);return}r({...D,role:A}),p(void 0),y(`Invited ${D.to} as ${A}.`),f("")},children:[m.jsx(Qr,{ref:x,label:"Invite a person or an agent",hint:"An email invites a person. An @handle invites an agent. An agent can comment or view, and suggests edits that people accept.",value:s,onChange:w=>f(w.target.value),error:S,autoComplete:"off"}),m.jsx(xl,{label:"Role",value:A,onChange:w=>v(w.target.value),children:j.map(w=>m.jsx("option",{value:w,children:Io[w]},w))}),m.jsx(ke,{type:"submit",variant:"primary",children:"Invite"})]}),m.jsx("p",{role:"status",className:"agd-share__sent",children:E}),m.jsx("ul",{className:"agd-share__people","aria-label":"People and agents with access",children:l.map(w=>{const{entry:D,role:T}=w;return m.jsxs("li",{children:[m.jsx(Ai,{entry:D}),T==="owner"?m.jsx("span",{className:"agd-share__owner",children:"Owner"}):m.jsxs("span",{className:"agd-share__controls",children:[m.jsx(xl,{label:`Access for ${e0(w)}`,hideLabel:!0,value:T,onChange:C=>c(D.id,C.target.value),children:DA(D,T).map(({role:C,allowed:B})=>m.jsx("option",{value:C,disabled:!B,children:B?Io[C]:`${Io[C]} (not allowed for agents)`},C))}),m.jsx(ke,{variant:"ghost",size:"sm","aria-label":`Remove access for ${e0(w)}`,onClick:()=>{o(D.id),x.current?.focus()},children:"Remove"})]})]},D.id)})})]})}var e0=l=>l.invitedAs??Oi(l.entry),t0=l=>l.toLocaleDateString("en",{day:"numeric",month:"short",year:"numeric"});function MA({link:l,onChangeLink:r,onCopy:c}){const o=l.expiresAt!=null&&l.expiresAt.getTime()<Date.now();return m.jsxs("div",{className:"agd-share",children:[m.jsx(y_,{label:"Anyone with the link",hint:l.enabled?void 0:"Only people you invite can open this page.",checked:l.enabled,onChange:s=>r({...l,enabled:s.target.checked})}),l.enabled&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"agd-share__row",children:[m.jsx(xl,{label:"Access",value:l.role,hint:l.role==="editor"?l.signedInOnly?"Anyone who signs in with the link can edit. That includes agents.":"Anyone with the link can edit without signing in. That includes agents.":void 0,onChange:s=>r({...l,role:s.target.value}),children:RS.map(s=>m.jsx("option",{value:s,children:Io[s]},s))}),m.jsx(xl,{label:"Link expires",value:l.expiry,hint:l.expiresAt&&!o?`Stops working on ${t0(l.expiresAt)}.`:void 0,error:o&&l.expiresAt?`This link expired on ${t0(l.expiresAt)}. Choose a new expiry.`:void 0,onChange:s=>r({...l,expiry:s.target.value}),children:Object.keys(Wp).map(s=>m.jsx("option",{value:s,children:Wp[s]},s))})]}),m.jsx(g_,{label:"Require sign-in",hint:"People must sign in before they open the link.",checked:l.signedInOnly,onChange:s=>r({...l,signedInOnly:s.target.checked})}),!o&&m.jsxs("div",{className:"agd-share__copy",children:[m.jsx(Qr,{label:"Link",value:l.url,readOnly:!0,onFocus:s=>s.target.select()}),m.jsx(ke,{onClick:()=>c(l.url),children:"Copy link"})]})]})]})}function zA({snapshot:l,onCopy:r}){return m.jsxs("div",{className:"agd-share",children:[m.jsx("p",{children:"A snapshot puts a read-only copy of this page inside the link. It needs no account and no server read. Later edits are not in it."}),m.jsx("div",{children:m.jsx(ke,{onClick:l.onCreate,children:l.url?"Create a new snapshot link":"Create snapshot link"})}),l.url&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"agd-share__copy",children:[m.jsx(Qr,{label:"Snapshot link",value:l.url,readOnly:!0,onFocus:c=>c.target.select()}),m.jsx(ke,{onClick:()=>r(l.url),children:"Copy link"})]}),m.jsx("p",{className:"agd-field__hint",children:"Anyone who has this link can read this copy. Share it like a password."})]})]})}function UA({resourceName:l,trigger:r,open:c,onOpenChange:o,...s}){return m.jsx(Om,{trigger:r,open:c,onOpenChange:o,title:`Share “${l}”`,description:"Choose who can open this page, and what they can do.",children:m.jsx(eA,{label:"Ways to share",tabs:[{value:"people",label:"People and agents",content:m.jsx(jA,{people:s.people,onInvite:s.onInvite,onChangeRole:s.onChangeRole,onRemove:s.onRemove})},{value:"link",label:"Link",content:m.jsx(MA,{link:s.link,onChangeLink:s.onChangeLink,onCopy:s.onCopy})},{value:"snapshot",label:"Snapshot",content:m.jsx(zA,{snapshot:s.snapshot,onCopy:s.onCopy})}]})})}var LA=Object.defineProperty,DS=(l,r)=>LA(l,"name",{value:r,configurable:!0}),jS="Popover",[MS,jR]=Ht(jS,[Mi]);Mi();var[MR,zR]=MS(jS),HA="PopoverPortal",[UR,LR]=MS(HA,{forceMount:void 0});function BA(l){return l?"open":"closed"}DS(BA,"getState");function GA(...l){const r=new Set;for(const c of l)if(typeof c=="string")for(const o of String(c).trim().split(/\s+/))o&&r.add(o);return r.size>0?Array.from(r).join(" "):void 0}DS(GA,"concatAriaDescribedby");const YA={create:"created this item",rename:"renamed it",move:"moved it",update:"replaced its content",share:"shared it",unshare:"stopped sharing it",delete:"moved it to the trash",restore:"restored it"};function VA(l){const r=l.detail??{};return l.action==="rename"?r.from===void 0?"":`from "${r.from}" to "${r.to}"`:l.action==="share"?r.subjectId?`with ${r.subjectId} as ${r.role}`:"":l.action==="unshare"&&r.subjectId?`from ${r.subjectId}`:""}const qA=l=>l.action==="share"&&l.detail?.via==="invite"?l.detail.role===void 0?"accepted an invite":`accepted an invite and now has the role ${l.detail.role}`:`${YA[l.action]} ${VA(l)}`.trim(),IA=({entry:l})=>l.actor.kind==="agent"?m.jsx("span",{className:"agd-pill",children:"AI agent"}):null;function XA({entries:l}){return l.length===0?m.jsx("p",{className:"drive-muted",children:"No activity yet."}):m.jsx("ol",{className:"drive-activity","aria-label":"Activity",children:l.map(r=>m.jsxs("li",{children:[m.jsx("strong",{children:r.actor.id})," ",m.jsx(IA,{entry:r})," ",qA(r)," ",m.jsx("time",{dateTime:new Date(r.at).toISOString(),children:new Date(r.at).toLocaleString()})]},r.id))})}function zS(l,{key:r,dir:c},o=s=>s.updatedAt){const s=c==="asc"?1:-1,f=r==="name"?(h,v)=>h.name.localeCompare(v.name,void 0,{numeric:!0}):(h,v)=>o(h)-o(v);return[...l].sort((h,v)=>(h.kind==="folder"?0:1)-(v.kind==="folder"?0:1)||s*f(h,v)||h.name.localeCompare(v.name))}function PA({at:l}){const r=new Date(l);return Number.isFinite(r.getTime())?m.jsx("time",{dateTime:r.toISOString(),children:QA.format(r)}):m.jsx("span",{children:"—"})}const QA=new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"});function KA({value:l,onChange:r}){const[c,o]=g.useState(!1),s=g.useRef(null),f=g.useRef(null),h=g.useRef(!1),v=c||!!l;g.useEffect(()=>{v?s.current?.focus():h.current&&(h.current=!1,f.current?.focus())},[v]);const S=()=>{h.current=!0,r(""),o(!1)};return v?m.jsxs("div",{className:"drive-search",role:"search",children:[m.jsx("input",{ref:s,type:"search",className:"drive-search__input","aria-label":"Search this folder",placeholder:"Search this folder",value:l,onChange:p=>r(p.target.value),onKeyDown:p=>{p.key==="Escape"&&S()}}),m.jsx(ke,{variant:"ghost",size:"sm",onClick:S,children:"Close search"})]}):m.jsx(ke,{ref:f,variant:"ghost",size:"sm",onClick:()=>o(!0),children:"Search"})}function US({label:l,items:r,sort:c,onSort:o,selected:s=new Set,onSelect:f,href:h,onOpen:v,who:S,actions:p,dateOf:E=y=>y.updatedAt}){const y=r.length>0&&r.every(w=>s.has(w.id)),x=!y&&r.some(w=>s.has(w.id)),O=g.useRef(null);g.useEffect(()=>{O.current&&(O.current.indeterminate=x)},[x]);const j=(w,D)=>{if(!f)return;const T=new Set(s);D?T.add(w):T.delete(w),f(T)},A=(w,D,T)=>m.jsx("th",{scope:"col",className:T,"aria-sort":c.key===w?c.dir==="asc"?"ascending":"descending":"none",children:m.jsxs("button",{type:"button",className:"drive-sort",onClick:()=>o(w),children:[D,m.jsx("span",{"aria-hidden":"true",children:c.key===w?c.dir==="asc"?" ↑":" ↓":""})]})});return m.jsxs("table",{className:"drive-table","aria-label":l,children:[m.jsx("thead",{children:m.jsxs("tr",{children:[f&&m.jsx("th",{scope:"col",className:"drive-table__check",children:m.jsx("input",{ref:O,type:"checkbox",className:"agd-checkbox","aria-label":"Select all items",checked:y,onChange:w=>f(w.target.checked?new Set(r.map(D=>D.id)):new Set)})}),A("name","Name"),m.jsx("th",{scope:"col",className:"drive-table__who",children:"Edited by"}),A("modified","Modified","drive-table__date"),m.jsx("th",{scope:"col",children:m.jsx("span",{className:"drive-sr",children:"Actions"})})]})}),m.jsx("tbody",{children:r.map(w=>m.jsxs("tr",{className:"drive-row","data-selected":s.has(w.id)||void 0,children:[f&&m.jsx("td",{className:"drive-table__check",children:m.jsx("input",{type:"checkbox",className:"agd-checkbox","aria-label":`Select ${w.name}`,checked:s.has(w.id),onChange:D=>j(w.id,D.target.checked)})}),m.jsx("td",{children:m.jsxs("div",{className:"drive-table__name",children:[m.jsx("span",{className:"drive-table__icon","aria-hidden":"true",children:w.kind==="folder"?m.jsx(wi,{}):m.jsx(Yr,{})}),m.jsx("a",{href:h(w),onClick:D=>v?.(D,w),children:w.name})]})}),m.jsx("td",{className:"drive-table__who",children:m.jsx(Ai,{entry:S(w.updatedBy,w.owner)})}),m.jsx("td",{className:"drive-table__date",children:m.jsx(PA,{at:E(w)})}),m.jsx("td",{className:"drive-table__actions",children:p(w)})]},w.id))})]})}function ZA({count:l,busy:r,onTrash:c,onClear:o}){return l===0?null:m.jsxs("div",{role:"region","aria-label":"Selected items",className:"drive-bulk",children:[m.jsxs("span",{role:"status",children:[l," selected"]}),m.jsx(ke,{variant:"danger",size:"sm",onClick:c,disabled:r,children:"Move to trash"}),m.jsx(ke,{variant:"ghost",size:"sm",onClick:o,children:"Clear selection"})]})}class Ut extends Error{constructor(r,c,o){super(o),this.code=r,this.status=c,this.name="DriveApiError"}code;status}const FA="/api/v1/drive",kA={NOT_FOUND:!0,NAME_TAKEN:!0,BLOB_EXISTS:!0,INVALID_NAME:!0,INVALID_PATH:!0,INVALID_REF:!0,NOT_A_FOLDER:!0,NOT_A_FILE:!0,MOVE_INTO_SELF:!0,TOO_DEEP:!0,PARENT_GONE:!0,TRASHED:!0,NOT_TRASHED:!0,IS_ROOT:!0,FORBIDDEN:!0,BLOB_MISSING:!0,TOO_LARGE:!0,INVALID_EXPIRY:!0,BUSY:!0,CROSS_DRIVE:!0,INVALID_SHARE:!0,TOO_MANY_ITEMS:!0,UNAUTHORIZED:!0,NOT_CONFIGURED:!0,INVALID_LINK:!0,INTERNAL:!0},JA=new Set(Object.keys(kA)),pl=l=>typeof l=="object"&&l!==null&&!Array.isArray(l),it=l=>typeof l=="string",na=l=>r=>r===null||l(r),aa=l=>typeof l=="number",LS={human:!0,agent_of_human:!0,agent_of_agent:!0,agent:!0,user_token:!0},pd=["viewer","commenter","editor","owner"],bl=l=>r=>typeof r=="string"&&l.includes(r),n0=l=>pl(l)&&it(l.id)&&bl(Object.keys(LS))(l.kind),Jt=l=>pl(l)&&it(l.id)&&it(l.owner)&&it(l.parentId)&&it(l.name)&&(l.kind==="folder"||l.kind==="file"||l.kind==="ref")&&aa(l.size)&&na(it)(l.mime)&&na(it)(l.hash)&&na(it)(l.ref)&&aa(l.createdAt)&&aa(l.updatedAt)&&n0(l.createdBy)&&n0(l.updatedBy)&&it(l.createdById)&&it(l.updatedById)&&typeof l.trashed=="boolean"&&na(aa)(l.trashedAt)&&typeof l.machineMade=="boolean",$A=["create","rename","move","update","share","unshare","delete","restore"],WA=l=>pl(l)&&it(l.id)&&it(l.itemId)&&bl($A)(l.action)&&pl(l.actor)&&it(l.actor.id)&&bl(["human","agent"])(l.actor.kind)&&bl(Object.keys(LS))(l.principalKind)&&aa(l.at)&&(l.detail===void 0||pl(l.detail)),Mo=l=>Jt(l)&&typeof l.path=="string",pn=l=>r=>Array.isArray(r)&&r.every(l),bn=l=>r=>pl(r)&&l(r),bd=(...l)=>bn(r=>l.every(c=>typeof r[c]=="number")),zo=bn(l=>l.ok===!0),eR=new Set([502,503,504]);function Xd(l){let r;try{const T=new URL(l.baseUrl);if(T.protocol!=="http:"&&T.protocol!=="https:")throw new Error("not http");r=T.origin}catch{throw new TypeError("baseUrl must be an http or https URL")}const{token:c}=l;if(c!==void 0&&(typeof c!="string"||!/^[A-Za-z0-9_-]{1,512}$/.test(c)))throw new TypeError("token must be 1 to 512 letters, digits, - or _");const o=l.retries??0;if(!Number.isInteger(o)||o<0||o>5)throw new RangeError("retries must be an integer from 0 to 5");const s=l.fetch??((T,C)=>globalThis.fetch(T,C)),f=T=>{const C=new URLSearchParams;for(const[z,L]of Object.entries(T))L!==void 0&&C.set(z,String(L));const B=C.toString();return B===""?"":`?${B}`};async function h(T,C,B){if(B.auth!==!1&&c===void 0)throw new TypeError("this call needs a token");const z={...c===void 0?{}:{authorization:`Bearer ${c}`},...B.headers};let L=B.body;B.json!==void 0&&(z["content-type"]="application/json",L=JSON.stringify(B.json));const q=T==="GET"?o+1:1;for(let Z=1;;Z++){let $;try{$=await s(`${r}${FA}${C}`,{method:T,headers:z,body:L,signal:B.signal,redirect:"manual",...L instanceof ReadableStream?{duplex:"half"}:{}})}catch(te){if(B.signal?.aborted||te instanceof Error&&te.name==="AbortError")throw te;if(Z<q){await v(Z,B.signal);continue}const re=L instanceof ReadableStream?" (a stream body may be refused by this runtime: send bytes)":"";throw new Ut("NETWORK_ERROR",0,`${te instanceof Error?`no answer: ${te.message}`:"no answer"}${re}`)}if(Z<q&&eR.has($.status)){await $.body?.cancel(),await v(Z,B.signal);continue}if($.type==="opaqueredirect"||$.status>=300&&$.status<400)throw await $.body?.cancel(),new Ut("BAD_RESPONSE",$.status,"the server redirected. Set baseUrl to the final URL.");if($.ok)return $;throw await S($,B.signal)}}async function v(T,C){C?.throwIfAborted(),await new Promise((B,z)=>{const L=setTimeout(()=>{C?.removeEventListener("abort",q),B()},Math.min(100*2**(T-1),1e3)),q=()=>{clearTimeout(L),z(C?.reason)};C?.addEventListener("abort",q,{once:!0})})}async function S(T,C){let B="BAD_RESPONSE",z=`the server answered ${T.status}`;try{const L=await T.json();typeof L.error?.code=="string"&&JA.has(L.error.code)?B=L.error.code:typeof L.error?.code=="string"&&(z=`the server answered ${T.status} with an unknown code, ${JSON.stringify(L.error.code.slice(0,40))}`),B!=="BAD_RESPONSE"&&typeof L.error?.message=="string"&&(z=L.error.message)}catch(L){if(C?.aborted)throw L}return new Ut(B,T.status,z)}async function p(T,C,B,z){const L=await h(T,C,B);let q;try{q=await L.json()}catch(Z){throw B.signal?.aborted?Z:Z instanceof SyntaxError?new Ut("BAD_RESPONSE",L.status,"the answer is not JSON"):new Ut("NETWORK_ERROR",0,"the connection dropped while the body came in")}if(!z(q))throw new Ut("BAD_RESPONSE",L.status,"the answer is not the shape that the API sends");return q}async function E(T,C,B=!1){const z=await h("GET",T,C);let L;try{L=new Uint8Array(await z.arrayBuffer())}catch(Z){throw C.signal?.aborted?Z:new Ut("NETWORK_ERROR",0,"the connection dropped while the body came in")}const q=z.headers.get("x-content-sha256")??"";if(B){if(!/^[0-9a-f]{64}$/.test(q))throw new Ut("BAD_RESPONSE",z.status,"the answer has no valid x-content-sha256");if(typeof crypto>"u"||!crypto.subtle)throw new Ut("BAD_RESPONSE",z.status,"this runtime has no WebCrypto, so the bytes cannot be checked. Use https.");const Z=new Uint8Array(await crypto.subtle.digest("SHA-256",L));if(Array.from(Z,$=>$.toString(16).padStart(2,"0")).join("")!==q)throw new Ut("BAD_RESPONSE",z.status,"the bytes do not match their hash")}return{data:L,contentType:z.headers.get("content-type")??"application/octet-stream",sha256:q}}const y=T=>{if(T!==void 0){if(!/^[A-Za-z0-9_-]{1,512}$/.test(T))throw new TypeError("a link token has 1 to 512 letters, digits, - or _");return{"x-link-token":T}}},x=T=>{if(typeof T!="string"||!/^[A-Za-z0-9_-][A-Za-z0-9_.-]*$/.test(T)||T==="."||T==="..")throw new TypeError("an item id has letters, digits, -, _ and . (not first), and is not . or ..");return T},O=bn(T=>typeof T.url=="string"&&/^https?:\/\//.test(T.url)&&URL.canParse(T.url)&&typeof T.expiresInSeconds=="number"),j=bn(T=>pn(bn(C=>(C.subjectKind==="human"||C.subjectKind==="agent")&&it(C.subjectId)&&bl(pd)(C.role)))(T.grants)&&pn(bn(C=>it(C.id)&&bl(pd)(C.role)&&typeof C.signedInOnly=="boolean"&&na(aa)(C.expiresAt)&&typeof C.revoked=="boolean"))(T.links)&&pn(bn(C=>it(C.id)&&bl(pd)(C.role)&&na(it)(C.email)&&na(it)(C.handle)&&na(aa)(C.expiresAt)&&typeof C.accepted=="boolean"))(T.invites)),A=bn(T=>pl(T.apps)&&Object.values(T.apps).every(aa)&&aa(T.files)&&pn(bn(C=>Mo(C)&&na(it)(C.app)))(T.items)),w=bn(T=>typeof T.id=="string"),D=bn(T=>typeof T.id=="string"&&typeof T.token=="string");return{list:(T="/",C={})=>p("GET",`/items${f({path:T})}`,C,pn(Jt)),listActivity:(T,C={})=>p("GET",`/items/${encodeURIComponent(T)}/activity${f({limit:C.limit})}`,C,pn(WA)),stat:(T,C={})=>p("GET",`/stat${f({path:T})}`,C,Jt),mkdir:(T,C={},B={})=>p("POST","/folders",{json:{path:T,parents:C.parents===!0},...B},Jt),upload:(T,C,B={},z={})=>p("PUT",`/files${f({path:T,mime:B.mime,parents:B.parents===!0?!0:void 0,onConflict:B.onConflict})}`,{body:typeof C=="string"?new TextEncoder().encode(C):C,headers:{"content-type":"application/octet-stream"},...z},Jt),download:(T,C={})=>E(`/files${f({path:T})}`,C,!0),url:(T,C,B={})=>p("GET",`/url${f({path:T,expires:C})}`,B,O),move:(T,C,B={},z={})=>p("POST","/move",{json:{src:T,folder:C,...B},...z},Jt),trash:(T,C={})=>p("POST","/trash",{json:{path:T},...C},Jt),listTrash:(T={})=>p("GET","/trash",T,pn(Jt)),restore:(T,C={},B={})=>p("POST","/restore",{json:{id:T,...C},...B},Jt),purge:(T,C={})=>p("POST","/purge",{json:{id:T},...C},bd("removed")),search:(T={},C={})=>p("GET",`/search${f(T)}`,C,pn(Mo)),export:async(T={})=>{const{data:C}=await E("/export",T);if(C[0]!==80||C[1]!==75)throw new Ut("BAD_RESPONSE",200,"the answer is not a zip");return C},deleteAccount:(T={})=>p("DELETE","/account?confirm=yes",T,bd("removed","grants","invites","anonymized")),home:(T={},C={})=>p("GET",`/home${f(T)}`,C,A),findByRef:(T,C={})=>p("GET",`/refs${f({ref:T})}`,C,pn(Mo)),listTrashWithPaths:(T={})=>p("GET","/trash/paths",T,pn(Mo)),claimRef:(T,C={})=>p("POST","/refs",{json:{path:T.path,ref:T.ref,subjectKind:T.subject.kind,subjectId:T.subject.id,role:T.role,parents:T.parents,onConflict:T.onConflict},...C},Jt),registerDocument:(T,C={})=>p("POST","/documents",{json:T,...C},Jt),forgetDocument:(T,C={})=>p("DELETE",`/documents${f({ref:T})}`,C,bd("trashed")),shares:(T,C={})=>p("GET",`/shares${f({path:T})}`,C,j),share:(T,C,B,z={})=>p("POST","/shares",{json:{path:T,subjectId:C.id,subjectKind:C.kind,role:B},...z},zo),unshare:(T,C,B={})=>p("DELETE",`/shares${f({path:T,subjectId:C.id,subjectKind:C.kind})}`,B,zo),invite:(T,C,B={})=>p("POST","/invites",{json:{path:T,...C},...B},w),acceptInvite:(T,C={})=>p("POST","/invites/accept",{json:{id:T},...C},zo),createLink:(T,C,B={})=>p("POST","/links",{json:{path:T,...C},...B},D),revokeLink:(T,C={})=>p("DELETE",`/links${f({id:T})}`,C,zo),openShared:async(T,C={})=>p("GET",`/shared/${x(T)}`,{auth:!1,headers:y(C.linkToken),signal:C.signal},Jt),listShared:async(T,C={})=>p("GET",`/shared/${x(T)}/items`,{auth:!1,headers:y(C.linkToken),signal:C.signal},pn(Jt)),readShared:async(T,C={})=>{const{data:B,contentType:z}=await E(`/shared/${x(T)}/content`,{auth:!1,headers:y(C.linkToken),signal:C.signal});return{data:B,contentType:z}}}}const Uo="agentic-drive-token",Cl=l=>l instanceof Ut?`${l.message} (${l.code})`:l instanceof Error?l.message:"Something went wrong",HS=(l,r)=>(l.kind==="folder"?0:1)-(r.kind==="folder"?0:1)||l.name.localeCompare(r.name),ko=(l,r)=>l.kind==="human"?{id:l.id,name:l.id,kind:"person"}:{id:l.id,name:l.id,kind:"agent",actingFor:r},Jo=({item:l})=>l.machineMade?m.jsx("span",{className:"agd-pill",children:"Created by agent"}):null;function Al(l){const[r,c]=g.useState({status:"loading"}),[o,s]=g.useState(0);return g.useEffect(()=>{const f=new AbortController;return l(f.signal).then(h=>!f.signal.aborted&&c({status:"ok",data:h}),h=>!f.signal.aborted&&c({status:"error",error:Cl(h)})),()=>f.abort()},[o]),[r,()=>s(f=>f+1)]}function Hi({state:l,retry:r,children:c}){return l.status==="loading"?m.jsxs("p",{role:"status",className:"drive-status",children:[m.jsx("span",{className:"agd-spinner","aria-hidden":"true"})," Loading…"]}):l.status==="error"?m.jsx("div",{role:"alert",children:m.jsx(Ri,{title:"Could not load this page",description:l.error,action:m.jsx(ke,{onClick:r,children:"Try again"})})}):m.jsx(m.Fragment,{children:c})}const BS=l=>l.replace(/^#\/?/,"").split("/"),tR=l=>{history.replaceState(null,"",`#/${l}`),dispatchEvent(new HashChangeEvent("hashchange"))};function nR({hash:l,client:r,origin:c,go:o,onOpenItem:s,folderLoc:f}){const h=BS(l);return h[0]==="trash"?m.jsx(oR,{client:r},"trash"):h[0]==="a"&&h[1]?m.jsx(cR,{client:r,id:h[1]},l):h[0]==="f"&&h[1]?m.jsx(fR,{client:r,id:h[1],origin:c,go:o},l):m.jsx(iR,{client:r,loc:f??(h[0]||"/"),go:o,origin:c,onOpenItem:s},l)}function aR(){const[l,r]=g.useState(()=>sessionStorage.getItem(Uo)??""),[c,o]=g.useState(location.hash);g.useEffect(()=>{const v=()=>o(location.hash);return addEventListener("hashchange",v),()=>removeEventListener("hashchange",v)},[]),g.useEffect(()=>{const v=S=>S.preventDefault();return addEventListener("dragover",v),addEventListener("drop",v),()=>{removeEventListener("dragover",v),removeEventListener("drop",v)}},[]);const s=g.useMemo(()=>{try{return Xd({baseUrl:location.origin,...l?{token:l}:{}})}catch{return Xd({baseUrl:location.origin})}},[l]);g.useEffect(()=>{l&&!/^[A-Za-z0-9_-]{1,512}$/.test(l)&&(sessionStorage.removeItem(Uo),r(""))},[l]);const f=()=>{sessionStorage.removeItem(Uo),r(""),location.hash="#/"},h=BS(c);return h[0]==="s"&&h[1]?m.jsx(Sd,{signedIn:!1,signOut:f,children:m.jsx(dR,{client:s,id:h[1],linkToken:h[2]},c)}):l?m.jsx(Sd,{signedIn:!0,signOut:f,current:h[0]==="trash"?"trash":"files",children:m.jsx(nR,{hash:c,client:s,origin:location.origin,go:tR})}):m.jsx(Sd,{signedIn:!1,signOut:f,children:m.jsx(lR,{onToken:v=>{sessionStorage.setItem(Uo,v),r(v)}})})}function Sd({children:l,signedIn:r,signOut:c,current:o}){const{preference:s,setPreference:f}=$x();return m.jsx(lA,{brand:"Drive",sidebar:r?m.jsx(iA,{label:"Places",items:[{href:"#/",label:"My files",icon:m.jsx(wi,{"aria-hidden":"true"}),current:o==="files"},{href:"#/trash",label:"Trash",current:o==="trash"}]}):m.jsx("p",{className:"drive-muted",children:"Sign in to see your files."}),topbar:m.jsxs(m.Fragment,{children:[m.jsxs(xl,{hideLabel:!0,label:"Theme",value:s,onChange:h=>f(h.target.value),children:[m.jsx("option",{value:"system",children:"Theme: system"}),m.jsx("option",{value:"light",children:"Theme: light"}),m.jsx("option",{value:"dark",children:"Theme: dark"})]}),r&&m.jsx(ke,{variant:"ghost",onClick:c,children:"Sign out"})]}),children:m.jsx("div",{className:"drive-main",children:l})})}function lR({onToken:l}){const[r,c]=g.useState(""),[o,s]=g.useState(),[f,h]=g.useState(!1),v=async S=>{S.preventDefault(),h(!0),s(void 0);try{await Xd({baseUrl:location.origin,token:r.trim()}).list("/"),l(r.trim())}catch(p){s(p instanceof TypeError?"A token has letters, digits, - and _ only.":p instanceof Ut&&p.code==="UNAUTHORIZED"?"This token is not valid.":Cl(p))}h(!1)};return m.jsxs("form",{onSubmit:v,className:"drive-signin","aria-labelledby":"signin-title",children:[m.jsx("h1",{id:"signin-title",children:"Sign in"}),m.jsx(Qr,{label:"Access token",type:"password",autoComplete:"off",value:r,onChange:S=>c(S.target.value),error:o,hint:"The bearer token of a person or an agent. The tab keeps it until you close it.",required:!0}),m.jsx(ke,{type:"submit",loading:f,children:"Sign in"})]})}function iR({client:l,loc:r,origin:c,onOpenItem:o,go:s}){const f=(J,Y)=>{J.defaultPrevented||J.button!==0||J.metaKey||J.ctrlKey||J.shiftKey||J.altKey||Y.kind!=="ref"||o?.(Y)===!0&&J.preventDefault()},h=yc(),[v,S]=g.useState(()=>localStorage.getItem("agentic-drive-view")==="grid"?"grid":"list"),[p,E]=g.useState(null),[y,x]=g.useState(!1),[O,j]=g.useState(!1),[A,w]=g.useState(""),[D,T]=g.useState({key:"name",dir:"asc"}),[C,B]=g.useState(new Set),z=g.useRef(null),[L,q]=Al(async()=>{const J=await l.stat("/"),Y=r==="/"?J:await l.stat(r),k=[];try{for(let fe=Y;fe.id!==J.id;fe=await l.stat(fe.parentId))k.unshift(fe)}catch(fe){if(!(fe instanceof Ut&&(fe.code==="NOT_FOUND"||fe.code==="FORBIDDEN")))throw fe}const K=async fe=>(await l.list(fe.id===J.id?"/":fe.id)).sort(HS),ne=await K(Y),W=new Map([[J.id,Z(await K(J))]]);for(const fe of k)W.set(fe.id,fe.id===Y.id?Z(ne):Z(await K(fe)));return{root:J,folder:Y,crumbs:k,items:ne,tree:W}});function Z(J){return J.filter(Y=>Y.kind==="folder")}const $=async(J,Y)=>{try{await J(),h({title:Y,tone:"success"}),E(null)}catch(k){h({title:"That did not work",description:Cl(k),tone:"danger"})}q()},te=async J=>{if(L.status!=="ok")return;if(O)return void h({title:"An upload is running",description:"Wait for it to finish, then add more files.",tone:"info"});const{folder:Y,root:k}=L.data;j(!0);for(const K of Array.from(J))await $(()=>l.upload(Y.id===k.id?`/${K.name}`:`${Y.id}/${K.name}`,K,{mime:K.type||void 0,onConflict:"rename"}),`Uploaded ${K.name}`);j(!1)},re=J=>{J.preventDefault(),x(!1),J.dataTransfer.files.length&&te(J.dataTransfer.files)},le=J=>T(Y=>({key:J,dir:Y.key===J&&Y.dir==="asc"?"desc":"asc"})),ae=async J=>{j(!0);const k=(await Promise.allSettled(J.map(K=>l.trash(K)))).filter(K=>K.status==="rejected");k.length?h({title:`${k.length} of ${J.length} items did not move`,description:Cl(k[0].reason),tone:"danger"}):h({title:`Moved ${J.length} ${J.length===1?"item":"items"} to trash`,tone:"success"}),B(new Set),j(!1),q()},se=J=>{B(new Set),localStorage.setItem("agentic-drive-view",J),S(J)};return m.jsx("section",{onDragOver:J=>{J.preventDefault(),x(!0)},onDragLeave:J=>{J.currentTarget.contains(J.relatedTarget)||x(!1)},onDrop:re,className:`drive-drop${y?" drive-drop--over":""}${v==="list"&&C.size?" drive-drop--bulk":""}`,"aria-label":"Files",children:m.jsx(Hi,{state:L,retry:q,children:L.status==="ok"&&(()=>{const{folder:J,root:Y,crumbs:k,tree:K}=L.data,ne=A.trim().toLowerCase(),W=zS(L.data.items.filter(I=>I.name.toLowerCase().includes(ne)),D),fe=W.filter(I=>C.has(I.id)).map(I=>I.id),Be=I=>m.jsxs(m.Fragment,{children:[m.jsx(Jo,{item:I}),m.jsx(WO,{align:"end",trigger:m.jsx(Tl,{label:`Actions for ${I.name}`,icon:m.jsx(bb,{}),variant:"ghost"}),items:[{label:"Rename",onSelect:()=>E({kind:"rename",item:I})},{label:"Move",onSelect:()=>E({kind:"move",item:I})},{label:"Activity",onSelect:()=>s(`a/${I.id}`)},{label:"Share",onSelect:()=>E({kind:"share",item:I})},"separator",{label:"Move to trash",danger:!0,onSelect:()=>{$(()=>l.trash(I.id),`Moved ${I.name} to trash`)}}]})]}),Pe=I=>I.kind==="folder"?`#/${I.id}`:`#/f/${I.id}`,N=I=>m.jsx("ul",{className:"drive-tree",children:(K.get(I)??[]).map(F=>m.jsxs("li",{children:[m.jsxs("a",{href:`#/${F.id}`,"aria-current":F.id===J.id?"page":void 0,children:[m.jsx(wi,{"aria-hidden":"true"})," ",F.name]}),K.has(F.id)&&N(F.id)]},F.id))});return m.jsxs(m.Fragment,{children:[m.jsx("nav",{"aria-label":"Breadcrumb",className:"drive-crumbs",children:m.jsxs("ol",{children:[m.jsx("li",{children:k.length?m.jsx("a",{href:"#/",children:"My files"}):m.jsx("span",{"aria-current":"page",children:"My files"})}),k.map((I,F)=>m.jsx("li",{children:F===k.length-1?m.jsx("span",{"aria-current":"page",children:I.name}):m.jsx("a",{href:`#/${I.id}`,children:I.name})},I.id))]})}),m.jsxs("div",{className:"drive-bar",children:[m.jsxs("div",{className:"drive-title",children:[m.jsx("h1",{children:J.id===Y.id?"My files":J.name}),J.id!==Y.id&&m.jsx(ke,{variant:"secondary",size:"sm",onClick:()=>E({kind:"share",item:J}),children:"Share"})]}),m.jsxs(gA,{label:"Folder actions",children:[m.jsx(jo,{label:"New folder",icon:m.jsx(s_,{}),onClick:()=>E({kind:"mkdir"})}),m.jsx(jo,{label:"Upload files",icon:m.jsx(Yr,{}),onClick:()=>z.current?.click(),disabled:O}),m.jsx(jo,{label:"List view",icon:m.jsx("span",{"aria-hidden":"true",children:"☰"}),pressed:v==="list",onClick:()=>se("list")}),m.jsx(jo,{label:"Grid view",icon:m.jsx("span",{"aria-hidden":"true",children:"▦"}),pressed:v==="grid",onClick:()=>se("grid")})]}),m.jsx("input",{ref:z,type:"file",multiple:!0,hidden:!0,"aria-label":"Choose files to upload",onChange:I=>{I.target.files&&te(I.target.files),I.target.value=""}})]}),m.jsxs("div",{className:"drive-split",children:[m.jsx("nav",{"aria-label":"Folders",className:"drive-folders",children:N(Y.id)}),m.jsxs("div",{children:[m.jsx("div",{className:"drive-tools",children:m.jsx(KA,{value:A,onChange:w})}),m.jsx("p",{role:"status",className:"drive-sr",children:ne?`${W.length} of ${L.data.items.length} items match`:""}),L.data.items.length===0?m.jsx(Ri,{title:"This folder is empty",description:"Drop files here, or use Upload files.",action:m.jsx(ke,{onClick:()=>z.current?.click(),disabled:O,children:"Upload files"})}):W.length===0?m.jsx(Ri,{title:"Nothing matches",description:`No item in this folder has “${A.trim()}” in its name.`,action:m.jsx(ke,{onClick:()=>w(""),children:"Clear search"})}):v==="list"?m.jsx(US,{label:`Items in ${J.name||"My files"}`,items:W,sort:D,onSort:le,selected:C,onSelect:B,onOpen:f,href:Pe,who:ko,actions:Be}):m.jsx("ul",{className:"drive-grid","aria-label":`Items in ${J.name||"My files"}`,children:W.map(I=>m.jsxs("li",{className:"drive-card",children:[m.jsx("span",{className:"drive-card__icon","aria-hidden":"true",children:I.kind==="folder"?m.jsx(wi,{}):m.jsx(Yr,{})}),m.jsx("a",{href:Pe(I),onClick:F=>f(F,I),className:"drive-card__name",children:I.name}),m.jsxs("span",{className:"drive-card__meta",children:["Edited by ",m.jsx(Ai,{entry:ko(I.updatedBy,I.owner)})]}),m.jsx("span",{className:"drive-card__actions",children:Be(I)})]},I.id))})]})]}),v==="list"&&m.jsx(ZA,{count:fe.length,busy:O,onTrash:()=>{ae(fe)},onClear:()=>B(new Set)}),p?.kind==="mkdir"&&m.jsx(a0,{open:!0,title:"New folder",label:"Folder name",initial:"",submit:"Create",onClose:()=>E(null),onSubmit:I=>$(()=>l.mkdir(J.id===Y.id?`/${I}`:`${J.id}/${I}`),`Created ${I}`)}),p?.kind==="rename"&&m.jsx(a0,{open:!0,title:"Rename",label:"New name",initial:p.item.name,submit:"Rename",onClose:()=>E(null),onSubmit:I=>$(()=>l.move(p.item.id,p.item.parentId,{name:I}),`Renamed to ${I}`)}),p?.kind==="move"&&m.jsx(rR,{client:l,item:p.item,onClose:()=>E(null),onMove:I=>$(()=>l.move(p.item.id,I),`Moved ${p.item.name}`)}),p?.kind==="share"&&m.jsx(uR,{client:l,item:p.item,origin:c,onClose:()=>E(null)})]})})()})})}function a0({open:l,title:r,label:c,initial:o,submit:s,onClose:f,onSubmit:h}){const[v,S]=g.useState(o),p=g.useRef(!1),[E,y]=g.useState(),x=O=>{if(O){if(O.includes("/"))return y("A name cannot have a slash.");y(void 0),p.current=!0,h(O).finally(()=>{p.current=!1})}};return m.jsx(Om,{open:!!l,onOpenChange:O=>{O||f()},title:r,children:m.jsxs("form",{onSubmit:O=>{O.preventDefault(),p.current||x(v.trim())},className:"drive-form",children:[m.jsx(Qr,{label:c,value:v,onChange:O=>S(O.target.value),error:E,required:!0}),m.jsxs("div",{className:"drive-form__actions",children:[m.jsx(bS,{asChild:!0,children:m.jsx(ke,{variant:"ghost",type:"button",children:"Cancel"})}),m.jsx(ke,{type:"submit",children:s})]})]})})}function rR({client:l,item:r,onClose:c,onMove:o}){const[s,f]=Al(async()=>{const p=await l.stat("/"),E=await l.search({kind:"folder",limit:1e3}),y=E.find(x=>x.id===r.id)?.path;return[{id:"/",path:"/",name:"My files"},...E.filter(x=>x.id!==p.id&&!(y&&(x.path===y||x.path.startsWith(`${y}/`))))]}),[h,v]=g.useState("/"),S=g.useRef(!1);return m.jsx(Om,{open:!0,onOpenChange:p=>{p||c()},title:`Move ${r.name}`,children:m.jsx(Hi,{state:s,retry:f,children:s.status==="ok"&&m.jsxs("form",{onSubmit:p=>{p.preventDefault(),!S.current&&(S.current=!0,o(h).finally(()=>{S.current=!1}))},className:"drive-form",children:[m.jsx(xl,{label:"Move to",value:h,onChange:p=>v(p.target.value),children:s.data.map(p=>m.jsx("option",{value:p.id,children:p.path==="/"?"My files":p.path},p.id))}),m.jsxs("div",{className:"drive-form__actions",children:[m.jsx(bS,{asChild:!0,children:m.jsx(ke,{variant:"ghost",type:"button",children:"Cancel"})}),m.jsx(ke,{type:"submit",children:"Move"})]})]})})})}const l0={never:void 0,"1d":864e5,"7d":7*864e5,"30d":30*864e5};function uR({client:l,item:r,origin:c,onClose:o}){const s=yc(),[f,h]=Al(()=>l.shares(r.id)),[v,S]=g.useState({role:"viewer",expiry:"never",signedInOnly:!1}),p=f.status==="ok"?f.data.links.filter(T=>!T.revoked&&(T.expiresAt===null||T.expiresAt>Date.now())):[],E=p[0],y=v.id?v:E?{...v,id:E.id,role:E.role==="owner"?"editor":E.role,signedInOnly:E.signedInOnly}:v,x=async T=>{try{await T()}catch(C){s({title:"That did not work",description:Cl(C),tone:"danger"})}h()},O=f.status==="ok"?f.data.grants.map(T=>({entry:{id:T.subjectId,name:T.subjectId,kind:T.subjectKind==="agent"?"agent":"person"},role:T.role})):[],j=T=>f.status==="ok"&&f.data.grants.find(C=>C.subjectId===T)?.subjectKind||"human",A=async()=>{for(const T of new Set([...p.map(C=>C.id),...y.id?[y.id]:[]]))await l.revokeLink(T)},w=T=>x(async()=>{await A();const C=await l.createLink(r.id,{role:T.role,signedInOnly:T.signedInOnly,...l0[T.expiry]?{expiresInMs:l0[T.expiry]}:{}});S({...T,id:C.id,token:C.token}),s({title:"New link made",description:y.id?"The old link no longer works.":void 0,tone:"info"})}),D={enabled:!!y.id,role:y.role,expiry:y.expiry,signedInOnly:y.signedInOnly,url:y.token?`${c}/#/s/${r.id}/${y.token}`:"Turn the link off and on to make a new one. The address shows once.",expiresAt:E?.expiresAt?new Date(E.expiresAt):null};return m.jsx(UA,{open:!0,onOpenChange:T=>{T||o()},resourceName:r.name,people:O,onInvite:T=>{x(async()=>{await l.invite(r.id,{role:T.role,...T.kind==="person"?{email:T.to}:{handle:T.to.replace(/^@/,"")}}),s({title:"Invite created",tone:"success"})})},onChangeRole:(T,C)=>{x(()=>l.share(r.id,{kind:j(T),id:T},C))},onRemove:T=>{x(()=>l.unshare(r.id,{kind:j(T),id:T}))},link:D,onChangeLink:T=>{if(!T.enabled)return void x(async()=>{await A(),S({...y,id:void 0,token:void 0})});w({role:T.role,expiry:T.expiry,signedInOnly:T.signedInOnly})},snapshot:{onCreate:()=>s({title:"Snapshot links are not available in Drive yet",tone:"info"})},onCopy:T=>y.token&&void navigator.clipboard?.writeText(T).then(()=>s({title:"Link copied",tone:"success"}),()=>s({title:"Could not copy",tone:"warning"}))})}const i0=l=>l.trashedAt??l.updatedAt;function oR({client:l}){const r=yc(),[c,o]=Al(()=>l.listTrash()),[s,f]=g.useState({key:"name",dir:"asc"}),h=S=>f(p=>({key:S,dir:p.key===S&&p.dir==="asc"?"desc":"asc"})),v=async S=>{try{await l.restore(S.id,{onConflict:"rename"}),r({title:`Restored ${S.name}`,tone:"success"})}catch(p){r({title:"Could not restore",description:Cl(p),tone:"danger"})}o()};return m.jsxs("section",{"aria-label":"Trash",children:[m.jsx("h1",{children:"Trash"}),m.jsx(Hi,{state:c,retry:o,children:c.status==="ok"&&(c.data.length===0?m.jsx(Ri,{title:"The trash is empty",description:"Items you move to the trash show up here."}):m.jsx(US,{label:"Items in the trash",items:zS(c.data,s,i0),dateOf:i0,sort:s,onSort:h,href:()=>"#/trash",who:ko,actions:S=>m.jsxs(m.Fragment,{children:[m.jsx(Jo,{item:S}),m.jsx(ke,{size:"sm",onClick:()=>{v(S)},children:`Restore ${S.name}`})]})}))})]})}function cR({client:l,id:r}){const[c,o]=Al(async()=>({item:await l.stat(r),entries:await l.listActivity(r)}));return m.jsx("section",{"aria-label":"Item activity",children:m.jsx(Hi,{state:c,retry:o,children:c.status==="ok"&&m.jsxs(m.Fragment,{children:[m.jsxs("h1",{children:["Activity: ",c.data.item.name]}),m.jsx("p",{children:m.jsx("a",{href:c.data.item.kind==="folder"?`#/${r}`:`#/${c.data.item.parentId==="root"?"":c.data.item.parentId}`,children:"Back to files"})}),m.jsx(XA,{entries:c.data.entries})]})})})}async function sR(l,r,c,o){const s=await l.stat(r,{signal:o});o.throwIfAborted();const{url:f}=await l.url(r,void 0,{signal:o});if(o.throwIfAborted(),new URL(f,c).origin!==c)throw new Error("The download link points to another site.");const h=document.createElement("a");return h.href=f,h.download=s.name,h.click(),s}function fR({client:l,id:r,origin:c,go:o}){const[s,f]=Al(async h=>{const v=await sR(l,r,c,h);return h.throwIfAborted(),o(v.parentId,{replace:!0}),v});return m.jsx(Hi,{state:s,retry:f,children:null})}function dR({client:l,id:r,linkToken:c}){const[o,s]=Al(async()=>{const v=await l.openShared(r,{linkToken:c});return{item:v,items:v.kind==="folder"?(await l.listShared(r,{linkToken:c})).sort(HS):[]}}),f=yc(),h=async()=>{if(o.status==="ok")try{const{data:v,contentType:S}=await l.readShared(r,{linkToken:c}),p=document.createElement("a");p.href=URL.createObjectURL(new Blob([v],{type:S})),p.download=o.data.item.name,p.click(),setTimeout(()=>URL.revokeObjectURL(p.href),1e4)}catch(v){f({title:"Could not download",description:Cl(v),tone:"danger"})}};return m.jsx("section",{"aria-label":"Shared item",children:m.jsx(Hi,{state:o,retry:s,children:o.status==="ok"&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"drive-bar",children:[m.jsxs("div",{className:"drive-title",children:[m.jsx("h1",{children:o.data.item.name}),m.jsx(Jo,{item:o.data.item})]}),o.data.item.kind!=="folder"&&m.jsx(ke,{onClick:()=>{h()},children:"Download"})]}),m.jsx("p",{className:"drive-muted",children:"Shared with you."}),o.data.item.kind==="folder"?o.data.items.length===0?m.jsx(Ri,{title:"This folder is empty"}):m.jsx(AA,{label:"Shared items",children:o.data.items.map(v=>m.jsx(NA,{name:v.name,href:`#/s/${v.id}${c?`/${c}`:""}`,kind:v.kind==="folder"?"folder":"file",modified:new Date(v.updatedAt),editedBy:ko(v.updatedBy,v.owner),actions:m.jsx(Jo,{item:v})},v.id))}):null]})})})}Qx.createRoot(document.getElementById("root")).render(m.jsx(g.StrictMode,{children:m.jsx(Jx,{children:m.jsx(gb,{children:m.jsx(nA,{children:m.jsx(aR,{})})})})}));
49
+ `)},$_=0,Ei=[];function W_(l){var r=g.useRef([]),c=g.useRef([0,0]),o=g.useRef(),s=g.useState($_++)[0],f=g.useState(Cb)[0],h=g.useRef(l);g.useEffect(function(){h.current=l},[l]),g.useEffect(function(){if(l.inert){document.body.classList.add("block-interactivity-".concat(s));var A=S_([l.lockRef.current],(l.shards||[]).map(Yp)).filter(Boolean);return A.forEach(function(w){return w.classList.add("allow-interactivity-".concat(s))}),function(){document.body.classList.remove("block-interactivity-".concat(s)),A.forEach(function(w){return w.classList.remove("allow-interactivity-".concat(s))})}}},[l.inert,l.lockRef.current,l.shards]);var v=g.useCallback(function(A,w){if("touches"in A&&A.touches.length===2||A.type==="wheel"&&A.ctrlKey)return!h.current.allowPinchZoom;var D=Ao(A),T=c.current,C="deltaX"in A?A.deltaX:T[0]-D[0],B="deltaY"in A?A.deltaY:T[1]-D[1],z,L=A.target,q=Math.abs(C)>Math.abs(B)?"h":"v";if("touches"in A&&q==="h"&&L.type==="range")return!1;var Z=window.getSelection(),$=Z&&Z.anchorNode,te=$?$===L||$.contains(L):!1;if(te)return!1;var re=Bp(q,L);if(!re)return!0;if(re?z=q:(z=q==="v"?"h":"v",re=Bp(q,L)),!re)return!1;if(!o.current&&"changedTouches"in A&&(C||B)&&(o.current=z),!z)return!0;var le=o.current||z;return F_(le,w,A,le==="h"?C:B)},[]),S=g.useCallback(function(A){var w=A;if(!(!Ei.length||Ei[Ei.length-1]!==f)){var D="deltaY"in w?Gp(w):Ao(w),T=r.current.filter(function(z){return z.name===w.type&&(z.target===w.target||w.target===z.shadowParent)&&k_(z.delta,D)})[0];if(T&&T.should){w.cancelable&&w.preventDefault();return}if(!T){var C=(h.current.shards||[]).map(Yp).filter(Boolean).filter(function(z){return z.contains(w.target)}),B=C.length>0?v(w,C[0]):!h.current.noIsolation;B&&w.cancelable&&w.preventDefault()}}},[]),p=g.useCallback(function(A,w,D,T){var C={name:A,delta:w,target:D,should:T,shadowParent:ew(D)};r.current.push(C),setTimeout(function(){r.current=r.current.filter(function(B){return B!==C})},1)},[]),E=g.useCallback(function(A){c.current=Ao(A),o.current=void 0},[]),y=g.useCallback(function(A){p(A.type,Gp(A),A.target,v(A,l.lockRef.current))},[]),x=g.useCallback(function(A){p(A.type,Ao(A),A.target,v(A,l.lockRef.current))},[]);g.useEffect(function(){return Ei.push(f),l.setCallbacks({onScrollCapture:y,onWheelCapture:y,onTouchMoveCapture:x}),document.addEventListener("wheel",S,Si),document.addEventListener("touchmove",S,Si),document.addEventListener("touchstart",E,Si),function(){Ei=Ei.filter(function(A){return A!==f}),document.removeEventListener("wheel",S,Si),document.removeEventListener("touchmove",S,Si),document.removeEventListener("touchstart",E,Si)}},[]);var O=l.removeScrollBar,j=l.inert;return g.createElement(g.Fragment,null,j?g.createElement(f,{styles:J_(s)}):null,O?g.createElement(q_,{noRelative:l.noRelative,gapMode:l.gapMode}):null)}function ew(l){for(var r=null;l!==null;)l instanceof ShadowRoot&&(r=l.host,l=l.host),l=l.parentNode;return r}var tw=R_(xb,W_),Ab=g.forwardRef(function(l,r){return g.createElement(sc,Un({},l,{ref:r,sideCar:tw}))});Ab.classNames=sc.classNames;var Rb=Ab,nw=function(l){if(typeof document>"u")return null;var r=Array.isArray(l)?l[0]:l;return r.ownerDocument.body},Ti=new WeakMap,Ro=new WeakMap,No={},hd=0,Nb=function(l){return l&&(l.host||Nb(l.parentNode))},aw=function(l,r){return r.map(function(c){if(l.contains(c))return c;var o=Nb(c);return o&&l.contains(o)?o:(console.error("aria-hidden",c,"in not contained inside",l,". Doing nothing"),null)}).filter(function(c){return!!c})},lw=function(l,r,c,o){var s=aw(r,Array.isArray(l)?l:[l]);No[c]||(No[c]=new WeakMap);var f=No[c],h=[],v=new Set,S=new Set(s),p=function(y){!y||v.has(y)||(v.add(y),p(y.parentNode))};s.forEach(p);var E=function(y){!y||S.has(y)||Array.prototype.forEach.call(y.children,function(x){if(v.has(x))E(x);else try{var O=x.getAttribute(o),j=O!==null&&O!=="false",A=(Ti.get(x)||0)+1,w=(f.get(x)||0)+1;Ti.set(x,A),f.set(x,w),h.push(x),A===1&&j&&Ro.set(x,!0),w===1&&x.setAttribute(c,"true"),j||x.setAttribute(o,"true")}catch(D){console.error("aria-hidden: cannot operate on ",x,D)}})};return E(r),v.clear(),hd++,function(){h.forEach(function(y){var x=Ti.get(y)-1,O=f.get(y)-1;Ti.set(y,x),f.set(y,O),x||(Ro.has(y)||y.removeAttribute(o),Ro.delete(y)),O||y.removeAttribute(c)}),hd--,hd||(Ti=new WeakMap,Ti=new WeakMap,Ro=new WeakMap,No={})}},Db=function(l,r,c){c===void 0&&(c="data-aria-hidden");var o=Array.from(Array.isArray(l)?l:[l]),s=nw(l);return s?(o.push.apply(o,Array.from(s.querySelectorAll("[aria-live], script"))),lw(o,s,c,"aria-hidden")):function(){return null}},iw=Object.defineProperty,Bt=(l,r)=>iw(l,"name",{value:r,configurable:!0}),dm="Dialog",[jb,gR]=Ht(dm),[rw,En]=jb(dm),uw=Bt(l=>{const{__scopeDialog:r,children:c,open:o,defaultOpen:s,onOpenChange:f,modal:h=!0}=l,v=g.useRef(null),S=g.useRef(null),{nodes:p,registry:E}=Jd(),[y,x]=_l({prop:o,defaultProp:s??!1,onChange:f,caller:dm}),[O,j]=g.useState(0),[A,w]=g.useState(0);return m.jsx(rw,{scope:r,triggerRef:v,contentRef:S,contentId:la(),titleId:la(),descriptionId:la(),titlePresent:O>0,descriptionPresent:A>0,setTitleCount:j,setDescriptionCount:w,open:y,onOpenChange:x,onOpenToggle:g.useCallback(()=>x(D=>!D),[x]),modal:h,branchNodes:p,branchRegistry:E,children:c})},"Dialog"),ow="DialogTrigger",cw=g.forwardRef(Bt(function(r,c){const{__scopeDialog:o,...s}=r,f=En(ow,o),h=Ie(c,f.triggerRef);return m.jsx(De.button,{type:"button","aria-haspopup":"dialog","aria-expanded":f.open,"aria-controls":f.open?f.contentId:void 0,"data-state":fc(f.open),...s,ref:h,onClick:he(r.onClick,f.onOpenToggle)})},"DialogTrigger")),Mb="DialogPortal",[sw,zb]=jb(Mb,{forceMount:void 0}),fw=Bt(l=>{const{__scopeDialog:r,forceMount:c,children:o,container:s}=l,f=En(Mb,r);return m.jsx(sw,{scope:r,forceMount:c,children:g.Children.map(o,h=>m.jsx(sa,{present:c||f.open,children:m.jsx(uc,{asChild:!0,container:s,children:h})}))})},"DialogPortal"),Ld="DialogOverlay",dw=g.forwardRef(Bt(function(r,c){const o=zb(Ld,r.__scopeDialog),{forceMount:s=o.forceMount,...f}=r,h=En(Ld,r.__scopeDialog);return h.modal?m.jsx(sa,{present:s||h.open,children:m.jsx(hw,{...f,ref:c})}):null},"DialogOverlay")),mw=qa("DialogOverlay.RemoveScroll"),hw=g.forwardRef(Bt(function(r,c){const{__scopeDialog:o,...s}=r,f=En(Ld,o),h=T0(),v=Ie(c,h);return m.jsx(Rb,{as:mw,allowPinchZoom:!0,shards:g.useMemo(()=>[f.contentRef,...f.branchNodes.map(S=>({current:S}))],[f.contentRef,f.branchNodes]),children:m.jsx(De.div,{"data-state":fc(f.open),...s,ref:v,style:{pointerEvents:"auto",...s.style}})})},"DialogOverlayImpl")),Vr="DialogContent",vw=g.forwardRef(Bt(function(r,c){const o=zb(Vr,r.__scopeDialog),{forceMount:s=o.forceMount,...f}=r,h=En(Vr,r.__scopeDialog);return m.jsx(sa,{present:s||h.open,children:h.modal?m.jsx(gw,{...f,ref:c}):m.jsx(yw,{...f,ref:c})})},"DialogContent")),gw=g.forwardRef(Bt(function(r,c){const o=En(Vr,r.__scopeDialog),s=g.useRef(null),f=Ie(c,o.contentRef,s);return g.useEffect(()=>{const h=s.current;if(h)return Db(h)},[]),m.jsx(Ub,{...r,ref:f,trapFocus:o.open,disableOutsidePointerEvents:o.open,onCloseAutoFocus:he(r.onCloseAutoFocus,h=>{h.preventDefault(),o.triggerRef.current?.focus()}),onPointerDownOutside:he(r.onPointerDownOutside,h=>{const v=h.detail.originalEvent,S=v.button===0&&v.ctrlKey===!0;(v.button===2||S)&&h.preventDefault()}),onFocusOutside:he(r.onFocusOutside,h=>h.preventDefault())})},"DialogContentModal")),yw=g.forwardRef(Bt(function(r,c){const o=En(Vr,r.__scopeDialog),s=g.useRef(!1),f=g.useRef(!1);return m.jsx(Ub,{...r,ref:c,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:h=>{r.onCloseAutoFocus?.(h),h.defaultPrevented||(s.current||o.triggerRef.current?.focus(),h.preventDefault()),s.current=!1,f.current=!1},onInteractOutside:h=>{r.onInteractOutside?.(h),h.defaultPrevented||(s.current=!0,h.detail.originalEvent.type==="pointerdown"&&(f.current=!0));const v=h.target;o.triggerRef.current?.contains(v)&&h.preventDefault(),h.detail.originalEvent.type==="focusin"&&f.current&&h.preventDefault()}})},"DialogContentNonModal")),Ub=g.forwardRef(Bt(function(r,c){const{__scopeDialog:o,trapFocus:s,onOpenAutoFocus:f,onCloseAutoFocus:h,"aria-describedby":v,children:S,...p}=r,E=En(Vr,o);return cc(),m.jsx(kd,{registry:E.branchRegistry,children:m.jsx(_0,{asChild:!0,loop:!0,trapped:s,branches:E.branchNodes,onMountAutoFocus:f,onUnmountAutoFocus:h,children:m.jsx(ec,{role:"dialog",id:E.contentId,"aria-labelledby":E.titlePresent?E.titleId:void 0,"aria-describedby":E.descriptionPresent?Hb(v,E.descriptionId):v,"data-state":fc(E.open),...p,ref:c,deferPointerDownOutside:!0,onDismiss:()=>E.onOpenChange(!1),children:S})})})},"DialogContentImpl")),pw=g.forwardRef(Bt(function(r,c){const{__scopeDialog:o,...s}=r,f=En("DialogTitle",o),{setTitleCount:h}=f;return xt(()=>(h(v=>v+1),()=>h(v=>v-1)),[h]),m.jsx(De.h2,{id:f.titleId,...s,ref:c})},"DialogTitle")),bw=g.forwardRef(Bt(function(r,c){const{__scopeDialog:o,...s}=r,f=En("DialogDescription",o),{setDescriptionCount:h}=f;return xt(()=>(h(v=>v+1),()=>h(v=>v-1)),[h]),m.jsx(De.p,{id:f.descriptionId,...s,ref:c})},"DialogDescription")),Sw="DialogClose",Lb=g.forwardRef(Bt(function(r,c){const{__scopeDialog:o,...s}=r,f=En(Sw,o);return m.jsx(De.button,{type:"button",...s,ref:c,onClick:he(r.onClick,()=>f.onOpenChange(!1))})},"DialogClose"));function Hb(...l){const r=new Set;for(const c of l)if(typeof c=="string")for(const o of String(c).trim().split(/\s+/))o&&r.add(o);return r.size>0?Array.from(r).join(" "):void 0}Bt(Hb,"concatAriaDescribedby");function fc(l){return l?"open":"closed"}Bt(fc,"getState");var Ew=Object.defineProperty,ut=(l,r)=>Ew(l,"name",{value:r,configurable:!0});function dc(l){const r=l+"CollectionProvider",[c,o]=Ht(r),[s,f]=c(r,{collectionRef:{current:null},itemMap:new Map}),h=ut(A=>{const{scope:w,children:D}=A,T=g.useRef(null),C=g.useRef(new Map).current;return m.jsx(s,{scope:w,itemMap:C,collectionRef:T,children:D})},"CollectionProvider");h.displayName=r;const v=l+"CollectionSlot",S=qa(v),p=g.forwardRef((A,w)=>{const{scope:D,children:T}=A,C=f(v,D),B=Ie(w,C.collectionRef);return m.jsx(S,{ref:B,children:T})});p.displayName=v;const E=l+"CollectionItemSlot",y="data-radix-collection-item",x=qa(E),O=g.forwardRef((A,w)=>{const{scope:D,children:T,...C}=A,B=g.useRef(null),z=Ie(w,B),L=f(E,D);return g.useEffect(()=>(L.itemMap.set(B,{ref:B,...C}),()=>{L.itemMap.delete(B)})),m.jsx(x,{[y]:"",ref:z,children:T})});O.displayName=E;function j(A){const w=f(l+"CollectionConsumer",A);return g.useCallback(()=>{const T=w.collectionRef.current;if(!T)return[];const C=Array.from(T.querySelectorAll(`[${y}]`));return Array.from(w.itemMap.values()).sort((L,q)=>C.indexOf(L.ref.current)-C.indexOf(q.ref.current))},[w.collectionRef,w.itemMap])}return ut(j,"useCollection"),[{Provider:h,Slot:p,ItemSlot:O},j,o]}ut(dc,"createCollection");var Vp=new WeakMap,$e,$t,Do=($t=class extends Map{constructor(c){super(c);ap(this,$e);Wf(this,$e,[...super.keys()]),Vp.set(this,!0)}set(c,o){return Vp.get(this)&&!this.has(c)&&Et(this,$e).push(c),super.set(c,o),this}insert(c,o,s){const f=this.has(o),h=f?this.size:this.size+1,v=mm(c),S=v>=0?Math.min(v,h-1):Math.max(h+v,0);if(f?Et(this,$e).indexOf(o)===S:S===this.size)return this.set(o,s),this;const p=Et(this,$e).filter(y=>y!==o);p.splice(S,0,o);const E=p.map(y=>[y,y===o?s:this.get(y)]);this.clear();for(const[y,x]of E)this.set(y,x);return this}with(c,o,s){const f=new $t(this);return f.insert(c,o,s),f}before(c){const o=Et(this,$e).indexOf(c)-1;if(!(o<0))return this.entryAt(o)}setBefore(c,o,s){const f=Et(this,$e).indexOf(c);if(f===-1)return this;const h=Et(this,$e).indexOf(o),v=h!==-1&&h<f?f-1:f;return this.insert(v,o,s)}after(c){let o=Et(this,$e).indexOf(c);if(o=o===-1||o===this.size-1?-1:o+1,o!==-1)return this.entryAt(o)}setAfter(c,o,s){const f=Et(this,$e).indexOf(c);if(f===-1)return this;const h=Et(this,$e).indexOf(o),v=h!==-1&&h<=f?f:f+1;return this.insert(v,o,s)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return Wf(this,$e,[]),super.clear()}delete(c){const o=super.delete(c);return o&&Et(this,$e).splice(Et(this,$e).indexOf(c),1),o}deleteAt(c){const o=this.keyAt(c);return o!==void 0?this.delete(o):!1}at(c){const o=Go(Et(this,$e),c);if(o!==void 0)return this.get(o)}entryAt(c){const o=Go(Et(this,$e),c);if(o!==void 0)return[o,this.get(o)]}indexOf(c){return Et(this,$e).indexOf(c)}keyAt(c){return Go(Et(this,$e),c)}from(c,o){const s=this.indexOf(c);if(s===-1)return;let f=s+o;return f<0&&(f=0),f>=this.size&&(f=this.size-1),this.at(f)}keyFrom(c,o){const s=this.indexOf(c);if(s===-1)return;let f=s+o;return f<0&&(f=0),f>=this.size&&(f=this.size-1),this.keyAt(f)}find(c,o){let s=0;for(const f of this){if(Reflect.apply(c,o,[f,s,this]))return f;s++}}findIndex(c,o){let s=0;for(const f of this){if(Reflect.apply(c,o,[f,s,this]))return s;s++}return-1}filter(c,o){const s=[];let f=0;for(const h of this)Reflect.apply(c,o,[h,f,this])&&s.push(h),f++;return new $t(s)}map(c,o){const s=[];let f=0;for(const h of this)s.push([h[0],Reflect.apply(c,o,[h,f,this])]),f++;return new $t(s)}reduce(...c){const[o,s]=c,f=c.length>1;if(!f&&this.size===0)throw new TypeError("Reduce of empty OrderedDict with no initial value");let h=0,v=s;for(const S of this)h===0&&!f?v=S:v=Reflect.apply(o,this,[v,S,h,this]),h++;return v}reduceRight(...c){const[o,s]=c,f=c.length>1;if(!f&&this.size===0)throw new TypeError("Reduce of empty OrderedDict with no initial value");let h=s;for(let v=this.size-1;v>=0;v--){const S=this.entryAt(v);v===this.size-1&&!f?h=S:h=Reflect.apply(o,this,[h,S,v,this])}return h}sort(c){if(typeof c!="function")throw new TypeError("OrderedDict.sort requires a compare function");const o=[...this.entries()].sort(c);this.clear();for(const[s,f]of o)this.set(s,f);return this}toSorted(c){if(typeof c!="function")throw new TypeError("OrderedDict.toSorted requires a compare function");const o=[...this.entries()].sort(c);return new $t(o)}toReversed(){const c=new $t;for(let o=this.size-1;o>=0;o--){const s=this.keyAt(o),f=this.get(s);c.set(s,f)}return c}toSpliced(...c){const o=[...this.entries()];return o.splice(...c),new $t(o)}slice(c,o){const s=new $t;for(const f of Et(this,$e).slice(c,o))s.set(f,this.get(f));return s}every(c,o){let s=0;for(const f of this){if(!Reflect.apply(c,o,[f,s,this]))return!1;s++}return!0}some(c,o){let s=0;for(const f of this){if(Reflect.apply(c,o,[f,s,this]))return!0;s++}return!1}},$e=new WeakMap,ut($t,"OrderedDict"),$t);function Go(l,r){if("at"in Array.prototype)return Array.prototype.at.call(l,r);const c=Bb(l,r);return c===-1?void 0:l[c]}ut(Go,"at");function Bb(l,r){const c=l.length,o=mm(r),s=o>=0?o:c+o;return s<0||s>=c?-1:s}ut(Bb,"toSafeIndex");function mm(l){return l!==l||l===0?0:Math.trunc(l)}ut(mm,"toSafeInteger");function Tw(l){const r=l+"CollectionProvider",[c,o]=Ht(r),[s,f]=c(r);s.displayName=l+"CollectionStableContextProvider";const[h,v]=c(r);h.displayName=l+"CollectionStatefulContextProvider";const S=ut(({state:L,...q})=>L?m.jsx(E,{...q,state:L}):m.jsx(p,{...q}),"CollectionProvider");S.displayName=r;const p=ut(L=>{const q=T();return m.jsx(E,{...L,state:q})},"CollectionInit");p.displayName=l+"CollectionInit";const E=ut(L=>{const{scope:q,children:Z,state:$}=L,te=g.useRef(null),[re,le]=g.useState(null),ae=Ie(te,le),[se,J]=$,Y=g.useRef(new Do),k=g.useCallback(()=>{const K=Y.current;return Vb(K)||K.sort(Yo),K},[]);return g.useEffect(()=>{if(!re)return;const K=qb(()=>{J(ne=>{const W=ne.toSorted(Yo);return W.some(([Be],Pe)=>ne.keyAt(Pe)!==Be)?W:ne})});return K.observe(re,{childList:!0,subtree:!0}),()=>{K.disconnect()}},[re,J]),m.jsx(s,{scope:q,collectionElementRef:ae,collectionElementRefObject:te,getCollection:k,setCollection:J,registryRef:Y,children:m.jsx(h,{scope:q,collectionElement:re,collection:se,children:Z})})},"CollectionProviderImpl");E.displayName=l+"CollectionProviderImpl";const y=l+"CollectionSlot",x=qa(y),O=g.forwardRef((L,q)=>{const{scope:Z,children:$}=L,te=f(y,Z),re=Ie(q,te.collectionElementRef);return m.jsx(x,{ref:re,children:$})});O.displayName=y;const j=l+"CollectionItemSlot",A="data-radix-collection-item",w=qa(j),D=g.forwardRef((L,q)=>{const{scope:Z,children:$,...te}=L,re=g.useRef(null),le=f(j,Z),{setCollection:ae,registryRef:se}=le,J=g.useRef(te);Gb(J.current,te)||(J.current=te);const Y=J.current,k=g.useCallback(W=>{const fe=se.current;W?fe.set(W,{...J.current,element:W}):re.current&&fe.delete(re.current)},[se]),K=Ie(q,k,re);xt(()=>{const W=re.current,fe=se.current;W&&fe.has(W)&&fe.set(W,{...Y,element:W})},[Y,se]);const ne=g.useRef(null);return g.useEffect(()=>{const W=re.current,fe=ne.current;(fe?.element??null)===W&&(!W||fe?.itemData===Y)||(ne.current=W?{element:W,itemData:Y}:null,ae(Be=>{const Pe=new Do(Be);return fe&&fe.element!==W&&Pe.delete(fe.element),W&&Pe.set(W,{...Y,element:W}),Pe.sort(Yo)}))}),g.useEffect(()=>()=>{const W=ne.current;ne.current=null,W&&ae(fe=>{if(!fe.has(W.element))return fe;const Be=new Do(fe);return Be.delete(W.element),Be})},[ae]),m.jsx(w,{[A]:"",ref:K,children:$})});D.displayName=j;function T(){return g.useState(new Do)}ut(T,"useInitCollection");function C(L){const{collection:q}=v(l+"CollectionConsumer",L);return q}ut(C,"useCollection");function B(L){const{getCollection:q}=f(l+"CollectionConsumer",L);return q}return ut(B,"useGetCollection"),[{Provider:S,Slot:O,ItemSlot:D},{createCollectionScope:o,useCollection:C,useGetCollection:B,useInitCollection:T}]}ut(Tw,"createCollection");function Gb(l,r){if(l===r)return!0;if(typeof l!="object"||typeof r!="object"||l==null||r==null)return!1;const c=Object.keys(l),o=Object.keys(r);if(c.length!==o.length)return!1;for(const s of c)if(!Object.prototype.hasOwnProperty.call(r,s)||l[s]!==r[s])return!1;return!0}ut(Gb,"shallowEqual");function Yb(l,r){return!!(r.compareDocumentPosition(l)&Node.DOCUMENT_POSITION_PRECEDING)}ut(Yb,"isElementPreceding");function Vb(l){let r;for(const c of l.keys()){if(r){const o=r.compareDocumentPosition(c);if(!(o&Node.DOCUMENT_POSITION_DISCONNECTED)&&o&Node.DOCUMENT_POSITION_PRECEDING)return!1}r=c}return!0}ut(Vb,"isInDocumentOrder");function Yo(l,r){return!l[1].element||!r[1].element?0:Yb(l[1].element,r[1].element)?-1:1}ut(Yo,"sortByDocumentPosition");function qb(l){return new MutationObserver(c=>{for(const o of c)if(o.type==="childList"){l();return}})}ut(qb,"getChildListObserver");var xw=Object.defineProperty,Cw=(l,r)=>xw(l,"name",{value:r,configurable:!0}),_w={LTR:"ltr"},ww=g.createContext(void 0);function Kr(l){const r=g.useContext(ww);return l||r||_w.LTR}Cw(Kr,"useDirection");var Ow=Object.defineProperty,hm=(l,r)=>Ow(l,"name",{value:r,configurable:!0}),vd=!1;function Ib(){const[l,r]=g.useState(vd);return g.useEffect(()=>{vd||(vd=!0,r(!0))},[]),l}hm(Ib,"useIsHydrated");var Xb=Pa[" useSyncExternalStore ".trim().toString()];function Pb(){return()=>{}}hm(Pb,"subscribe");function Qb(){return Xb(Pb,()=>!0,()=>!1)}hm(Qb,"useIsHydratedModern");var Aw=typeof Xb=="function"?Qb:Ib,Rw=Object.defineProperty,wl=(l,r)=>Rw(l,"name",{value:r,configurable:!0}),gd="rovingFocusGroup.onEntryFocus",Nw={bubbles:!1,cancelable:!0},mc="RovingFocusGroup",[Hd,Kb,Dw]=dc(mc),[jw,Ka]=Ht(mc,[Dw]),qp={Vertical:"vertical",Horizontal:"horizontal"},Mw={RTL:"rtl"},[zw,Uw]=jw(mc),vm=g.forwardRef(wl(function(r,c){return m.jsx(Hd.Provider,{scope:r.__scopeRovingFocusGroup,children:m.jsx(Hd.Slot,{scope:r.__scopeRovingFocusGroup,children:m.jsx(Lw,{...r,ref:c})})})},"RovingFocusGroup")),Lw=g.forwardRef(wl(function(r,c){const{__scopeRovingFocusGroup:o,orientation:s,loop:f=!1,dir:h,currentTabStopId:v,defaultCurrentTabStopId:S,onCurrentTabStopIdChange:p,onEntryFocus:E,preventScrollOnEntryFocus:y=!1,...x}=r,O=g.useRef(null),j=Ie(c,O),A=Kr(h),[w,D]=_l({prop:v,defaultProp:S??null,onChange:p,caller:mc}),[T,C]=g.useState(!1),B=Wt(E),z=Kb(o),L=g.useRef(!1),[q,Z]=g.useState(0);return g.useEffect(()=>{const $=O.current;if($)return $.addEventListener(gd,B),()=>$.removeEventListener(gd,B)},[B]),m.jsx(zw,{scope:o,orientation:s,dir:A,loop:f,currentTabStopId:w,onItemFocus:g.useCallback($=>D($),[D]),onItemShiftTab:g.useCallback(()=>C(!0),[]),onFocusableItemAdd:g.useCallback(()=>Z($=>$+1),[]),onFocusableItemRemove:g.useCallback(()=>Z($=>$-1),[]),children:m.jsx(De.div,{tabIndex:T||q===0?-1:0,"data-orientation":s,...x,ref:j,style:{outline:"none",...r.style},onMouseDown:he(r.onMouseDown,()=>{L.current=!0}),onFocus:he(r.onFocus,$=>{const te=!L.current;if($.target===$.currentTarget&&te&&!T){const re=new CustomEvent(gd,Nw);if($.currentTarget.dispatchEvent(re),!re.defaultPrevented){const le=z().filter(k=>k.focusable),ae=le.find(k=>k.active),se=le.find(k=>k.id===w),Y=[ae,se,...le].filter(Boolean).map(k=>k.ref.current);ym(Y,y)}}L.current=!1}),onBlur:he(r.onBlur,()=>C(!1))})})},"RovingFocusGroupImpl")),Hw="RovingFocusGroupItem",gm=g.forwardRef(wl(function(r,c){const{__scopeRovingFocusGroup:o,focusable:s=!0,active:f=!1,tabStopId:h,children:v,...S}=r,p=la(),E=h||p,y=Uw(Hw,o),x=y.currentTabStopId===E,O=Kb(o),{onFocusableItemAdd:j,onFocusableItemRemove:A,currentTabStopId:w}=y,D=Aw();return xt(()=>{if(!(!D||!s))return j(),()=>A()},[D,s,j,A]),g.useEffect(()=>{if(!(D||!s))return j(),()=>A()},[D,s,j,A]),m.jsx(Hd.ItemSlot,{scope:o,id:E,focusable:s,active:f,children:m.jsx(De.span,{tabIndex:x?0:-1,"data-orientation":y.orientation,...S,ref:c,onMouseDown:he(r.onMouseDown,T=>{s?y.onItemFocus(E):T.preventDefault()}),onFocus:he(r.onFocus,()=>y.onItemFocus(E)),onKeyDown:he(r.onKeyDown,T=>{if(T.key==="Tab"&&T.shiftKey){y.onItemShiftTab();return}if(T.target!==T.currentTarget)return;const C=Fb(T,y.orientation,y.dir);if(C!==void 0){if(T.metaKey||T.ctrlKey||T.altKey||T.shiftKey)return;T.preventDefault();let z=O().filter(L=>L.focusable).map(L=>L.ref.current);if(C==="last")z.reverse();else if(C==="prev"||C==="next"){C==="prev"&&z.reverse();const L=z.indexOf(T.currentTarget);z=y.loop?kb(z,L+1):z.slice(L+1)}setTimeout(()=>ym(z))}}),children:typeof v=="function"?v({isCurrentTabStop:x,hasTabStop:w!=null}):v})})},"RovingFocusGroupItem")),Bw={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Zb(l,r){return r!==Mw.RTL?l:l==="ArrowLeft"?"ArrowRight":l==="ArrowRight"?"ArrowLeft":l}wl(Zb,"getDirectionAwareKey");function Fb(l,r,c){const o=Zb(l.key,c);if(!(r===qp.Vertical&&["ArrowLeft","ArrowRight"].includes(o))&&!(r===qp.Horizontal&&["ArrowUp","ArrowDown"].includes(o)))return Bw[o]}wl(Fb,"getFocusIntent");function ym(l,r=!1){const c=document.activeElement;for(const o of l)if(o===c||(o.focus({preventScroll:r}),document.activeElement!==c))return}wl(ym,"focusFirst");function kb(l,r){return l.map((c,o)=>l[(r+o)%l.length])}wl(kb,"wrapArray");var Gw=Object.defineProperty,qe=(l,r)=>Gw(l,"name",{value:r,configurable:!0}),Yw=["Enter"," "],Vw=["ArrowDown","PageUp","Home"],Jb=["ArrowUp","PageDown","End"],qw=[...Vw,...Jb],hc="Menu",[Bd,Iw,Xw]=dc(hc),[Ol,$b]=Ht(hc,[Xw,Mi,Ka]),pm=Mi(),Wb=Ka(),[Pw,Zr]=Ol(hc),[Qw,bm]=Ol(hc),Kw=qe(l=>{const{__scopeMenu:r,open:c=!1,children:o,dir:s,onOpenChange:f,modal:h=!0}=l,v=pm(r),[S,p]=g.useState(null),E=g.useRef(!1),y=Wt(f),x=Kr(s);return g.useEffect(()=>{const O=qe(()=>{E.current=!0,document.addEventListener("pointerdown",j,{capture:!0,once:!0}),document.addEventListener("pointermove",j,{capture:!0,once:!0})},"handleKeyDown"),j=qe(()=>E.current=!1,"handlePointer");return document.addEventListener("keydown",O,{capture:!0}),()=>{document.removeEventListener("keydown",O,{capture:!0}),document.removeEventListener("pointerdown",j,{capture:!0}),document.removeEventListener("pointermove",j,{capture:!0})}},[]),g.useEffect(()=>{if(!c)return;const O=qe(()=>y(!1),"handleBlur");return window.addEventListener("blur",O),()=>window.removeEventListener("blur",O)},[c,y]),m.jsx(Z0,{...v,children:m.jsx(Pw,{scope:r,open:c,onOpenChange:y,content:S,onContentChange:p,children:m.jsx(Qw,{scope:r,onClose:g.useCallback(()=>y(!1),[y]),isUsingKeyboardRef:E,dir:x,modal:h,children:o})})})},"Menu"),Zw=g.forwardRef(qe(function(r,c){const{__scopeMenu:o,...s}=r,f=pm(o);return m.jsx(F0,{...f,...s,ref:c})},"MenuAnchor")),eS="MenuPortal",[Fw,kw]=Ol(eS,{forceMount:void 0}),Jw=qe(l=>{const{__scopeMenu:r,forceMount:c,children:o,container:s}=l,f=Zr(eS,r);return m.jsx(Fw,{scope:r,forceMount:c,children:m.jsx(sa,{present:c||f.open,children:m.jsx(uc,{asChild:!0,container:s,children:o})})})},"MenuPortal"),Va="MenuContent",[$w,tS]=Ol(Va),Ww=g.forwardRef(qe(function(r,c){const o=kw(Va,r.__scopeMenu),{forceMount:s=o.forceMount,...f}=r,h=Zr(Va,r.__scopeMenu),v=bm(Va,r.__scopeMenu);return m.jsx(Bd.Provider,{scope:r.__scopeMenu,children:m.jsx(sa,{present:s||h.open,children:m.jsx(Bd.Slot,{scope:r.__scopeMenu,children:v.modal?m.jsx(eO,{...f,ref:c}):m.jsx(tO,{...f,ref:c})})})})},"MenuContent")),eO=g.forwardRef(qe(function(r,c){const o=Zr(Va,r.__scopeMenu),s=g.useRef(null),f=Ie(c,s);return g.useEffect(()=>{const h=s.current;if(h)return Db(h)},[]),m.jsx(nS,{...r,ref:f,trapFocus:o.open,disableOutsidePointerEvents:o.open,disableOutsideScroll:!0,onFocusOutside:he(r.onFocusOutside,h=>h.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>o.onOpenChange(!1)})},"MenuRootContentModal")),tO=g.forwardRef(qe(function(r,c){const o=Zr(Va,r.__scopeMenu);return m.jsx(nS,{...r,ref:c,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>o.onOpenChange(!1)})},"MenuRootContentNonModal")),nO=qa("MenuContent.ScrollLock"),nS=g.forwardRef(qe(function(r,c){const{__scopeMenu:o,loop:s=!1,trapFocus:f,onOpenAutoFocus:h,onCloseAutoFocus:v,disableOutsidePointerEvents:S,onEntryFocus:p,onEscapeKeyDown:E,onPointerDownOutside:y,onFocusOutside:x,onInteractOutside:O,onDismiss:j,disableOutsideScroll:A,...w}=r,D=Zr(Va,o),T=bm(Va,o),C=pm(o),B=Wb(o),z=Iw(o),[L,q]=g.useState(null),Z=g.useRef(null),[$,te]=g.useState(null);$d($);const{nodes:re,registry:le}=Jd(),ae=!!(f||A),se=Ie(c,Z,D.onContentChange,te),J=g.useRef(0),Y=g.useRef(""),k=g.useRef(0),K=g.useRef(null),ne=g.useRef("right"),W=g.useRef(0),fe=g.useMemo(()=>A?[Z,...re.map(F=>({current:F}))]:[],[Z,re,A]),Be=A?Rb:g.Fragment,Pe=A?{as:nO,allowPinchZoom:!0,shards:fe}:void 0,N=qe(F=>{const oe=Y.current+F,ye=z().filter(Ke=>!Ke.disabled),pe=document.activeElement,Te=ye.find(Ke=>Ke.ref.current===pe)?.textValue,ue=ye.map(Ke=>Ke.textValue),me=uS(ue,oe,Te),mt=ye.find(Ke=>Ke.textValue===me)?.ref.current;function Gt(Ke){Y.current=Ke,window.clearTimeout(J.current),Ke!==""&&(J.current=window.setTimeout(()=>Gt(""),1e3))}qe(Gt,"updateSearch"),Gt(oe),mt&&setTimeout(()=>mt.focus())},"handleTypeaheadSearch");g.useEffect(()=>()=>window.clearTimeout(J.current),[]),cc();const I=g.useCallback(F=>ne.current===K.current?.side&&cS(F,K.current?.area),[]);return m.jsx($w,{scope:o,searchRef:Y,onItemEnter:g.useCallback(F=>{I(F)&&F.preventDefault()},[I]),onItemLeave:g.useCallback(F=>{I(F)||(Z.current?.focus(),q(null))},[I]),onTriggerLeave:g.useCallback(F=>{I(F)&&F.preventDefault()},[I]),pointerGraceTimerRef:k,onPointerGraceIntentChange:g.useCallback(F=>{K.current=F},[]),children:m.jsx(kd,{registry:ae?le:null,children:m.jsx(Be,{...Pe,children:m.jsx(_0,{asChild:!0,trapped:f,branches:re,onMountAutoFocus:he(h,F=>{F.preventDefault(),Z.current?.focus({preventScroll:!0})}),onUnmountAutoFocus:v,children:m.jsx(ec,{asChild:!0,disableOutsidePointerEvents:S,onEscapeKeyDown:E,onPointerDownOutside:y,onFocusOutside:x,onInteractOutside:O,onDismiss:j,children:m.jsx(vm,{asChild:!0,...B,dir:T.dir,orientation:"vertical",loop:s,currentTabStopId:L,onCurrentTabStopIdChange:q,onEntryFocus:he(p,F=>{T.isUsingKeyboardRef.current||F.preventDefault()}),preventScrollOnEntryFocus:!0,children:m.jsx(J0,{role:"menu","aria-orientation":"vertical","data-state":aS(D.open),"data-radix-menu-content":"",dir:T.dir,...C,...w,ref:se,style:{outline:"none",...w.style},onKeyDown:he(w.onKeyDown,F=>{const ye=F.target.closest("[data-radix-menu-content]")===F.currentTarget,pe=F.ctrlKey||F.altKey||F.metaKey,Te=F.key.length===1;ye&&(F.key==="Tab"&&F.preventDefault(),!pe&&Te&&N(F.key));const ue=Z.current;if(F.target!==ue||!qw.includes(F.key))return;F.preventDefault();const mt=z().filter(Gt=>!Gt.disabled).map(Gt=>Gt.ref.current);Jb.includes(F.key)&&mt.reverse(),iS(mt)}),onBlur:he(r.onBlur,F=>{F.currentTarget.contains(F.target)||(window.clearTimeout(J.current),Y.current="")}),onPointerMove:he(r.onPointerMove,Fo(F=>{const oe=F.target,ye=W.current!==F.clientX;if(F.currentTarget.contains(oe)&&ye){const pe=F.clientX>W.current?"right":"left";ne.current=pe,W.current=F.clientX}}))})})})})})})})},"MenuContentImpl")),Gd="MenuItem",Ip="menu.itemSelect",aO=g.forwardRef(qe(function(r,c){const{disabled:o=!1,onSelect:s,...f}=r,h=g.useRef(null),v=bm(Gd,r.__scopeMenu),S=tS(Gd,r.__scopeMenu),p=Ie(c,h),E=g.useRef(!1),y=qe(()=>{const x=h.current;if(!o&&x){const O=new CustomEvent(Ip,{bubbles:!0,cancelable:!0});x.addEventListener(Ip,j=>s?.(j),{once:!0}),Wo(x,O),O.defaultPrevented?E.current=!1:v.onClose()}},"handleSelect");return m.jsx(lO,{...f,ref:p,disabled:o,onClick:he(r.onClick,y),onPointerDown:x=>{r.onPointerDown?.(x),E.current=!0},onPointerUp:he(r.onPointerUp,x=>{E.current||x.currentTarget?.click()}),onKeyDown:he(r.onKeyDown,x=>{o||x.target!==x.currentTarget||S.searchRef.current!==""&&x.key===" "||Yw.includes(x.key)&&(x.currentTarget.click(),x.preventDefault())})})},"MenuItem")),lO=g.forwardRef(qe(function(r,c){const{__scopeMenu:o,disabled:s=!1,textValue:f,...h}=r,v=tS(Gd,o),S=Wb(o),p=g.useRef(null),E=Ie(c,p),[y,x]=g.useState(!1),[O,j]=g.useState("");return g.useEffect(()=>{const A=p.current;A&&j((A.textContent??"").trim())},[h.children]),m.jsx(Bd.ItemSlot,{scope:o,disabled:s,textValue:f??O,children:m.jsx(gm,{asChild:!0,...S,focusable:!s,children:m.jsx(De.div,{role:"menuitem","data-highlighted":y?"":void 0,"aria-disabled":s||void 0,"data-disabled":s?"":void 0,...h,ref:E,onPointerMove:he(r.onPointerMove,Fo(A=>{s?v.onItemLeave(A):(v.onItemEnter(A),A.defaultPrevented||A.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:he(r.onPointerLeave,Fo(A=>v.onItemLeave(A))),onFocus:he(r.onFocus,()=>x(!0)),onBlur:he(r.onBlur,()=>x(!1))})})})},"MenuItemImpl")),iO="MenuRadioGroup",[yR,pR]=Ol(iO,{value:void 0,onValueChange:qe(()=>{},"onValueChange")}),rO="MenuItemIndicator",[bR,SR]=Ol(rO,{checked:!1}),uO=g.forwardRef(qe(function(r,c){const{__scopeMenu:o,...s}=r;return m.jsx(De.div,{role:"separator","aria-orientation":"horizontal",...s,ref:c})},"MenuSeparator")),oO="MenuSub",[ER,TR]=Ol(oO);function aS(l){return l?"open":"closed"}qe(aS,"getOpenState");function lS(l){return l==="indeterminate"}qe(lS,"isIndeterminate");function cO(l){return lS(l)?"indeterminate":l?"checked":"unchecked"}qe(cO,"getCheckedState");function iS(l){const r=document.activeElement;for(const c of l)if(c===r||(c.focus(),document.activeElement!==r))return}qe(iS,"focusFirst");function rS(l,r){return l.map((c,o)=>l[(r+o)%l.length])}qe(rS,"wrapArray");function uS(l,r,c){const s=r.length>1&&Array.from(r).every(p=>p===r[0])?r[0]:r,f=c?l.indexOf(c):-1;let h=rS(l,Math.max(f,0));s.length===1&&(h=h.filter(p=>p!==c));const S=h.find(p=>p.toLowerCase().startsWith(s.toLowerCase()));return S!==c?S:void 0}qe(uS,"getNextMatch");function oS(l,r){const{x:c,y:o}=l;let s=!1;for(let f=0,h=r.length-1;f<r.length;h=f++){const v=r[f],S=r[h],p=v.x,E=v.y,y=S.x,x=S.y;E>o!=x>o&&c<(y-p)*(o-E)/(x-E)+p&&(s=!s)}return s}qe(oS,"isPointInPolygon");function cS(l,r){if(!r)return!1;const c={x:l.clientX,y:l.clientY};return oS(c,r)}qe(cS,"isPointerInGraceArea");function Fo(l){return r=>r.pointerType==="mouse"?l(r):void 0}qe(Fo,"whenMouse");var sO=Object.defineProperty,zi=(l,r)=>sO(l,"name",{value:r,configurable:!0}),Sm="DropdownMenu",[fO,xR]=Ht(Sm,[$b]),Ui=$b(),[dO,sS]=fO(Sm),mO=zi(l=>{const{__scopeDropdownMenu:r,children:c,dir:o,open:s,defaultOpen:f,onOpenChange:h,modal:v=!0}=l,S=Ui(r),p=g.useRef(null),[E,y]=_l({prop:s,defaultProp:f??!1,onChange:h,caller:Sm});return m.jsx(dO,{scope:r,triggerId:la(),triggerRef:p,contentId:la(),open:E,onOpenChange:y,onOpenToggle:g.useCallback(()=>y(x=>!x),[y]),modal:v,children:m.jsx(Kw,{...S,open:E,onOpenChange:y,dir:o,modal:v,children:c})})},"DropdownMenu"),hO="DropdownMenuTrigger",vO=g.forwardRef(zi(function(r,c){const{__scopeDropdownMenu:o,disabled:s=!1,...f}=r,h=sS(hO,o),v=Ui(o),S=Ie(c,h.triggerRef);return m.jsx(Zw,{asChild:!0,...v,children:m.jsx(De.button,{type:"button",id:h.triggerId,"aria-haspopup":"menu","aria-expanded":h.open,"aria-controls":h.open?h.contentId:void 0,"data-state":h.open?"open":"closed","data-disabled":s?"":void 0,disabled:s,...f,ref:S,onPointerDown:he(r.onPointerDown,p=>{!s&&p.button===0&&p.ctrlKey===!1&&(h.onOpenToggle(),h.open||p.preventDefault())}),onKeyDown:he(r.onKeyDown,p=>{s||(["Enter"," "].includes(p.key)&&h.onOpenToggle(),p.key==="ArrowDown"&&h.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(p.key)&&p.preventDefault())})})})},"DropdownMenuTrigger")),gO=zi(l=>{const{__scopeDropdownMenu:r,...c}=l,o=Ui(r);return m.jsx(Jw,{...o,...c})},"DropdownMenuPortal"),yO="DropdownMenuContent",pO=g.forwardRef(zi(function(r,c){const{__scopeDropdownMenu:o,...s}=r,f=sS(yO,o),h=Ui(o),v=g.useRef(!1);return m.jsx(Ww,{id:f.contentId,"aria-labelledby":f.triggerId,...h,...s,ref:c,onCloseAutoFocus:he(r.onCloseAutoFocus,S=>{v.current||f.triggerRef.current?.focus(),v.current=!1,S.preventDefault()}),onInteractOutside:he(r.onInteractOutside,S=>{const p=S.detail.originalEvent,E=p.button===0&&p.ctrlKey===!0,y=p.button===2||E;(!f.modal||y)&&(v.current=!0)}),style:{...r.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuContent")),bO=g.forwardRef(zi(function(r,c){const{__scopeDropdownMenu:o,...s}=r,f=Ui(o);return m.jsx(aO,{...f,...s,ref:c})},"DropdownMenuItem")),SO=g.forwardRef(zi(function(r,c){const{__scopeDropdownMenu:o,...s}=r,f=Ui(o);return m.jsx(uO,{...f,...s,ref:c})},"DropdownMenuSeparator")),EO=Object.defineProperty,Li=(l,r)=>EO(l,"name",{value:r,configurable:!0}),fS={Automatic:"automatic",Manual:"manual"},Em="Tabs",[TO,CR]=Ht(Em,[Ka]),dS=Ka(),[xO,Tm]=TO(Em),CO=g.forwardRef(Li(function(r,c){const{__scopeTabs:o,value:s,onValueChange:f,defaultValue:h,orientation:v="horizontal",dir:S,activationMode:p=fS.Automatic,...E}=r,y=Kr(S),[x,O]=_l({prop:s,onChange:f,defaultProp:h??"",caller:Em});return m.jsx(xO,{scope:o,baseId:la(),value:x,onValueChange:O,orientation:v,dir:y,activationMode:p,children:m.jsx(De.div,{dir:y,"data-orientation":v,...E,ref:c})})},"Tabs")),_O="TabsList",wO=g.forwardRef(Li(function(r,c){const{__scopeTabs:o,loop:s=!0,...f}=r,h=Tm(_O,o),v=dS(o);return m.jsx(vm,{asChild:!0,...v,orientation:h.orientation,dir:h.dir,loop:s,children:m.jsx(De.div,{role:"tablist","aria-orientation":h.orientation,...f,ref:c})})},"TabsList")),OO="TabsTrigger",AO=g.forwardRef(Li(function(r,c){const{__scopeTabs:o,value:s,disabled:f=!1,...h}=r,v=Tm(OO,o),S=dS(o),p=xm(v.baseId,s),E=Cm(v.baseId,s),y=s===v.value;return m.jsx(gm,{asChild:!0,...S,focusable:!f,active:y,children:m.jsx(De.button,{type:"button",role:"tab","aria-selected":y,"aria-controls":E,"data-state":y?"active":"inactive","data-disabled":f?"":void 0,disabled:f,id:p,...h,ref:c,onMouseDown:he(r.onMouseDown,x=>{!f&&x.button===0&&x.ctrlKey===!1?(x.currentTarget.focus(),v.onValueChange(s)):x.preventDefault()}),onKeyDown:he(r.onKeyDown,x=>{f||x.target!==x.currentTarget||[" ","Enter"].includes(x.key)&&v.onValueChange(s)}),onFocus:he(r.onFocus,()=>{const x=v.activationMode!==fS.Manual;!y&&!f&&x&&v.onValueChange(s)})})})},"TabsTrigger")),RO="TabsContent",NO=g.forwardRef(Li(function(r,c){const{__scopeTabs:o,value:s,forceMount:f,children:h,...v}=r,S=Tm(RO,o),p=xm(S.baseId,s),E=Cm(S.baseId,s),y=s===S.value,x=g.useRef(y);return g.useEffect(()=>{const O=requestAnimationFrame(()=>x.current=!1);return()=>cancelAnimationFrame(O)},[]),m.jsx(sa,{present:f||y,children:({present:O})=>m.jsx(De.div,{"data-state":y?"active":"inactive","data-orientation":S.orientation,role:"tabpanel","aria-labelledby":p,hidden:!O,id:E,tabIndex:0,...v,ref:c,style:{...r.style,animationDuration:x.current?"0s":void 0},children:O&&h})})},"TabsContent"));function xm(l,r){return`${l}-trigger-${r}`}Li(xm,"makeTriggerId");function Cm(l,r){return`${l}-content-${r}`}Li(Cm,"makeContentId");var DO=Object.defineProperty,He=(l,r)=>DO(l,"name",{value:r,configurable:!0}),Xp=Pa[" startTransition ".trim().toString()]||(()=>{}),mS="ToastProvider",[_m,hS,jO]=dc("Toast"),Yd={Left:"left",Right:"right"},Pp={Foreground:"foreground"},[vS,_R]=Ht("Toast",[jO]),[MO,vc]=vS(mS);function Vo(l){typeof Xp=="function"?Xp(l):l()}He(Vo,"scheduleUpdate");var zO=He(l=>{const{__scopeToast:r,label:c="Notification",duration:o=5e3,swipeDirection:s=Yd.Right,swipeThreshold:f=50,announcerContainer:h,children:v}=l,[S,p]=g.useState(null),[E,y]=g.useState(0),x=g.useRef(!1),O=g.useCallback(w=>{Vo(()=>p(w))},[]),j=g.useCallback(()=>{Vo(()=>y(w=>w+1))},[]),A=g.useCallback(()=>{Vo(()=>y(w=>w-1))},[]);return c.trim()||console.error(`Invalid prop \`label\` supplied to \`${mS}\`. Expected non-empty \`string\`.`),m.jsx(_m.Provider,{scope:r,children:m.jsx(MO,{scope:r,label:c,duration:o,swipeDirection:s,swipeThreshold:f,toastCount:E,viewport:S,onViewportChange:O,onToastAdd:j,onToastRemove:A,isClosePausedRef:x,announcerContainer:h,children:v})})},"ToastProvider"),UO="ToastViewport",LO=["F8"],Vd="toast.viewportPause",qd="toast.viewportResume",HO=g.forwardRef(He(function(r,c){const{__scopeToast:o,hotkey:s=LO,label:f="Notifications ({hotkey})",...h}=r,v=vc(UO,o),S=hS(o),p=g.useRef(null),E=g.useRef(null),y=g.useRef(null),x=g.useRef(null),O=Ie(c,x,v.onViewportChange),j=s.join("+").replace(/Key/g,"").replace(/Digit/g,""),A=v.toastCount>0;g.useEffect(()=>{const D=He(T=>{s.length!==0&&s.every(B=>T[B]||T.code===B)&&x.current?.focus()},"handleKeyDown");return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[s]),g.useEffect(()=>{const D=p.current,T=x.current;if(A&&D&&T){const C=He(()=>{if(!v.isClosePausedRef.current){const q=new CustomEvent(Vd);T.dispatchEvent(q),v.isClosePausedRef.current=!0}},"handlePause"),B=He(()=>{if(v.isClosePausedRef.current){const q=new CustomEvent(qd);T.dispatchEvent(q),v.isClosePausedRef.current=!1}},"handleResume"),z=He(q=>{!D.contains(q.relatedTarget)&&B()},"handleFocusOutResume"),L=He(()=>{D.contains(document.activeElement)||B()},"handlePointerLeaveResume");return D.addEventListener("focusin",C),D.addEventListener("focusout",z),D.addEventListener("pointermove",C),D.addEventListener("pointerleave",L),window.addEventListener("blur",C),window.addEventListener("focus",B),()=>{D.removeEventListener("focusin",C),D.removeEventListener("focusout",z),D.removeEventListener("pointermove",C),D.removeEventListener("pointerleave",L),window.removeEventListener("blur",C),window.removeEventListener("focus",B)}}},[A,v.isClosePausedRef]);const w=g.useCallback(({tabbingDirection:D})=>{const C=S().map(B=>{const z=B.ref.current,L=[z,...pS(z)];return D==="forwards"?L:L.reverse()});return(D==="forwards"?C.reverse():C).flat()},[S]);return g.useEffect(()=>{const D=x.current;if(D){const T=He(C=>{const B=C.altKey||C.ctrlKey||C.metaKey;if(C.key==="Tab"&&!B){const L=document.activeElement,q=C.shiftKey;if(C.target===D&&q){E.current?.focus();return}const te=w({tabbingDirection:q?"backwards":"forwards"}),re=te.findIndex(le=>le===L);qo(te.slice(re+1))?C.preventDefault():q?E.current?.focus():y.current?.focus()}},"handleKeyDown");return D.addEventListener("keydown",T),()=>D.removeEventListener("keydown",T)}},[S,w]),m.jsxs(y1,{ref:p,role:"region","aria-label":f.replace("{hotkey}",j),tabIndex:-1,style:{pointerEvents:A?void 0:"none"},children:[A&&m.jsx(Qp,{ref:E,onFocusFromOutsideViewport:()=>{const D=w({tabbingDirection:"forwards"});qo(D)}}),m.jsx(_m.Slot,{scope:o,children:m.jsx(De.ol,{tabIndex:-1,...h,ref:O})}),A&&m.jsx(Qp,{ref:y,onFocusFromOutsideViewport:()=>{const D=w({tabbingDirection:"backwards"});qo(D)}})]})},"ToastViewport")),BO="ToastFocusProxy",Qp=g.forwardRef(He(function(r,c){const{__scopeToast:o,onFocusFromOutsideViewport:s,...f}=r,h=vc(BO,o);return m.jsx(rm,{tabIndex:0,...f,ref:c,style:{position:"fixed"},onFocus:v=>{const S=v.relatedTarget;!h.viewport?.contains(S)&&s()}})},"ToastFocusProxy")),gc="Toast",GO="toast.swipeStart",YO="toast.swipeMove",VO="toast.swipeCancel",qO="toast.swipeEnd",IO=g.forwardRef(He(function(r,c){const{forceMount:o,open:s,defaultOpen:f,onOpenChange:h,...v}=r,[S,p]=_l({prop:s,defaultProp:f??!0,onChange:h,caller:gc});return m.jsx(sa,{present:o||S,children:m.jsx(QO,{open:S,...v,ref:c,onClose:()=>p(!1),onPause:Wt(r.onPause),onResume:Wt(r.onResume),onSwipeStart:he(r.onSwipeStart,E=>{E.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:he(r.onSwipeMove,E=>{const{x:y,y:x}=E.detail.delta;E.currentTarget.setAttribute("data-swipe","move"),E.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${y}px`),E.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${x}px`)}),onSwipeCancel:he(r.onSwipeCancel,E=>{E.currentTarget.setAttribute("data-swipe","cancel"),E.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),E.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),E.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),E.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:he(r.onSwipeEnd,E=>{const{x:y,y:x}=E.detail.delta;E.currentTarget.setAttribute("data-swipe","end"),E.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),E.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),E.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${y}px`),E.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${x}px`),p(!1)})})})},"Toast")),[XO,PO]=vS(gc,{onClose(){}}),QO=g.forwardRef(He(function(r,c){const{__scopeToast:o,type:s=Pp.Foreground,duration:f,open:h,onClose:v,onEscapeKeyDown:S,onPause:p,onResume:E,onSwipeStart:y,onSwipeMove:x,onSwipeCancel:O,onSwipeEnd:j,...A}=r,w=vc(gc,o),D=hS(o),[T,C]=g.useState(null),B=Ie(c,C),z=g.useRef(null),L=g.useRef(null),q=f||w.duration,Z=g.useRef(0),$=g.useRef(q),te=g.useRef(0),{onToastAdd:re,onToastRemove:le}=w,ae=Wt(()=>{T?.contains(document.activeElement)&&w.viewport?.focus(),v()}),se=g.useCallback(Y=>{!Y||Y===1/0||(window.clearTimeout(te.current),Z.current=new Date().getTime(),te.current=window.setTimeout(ae,Y))},[ae]);g.useEffect(()=>{const Y=w.viewport;if(Y){const k=He(()=>{se($.current),E?.()},"handleResume"),K=He(()=>{const ne=new Date().getTime()-Z.current;$.current=$.current-ne,window.clearTimeout(te.current),p?.()},"handlePause");return Y.addEventListener(Vd,K),Y.addEventListener(qd,k),()=>{Y.removeEventListener(Vd,K),Y.removeEventListener(qd,k)}}},[w.viewport,q,p,E,se]),g.useEffect(()=>{$.current=q,h&&!w.isClosePausedRef.current&&se(q)},[h,q,w.isClosePausedRef,se]),g.useEffect(()=>()=>{window.clearTimeout(te.current)},[]),g.useEffect(()=>(re(),()=>le()),[re,le]);const J=g.useMemo(()=>T?wm(T):null,[T]);return w.viewport?m.jsxs(m.Fragment,{children:[J&&m.jsx(KO,{__scopeToast:o,role:"status","aria-live":s===Pp.Foreground?"assertive":"polite",children:J}),m.jsx(XO,{scope:o,onClose:ae,children:$o.createPortal(m.jsx(_m.ItemSlot,{scope:o,children:m.jsx(ec,{asChild:!0,onEscapeKeyDown:he(S,Y=>{D().some(K=>K.ref.current?.contains(Y.target))||ae()}),children:m.jsx(De.li,{tabIndex:0,"data-state":h?"open":"closed","data-swipe-direction":w.swipeDirection,...A,ref:B,style:{userSelect:"none",touchAction:"none",...r.style},onKeyDown:he(r.onKeyDown,Y=>{Y.key==="Escape"&&(S?.(Y.nativeEvent),Y.nativeEvent.defaultPrevented||ae())}),onPointerDown:he(r.onPointerDown,Y=>{Y.button===0&&(z.current={x:Y.clientX,y:Y.clientY})}),onPointerMove:he(r.onPointerMove,Y=>{if(!z.current)return;const k=Y.clientX-z.current.x,K=Y.clientY-z.current.y,ne=!!L.current,W=["left","right"].includes(w.swipeDirection),fe=["left","up"].includes(w.swipeDirection)?Math.min:Math.max,Be=W?fe(0,k):0,Pe=W?0:fe(0,K),N=Y.pointerType==="touch"?10:2,I={x:Be,y:Pe},F={originalEvent:Y,delta:I};ne?(L.current=I,Ur(YO,x,F,{discrete:!1})):Kp(I,w.swipeDirection,N)?(L.current=I,Ur(GO,y,F,{discrete:!1}),Y.target.setPointerCapture(Y.pointerId)):(Math.abs(k)>N||Math.abs(K)>N)&&(z.current=null)}),onPointerUp:he(r.onPointerUp,Y=>{const k=L.current,K=Y.target;if(K.hasPointerCapture(Y.pointerId)&&K.releasePointerCapture(Y.pointerId),L.current=null,z.current=null,k){const ne=Y.currentTarget,W={originalEvent:Y,delta:k};Kp(k,w.swipeDirection,w.swipeThreshold)?Ur(qO,j,W,{discrete:!0}):Ur(VO,O,W,{discrete:!0}),ne.addEventListener("click",fe=>fe.preventDefault(),{once:!0})}})})})}),w.viewport)})]}):null},"ToastImpl")),KO=He(l=>{const{__scopeToast:r,children:c,...o}=l,s=vc(gc,r),[f,h]=g.useState(!1),[v,S]=g.useState(!1);return gS(()=>h(!0)),g.useEffect(()=>{const p=window.setTimeout(()=>S(!0),1e3);return()=>window.clearTimeout(p)},[]),v?null:m.jsx(uc,{asChild:!0,container:s.announcerContainer||void 0,children:m.jsx(rm,{...o,children:f&&m.jsxs(m.Fragment,{children:[s.label," ",c]})})})},"ToastAnnounce"),ZO=g.forwardRef(He(function(r,c){const{__scopeToast:o,...s}=r;return m.jsx(De.div,{...s,ref:c})},"ToastTitle")),FO=g.forwardRef(He(function(r,c){const{__scopeToast:o,...s}=r;return m.jsx(De.div,{...s,ref:c})},"ToastDescription")),kO="ToastClose",JO=g.forwardRef(He(function(r,c){const{__scopeToast:o,...s}=r,f=PO(kO,o);return m.jsx($O,{asChild:!0,children:m.jsx(De.button,{type:"button",...s,ref:c,onClick:he(r.onClick,f.onClose)})})},"ToastClose")),$O=g.forwardRef(He(function(r,c){const{__scopeToast:o,altText:s,...f}=r;return m.jsx(De.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":s||void 0,...f,ref:c})},"ToastAnnounceExclude"));function wm(l){const r=[];return Array.from(l.childNodes).forEach(o=>{if(o.nodeType===o.TEXT_NODE&&o.textContent&&r.push(o.textContent),yS(o)){const s=o.ariaHidden||o.hidden||o.style.display==="none",f=o.dataset.radixToastAnnounceExclude==="";if(!s)if(f){const h=o.dataset.radixToastAnnounceAlt;h&&r.push(h)}else r.push(...wm(o))}}),r}He(wm,"getAnnounceTextContent");function Ur(l,r,c,{discrete:o}){const s=c.originalEvent.currentTarget,f=new CustomEvent(l,{bubbles:!0,cancelable:!0,detail:c});r&&s.addEventListener(l,r,{once:!0}),o?Wo(s,f):s.dispatchEvent(f)}He(Ur,"handleAndDispatchCustomEvent");var Kp=He((l,r,c=0)=>{const o=Math.abs(l.x),s=Math.abs(l.y),f=o>s;return r===Yd.Left||r===Yd.Right?f&&o>c:!f&&s>c},"isDeltaInDirection");function gS(l=()=>{}){const r=Wt(l);xt(()=>{let c=0,o=0;return c=window.requestAnimationFrame(()=>o=window.requestAnimationFrame(r)),()=>{window.cancelAnimationFrame(c),window.cancelAnimationFrame(o)}},[r])}He(gS,"useNextFrame");function yS(l){return l.nodeType===l.ELEMENT_NODE}He(yS,"isHTMLElement");function pS(l){const r=[],c=document.createTreeWalker(l,NodeFilter.SHOW_ELEMENT,{acceptNode:He(o=>{const s=o.tagName==="INPUT"&&o.type==="hidden";return o.disabled||o.hidden||s?NodeFilter.FILTER_SKIP:o.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;c.nextNode();)r.push(c.currentNode);return r}He(pS,"getTabbableCandidates");function qo(l){const r=document.activeElement;return l.some(c=>c===r?!0:(c.focus(),document.activeElement!==r))}He(qo,"focusFirst");function Om({open:l,onOpenChange:r,trigger:c,title:o,description:s,children:f,footer:h}){if(o.trim()==="")throw new Error("A dialog needs a non-empty title.");const v=g.useRef(null),S=g.useRef(!1);if(l&&!S.current&&typeof document<"u"){const p=document.activeElement,E=p?.closest('[role="menu"]')?.getAttribute("aria-labelledby");v.current=E&&document.getElementById(E)||p}return S.current=!!l,m.jsxs(uw,{open:l,onOpenChange:r,children:[c&&m.jsx(cw,{asChild:!0,children:c}),m.jsxs(fw,{children:[m.jsx(dw,{className:"agd-overlay"}),m.jsxs(vw,{className:"agd-dialog",...s?{}:{"aria-describedby":void 0},onCloseAutoFocus:p=>{!c&&v.current instanceof HTMLElement&&v.current.isConnected&&(p.preventDefault(),v.current.focus())},onOpenAutoFocus:p=>{const E=p.currentTarget.querySelector("[data-autofocus]");E&&(p.preventDefault(),E.focus())},children:[m.jsx(pw,{className:"agd-dialog__title",children:o}),m.jsx(Lb,{asChild:!0,children:m.jsx(Tl,{label:"Close",icon:m.jsx(yb,{}),size:"sm",className:"agd-dialog__close",tooltip:!1})}),s&&m.jsx(bw,{className:"agd-dialog__description",children:s}),f&&m.jsx("div",{className:"agd-dialog__body",children:f}),h&&m.jsx("div",{className:"agd-dialog__footer",children:h})]})]})]})}var bS=Lb;function WO({trigger:l,items:r,align:c="end"}){for(const s of r)if(s!=="separator"&&s.label.trim()==="")throw new Error("A menu item needs a non-empty label.");const o=g.isValidElement(l)&&l.type===Tl?g.cloneElement(l,{tooltip:!1}):l;return m.jsxs(mO,{modal:!1,children:[m.jsx(vO,{asChild:!0,children:o}),m.jsx(gO,{children:m.jsx(pO,{className:"agd-menu",align:c,sideOffset:6,children:r.map((s,f)=>s==="separator"?m.jsx(SO,{className:"agd-menu__separator"},`sep-${f}`):m.jsxs(bO,{className:s.danger?"agd-menu__item agd-menu__item--danger":"agd-menu__item",disabled:s.disabled,onSelect:s.onSelect,children:[s.icon,m.jsx("span",{children:s.label}),s.shortcut&&m.jsx("kbd",{className:"agd-menu__shortcut",children:s.shortcut})]},`${f}-${s.label}`))})})]})}function eA({label:l,tabs:r,value:c,defaultValue:o,onValueChange:s}){if(l.trim()==="")throw new Error("Tabs need a non-empty label.");const[f,h]=g.useState(o??r[0]?.value),v=c??f,S=r.some(p=>p.value===v)?v:r[0]?.value;return m.jsxs(CO,{className:"agd-tabs",value:v,onValueChange:p=>{h(p),s?.(p)},children:[m.jsx(wO,{className:"agd-tabs__list","aria-label":l,tabIndex:-1,children:r.map(p=>m.jsx(AO,{value:p.value,className:"agd-tabs__trigger",tabIndex:p.value===S?0:-1,children:p.label},p.value))}),r.map(p=>m.jsx(NO,{value:p.value,className:"agd-tabs__panel",children:p.content},p.value))]})}var SS=g.createContext(null),Zp={info:f_,success:c_,warning:pb,danger:h_},tA={info:"Notice",success:"Success",warning:"Warning",danger:"Error"};function nA({children:l}){const[r,c]=g.useState([]),o=g.useCallback(f=>{if(typeof f.title!="string"||f.title.trim()==="")throw new Error("A toast needs a non-empty title.");const h=f.tone===void 0?"info":Object.hasOwn(Zp,f.tone)?f.tone:"danger";c(v=>[...v,{...f,tone:h,id:Date.now()+Math.random()}])},[]),s=f=>c(h=>h.filter(v=>v.id!==f));return m.jsx(SS.Provider,{value:o,children:m.jsxs(zO,{swipeDirection:"right",children:[l,r.map(({id:f,title:h,description:v,tone:S="info"})=>{const p=Zp[S];return m.jsxs(IO,{className:`agd-toast agd-toast--${S}`,type:S==="danger"?"foreground":"background",duration:S==="danger"?1/0:8e3,onOpenChange:E=>!E&&s(f),children:[m.jsx(p,{className:"agd-toast__icon"}),m.jsxs("div",{children:[m.jsxs(ZO,{className:"agd-toast__title",children:[m.jsxs("span",{className:"agd-sr-only",children:[tA[S],": "]}),h]}),v&&m.jsx(FO,{className:"agd-toast__description",children:v})]}),m.jsx(JO,{asChild:!0,children:m.jsx(Tl,{label:"Dismiss",icon:m.jsx(yb,{}),size:"sm",tooltip:!1})})]},f)}),m.jsx(HO,{className:"agd-toast-viewport",label:"Notifications ({hotkey})"})]})})}function yc(){const l=g.useContext(SS);if(!l)throw new Error("useToast needs a ToastProvider above it.");return l}var ES="(max-width: 47.99rem)",aA=l=>{const r=window.matchMedia(ES);return r.addEventListener("change",l),()=>r.removeEventListener("change",l)};function lA({brand:l,sidebar:r,title:c,topbar:o,secondary:s,panel:f,panelLabel:h,children:v}){const S=f!=null&&f!==!1;if(S&&(h??"").trim()==="")throw new Error("A side panel needs a non-empty label.");const p=s!=null&&s!==!1,[E,y]=g.useState(!1),x=g.useRef(null),O=g.useRef(null),j=g.useRef(null),A=g.useRef(!1),[w,D]=g.useState(!1),T=g.useRef(null),C=g.useId(),B=g.useId(),z=g.useId(),L=g.useSyncExternalStore(aA,()=>window.matchMedia(ES).matches,()=>!1),q=g.useRef(L),Z=g.useRef(null),$=g.useRef(null);if(L!==q.current){const ae=document.activeElement,se=Z.current;$.current=Z.current??ae,Z.current=null,q.current=L,A.current=!1,y(L&&(!!se||!!x.current?.contains(ae))),D(L&&!!j.current?.contains(ae))}g.useLayoutEffect(()=>{const ae=$.current;$.current=null,ae instanceof HTMLElement&&ae.isConnected&&ae!==document.activeElement&&ae!==document.body&&ae.focus()},[L]),g.useEffect(()=>{E&&A.current&&x.current?.querySelector("a, [href]")?.focus()},[E]);const te=ae=>{if(ae.key!=="Escape")return;const se=ae.target;if(w&&(j.current?.contains(se)||T.current?.contains(se))&&!se.closest?.('[role="menu"], [role="dialog"]')){D(!1),T.current?.focus();return}E&&(!x.current?.contains(se)&&!O.current?.contains(se)||(y(!1),O.current?.focus()))},re=m.jsxs("header",{className:"agd-shell__topbar",children:[m.jsx("p",{className:"agd-shell__brand",children:l}),m.jsx(Tl,{ref:O,className:"agd-shell__menu",label:"Navigation",icon:m.jsx(d_,{}),"aria-expanded":E,"aria-controls":C,onClick:()=>{A.current=!E,y(ae=>!ae)}}),c!=null&&c!==!1&&m.jsx("div",{className:"agd-shell__title",children:c}),m.jsx("div",{className:"agd-shell__actions",children:o}),p&&m.jsxs(m.Fragment,{children:[m.jsx(Tl,{ref:T,className:"agd-shell__more",label:"More options",icon:m.jsx(bb,{}),"aria-expanded":w,"aria-controls":B,onClick:()=>D(ae=>!ae)}),m.jsx("div",{id:B,ref:j,className:"agd-shell__secondary","data-open":w,children:s})]})]},"topbar"),le=m.jsx("div",{id:C,ref:x,className:"agd-shell__sidebar","data-open":E,onBlur:ae=>{!q.current&&!ae.relatedTarget&&x.current&&getComputedStyle(x.current).display==="none"&&(Z.current=ae.target)},onFocus:()=>{Z.current=null},children:r},"sidebar");return m.jsxs("div",{className:"agd-shell","data-panel":S?"":void 0,onKeyDown:te,children:[m.jsx("a",{className:"agd-skip-link",href:`#${z}`,children:"Skip to content"}),L?[re,le]:[le,re],m.jsx("main",{id:z,className:"agd-shell__content",tabIndex:-1,children:v}),S&&m.jsx("aside",{className:"agd-shell__panel","aria-label":h,children:f})]})}function iA({label:l,items:r,linkComponent:c="a",renderLink:o}){return m.jsx("nav",{"aria-label":l,children:m.jsx("ul",{className:"agd-sidebar-nav",children:r.map(s=>{const f={className:"agd-sidebar-nav__link",href:s.href,"aria-current":s.current?"page":void 0,children:m.jsxs(m.Fragment,{children:[s.icon,s.label]})};return m.jsx("li",{children:o?o(f,s):m.jsx(c,{...f})},s.href)})})})}var rA=Object.defineProperty,uA=(l,r)=>rA(l,"name",{value:r,configurable:!0}),oA={Horizontal:"horizontal",Vertical:"vertical"},cA=Object.values(oA);function sA(l){return cA.includes(l)}uA(sA,"isValidOrientation");var Am="ToggleGroup",[TS,xS]=Ht(Am,[Ka]);Ka();var[wR,OR]=TS(Am),[AR,RR]=TS(Am),fA=Object.defineProperty,CS=(l,r)=>fA(l,"name",{value:r,configurable:!0}),_S="Toolbar",[dA,NR]=Ht(_S,[Ka,xS]),wS=Ka();xS();var[mA,DR]=dA(_S),hA=g.forwardRef(CS(function(r,c){const{__scopeToolbar:o,orientation:s="horizontal",dir:f,loop:h=!0,...v}=r,S=wS(o),p=Kr(f);return m.jsx(mA,{scope:o,orientation:s,dir:p,children:m.jsx(vm,{asChild:!0,...S,orientation:s,dir:p,loop:h,children:m.jsx(De.div,{role:"toolbar","aria-orientation":s,dir:p,...v,ref:c})})})},"Toolbar")),vA=g.forwardRef(CS(function(r,c){const{__scopeToolbar:o,...s}=r,f=wS(o);return m.jsx(gm,{asChild:!0,...f,focusable:!r.disabled,children:m.jsx(De.button,{type:"button",...s,ref:c})})},"ToolbarButton"));function gA({label:l,children:r,dir:c}){const o=c??(typeof document<"u"&&document.documentElement.dir==="rtl"?"rtl":"ltr");return m.jsx(hA,{className:"agd-toolbar","aria-label":l,dir:o,children:r})}var jo=g.forwardRef(function({pressed:r,...c},o){return m.jsx(vA,{asChild:!0,children:m.jsx(Tl,{ref:o,size:"sm","aria-pressed":r,...c})})}),yA=40,pA=/^[\p{L}\p{M}\p{N}\p{P}\p{S}\p{Zs}\u200C\u200D]*$/u,bA=/(?![\p{Default_Ignorable_Code_Point}\u2800])[\p{L}\p{N}\p{P}\p{S}]/u,Fp="[\\p{Script=Arabic}\\p{Script=Devanagari}\\p{Script=Bengali}\\p{Script=Gujarati}\\p{Script=Gurmukhi}\\p{Script=Tamil}\\p{Script=Telugu}\\p{Script=Kannada}\\p{Script=Malayalam}\\p{Script=Sinhala}\\p{Extended_Pictographic}\\p{Emoji_Modifier}]",SA=new RegExp(`(?<=${Fp}\\p{M}*)[\\u200C\\u200D](?=${Fp})`,"gu"),EA=/[\p{Default_Ignorable_Code_Point}\u2800]/u,TA=/^[\p{M}\u200C-\u200F]/u,xA=new RegExp("\\p{M}{5,}","u");function Rm(l){return Nm(l,yA)}function Nm(l,r){if(typeof l!="string"||l.length>r)return null;const c=l.replace(SA,"");return/[\u200C-\u200F]/.test(c)||!pA.test(l)||!bA.test(l)||xA.test(c)||EA.test(c)||TA.test(l)||new RegExp("^\\s|\\s$|\\s{2,}|(?! )\\p{Zs}|[\\u200C-\\u200F]$|[\\u200C-\\u200F]{2,}","u").test(l)?null:l}var kp={active:"",away:"Away",paused:"Paused"},qr=l=>l.kind==="person"?"person":"agent",OS=l=>typeof l.status=="string"&&Object.hasOwn(kp,l.status)?kp[l.status]:"";function Oi(l){return Rm(l.name)??(qr(l)==="agent"?"Unnamed agent":"Unnamed person")}function CA(l){const r=l.trim().split(/\s+/).filter(Boolean);return(r.length>1?[r[0],r[r.length-1]]:[r[0]??""]).map(o=>Array.from(o).find(s=>/[\p{L}\p{N}]/u.test(s))?.toUpperCase()??"").join("")}function _A({entry:l,label:r}){return m.jsx("span",{className:Gn("agd-avatar",`agd-avatar--${qr(l)}`),role:r?"img":void 0,"aria-label":r,"aria-hidden":r?void 0:!0,children:qr(l)==="agent"?m.jsx(m_,{"aria-hidden":"true"}):CA(Oi(l))})}function wA(l){const r=qr(l)==="agent",c=l.actingFor===void 0?null:Rm(l.actingFor)??"Unnamed person";return[Oi(l),r?"agent":"person",r&&`acting for ${c??"an unknown person"}`,OS(l).toLowerCase()].filter(Boolean).join(", ")}function Ai({entry:l,className:r}){const c=Oi(l),o=OS(l),s=qr(l)==="agent",f=l.actingFor===void 0?null:Rm(l.actingFor)??"Unnamed person";return m.jsxs("span",{className:Gn("agd-chip",r),children:[m.jsx(_A,{entry:l}),m.jsx("span",{className:"agd-chip__name",title:c,"aria-hidden":"true",children:c}),s&&m.jsx("span",{className:"agd-pill","aria-hidden":"true",title:f?`An agent acting for ${f}.`:"An agent, not a person.",children:"Agent"}),s&&m.jsxs("span",{className:"agd-chip__meta","aria-hidden":"true",children:["for ",f??"unknown"]}),o&&m.jsx("span",{className:"agd-chip__meta","aria-hidden":"true",children:o}),m.jsx("span",{className:"agd-sr-only",children:wA(l)})]})}function Ri({title:l,description:r,action:c}){return m.jsxs("div",{className:"agd-empty",children:[m.jsx("h2",{className:"agd-empty__title",children:l}),r&&m.jsx("p",{className:"agd-empty__description",children:r}),c]})}var AS=200,yd=[{key:"name",label:"Name"},{key:"owner",label:"Owner"},{key:"modified",label:"Modified"}],Lr=l=>Nm(l.name,AS)??"Untitled",Id=l=>l instanceof Date&&!Number.isNaN(l.getTime());function OA(l,{key:r,direction:c},o){const s=new Intl.Collator(o,{numeric:!0,sensitivity:"base"}),f=c==="ascending"?1:-1;return[...l].sort((h,v)=>{if(r==="modified"){const[S,p]=[Id(h.modified),Id(v.modified)];if(S!==p)return S?-1:1;if(S&&p&&h.modified.getTime()!==v.modified.getTime())return f*(h.modified.getTime()-v.modified.getTime())}else if(r==="owner"){const S=s.compare(Oi(h.owner),Oi(v.owner));if(S!==0)return f*S}else{const S=s.compare(Lr(h),Lr(v));if(S!==0)return f*S}return s.compare(Lr(h),Lr(v))})}function Jp(l,r){return Id(l)?m.jsx("time",{dateTime:l.toISOString(),children:l.toLocaleDateString(r,{day:"numeric",month:"short",year:"numeric"})}):m.jsx("span",{children:"Date unknown"})}var $p=({item:l})=>{const r=Lr(l);return m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"agd-file-row__icon","aria-hidden":"true",children:l.kind==="folder"?m.jsx(wi,{}):m.jsx(Yr,{})}),m.jsx("a",{className:"agd-file-row__name",href:l.href,title:r,children:r})]})};function AA(l){return"items"in l?m.jsx(RA,{...l}):m.jsx("ul",{className:"agd-files","aria-label":l.label,children:l.children})}function RA({label:l,items:r,view:c="table",defaultSort:o={key:"name",direction:"ascending"},sort:s,onSortChange:f,loading:h=!1,empty:v,locale:S="en"}){const[p,E]=g.useState(o),y=s??p,x=g.useMemo(()=>s?r:OA(r,y,S),[r,y,s,S]),[O,j]=g.useState(""),A=g.useRef(y);g.useEffect(()=>{A.current.key===y.key&&A.current.direction===y.direction||(A.current=y,j(`Sorted by ${yd.find(z=>z.key===y.key)?.label.toLowerCase()}, ${y.direction}`))},[y]);const w=g.useRef(h);g.useEffect(()=>{w.current&&!h&&j(`${r.length} ${r.length===1?"file":"files"}`),w.current=h},[h,r.length]);const D=z=>{E(z),f?.(z)},T=z=>D({key:z,direction:y.key===z&&y.direction==="ascending"?"descending":"ascending"}),C=m.jsx("p",{className:"agd-sr-only",role:"status",children:h?"Loading files":O}),B=!h&&x.length===0?v??m.jsx(Ri,{title:"No files",description:"Nothing is here yet."}):c==="grid"?m.jsxs("div",{className:"agd-filegrid-wrap",children:[m.jsx(xl,{label:"Sort by",value:`${y.key}:${y.direction}`,onChange:z=>{const[L,q]=z.target.value.split(":");D({key:L,direction:q})},children:yd.flatMap(z=>[m.jsxs("option",{value:`${z.key}:ascending`,children:[z.label,", ",z.key==="modified"?"oldest first":"A to Z"]},`${z.key}:ascending`),m.jsxs("option",{value:`${z.key}:descending`,children:[z.label,", ",z.key==="modified"?"newest first":"Z to A"]},`${z.key}:descending`)])}),m.jsx("ul",{className:"agd-filegrid","aria-label":l,"aria-busy":h||void 0,children:h?[0,1,2,3].map(z=>m.jsx("li",{className:"agd-filegrid__item agd-skeleton","aria-hidden":"true"},z)):x.map(z=>m.jsxs("li",{className:"agd-filegrid__item",children:[m.jsx("span",{className:"agd-filegrid__head",children:m.jsx($p,{item:z})}),m.jsx(Ai,{entry:z.owner}),m.jsx("span",{className:"agd-file-row__time",children:Jp(z.modified,S)}),z.actions&&m.jsx("span",{className:"agd-file-row__actions",children:z.actions})]},z.id))})]}):m.jsx("div",{className:"agd-filetable-wrap",children:m.jsxs("table",{className:"agd-filetable",role:"table","aria-busy":h||void 0,children:[m.jsx("caption",{className:"agd-sr-only",children:l}),m.jsx("thead",{role:"rowgroup",children:m.jsxs("tr",{role:"row",children:[yd.map(z=>{const L=y.key===z.key;return m.jsx("th",{role:"columnheader",scope:"col","aria-sort":L?y.direction:void 0,children:m.jsxs("button",{type:"button",className:"agd-filetable__sort",onClick:()=>T(z.key),children:[z.label,m.jsx("span",{className:"agd-filetable__arrow","aria-hidden":"true",children:L?y.direction==="ascending"?"↑":"↓":""})]})},z.key)}),m.jsx("th",{role:"columnheader",scope:"col",children:m.jsx("span",{className:"agd-sr-only",children:"Actions"})})]})}),m.jsx("tbody",{role:"rowgroup",children:h?[0,1,2,3].map(z=>m.jsx("tr",{role:"row","aria-hidden":"true",children:[0,1,2,3].map(L=>m.jsx("td",{role:"cell",children:m.jsx("span",{className:"agd-skeleton"})},L))},z)):x.map(z=>m.jsxs("tr",{role:"row",children:[m.jsx("td",{role:"cell",children:m.jsx("span",{className:"agd-filetable__name",children:m.jsx($p,{item:z})})}),m.jsx("td",{role:"cell",children:m.jsx(Ai,{entry:z.owner})}),m.jsx("td",{role:"cell",children:m.jsx("span",{className:"agd-file-row__time",children:Jp(z.modified,S)})}),m.jsx("td",{role:"cell",children:m.jsx("span",{className:"agd-file-row__actions",children:z.actions})})]},z.id))})]})});return m.jsxs(m.Fragment,{children:[C,B]})}function NA({name:l,href:r,kind:c="file",modified:o,editedBy:s,actions:f}){const h=Nm(l,AS)??"Untitled",v=o instanceof Date&&!Number.isNaN(o.getTime());return m.jsxs("li",{className:"agd-file-row",children:[m.jsx("span",{className:"agd-file-row__icon","aria-hidden":"true",children:c==="folder"?m.jsx(wi,{}):m.jsx(Yr,{})}),m.jsx("a",{className:"agd-file-row__name",href:r,title:h,children:h}),m.jsxs("span",{className:"agd-file-row__meta",children:["Edited by ",m.jsx(Ai,{entry:s})]}),v?m.jsx("time",{className:"agd-file-row__time",dateTime:o.toISOString(),children:o.toLocaleDateString("en",{day:"numeric",month:"short",year:"numeric"})}):m.jsx("span",{className:"agd-file-row__time",children:"Date unknown"}),f&&m.jsx("span",{className:"agd-file-row__actions",children:f})]})}var Io={editor:"Can edit",commenter:"Can comment",viewer:"Can view"},RS=["editor","commenter","viewer"],NS=l=>l==="agent"?["commenter","viewer"]:RS,Wp={never:"Never","1d":"In 1 day","7d":"In 7 days","30d":"In 30 days"};function DA(l,r){const c=l.kind==="person"?"person":"agent",o=NS(c),s=o.map(f=>({role:f,allowed:!0}));return o.includes(r)?s:[{role:r,allowed:!1},...s]}function jA({people:l,onInvite:r,onChangeRole:c,onRemove:o}){const[s,f]=g.useState(""),[h,v]=g.useState("viewer"),[S,p]=g.useState(),[E,y]=g.useState(""),x=g.useRef(null),O=hp(s)?.kind??"person",j=NS(O),A=j.includes(h)?h:"viewer";return m.jsxs("div",{className:"agd-share",children:[m.jsxs("form",{className:"agd-share__invite",noValidate:!0,onSubmit:w=>{w.preventDefault();const D=hp(s);if(!D){y(""),p("Enter an email like ada@example.org, or an agent handle like @claude.");return}const T=C=>C?.replace(/^@/,"").toLowerCase()===D.to.replace(/^@/,"").toLowerCase();if(l.some(C=>T(C.invitedAs)||T(C.entry.id)||T(C.entry.name))){y(""),p(`${D.to} already has access. Change their role in the list below.`);return}r({...D,role:A}),p(void 0),y(`Invited ${D.to} as ${A}.`),f("")},children:[m.jsx(Qr,{ref:x,label:"Invite a person or an agent",hint:"An email invites a person. An @handle invites an agent. An agent can comment or view, and suggests edits that people accept.",value:s,onChange:w=>f(w.target.value),error:S,autoComplete:"off"}),m.jsx(xl,{label:"Role",value:A,onChange:w=>v(w.target.value),children:j.map(w=>m.jsx("option",{value:w,children:Io[w]},w))}),m.jsx(ke,{type:"submit",variant:"primary",children:"Invite"})]}),m.jsx("p",{role:"status",className:"agd-share__sent",children:E}),m.jsx("ul",{className:"agd-share__people","aria-label":"People and agents with access",children:l.map(w=>{const{entry:D,role:T}=w;return m.jsxs("li",{children:[m.jsx(Ai,{entry:D}),T==="owner"?m.jsx("span",{className:"agd-share__owner",children:"Owner"}):m.jsxs("span",{className:"agd-share__controls",children:[m.jsx(xl,{label:`Access for ${e0(w)}`,hideLabel:!0,value:T,onChange:C=>c(D.id,C.target.value),children:DA(D,T).map(({role:C,allowed:B})=>m.jsx("option",{value:C,disabled:!B,children:B?Io[C]:`${Io[C]} (not allowed for agents)`},C))}),m.jsx(ke,{variant:"ghost",size:"sm","aria-label":`Remove access for ${e0(w)}`,onClick:()=>{o(D.id),x.current?.focus()},children:"Remove"})]})]},D.id)})})]})}var e0=l=>l.invitedAs??Oi(l.entry),t0=l=>l.toLocaleDateString("en",{day:"numeric",month:"short",year:"numeric"});function MA({link:l,onChangeLink:r,onCopy:c}){const o=l.expiresAt!=null&&l.expiresAt.getTime()<Date.now();return m.jsxs("div",{className:"agd-share",children:[m.jsx(y_,{label:"Anyone with the link",hint:l.enabled?void 0:"Only people you invite can open this page.",checked:l.enabled,onChange:s=>r({...l,enabled:s.target.checked})}),l.enabled&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"agd-share__row",children:[m.jsx(xl,{label:"Access",value:l.role,hint:l.role==="editor"?l.signedInOnly?"Anyone who signs in with the link can edit. That includes agents.":"Anyone with the link can edit without signing in. That includes agents.":void 0,onChange:s=>r({...l,role:s.target.value}),children:RS.map(s=>m.jsx("option",{value:s,children:Io[s]},s))}),m.jsx(xl,{label:"Link expires",value:l.expiry,hint:l.expiresAt&&!o?`Stops working on ${t0(l.expiresAt)}.`:void 0,error:o&&l.expiresAt?`This link expired on ${t0(l.expiresAt)}. Choose a new expiry.`:void 0,onChange:s=>r({...l,expiry:s.target.value}),children:Object.keys(Wp).map(s=>m.jsx("option",{value:s,children:Wp[s]},s))})]}),m.jsx(g_,{label:"Require sign-in",hint:"People must sign in before they open the link.",checked:l.signedInOnly,onChange:s=>r({...l,signedInOnly:s.target.checked})}),!o&&m.jsxs("div",{className:"agd-share__copy",children:[m.jsx(Qr,{label:"Link",value:l.url,readOnly:!0,onFocus:s=>s.target.select()}),m.jsx(ke,{onClick:()=>c(l.url),children:"Copy link"})]})]})]})}function zA({snapshot:l,onCopy:r}){return m.jsxs("div",{className:"agd-share",children:[m.jsx("p",{children:"A snapshot puts a read-only copy of this page inside the link. It needs no account and no server read. Later edits are not in it."}),m.jsx("div",{children:m.jsx(ke,{onClick:l.onCreate,children:l.url?"Create a new snapshot link":"Create snapshot link"})}),l.url&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"agd-share__copy",children:[m.jsx(Qr,{label:"Snapshot link",value:l.url,readOnly:!0,onFocus:c=>c.target.select()}),m.jsx(ke,{onClick:()=>r(l.url),children:"Copy link"})]}),m.jsx("p",{className:"agd-field__hint",children:"Anyone who has this link can read this copy. Share it like a password."})]})]})}function UA({resourceName:l,trigger:r,open:c,onOpenChange:o,...s}){return m.jsx(Om,{trigger:r,open:c,onOpenChange:o,title:`Share “${l}”`,description:"Choose who can open this page, and what they can do.",children:m.jsx(eA,{label:"Ways to share",tabs:[{value:"people",label:"People and agents",content:m.jsx(jA,{people:s.people,onInvite:s.onInvite,onChangeRole:s.onChangeRole,onRemove:s.onRemove})},{value:"link",label:"Link",content:m.jsx(MA,{link:s.link,onChangeLink:s.onChangeLink,onCopy:s.onCopy})},{value:"snapshot",label:"Snapshot",content:m.jsx(zA,{snapshot:s.snapshot,onCopy:s.onCopy})}]})})}var LA=Object.defineProperty,DS=(l,r)=>LA(l,"name",{value:r,configurable:!0}),jS="Popover",[MS,jR]=Ht(jS,[Mi]);Mi();var[MR,zR]=MS(jS),HA="PopoverPortal",[UR,LR]=MS(HA,{forceMount:void 0});function BA(l){return l?"open":"closed"}DS(BA,"getState");function GA(...l){const r=new Set;for(const c of l)if(typeof c=="string")for(const o of String(c).trim().split(/\s+/))o&&r.add(o);return r.size>0?Array.from(r).join(" "):void 0}DS(GA,"concatAriaDescribedby");const YA={create:"created this item",rename:"renamed it",move:"moved it",update:"replaced its content",share:"shared it",unshare:"stopped sharing it",delete:"moved it to the trash",restore:"restored it"};function VA(l){const r=l.detail??{};return l.action==="rename"?r.from===void 0?"":`from "${r.from}" to "${r.to}"`:l.action==="share"?r.subjectId?`with ${r.subjectId} as ${r.role}`:"":l.action==="unshare"&&r.subjectId?`from ${r.subjectId}`:""}const qA=l=>l.action==="share"&&l.detail?.via==="invite"?l.detail.role===void 0?"accepted an invite":`accepted an invite and now has the role ${l.detail.role}`:`${YA[l.action]} ${VA(l)}`.trim(),IA=({entry:l})=>l.actor.kind==="agent"?m.jsx("span",{className:"agd-pill",children:"AI agent"}):null;function XA({entries:l}){return l.length===0?m.jsx("p",{className:"drive-muted",children:"No activity yet."}):m.jsx("ol",{className:"drive-activity","aria-label":"Activity",children:l.map(r=>m.jsxs("li",{children:[m.jsx("strong",{children:r.actor.id})," ",m.jsx(IA,{entry:r})," ",qA(r)," ",m.jsx("time",{dateTime:new Date(r.at).toISOString(),children:new Date(r.at).toLocaleString()})]},r.id))})}function zS(l,{key:r,dir:c},o=s=>s.updatedAt){const s=c==="asc"?1:-1,f=r==="name"?(h,v)=>h.name.localeCompare(v.name,void 0,{numeric:!0}):(h,v)=>o(h)-o(v);return[...l].sort((h,v)=>(h.kind==="folder"?0:1)-(v.kind==="folder"?0:1)||s*f(h,v)||h.name.localeCompare(v.name))}function PA({at:l}){const r=new Date(l);return Number.isFinite(r.getTime())?m.jsx("time",{dateTime:r.toISOString(),children:QA.format(r)}):m.jsx("span",{children:"—"})}const QA=new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"});function KA({value:l,onChange:r}){const[c,o]=g.useState(!1),s=g.useRef(null),f=g.useRef(null),h=g.useRef(!1),v=c||!!l;g.useEffect(()=>{v?s.current?.focus():h.current&&(h.current=!1,f.current?.focus())},[v]);const S=()=>{h.current=!0,r(""),o(!1)};return v?m.jsxs("div",{className:"drive-search",role:"search",children:[m.jsx("input",{ref:s,type:"search",className:"drive-search__input","aria-label":"Search this folder",placeholder:"Search this folder",value:l,onChange:p=>r(p.target.value),onKeyDown:p=>{p.key==="Escape"&&S()}}),m.jsx(ke,{variant:"ghost",size:"sm",onClick:S,children:"Close search"})]}):m.jsx(ke,{ref:f,variant:"ghost",size:"sm",onClick:()=>o(!0),children:"Search"})}function US({label:l,items:r,sort:c,onSort:o,selected:s=new Set,onSelect:f,href:h,onOpen:v,who:S,actions:p,dateOf:E=y=>y.updatedAt}){const y=r.length>0&&r.every(w=>s.has(w.id)),x=!y&&r.some(w=>s.has(w.id)),O=g.useRef(null);g.useEffect(()=>{O.current&&(O.current.indeterminate=x)},[x]);const j=(w,D)=>{if(!f)return;const T=new Set(s);D?T.add(w):T.delete(w),f(T)},A=(w,D,T)=>m.jsx("th",{scope:"col",className:T,"aria-sort":c.key===w?c.dir==="asc"?"ascending":"descending":"none",children:m.jsxs("button",{type:"button",className:"drive-sort",onClick:()=>o(w),children:[D,m.jsx("span",{"aria-hidden":"true",children:c.key===w?c.dir==="asc"?" ↑":" ↓":""})]})});return m.jsxs("table",{className:"drive-table","aria-label":l,children:[m.jsx("thead",{children:m.jsxs("tr",{children:[f&&m.jsx("th",{scope:"col",className:"drive-table__check",children:m.jsx("input",{ref:O,type:"checkbox",className:"agd-checkbox","aria-label":"Select all items",checked:y,onChange:w=>f(w.target.checked?new Set(r.map(D=>D.id)):new Set)})}),A("name","Name"),m.jsx("th",{scope:"col",className:"drive-table__who",children:"Edited by"}),A("modified","Modified","drive-table__date"),m.jsx("th",{scope:"col",children:m.jsx("span",{className:"drive-sr",children:"Actions"})})]})}),m.jsx("tbody",{children:r.map(w=>m.jsxs("tr",{className:"drive-row","data-selected":s.has(w.id)||void 0,children:[f&&m.jsx("td",{className:"drive-table__check",children:m.jsx("input",{type:"checkbox",className:"agd-checkbox","aria-label":`Select ${w.name}`,checked:s.has(w.id),onChange:D=>j(w.id,D.target.checked)})}),m.jsx("td",{children:m.jsxs("div",{className:"drive-table__name",children:[m.jsx("span",{className:"drive-table__icon","aria-hidden":"true",children:w.kind==="folder"?m.jsx(wi,{}):m.jsx(Yr,{})}),m.jsx("a",{href:h(w),onClick:D=>v?.(D,w),children:w.name})]})}),m.jsx("td",{className:"drive-table__who",children:m.jsx(Ai,{entry:S(w.updatedBy,w.owner)})}),m.jsx("td",{className:"drive-table__date",children:m.jsx(PA,{at:E(w)})}),m.jsx("td",{className:"drive-table__actions",children:p(w)})]},w.id))})]})}function ZA({count:l,busy:r,onTrash:c,onClear:o}){return l===0?null:m.jsxs("div",{role:"region","aria-label":"Selected items",className:"drive-bulk",children:[m.jsxs("span",{role:"status",children:[l," selected"]}),m.jsx(ke,{variant:"danger",size:"sm",onClick:c,disabled:r,children:"Move to trash"}),m.jsx(ke,{variant:"ghost",size:"sm",onClick:o,children:"Clear selection"})]})}class Ut extends Error{constructor(r,c,o){super(o),this.code=r,this.status=c,this.name="DriveApiError"}code;status}const FA="/api/v1/drive",kA={REF_CONFLICT:!0,NOT_FOUND:!0,NAME_TAKEN:!0,BLOB_EXISTS:!0,INVALID_NAME:!0,INVALID_PATH:!0,INVALID_REF:!0,NOT_A_FOLDER:!0,NOT_A_FILE:!0,MOVE_INTO_SELF:!0,TOO_DEEP:!0,PARENT_GONE:!0,TRASHED:!0,NOT_TRASHED:!0,IS_ROOT:!0,FORBIDDEN:!0,BLOB_MISSING:!0,TOO_LARGE:!0,INVALID_EXPIRY:!0,BUSY:!0,CROSS_DRIVE:!0,INVALID_SHARE:!0,TOO_MANY_ITEMS:!0,UNAUTHORIZED:!0,NOT_CONFIGURED:!0,INVALID_LINK:!0,INTERNAL:!0},JA=new Set(Object.keys(kA)),pl=l=>typeof l=="object"&&l!==null&&!Array.isArray(l),it=l=>typeof l=="string",na=l=>r=>r===null||l(r),aa=l=>typeof l=="number",LS={human:!0,agent_of_human:!0,agent_of_agent:!0,agent:!0,user_token:!0},pd=["viewer","commenter","editor","owner"],bl=l=>r=>typeof r=="string"&&l.includes(r),n0=l=>pl(l)&&it(l.id)&&bl(Object.keys(LS))(l.kind),Jt=l=>pl(l)&&it(l.id)&&it(l.owner)&&it(l.parentId)&&it(l.name)&&(l.kind==="folder"||l.kind==="file"||l.kind==="ref")&&aa(l.size)&&na(it)(l.mime)&&na(it)(l.hash)&&na(it)(l.ref)&&aa(l.createdAt)&&aa(l.updatedAt)&&n0(l.createdBy)&&n0(l.updatedBy)&&it(l.createdById)&&it(l.updatedById)&&typeof l.trashed=="boolean"&&na(aa)(l.trashedAt)&&typeof l.machineMade=="boolean",$A=["create","rename","move","update","share","unshare","delete","restore"],WA=l=>pl(l)&&it(l.id)&&it(l.itemId)&&bl($A)(l.action)&&pl(l.actor)&&it(l.actor.id)&&bl(["human","agent"])(l.actor.kind)&&bl(Object.keys(LS))(l.principalKind)&&aa(l.at)&&(l.detail===void 0||pl(l.detail)),Mo=l=>Jt(l)&&typeof l.path=="string",pn=l=>r=>Array.isArray(r)&&r.every(l),bn=l=>r=>pl(r)&&l(r),bd=(...l)=>bn(r=>l.every(c=>typeof r[c]=="number")),zo=bn(l=>l.ok===!0),eR=new Set([502,503,504]);function Xd(l){let r;try{const T=new URL(l.baseUrl);if(T.protocol!=="http:"&&T.protocol!=="https:")throw new Error("not http");r=T.origin}catch{throw new TypeError("baseUrl must be an http or https URL")}const{token:c}=l;if(c!==void 0&&(typeof c!="string"||!/^[A-Za-z0-9_-]{1,512}$/.test(c)))throw new TypeError("token must be 1 to 512 letters, digits, - or _");const o=l.retries??0;if(!Number.isInteger(o)||o<0||o>5)throw new RangeError("retries must be an integer from 0 to 5");const s=l.fetch??((T,C)=>globalThis.fetch(T,C)),f=T=>{const C=new URLSearchParams;for(const[z,L]of Object.entries(T))L!==void 0&&C.set(z,String(L));const B=C.toString();return B===""?"":`?${B}`};async function h(T,C,B){if(B.auth!==!1&&c===void 0)throw new TypeError("this call needs a token");const z={...c===void 0?{}:{authorization:`Bearer ${c}`},...B.headers};let L=B.body;B.json!==void 0&&(z["content-type"]="application/json",L=JSON.stringify(B.json));const q=T==="GET"?o+1:1;for(let Z=1;;Z++){let $;try{$=await s(`${r}${FA}${C}`,{method:T,headers:z,body:L,signal:B.signal,redirect:"manual",...L instanceof ReadableStream?{duplex:"half"}:{}})}catch(te){if(B.signal?.aborted||te instanceof Error&&te.name==="AbortError")throw te;if(Z<q){await v(Z,B.signal);continue}const re=L instanceof ReadableStream?" (a stream body may be refused by this runtime: send bytes)":"";throw new Ut("NETWORK_ERROR",0,`${te instanceof Error?`no answer: ${te.message}`:"no answer"}${re}`)}if(Z<q&&eR.has($.status)){await $.body?.cancel(),await v(Z,B.signal);continue}if($.type==="opaqueredirect"||$.status>=300&&$.status<400)throw await $.body?.cancel(),new Ut("BAD_RESPONSE",$.status,"the server redirected. Set baseUrl to the final URL.");if($.ok)return $;throw await S($,B.signal)}}async function v(T,C){C?.throwIfAborted(),await new Promise((B,z)=>{const L=setTimeout(()=>{C?.removeEventListener("abort",q),B()},Math.min(100*2**(T-1),1e3)),q=()=>{clearTimeout(L),z(C?.reason)};C?.addEventListener("abort",q,{once:!0})})}async function S(T,C){let B="BAD_RESPONSE",z=`the server answered ${T.status}`;try{const L=await T.json();typeof L.error?.code=="string"&&JA.has(L.error.code)?B=L.error.code:typeof L.error?.code=="string"&&(z=`the server answered ${T.status} with an unknown code, ${JSON.stringify(L.error.code.slice(0,40))}`),B!=="BAD_RESPONSE"&&typeof L.error?.message=="string"&&(z=L.error.message)}catch(L){if(C?.aborted)throw L}return new Ut(B,T.status,z)}async function p(T,C,B,z){const L=await h(T,C,B);let q;try{q=await L.json()}catch(Z){throw B.signal?.aborted?Z:Z instanceof SyntaxError?new Ut("BAD_RESPONSE",L.status,"the answer is not JSON"):new Ut("NETWORK_ERROR",0,"the connection dropped while the body came in")}if(!z(q))throw new Ut("BAD_RESPONSE",L.status,"the answer is not the shape that the API sends");return q}async function E(T,C,B=!1){const z=await h("GET",T,C);let L;try{L=new Uint8Array(await z.arrayBuffer())}catch(Z){throw C.signal?.aborted?Z:new Ut("NETWORK_ERROR",0,"the connection dropped while the body came in")}const q=z.headers.get("x-content-sha256")??"";if(B){if(!/^[0-9a-f]{64}$/.test(q))throw new Ut("BAD_RESPONSE",z.status,"the answer has no valid x-content-sha256");if(typeof crypto>"u"||!crypto.subtle)throw new Ut("BAD_RESPONSE",z.status,"this runtime has no WebCrypto, so the bytes cannot be checked. Use https.");const Z=new Uint8Array(await crypto.subtle.digest("SHA-256",L));if(Array.from(Z,$=>$.toString(16).padStart(2,"0")).join("")!==q)throw new Ut("BAD_RESPONSE",z.status,"the bytes do not match their hash")}return{data:L,contentType:z.headers.get("content-type")??"application/octet-stream",sha256:q}}const y=T=>{if(T!==void 0){if(!/^[A-Za-z0-9_-]{1,512}$/.test(T))throw new TypeError("a link token has 1 to 512 letters, digits, - or _");return{"x-link-token":T}}},x=T=>{if(typeof T!="string"||!/^[A-Za-z0-9_-][A-Za-z0-9_.-]*$/.test(T)||T==="."||T==="..")throw new TypeError("an item id has letters, digits, -, _ and . (not first), and is not . or ..");return T},O=bn(T=>typeof T.url=="string"&&/^https?:\/\//.test(T.url)&&URL.canParse(T.url)&&typeof T.expiresInSeconds=="number"),j=bn(T=>pn(bn(C=>(C.subjectKind==="human"||C.subjectKind==="agent")&&it(C.subjectId)&&bl(pd)(C.role)))(T.grants)&&pn(bn(C=>it(C.id)&&bl(pd)(C.role)&&typeof C.signedInOnly=="boolean"&&na(aa)(C.expiresAt)&&typeof C.revoked=="boolean"))(T.links)&&pn(bn(C=>it(C.id)&&bl(pd)(C.role)&&na(it)(C.email)&&na(it)(C.handle)&&na(aa)(C.expiresAt)&&typeof C.accepted=="boolean"))(T.invites)),A=bn(T=>pl(T.apps)&&Object.values(T.apps).every(aa)&&aa(T.files)&&pn(bn(C=>Mo(C)&&na(it)(C.app)))(T.items)),w=bn(T=>typeof T.id=="string"),D=bn(T=>typeof T.id=="string"&&typeof T.token=="string");return{list:(T="/",C={})=>p("GET",`/items${f({path:T})}`,C,pn(Jt)),listActivity:(T,C={})=>p("GET",`/items/${encodeURIComponent(T)}/activity${f({limit:C.limit})}`,C,pn(WA)),stat:(T,C={})=>p("GET",`/stat${f({path:T})}`,C,Jt),mkdir:(T,C={},B={})=>p("POST","/folders",{json:{path:T,parents:C.parents===!0},...B},Jt),upload:(T,C,B={},z={})=>p("PUT",`/files${f({path:T,mime:B.mime,parents:B.parents===!0?!0:void 0,onConflict:B.onConflict})}`,{body:typeof C=="string"?new TextEncoder().encode(C):C,headers:{"content-type":"application/octet-stream"},...z},Jt),download:(T,C={})=>E(`/files${f({path:T})}`,C,!0),url:(T,C,B={})=>p("GET",`/url${f({path:T,expires:C})}`,B,O),move:(T,C,B={},z={})=>p("POST","/move",{json:{src:T,folder:C,...B},...z},Jt),trash:(T,C={})=>p("POST","/trash",{json:{path:T},...C},Jt),listTrash:(T={})=>p("GET","/trash",T,pn(Jt)),restore:(T,C={},B={})=>p("POST","/restore",{json:{id:T,...C},...B},Jt),purge:(T,C={})=>p("POST","/purge",{json:{id:T},...C},bd("removed")),search:(T={},C={})=>p("GET",`/search${f(T)}`,C,pn(Mo)),export:async(T={})=>{const{data:C}=await E("/export",T);if(C[0]!==80||C[1]!==75)throw new Ut("BAD_RESPONSE",200,"the answer is not a zip");return C},deleteAccount:(T={})=>p("DELETE","/account?confirm=yes",T,bd("removed","grants","invites","anonymized")),home:(T={},C={})=>p("GET",`/home${f(T)}`,C,A),findByRef:(T,C={})=>p("GET",`/refs${f({ref:T})}`,C,pn(Mo)),listTrashWithPaths:(T={})=>p("GET","/trash/paths",T,pn(Mo)),claimRef:(T,C={})=>p("POST","/refs",{json:{path:T.path,ref:T.ref,subjectKind:T.subject.kind,subjectId:T.subject.id,role:T.role,parents:T.parents,onConflict:T.onConflict},...C},Jt),registerDocument:(T,C={})=>p("POST","/documents",{json:T,...C},Jt),forgetDocument:(T,C={})=>p("DELETE",`/documents${f({ref:T})}`,C,bd("trashed")),shares:(T,C={})=>p("GET",`/shares${f({path:T})}`,C,j),share:(T,C,B,z={})=>p("POST","/shares",{json:{path:T,subjectId:C.id,subjectKind:C.kind,role:B},...z},zo),unshare:(T,C,B={})=>p("DELETE",`/shares${f({path:T,subjectId:C.id,subjectKind:C.kind})}`,B,zo),invite:(T,C,B={})=>p("POST","/invites",{json:{path:T,...C},...B},w),acceptInvite:(T,C={})=>p("POST","/invites/accept",{json:{id:T},...C},zo),createLink:(T,C,B={})=>p("POST","/links",{json:{path:T,...C},...B},D),revokeLink:(T,C={})=>p("DELETE",`/links${f({id:T})}`,C,zo),openShared:async(T,C={})=>p("GET",`/shared/${x(T)}`,{auth:!1,headers:y(C.linkToken),signal:C.signal},Jt),listShared:async(T,C={})=>p("GET",`/shared/${x(T)}/items`,{auth:!1,headers:y(C.linkToken),signal:C.signal},pn(Jt)),readShared:async(T,C={})=>{const{data:B,contentType:z}=await E(`/shared/${x(T)}/content`,{auth:!1,headers:y(C.linkToken),signal:C.signal});return{data:B,contentType:z}}}}const Uo="agentic-drive-token",Cl=l=>l instanceof Ut?`${l.message} (${l.code})`:l instanceof Error?l.message:"Something went wrong",HS=(l,r)=>(l.kind==="folder"?0:1)-(r.kind==="folder"?0:1)||l.name.localeCompare(r.name),ko=(l,r)=>l.kind==="human"?{id:l.id,name:l.id,kind:"person"}:{id:l.id,name:l.id,kind:"agent",actingFor:r},Jo=({item:l})=>l.machineMade?m.jsx("span",{className:"agd-pill",children:"Created by agent"}):null;function Al(l){const[r,c]=g.useState({status:"loading"}),[o,s]=g.useState(0);return g.useEffect(()=>{const f=new AbortController;return l(f.signal).then(h=>!f.signal.aborted&&c({status:"ok",data:h}),h=>!f.signal.aborted&&c({status:"error",error:Cl(h)})),()=>f.abort()},[o]),[r,()=>s(f=>f+1)]}function Hi({state:l,retry:r,children:c}){return l.status==="loading"?m.jsxs("p",{role:"status",className:"drive-status",children:[m.jsx("span",{className:"agd-spinner","aria-hidden":"true"})," Loading…"]}):l.status==="error"?m.jsx("div",{role:"alert",children:m.jsx(Ri,{title:"Could not load this page",description:l.error,action:m.jsx(ke,{onClick:r,children:"Try again"})})}):m.jsx(m.Fragment,{children:c})}const BS=l=>l.replace(/^#\/?/,"").split("/"),tR=l=>{history.replaceState(null,"",`#/${l}`),dispatchEvent(new HashChangeEvent("hashchange"))};function nR({hash:l,client:r,origin:c,go:o,onOpenItem:s,folderLoc:f}){const h=BS(l);return h[0]==="trash"?m.jsx(oR,{client:r},"trash"):h[0]==="a"&&h[1]?m.jsx(cR,{client:r,id:h[1]},l):h[0]==="f"&&h[1]?m.jsx(fR,{client:r,id:h[1],origin:c,go:o},l):m.jsx(iR,{client:r,loc:f??(h[0]||"/"),go:o,origin:c,onOpenItem:s},l)}function aR(){const[l,r]=g.useState(()=>sessionStorage.getItem(Uo)??""),[c,o]=g.useState(location.hash);g.useEffect(()=>{const v=()=>o(location.hash);return addEventListener("hashchange",v),()=>removeEventListener("hashchange",v)},[]),g.useEffect(()=>{const v=S=>S.preventDefault();return addEventListener("dragover",v),addEventListener("drop",v),()=>{removeEventListener("dragover",v),removeEventListener("drop",v)}},[]);const s=g.useMemo(()=>{try{return Xd({baseUrl:location.origin,...l?{token:l}:{}})}catch{return Xd({baseUrl:location.origin})}},[l]);g.useEffect(()=>{l&&!/^[A-Za-z0-9_-]{1,512}$/.test(l)&&(sessionStorage.removeItem(Uo),r(""))},[l]);const f=()=>{sessionStorage.removeItem(Uo),r(""),location.hash="#/"},h=BS(c);return h[0]==="s"&&h[1]?m.jsx(Sd,{signedIn:!1,signOut:f,children:m.jsx(dR,{client:s,id:h[1],linkToken:h[2]},c)}):l?m.jsx(Sd,{signedIn:!0,signOut:f,current:h[0]==="trash"?"trash":"files",children:m.jsx(nR,{hash:c,client:s,origin:location.origin,go:tR})}):m.jsx(Sd,{signedIn:!1,signOut:f,children:m.jsx(lR,{onToken:v=>{sessionStorage.setItem(Uo,v),r(v)}})})}function Sd({children:l,signedIn:r,signOut:c,current:o}){const{preference:s,setPreference:f}=$x();return m.jsx(lA,{brand:"Drive",sidebar:r?m.jsx(iA,{label:"Places",items:[{href:"#/",label:"My files",icon:m.jsx(wi,{"aria-hidden":"true"}),current:o==="files"},{href:"#/trash",label:"Trash",current:o==="trash"}]}):m.jsx("p",{className:"drive-muted",children:"Sign in to see your files."}),topbar:m.jsxs(m.Fragment,{children:[m.jsxs(xl,{hideLabel:!0,label:"Theme",value:s,onChange:h=>f(h.target.value),children:[m.jsx("option",{value:"system",children:"Theme: system"}),m.jsx("option",{value:"light",children:"Theme: light"}),m.jsx("option",{value:"dark",children:"Theme: dark"})]}),r&&m.jsx(ke,{variant:"ghost",onClick:c,children:"Sign out"})]}),children:m.jsx("div",{className:"drive-main",children:l})})}function lR({onToken:l}){const[r,c]=g.useState(""),[o,s]=g.useState(),[f,h]=g.useState(!1),v=async S=>{S.preventDefault(),h(!0),s(void 0);try{await Xd({baseUrl:location.origin,token:r.trim()}).list("/"),l(r.trim())}catch(p){s(p instanceof TypeError?"A token has letters, digits, - and _ only.":p instanceof Ut&&p.code==="UNAUTHORIZED"?"This token is not valid.":Cl(p))}h(!1)};return m.jsxs("form",{onSubmit:v,className:"drive-signin","aria-labelledby":"signin-title",children:[m.jsx("h1",{id:"signin-title",children:"Sign in"}),m.jsx(Qr,{label:"Access token",type:"password",autoComplete:"off",value:r,onChange:S=>c(S.target.value),error:o,hint:"The bearer token of a person or an agent. The tab keeps it until you close it.",required:!0}),m.jsx(ke,{type:"submit",loading:f,children:"Sign in"})]})}function iR({client:l,loc:r,origin:c,onOpenItem:o,go:s}){const f=(J,Y)=>{J.defaultPrevented||J.button!==0||J.metaKey||J.ctrlKey||J.shiftKey||J.altKey||Y.kind!=="ref"||o?.(Y)===!0&&J.preventDefault()},h=yc(),[v,S]=g.useState(()=>localStorage.getItem("agentic-drive-view")==="grid"?"grid":"list"),[p,E]=g.useState(null),[y,x]=g.useState(!1),[O,j]=g.useState(!1),[A,w]=g.useState(""),[D,T]=g.useState({key:"name",dir:"asc"}),[C,B]=g.useState(new Set),z=g.useRef(null),[L,q]=Al(async()=>{const J=await l.stat("/"),Y=r==="/"?J:await l.stat(r),k=[];try{for(let fe=Y;fe.id!==J.id;fe=await l.stat(fe.parentId))k.unshift(fe)}catch(fe){if(!(fe instanceof Ut&&(fe.code==="NOT_FOUND"||fe.code==="FORBIDDEN")))throw fe}const K=async fe=>(await l.list(fe.id===J.id?"/":fe.id)).sort(HS),ne=await K(Y),W=new Map([[J.id,Z(await K(J))]]);for(const fe of k)W.set(fe.id,fe.id===Y.id?Z(ne):Z(await K(fe)));return{root:J,folder:Y,crumbs:k,items:ne,tree:W}});function Z(J){return J.filter(Y=>Y.kind==="folder")}const $=async(J,Y)=>{try{await J(),h({title:Y,tone:"success"}),E(null)}catch(k){h({title:"That did not work",description:Cl(k),tone:"danger"})}q()},te=async J=>{if(L.status!=="ok")return;if(O)return void h({title:"An upload is running",description:"Wait for it to finish, then add more files.",tone:"info"});const{folder:Y,root:k}=L.data;j(!0);for(const K of Array.from(J))await $(()=>l.upload(Y.id===k.id?`/${K.name}`:`${Y.id}/${K.name}`,K,{mime:K.type||void 0,onConflict:"rename"}),`Uploaded ${K.name}`);j(!1)},re=J=>{J.preventDefault(),x(!1),J.dataTransfer.files.length&&te(J.dataTransfer.files)},le=J=>T(Y=>({key:J,dir:Y.key===J&&Y.dir==="asc"?"desc":"asc"})),ae=async J=>{j(!0);const k=(await Promise.allSettled(J.map(K=>l.trash(K)))).filter(K=>K.status==="rejected");k.length?h({title:`${k.length} of ${J.length} items did not move`,description:Cl(k[0].reason),tone:"danger"}):h({title:`Moved ${J.length} ${J.length===1?"item":"items"} to trash`,tone:"success"}),B(new Set),j(!1),q()},se=J=>{B(new Set),localStorage.setItem("agentic-drive-view",J),S(J)};return m.jsx("section",{onDragOver:J=>{J.preventDefault(),x(!0)},onDragLeave:J=>{J.currentTarget.contains(J.relatedTarget)||x(!1)},onDrop:re,className:`drive-drop${y?" drive-drop--over":""}${v==="list"&&C.size?" drive-drop--bulk":""}`,"aria-label":"Files",children:m.jsx(Hi,{state:L,retry:q,children:L.status==="ok"&&(()=>{const{folder:J,root:Y,crumbs:k,tree:K}=L.data,ne=A.trim().toLowerCase(),W=zS(L.data.items.filter(I=>I.name.toLowerCase().includes(ne)),D),fe=W.filter(I=>C.has(I.id)).map(I=>I.id),Be=I=>m.jsxs(m.Fragment,{children:[m.jsx(Jo,{item:I}),m.jsx(WO,{align:"end",trigger:m.jsx(Tl,{label:`Actions for ${I.name}`,icon:m.jsx(bb,{}),variant:"ghost"}),items:[{label:"Rename",onSelect:()=>E({kind:"rename",item:I})},{label:"Move",onSelect:()=>E({kind:"move",item:I})},{label:"Activity",onSelect:()=>s(`a/${I.id}`)},{label:"Share",onSelect:()=>E({kind:"share",item:I})},"separator",{label:"Move to trash",danger:!0,onSelect:()=>{$(()=>l.trash(I.id),`Moved ${I.name} to trash`)}}]})]}),Pe=I=>I.kind==="folder"?`#/${I.id}`:`#/f/${I.id}`,N=I=>m.jsx("ul",{className:"drive-tree",children:(K.get(I)??[]).map(F=>m.jsxs("li",{children:[m.jsxs("a",{href:`#/${F.id}`,"aria-current":F.id===J.id?"page":void 0,children:[m.jsx(wi,{"aria-hidden":"true"})," ",F.name]}),K.has(F.id)&&N(F.id)]},F.id))});return m.jsxs(m.Fragment,{children:[m.jsx("nav",{"aria-label":"Breadcrumb",className:"drive-crumbs",children:m.jsxs("ol",{children:[m.jsx("li",{children:k.length?m.jsx("a",{href:"#/",children:"My files"}):m.jsx("span",{"aria-current":"page",children:"My files"})}),k.map((I,F)=>m.jsx("li",{children:F===k.length-1?m.jsx("span",{"aria-current":"page",children:I.name}):m.jsx("a",{href:`#/${I.id}`,children:I.name})},I.id))]})}),m.jsxs("div",{className:"drive-bar",children:[m.jsxs("div",{className:"drive-title",children:[m.jsx("h1",{children:J.id===Y.id?"My files":J.name}),J.id!==Y.id&&m.jsx(ke,{variant:"secondary",size:"sm",onClick:()=>E({kind:"share",item:J}),children:"Share"})]}),m.jsxs(gA,{label:"Folder actions",children:[m.jsx(jo,{label:"New folder",icon:m.jsx(s_,{}),onClick:()=>E({kind:"mkdir"})}),m.jsx(jo,{label:"Upload files",icon:m.jsx(Yr,{}),onClick:()=>z.current?.click(),disabled:O}),m.jsx(jo,{label:"List view",icon:m.jsx("span",{"aria-hidden":"true",children:"☰"}),pressed:v==="list",onClick:()=>se("list")}),m.jsx(jo,{label:"Grid view",icon:m.jsx("span",{"aria-hidden":"true",children:"▦"}),pressed:v==="grid",onClick:()=>se("grid")})]}),m.jsx("input",{ref:z,type:"file",multiple:!0,hidden:!0,"aria-label":"Choose files to upload",onChange:I=>{I.target.files&&te(I.target.files),I.target.value=""}})]}),m.jsxs("div",{className:"drive-split",children:[m.jsx("nav",{"aria-label":"Folders",className:"drive-folders",children:N(Y.id)}),m.jsxs("div",{children:[m.jsx("div",{className:"drive-tools",children:m.jsx(KA,{value:A,onChange:w})}),m.jsx("p",{role:"status",className:"drive-sr",children:ne?`${W.length} of ${L.data.items.length} items match`:""}),L.data.items.length===0?m.jsx(Ri,{title:"This folder is empty",description:"Drop files here, or use Upload files.",action:m.jsx(ke,{onClick:()=>z.current?.click(),disabled:O,children:"Upload files"})}):W.length===0?m.jsx(Ri,{title:"Nothing matches",description:`No item in this folder has “${A.trim()}” in its name.`,action:m.jsx(ke,{onClick:()=>w(""),children:"Clear search"})}):v==="list"?m.jsx(US,{label:`Items in ${J.name||"My files"}`,items:W,sort:D,onSort:le,selected:C,onSelect:B,onOpen:f,href:Pe,who:ko,actions:Be}):m.jsx("ul",{className:"drive-grid","aria-label":`Items in ${J.name||"My files"}`,children:W.map(I=>m.jsxs("li",{className:"drive-card",children:[m.jsx("span",{className:"drive-card__icon","aria-hidden":"true",children:I.kind==="folder"?m.jsx(wi,{}):m.jsx(Yr,{})}),m.jsx("a",{href:Pe(I),onClick:F=>f(F,I),className:"drive-card__name",children:I.name}),m.jsxs("span",{className:"drive-card__meta",children:["Edited by ",m.jsx(Ai,{entry:ko(I.updatedBy,I.owner)})]}),m.jsx("span",{className:"drive-card__actions",children:Be(I)})]},I.id))})]})]}),v==="list"&&m.jsx(ZA,{count:fe.length,busy:O,onTrash:()=>{ae(fe)},onClear:()=>B(new Set)}),p?.kind==="mkdir"&&m.jsx(a0,{open:!0,title:"New folder",label:"Folder name",initial:"",submit:"Create",onClose:()=>E(null),onSubmit:I=>$(()=>l.mkdir(J.id===Y.id?`/${I}`:`${J.id}/${I}`),`Created ${I}`)}),p?.kind==="rename"&&m.jsx(a0,{open:!0,title:"Rename",label:"New name",initial:p.item.name,submit:"Rename",onClose:()=>E(null),onSubmit:I=>$(()=>l.move(p.item.id,p.item.parentId,{name:I}),`Renamed to ${I}`)}),p?.kind==="move"&&m.jsx(rR,{client:l,item:p.item,onClose:()=>E(null),onMove:I=>$(()=>l.move(p.item.id,I),`Moved ${p.item.name}`)}),p?.kind==="share"&&m.jsx(uR,{client:l,item:p.item,origin:c,onClose:()=>E(null)})]})})()})})}function a0({open:l,title:r,label:c,initial:o,submit:s,onClose:f,onSubmit:h}){const[v,S]=g.useState(o),p=g.useRef(!1),[E,y]=g.useState(),x=O=>{if(O){if(O.includes("/"))return y("A name cannot have a slash.");y(void 0),p.current=!0,h(O).finally(()=>{p.current=!1})}};return m.jsx(Om,{open:!!l,onOpenChange:O=>{O||f()},title:r,children:m.jsxs("form",{onSubmit:O=>{O.preventDefault(),p.current||x(v.trim())},className:"drive-form",children:[m.jsx(Qr,{label:c,value:v,onChange:O=>S(O.target.value),error:E,required:!0}),m.jsxs("div",{className:"drive-form__actions",children:[m.jsx(bS,{asChild:!0,children:m.jsx(ke,{variant:"ghost",type:"button",children:"Cancel"})}),m.jsx(ke,{type:"submit",children:s})]})]})})}function rR({client:l,item:r,onClose:c,onMove:o}){const[s,f]=Al(async()=>{const p=await l.stat("/"),E=await l.search({kind:"folder",limit:1e3}),y=E.find(x=>x.id===r.id)?.path;return[{id:"/",path:"/",name:"My files"},...E.filter(x=>x.id!==p.id&&!(y&&(x.path===y||x.path.startsWith(`${y}/`))))]}),[h,v]=g.useState("/"),S=g.useRef(!1);return m.jsx(Om,{open:!0,onOpenChange:p=>{p||c()},title:`Move ${r.name}`,children:m.jsx(Hi,{state:s,retry:f,children:s.status==="ok"&&m.jsxs("form",{onSubmit:p=>{p.preventDefault(),!S.current&&(S.current=!0,o(h).finally(()=>{S.current=!1}))},className:"drive-form",children:[m.jsx(xl,{label:"Move to",value:h,onChange:p=>v(p.target.value),children:s.data.map(p=>m.jsx("option",{value:p.id,children:p.path==="/"?"My files":p.path},p.id))}),m.jsxs("div",{className:"drive-form__actions",children:[m.jsx(bS,{asChild:!0,children:m.jsx(ke,{variant:"ghost",type:"button",children:"Cancel"})}),m.jsx(ke,{type:"submit",children:"Move"})]})]})})})}const l0={never:void 0,"1d":864e5,"7d":7*864e5,"30d":30*864e5};function uR({client:l,item:r,origin:c,onClose:o}){const s=yc(),[f,h]=Al(()=>l.shares(r.id)),[v,S]=g.useState({role:"viewer",expiry:"never",signedInOnly:!1}),p=f.status==="ok"?f.data.links.filter(T=>!T.revoked&&(T.expiresAt===null||T.expiresAt>Date.now())):[],E=p[0],y=v.id?v:E?{...v,id:E.id,role:E.role==="owner"?"editor":E.role,signedInOnly:E.signedInOnly}:v,x=async T=>{try{await T()}catch(C){s({title:"That did not work",description:Cl(C),tone:"danger"})}h()},O=f.status==="ok"?f.data.grants.map(T=>({entry:{id:T.subjectId,name:T.subjectId,kind:T.subjectKind==="agent"?"agent":"person"},role:T.role})):[],j=T=>f.status==="ok"&&f.data.grants.find(C=>C.subjectId===T)?.subjectKind||"human",A=async()=>{for(const T of new Set([...p.map(C=>C.id),...y.id?[y.id]:[]]))await l.revokeLink(T)},w=T=>x(async()=>{await A();const C=await l.createLink(r.id,{role:T.role,signedInOnly:T.signedInOnly,...l0[T.expiry]?{expiresInMs:l0[T.expiry]}:{}});S({...T,id:C.id,token:C.token}),s({title:"New link made",description:y.id?"The old link no longer works.":void 0,tone:"info"})}),D={enabled:!!y.id,role:y.role,expiry:y.expiry,signedInOnly:y.signedInOnly,url:y.token?`${c}/#/s/${r.id}/${y.token}`:"Turn the link off and on to make a new one. The address shows once.",expiresAt:E?.expiresAt?new Date(E.expiresAt):null};return m.jsx(UA,{open:!0,onOpenChange:T=>{T||o()},resourceName:r.name,people:O,onInvite:T=>{x(async()=>{await l.invite(r.id,{role:T.role,...T.kind==="person"?{email:T.to}:{handle:T.to.replace(/^@/,"")}}),s({title:"Invite created",tone:"success"})})},onChangeRole:(T,C)=>{x(()=>l.share(r.id,{kind:j(T),id:T},C))},onRemove:T=>{x(()=>l.unshare(r.id,{kind:j(T),id:T}))},link:D,onChangeLink:T=>{if(!T.enabled)return void x(async()=>{await A(),S({...y,id:void 0,token:void 0})});w({role:T.role,expiry:T.expiry,signedInOnly:T.signedInOnly})},snapshot:{onCreate:()=>s({title:"Snapshot links are not available in Drive yet",tone:"info"})},onCopy:T=>y.token&&void navigator.clipboard?.writeText(T).then(()=>s({title:"Link copied",tone:"success"}),()=>s({title:"Could not copy",tone:"warning"}))})}const i0=l=>l.trashedAt??l.updatedAt;function oR({client:l}){const r=yc(),[c,o]=Al(()=>l.listTrash()),[s,f]=g.useState({key:"name",dir:"asc"}),h=S=>f(p=>({key:S,dir:p.key===S&&p.dir==="asc"?"desc":"asc"})),v=async S=>{try{await l.restore(S.id,{onConflict:"rename"}),r({title:`Restored ${S.name}`,tone:"success"})}catch(p){r({title:"Could not restore",description:Cl(p),tone:"danger"})}o()};return m.jsxs("section",{"aria-label":"Trash",children:[m.jsx("h1",{children:"Trash"}),m.jsx(Hi,{state:c,retry:o,children:c.status==="ok"&&(c.data.length===0?m.jsx(Ri,{title:"The trash is empty",description:"Items you move to the trash show up here."}):m.jsx(US,{label:"Items in the trash",items:zS(c.data,s,i0),dateOf:i0,sort:s,onSort:h,href:()=>"#/trash",who:ko,actions:S=>m.jsxs(m.Fragment,{children:[m.jsx(Jo,{item:S}),m.jsx(ke,{size:"sm",onClick:()=>{v(S)},children:`Restore ${S.name}`})]})}))})]})}function cR({client:l,id:r}){const[c,o]=Al(async()=>({item:await l.stat(r),entries:await l.listActivity(r)}));return m.jsx("section",{"aria-label":"Item activity",children:m.jsx(Hi,{state:c,retry:o,children:c.status==="ok"&&m.jsxs(m.Fragment,{children:[m.jsxs("h1",{children:["Activity: ",c.data.item.name]}),m.jsx("p",{children:m.jsx("a",{href:c.data.item.kind==="folder"?`#/${r}`:`#/${c.data.item.parentId==="root"?"":c.data.item.parentId}`,children:"Back to files"})}),m.jsx(XA,{entries:c.data.entries})]})})})}async function sR(l,r,c,o){const s=await l.stat(r,{signal:o});o.throwIfAborted();const{url:f}=await l.url(r,void 0,{signal:o});if(o.throwIfAborted(),new URL(f,c).origin!==c)throw new Error("The download link points to another site.");const h=document.createElement("a");return h.href=f,h.download=s.name,h.click(),s}function fR({client:l,id:r,origin:c,go:o}){const[s,f]=Al(async h=>{const v=await sR(l,r,c,h);return h.throwIfAborted(),o(v.parentId,{replace:!0}),v});return m.jsx(Hi,{state:s,retry:f,children:null})}function dR({client:l,id:r,linkToken:c}){const[o,s]=Al(async()=>{const v=await l.openShared(r,{linkToken:c});return{item:v,items:v.kind==="folder"?(await l.listShared(r,{linkToken:c})).sort(HS):[]}}),f=yc(),h=async()=>{if(o.status==="ok")try{const{data:v,contentType:S}=await l.readShared(r,{linkToken:c}),p=document.createElement("a");p.href=URL.createObjectURL(new Blob([v],{type:S})),p.download=o.data.item.name,p.click(),setTimeout(()=>URL.revokeObjectURL(p.href),1e4)}catch(v){f({title:"Could not download",description:Cl(v),tone:"danger"})}};return m.jsx("section",{"aria-label":"Shared item",children:m.jsx(Hi,{state:o,retry:s,children:o.status==="ok"&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"drive-bar",children:[m.jsxs("div",{className:"drive-title",children:[m.jsx("h1",{children:o.data.item.name}),m.jsx(Jo,{item:o.data.item})]}),o.data.item.kind!=="folder"&&m.jsx(ke,{onClick:()=>{h()},children:"Download"})]}),m.jsx("p",{className:"drive-muted",children:"Shared with you."}),o.data.item.kind==="folder"?o.data.items.length===0?m.jsx(Ri,{title:"This folder is empty"}):m.jsx(AA,{label:"Shared items",children:o.data.items.map(v=>m.jsx(NA,{name:v.name,href:`#/s/${v.id}${c?`/${c}`:""}`,kind:v.kind==="folder"?"folder":"file",modified:new Date(v.updatedAt),editedBy:ko(v.updatedBy,v.owner),actions:m.jsx(Jo,{item:v})},v.id))}):null]})})})}Qx.createRoot(document.getElementById("root")).render(m.jsx(g.StrictMode,{children:m.jsx(Jx,{children:m.jsx(gb,{children:m.jsx(nA,{children:m.jsx(aR,{})})})})}));
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
6
  <title>Drive</title>
7
7
  <script src="/theme-init.js"></script>
8
- <script type="module" crossorigin src="/assets/index-C2fZap97.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-CSHYaonS.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/index-Csg2i9S0.css">
10
10
  </head>
11
11
  <body>