import { A as any, F as object, I as string, L as union, M as boolean, P as literal, a as BaseDocumentStateSchema, b as isDocumentAction, f as createAction, g as createState, h as createReducer, i as BaseDocumentHeaderSchema, j as array, k as _enum, v as defaultBaseState } from "./dist-COZZnek9.js";
//#region node_modules/.pnpm/@powerhousedao+reactor@6.2.0-dev.43_@sentry+node-core@10.53.1_@opentelemetry+api@1.9.1__3858e0f9827de08776e4149c20ec48d0/node_modules/@powerhousedao/reactor/dist/drive-container-types-BuFNr0j0.js
const DRIVE_COLLECTION_PREFIX = "drive.";
/**
* Identifies the collection a remote synchronizes. Collections are drive-level
* abstractions (document-drive and reactor-drive), so a collection id is the
* drive document id plus the branch it scopes to rather than an opaque string.
*
* The canonical string form (`drive.${branch}.${driveId}`) is produced only by
* `key` and parsed only by `fromKey`; that string is the wire and storage
* representation and is byte-for-byte identical to the legacy
* `driveCollectionId(branch, driveId)` output, so existing `document_collections`
* rows and persisted remotes remain valid without migration.
*/
var DriveCollectionId = class DriveCollectionId {
	constructor(driveId, branch) {
		this.driveId = driveId;
		this.branch = branch;
	}
	static forDrive(driveId, branch = "main") {
		return new DriveCollectionId(driveId, branch);
	}
	/**
	* The single deserializer for the wire/storage form. `branch` may contain
	* dots, while `driveId` is a dot-free document id, so the drive id is the
	* final dot-delimited segment.
	*/
	static fromKey(key) {
		if (!key.startsWith(DRIVE_COLLECTION_PREFIX)) throw new Error(`Unsupported collection id: ${key}`);
		const rest = key.slice(6);
		const lastDot = rest.lastIndexOf(".");
		if (lastDot === -1 || lastDot === rest.length - 1) throw new Error(`Malformed drive collection id: ${key}`);
		return new DriveCollectionId(rest.slice(lastDot + 1), rest.slice(0, lastDot));
	}
	get key() {
		return `${DRIVE_COLLECTION_PREFIX}${this.branch}.${this.driveId}`;
	}
	toString() {
		return this.key;
	}
	equals(other) {
		return this.driveId === other.driveId && this.branch === other.branch;
	}
};
Object.defineProperty;
const isDefinedNonNullAny = (v) => v !== void 0 && v !== null;
any().refine((v) => isDefinedNonNullAny(v));
const TransmitterTypeSchema = _enum([
	"Internal",
	"MatrixConnect",
	"PullResponder",
	"RESTWebhook",
	"SecureConnect",
	"SwitchboardPush"
]);
const TriggerTypeSchema = _enum(["PullResponder"]);
function AddFileInputSchema() {
	return object({
		documentType: string(),
		id: string(),
		name: string(),
		parentFolder: string().nullish()
	});
}
function AddFolderInputSchema() {
	return object({
		id: string(),
		name: string(),
		parentFolder: string().nullish()
	});
}
function AddListenerInputSchema() {
	return object({ listener: ListenerInputSchema() });
}
function AddTriggerInputSchema() {
	return object({ trigger: TriggerInputSchema() });
}
function CopyNodeInputSchema() {
	return object({
		srcId: string(),
		targetId: string(),
		targetName: string().nullish(),
		targetParentFolder: string().nullish()
	});
}
function DeleteNodeInputSchema() {
	return object({ id: string() });
}
function DocumentDriveLocalStateSchema() {
	return object({
		__typename: literal("DocumentDriveLocalState").optional(),
		availableOffline: boolean(),
		listeners: array(ListenerSchema()),
		sharingType: string().nullable(),
		triggers: array(TriggerSchema())
	});
}
function DocumentDriveStateSchema() {
	return object({
		__typename: literal("DocumentDriveState").optional(),
		icon: string().nullable(),
		name: string(),
		nodes: array(NodeSchema())
	});
}
function FileNodeSchema() {
	return object({
		__typename: literal("FileNode").optional(),
		documentType: string(),
		id: string(),
		kind: string(),
		name: string(),
		parentFolder: string().nullable()
	});
}
function FolderNodeSchema() {
	return object({
		__typename: literal("FolderNode").optional(),
		id: string(),
		kind: string(),
		name: string(),
		parentFolder: string().nullable()
	});
}
function ListenerSchema() {
	return object({
		__typename: literal("Listener").optional(),
		block: boolean(),
		callInfo: ListenerCallInfoSchema().nullable(),
		filter: ListenerFilterSchema(),
		label: string().nullable(),
		listenerId: string(),
		system: boolean()
	});
}
function ListenerInputSchema() {
	return object({
		block: boolean(),
		callInfo: ListenerCallInfoInputSchema().nullish(),
		filter: ListenerFilterInputSchema(),
		label: string().nullish(),
		listenerId: string(),
		system: boolean()
	});
}
function ListenerCallInfoSchema() {
	return object({
		__typename: literal("ListenerCallInfo").optional(),
		data: string().nullable(),
		name: string().nullable(),
		transmitterType: TransmitterTypeSchema.nullable()
	});
}
function ListenerCallInfoInputSchema() {
	return object({
		data: string().nullish(),
		name: string().nullish(),
		transmitterType: TransmitterTypeSchema.nullish()
	});
}
function ListenerFilterSchema() {
	return object({
		__typename: literal("ListenerFilter").optional(),
		branch: array(string()).nullable(),
		documentId: array(string()).nullable(),
		documentType: array(string()),
		scope: array(string()).nullable()
	});
}
function ListenerFilterInputSchema() {
	return object({
		branch: array(string()).nullish(),
		documentId: array(string()).nullish(),
		documentType: array(string()).nullish(),
		scope: array(string()).nullish()
	});
}
function MoveNodeInputSchema() {
	return object({
		srcFolder: string(),
		targetParentFolder: string().nullish()
	});
}
function NodeSchema() {
	return union([FileNodeSchema(), FolderNodeSchema()]);
}
function PullResponderTriggerDataSchema() {
	return object({
		__typename: literal("PullResponderTriggerData").optional(),
		interval: string(),
		listenerId: string(),
		url: string()
	});
}
function PullResponderTriggerDataInputSchema() {
	return object({
		interval: string(),
		listenerId: string(),
		url: string()
	});
}
function RemoveListenerInputSchema() {
	return object({ listenerId: string() });
}
function RemoveTriggerInputSchema() {
	return object({ triggerId: string() });
}
function SetAvailableOfflineInputSchema() {
	return object({ availableOffline: boolean() });
}
function SetDriveIconInputSchema() {
	return object({ icon: string() });
}
function SetDriveNameInputSchema() {
	return object({ name: string() });
}
function SetSharingTypeInputSchema() {
	return object({ type: string() });
}
function TriggerSchema() {
	return object({
		__typename: literal("Trigger").optional(),
		data: TriggerDataSchema().nullable(),
		id: string(),
		type: TriggerTypeSchema
	});
}
function TriggerInputSchema() {
	return object({
		data: PullResponderTriggerDataInputSchema().nullish(),
		id: string(),
		type: TriggerTypeSchema
	});
}
function TriggerDataSchema() {
	return PullResponderTriggerDataSchema();
}
function UpdateFileInputSchema() {
	return object({
		documentType: string().nullish(),
		id: string(),
		name: string().nullish(),
		parentFolder: string().nullish()
	});
}
function UpdateNodeInputSchema() {
	return object({
		id: string(),
		name: string().nullish(),
		parentFolder: string().nullish()
	});
}
const addFolder = (input) => createAction("ADD_FOLDER", { ...input }, void 0, AddFolderInputSchema, "global");
const updateNode = (input) => createAction("UPDATE_NODE", { ...input }, void 0, UpdateNodeInputSchema, "global");
const copyNode = (input) => createAction("COPY_NODE", { ...input }, void 0, CopyNodeInputSchema, "global");
const moveNode = (input) => createAction("MOVE_NODE", { ...input }, void 0, MoveNodeInputSchema, "global");
const driveDocumentModel = {
	id: "powerhouse/document-drive",
	name: "DocumentDrive",
	extension: "phdd",
	description: "",
	author: {
		name: "Powerhouse Inc",
		website: "https://www.powerhouse.inc/"
	},
	specifications: [{
		version: 1,
		changeLog: [],
		state: {
			global: {
				schema: "type FolderNode {\n    id: String!\n    name: String!\n    kind: String!\n    parentFolder: String\n}\n\ntype FileNode {\n    id: String!\n    name: String!\n    kind: String!\n    documentType: String!\n    parentFolder: String\n}\n\nunion Node = FolderNode | FileNode\n\ntype DocumentDriveState {\n    name: String!\n    nodes: [Node!]!\n    icon: String\n}",
				initialValue: "\"{\\\"name\\\":\\\"\\\",\\\"nodes\\\":[],\\\"icon\\\":null}\"",
				examples: []
			},
			local: {
				schema: "type ListenerFilter {\n    documentType: [String!]!\n    documentId: [ID!]\n    scope: [String!]\n    branch: [String!]\n}\n\nenum TransmitterType {\n    Internal,\n    SwitchboardPush,\n    PullResponder,\n    SecureConnect, \n    MatrixConnect,\n    RESTWebhook\n}\n\ntype ListenerCallInfo {\n    transmitterType: TransmitterType\n    name: String\n    data: String\n}\n\ntype Listener {\n    listenerId: ID!\n    label: String\n    block: Boolean!\n    system: Boolean!\n    filter: ListenerFilter!\n    callInfo: ListenerCallInfo\n}\n\nenum TriggerType {\n    PullResponder\n}\n\ntype PullResponderTriggerData {\n    listenerId: ID!\n    url: String!\n    interval: String!\n}\n\nunion TriggerData = PullResponderTriggerData\n\ntype Trigger {\n    id: ID!\n    type: TriggerType!\n    data: TriggerData\n}\n\ntype DocumentDriveLocalState{\n    sharingType: String\n    listeners: [Listener!]!\n    triggers: [Trigger!]!\n    availableOffline: Boolean!\n}",
				initialValue: "\"{ \\\"listeners\\\": [], \\\"triggers\\\": [], \\\"sharingType\\\": \\\"private\\\", \\\"availableOffline\\\": false}\"",
				examples: []
			}
		},
		modules: [{
			id: "GRzuvv78tBvmB6ciitokLfonNHA=",
			name: "Node",
			description: "",
			operations: [
				{
					id: "7xiTdxonc9yEASR8sfV/KnbSV10=",
					name: "ADD_FILE",
					description: "",
					schema: "input AddFileInput {\n    id: ID!\n    name: String!\n    documentType: String!\n    parentFolder: ID\n}",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "global"
				},
				{
					id: "4lzNMMKKdIAtEU6i12xLgi9hp+U=",
					name: "ADD_FOLDER",
					description: "",
					schema: "input AddFolderInput {\n    id: ID!\n    name: String!\n    parentFolder: ID\n}",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "global"
				},
				{
					id: "53jH2/3TWTTcgCJiv2C+BmuC6i0=",
					name: "DELETE_NODE",
					description: "",
					schema: "input DeleteNodeInput {\n    id: ID!\n}",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "global"
				},
				{
					id: "pNn+Y1/HVq/GNMk7t0u3g3gtMLE=",
					name: "UPDATE_FILE",
					description: "",
					schema: "input UpdateFileInput {\n    id: ID!\n    parentFolder: ID\n    name: String\n    documentType: String\n}",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "global"
				},
				{
					id: "P0x1M8Mnt+Q/+9nggkwgVbfybsc=",
					name: "UPDATE_NODE",
					description: "",
					schema: "input UpdateNodeInput {\n    id: ID!\n    parentFolder: ID\n    name: String\n}",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "global"
				},
				{
					id: "vnQ7OB5b3wGLgjhbgJqAIpA+JLE=",
					name: "COPY_NODE",
					description: "",
					schema: "input CopyNodeInput {\n    srcId: ID!\n    targetId: ID!\n    targetName: String\n    targetParentFolder: ID\n}",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "global"
				},
				{
					id: "VNyiD/sNGzk6k9A1Qe7s8dmrJxA=",
					name: "MOVE_NODE",
					description: "",
					schema: "input MoveNodeInput {\n    srcFolder: ID!\n    targetParentFolder: ID\n}",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "global"
				}
			]
		}, {
			id: "0dHwHlxOM9x0vMZ+gLnKxf2qTEo=",
			name: "Drive",
			description: "",
			operations: [
				{
					id: "qGCiPGpTt/cyz3HzyrBn92z1dsU=",
					name: "SET_DRIVE_NAME",
					description: "",
					schema: "input SetDriveNameInput {\n    name: String!\n}",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "global"
				},
				{
					id: "qGCiPGpTt/cyz3HzyrBn92z30dsU=",
					name: "SET_DRIVE_ICON",
					description: "",
					schema: "input SetDriveIconInput {\n    icon: String!\n}",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "global"
				},
				{
					id: "qGCiPGpTt/cyz3HzyrBn92z2dsU=",
					name: "SET_SHARING_TYPE",
					description: "",
					schema: "input SetSharingTypeInput {\n    type: String!\n}",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "local"
				},
				{
					id: "qGCiPGpTt/cyz3HzyrBn92z3dsU=",
					name: "SET_AVAILABLE_OFFLINE",
					description: "",
					schema: "input SetAvailableOfflineInput {\n    availableOffline: Boolean!\n}",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "local"
				},
				{
					id: "qGCiPGpTt/cyz3HzyrBn92z9dsU=",
					name: "ADD_LISTENER",
					description: "",
					schema: "input ListenerFilterInput {\n    documentType: [String!]\n    documentId: [ID!]\n    scope: [String!]\n    branch: [String!]\n}\n\ninput ListenerCallInfoInput {\n    transmitterType: TransmitterType\n    name: String\n    data: String\n}\n\ninput ListenerInput {\n    listenerId: ID!\n    label: String\n    block: Boolean!\n    system: Boolean!\n    filter: ListenerFilterInput!\n    callInfo: ListenerCallInfoInput\n}\n\ninput AddListenerInput {\n    listener: ListenerInput!\n}",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "local"
				},
				{
					id: "qGCiPGpTt/cyz3HzyrBn92z10dsU=",
					name: "REMOVE_LISTENER",
					description: "",
					schema: "input RemoveListenerInput {\n    listenerId: String!\n}",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "local"
				},
				{
					id: "qGCiPGpTt/cyz3HzyrBn92z20dsU=",
					name: "ADD_TRIGGER",
					description: "",
					schema: "input PullResponderTriggerDataInput {\n    listenerId: ID!\n    url: String!\n    interval: String!\n}\n\ninput TriggerInput {\n    id: ID!\n    type: TriggerType!\n    data: PullResponderTriggerDataInput\n}\n\ninput AddTriggerInput {\n    trigger: TriggerInput!\n}",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "local"
				},
				{
					id: "qGCiPGpTt/cyz3HzyrBn92z30dsU=",
					name: "REMOVE_TRIGGER",
					description: "",
					schema: "input RemoveTriggerInput {\n    triggerId: String!\n}",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "local"
				}
			]
		}]
	}]
};
/** Schema for validating the header object of a Drive document */
const DriveDocumentHeaderSchema = BaseDocumentHeaderSchema.extend({ documentType: literal("powerhouse/document-drive") });
/** Schema for validating the state object of a Drive document */
const DrivePHStateSchema = BaseDocumentStateSchema.extend({
	global: DocumentDriveStateSchema(),
	local: DocumentDriveLocalStateSchema()
});
object({
	header: DriveDocumentHeaderSchema,
	state: DrivePHStateSchema,
	initialState: DrivePHStateSchema
});
const driveReducer = {
	setDriveNameOperation(state, action, dispatch) {
		state.name = action.input.name;
	},
	setDriveIconOperation(state, action, dispatch) {
		state.icon = action.input.icon;
	},
	setSharingTypeOperation(state, action, dispatch) {
		state.sharingType = action.input.type;
	},
	setAvailableOfflineOperation(state, action, dispatch) {
		state.availableOffline = action.input.availableOffline;
	},
	addListenerOperation(state, action, dispatch) {
		const { listener: input } = action.input;
		if (state.listeners.find((l) => l.listenerId === input.listenerId)) throw new Error(`A listener with Id: ${input.listenerId} already exists`);
		const listener = {
			listenerId: input.listenerId,
			label: input.label ?? null,
			block: input.block,
			system: input.system,
			filter: {
				documentType: input.filter.documentType ?? null,
				documentId: input.filter.documentId ?? null,
				scope: input.filter.scope ?? null,
				branch: input.filter.branch ?? null
			},
			callInfo: input.callInfo ? {
				transmitterType: input.callInfo.transmitterType ?? null,
				name: input.callInfo.name ?? null,
				data: input.callInfo.data ?? null
			} : null
		};
		state.listeners.push(listener);
	},
	removeListenerOperation(state, action, dispatch) {
		state.listeners = state.listeners.filter((listener) => listener.listenerId !== action.input.listenerId);
	},
	addTriggerOperation(state, action, dispatch) {
		const { trigger: input } = action.input;
		if (state.triggers.find((t) => t.id === input.id)) throw new Error(`A trigger with Id: ${input.id} already exists`);
		const trigger = {
			id: input.id,
			type: input.type,
			data: input.data ? { ...input.data } : null
		};
		state.triggers.push(trigger);
	},
	removeTriggerOperation(state, action, dispatch) {
		state.triggers = state.triggers.filter((trigger) => trigger.id !== action.input.triggerId);
	}
};
function isFileNode(node) {
	return node.kind === "file";
}
function isFolderNode(node) {
	return node.kind === "folder";
}
function getDescendants(node, allNodes) {
	const children = allNodes.filter((_node) => _node.parentFolder === node.id);
	const descendants = children.map((child) => getDescendants(child, allNodes));
	return [...children, ...descendants.flat()];
}
/**
* Generates a copy of nodes based on the provided source and target information.
* @param src - The source information for generating the copy.
* @param idGenerator - The function used to generate new IDs for the copied nodes.
* @param nodes - The array of nodes to copy from.
* @returns An array of copied nodes with updated IDs and parent folders.
* @throws Error if the root node with the specified ID is not found.
*/
function generateNodesCopy(src, idGenerator, nodes) {
	const rootNode = nodes.find((node) => node.id === src.srcId);
	if (!rootNode) throw new Error(`Node with id ${src.srcId} not found`);
	const nodesToCopy = [{
		...rootNode,
		name: src.targetName || rootNode.name,
		parentFolder: src.targetParentFolder || null
	}, ...getDescendants(rootNode, nodes)];
	const ids = {};
	if (src.targetParentFolder) ids[src.targetParentFolder] = src.targetParentFolder;
	const getNewNodeId = (node) => {
		let newId = ids[node.id];
		if (!newId) {
			const oldId = node.id;
			newId = idGenerator(node);
			ids[oldId] = newId;
		}
		return newId;
	};
	return nodesToCopy.map((node) => ({
		srcId: node.id,
		targetId: getNewNodeId(node),
		targetName: node.name,
		targetParentFolder: node.parentFolder ? ids[node.parentFolder] : null
	}));
}
function getNextCopyNumber(files, baseFilename) {
	let maxNumber = 0;
	const regex = new RegExp(`^${escapeRegExp(baseFilename)} \\(copy\\)(?: (\\d+))?$`);
	for (const file of files) {
		const match = file.match(regex);
		if (match) {
			const number = match[1] ? parseInt(match[1], 10) : 1;
			if (number > maxNumber) maxNumber = number;
		}
	}
	return maxNumber + 1;
}
function escapeRegExp(string) {
	return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function handleTargetNameCollisions(params) {
	const { nodes, targetParentFolder, srcName, srcKind } = params;
	const targetNodeChildrenNames = nodes.filter((node) => targetParentFolder === "" ? node.parentFolder === null : node.parentFolder === targetParentFolder).filter((node) => node.kind === srcKind).map((node) => node.name);
	return targetNodeChildrenNames.includes(srcName) ? `${srcName} (copy) ${getNextCopyNumber(targetNodeChildrenNames, srcName)}` : srcName;
}
const isValidName = (name) => {
	return name.trim().length > 0 && !/[\u0000-\u001F\u007F]/.test(name);
};
const nodeReducer = {
	addFileOperation(state, action, dispatch) {
		if (state.nodes.find((node) => node.id === action.input.id)) throw new Error(`Node with id ${action.input.id} already exists!`);
		if (!isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must not be empty or contain control characters.`);
		const name = handleTargetNameCollisions({
			nodes: state.nodes,
			srcName: action.input.name,
			srcKind: "file",
			targetParentFolder: action.input.parentFolder || null
		});
		const fileNode = {
			id: action.input.id,
			name,
			kind: "file",
			parentFolder: action.input.parentFolder ?? null,
			documentType: action.input.documentType
		};
		state.nodes.push(fileNode);
		state.nodes.sort((a, b) => a.id.localeCompare(b.id));
		dispatch?.({
			type: "CREATE_CHILD_DOCUMENT",
			input: {
				id: action.input.id,
				documentType: action.input.documentType
			}
		});
	},
	addFolderOperation(state, action) {
		if (state.nodes.find((node) => node.id === action.input.id)) throw new Error(`Node with id ${action.input.id} already exists!`);
		if (!isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must not be empty or contain control characters.`);
		const name = handleTargetNameCollisions({
			nodes: state.nodes,
			srcName: action.input.name,
			srcKind: "folder",
			targetParentFolder: action.input.parentFolder || null
		});
		state.nodes.push({
			...action.input,
			name,
			kind: "folder",
			parentFolder: action.input.parentFolder ?? null
		});
		state.nodes.sort((a, b) => a.id.localeCompare(b.id));
	},
	deleteNodeOperation(state, action, dispatch) {
		const node = state.nodes.find((node) => node.id === action.input.id);
		if (!node) throw new Error(`Node with id ${action.input.id} not found`);
		const descendants = getDescendants(node, state.nodes);
		state.nodes = state.nodes.filter((node) => node.id !== action.input.id && !descendants.find((descendant) => descendant.id === node.id));
		[node, ...descendants].filter((node) => isFileNode(node)).forEach((node) => {
			dispatch?.({
				type: "DELETE_CHILD_DOCUMENT",
				input: { id: node.id }
			});
		});
	},
	updateFileOperation(state, action) {
		if (action.input.name && !isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must not be empty or contain control characters.`);
		state.nodes = state.nodes.map((node) => node.id === action.input.id ? {
			...node,
			name: handleTargetNameCollisions({
				nodes: state.nodes.filter((n) => n.id !== action.input.id),
				srcName: action.input.name ?? node.name,
				srcKind: "file",
				targetParentFolder: action.input.parentFolder ?? node.parentFolder
			}),
			documentType: action.input.documentType ?? node.documentType
		} : node);
		state.nodes.sort((a, b) => a.id.localeCompare(b.id));
	},
	updateNodeOperation(state, action) {
		if (action.input.name && !isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must not be empty or contain control characters.`);
		state.nodes = state.nodes.map((node) => node.id === action.input.id ? {
			...node,
			name: handleTargetNameCollisions({
				nodes: state.nodes.filter((n) => n.id !== action.input.id),
				srcName: action.input.name ?? node.name,
				srcKind: node.kind === "file" ? "file" : "folder",
				targetParentFolder: action.input.parentFolder ?? node.parentFolder
			}),
			parentFolder: action.input.parentFolder === null ? null : node.parentFolder
		} : node);
		state.nodes.sort((a, b) => a.id.localeCompare(b.id));
	},
	copyNodeOperation(state, action, dispatch) {
		const node = state.nodes.find((node) => node.id === action.input.srcId);
		if (!node) throw new Error(`Node with id ${action.input.srcId} not found`);
		if (state.nodes.find((node) => node.id === action.input.targetId)) throw new Error(`Node with id ${action.input.targetId} already exists`);
		const name = handleTargetNameCollisions({
			nodes: state.nodes,
			srcName: action.input.targetName || node.name,
			srcKind: node.kind === "file" ? "file" : "folder",
			targetParentFolder: action.input.targetParentFolder || null
		});
		const newNode = {
			...node,
			id: action.input.targetId,
			slug: action.input.targetId,
			name,
			parentFolder: action.input.targetParentFolder || null
		};
		state.nodes.push(newNode);
		state.nodes.sort((a, b) => a.id.localeCompare(b.id));
		if (isFileNode(newNode)) dispatch?.({
			type: "COPY_CHILD_DOCUMENT",
			input: {
				id: action.input.srcId,
				newId: action.input.targetId
			}
		});
	},
	moveNodeOperation(state, action) {
		if (action.input.srcFolder === action.input.targetParentFolder) throw new Error("Circular Reference Error: Attempting to move a node to its current parent folder");
		const node = state.nodes.find((node) => node.id === action.input.srcFolder);
		if (!node) throw new Error(`Node with id ${action.input.srcFolder} not found`);
		const name = handleTargetNameCollisions({
			nodes: state.nodes,
			srcName: node.name,
			srcKind: node.kind === "file" ? "file" : "folder",
			targetParentFolder: action.input.targetParentFolder || null
		});
		if (isFolderNode(node)) {
			if (getDescendants(node, state.nodes).find((descendant) => descendant.id === action.input.targetParentFolder)) throw new Error("Circular Reference Error: Cannot move a folder to one of its descendants");
		}
		state.nodes = state.nodes.map((node) => {
			if (node.id === action.input.srcFolder) return {
				...node,
				name,
				parentFolder: action.input.targetParentFolder || null
			};
			return node;
		});
		state.nodes.sort((a, b) => a.id.localeCompare(b.id));
	}
};
const driveStateReducer = (state, action, dispatch) => {
	if (isDocumentAction(action)) return state;
	const typedAction = action;
	switch (typedAction.type) {
		case "ADD_FILE":
			AddFileInputSchema().parse(typedAction.input);
			nodeReducer.addFileOperation(state[typedAction.scope], action, dispatch);
			break;
		case "ADD_FOLDER":
			AddFolderInputSchema().parse(typedAction.input);
			nodeReducer.addFolderOperation(state[typedAction.scope], action, dispatch);
			break;
		case "DELETE_NODE":
			DeleteNodeInputSchema().parse(typedAction.input);
			nodeReducer.deleteNodeOperation(state[typedAction.scope], action, dispatch);
			break;
		case "UPDATE_FILE":
			UpdateFileInputSchema().parse(typedAction.input);
			nodeReducer.updateFileOperation(state[typedAction.scope], action, dispatch);
			break;
		case "UPDATE_NODE":
			UpdateNodeInputSchema().parse(typedAction.input);
			nodeReducer.updateNodeOperation(state[typedAction.scope], action, dispatch);
			break;
		case "COPY_NODE":
			CopyNodeInputSchema().parse(typedAction.input);
			nodeReducer.copyNodeOperation(state[typedAction.scope], action, dispatch);
			break;
		case "MOVE_NODE":
			MoveNodeInputSchema().parse(typedAction.input);
			nodeReducer.moveNodeOperation(state[typedAction.scope], action, dispatch);
			break;
		case "SET_DRIVE_NAME":
			SetDriveNameInputSchema().parse(typedAction.input);
			driveReducer.setDriveNameOperation(state[typedAction.scope], action, dispatch);
			break;
		case "SET_DRIVE_ICON":
			SetDriveIconInputSchema().parse(typedAction.input);
			driveReducer.setDriveIconOperation(state[typedAction.scope], action, dispatch);
			break;
		case "SET_SHARING_TYPE":
			SetSharingTypeInputSchema().parse(typedAction.input);
			driveReducer.setSharingTypeOperation(state[typedAction.scope], action, dispatch);
			break;
		case "SET_AVAILABLE_OFFLINE":
			SetAvailableOfflineInputSchema().parse(typedAction.input);
			driveReducer.setAvailableOfflineOperation(state[typedAction.scope], action, dispatch);
			break;
		case "ADD_LISTENER":
			AddListenerInputSchema().parse(typedAction.input);
			driveReducer.addListenerOperation(state[typedAction.scope], action, dispatch);
			break;
		case "REMOVE_LISTENER":
			RemoveListenerInputSchema().parse(typedAction.input);
			driveReducer.removeListenerOperation(state[typedAction.scope], action, dispatch);
			break;
		case "ADD_TRIGGER":
			AddTriggerInputSchema().parse(typedAction.input);
			driveReducer.addTriggerOperation(state[typedAction.scope], action, dispatch);
			break;
		case "REMOVE_TRIGGER":
			RemoveTriggerInputSchema().parse(typedAction.input);
			driveReducer.removeTriggerOperation(state[typedAction.scope], action, dispatch);
			break;
		default: return state;
	}
};
createReducer(driveStateReducer);
createState(defaultBaseState(), driveDocumentModel);
//#endregion
//#region node_modules/.pnpm/@powerhousedao+reactor@6.2.0-dev.43_@sentry+node-core@10.53.1_@opentelemetry+api@1.9.1__3858e0f9827de08776e4149c20ec48d0/node_modules/@powerhousedao/reactor/dist/index.js
/**
* Describes the types of document changes that can occur.
*/
let DocumentChangeType = /* @__PURE__ */ function(DocumentChangeType) {
	DocumentChangeType["Created"] = "created";
	DocumentChangeType["Deleted"] = "deleted";
	DocumentChangeType["Updated"] = "updated";
	DocumentChangeType["ParentAdded"] = "parent_added";
	DocumentChangeType["ParentRemoved"] = "parent_removed";
	DocumentChangeType["ChildAdded"] = "child_added";
	DocumentChangeType["ChildRemoved"] = "child_removed";
	return DocumentChangeType;
}({});
let SyncStatus = /* @__PURE__ */ function(SyncStatus) {
	SyncStatus["Synced"] = "SYNCED";
	SyncStatus["Outgoing"] = "OUTGOING";
	SyncStatus["Incoming"] = "INCOMING";
	SyncStatus["OutgoingAndIncoming"] = "OUTGOING_AND_INCOMING";
	SyncStatus["Error"] = "ERROR";
	return SyncStatus;
}({});
//#endregion
export { generateNodesCopy as a, isFolderNode as c, DriveCollectionId as d, copyNode as i, moveNode as l, SyncStatus as n, handleTargetNameCollisions as o, addFolder as r, isFileNode as s, DocumentChangeType as t, updateNode as u };

//# sourceMappingURL=dist-DGM8GwFD.js.map