import { S as createState, X as generateId, g as baseLoadFromInput, h as baseCreateDocument, k as isDocumentAction, v as baseSaveToFileHandle, w as defaultBaseState, x as createReducer } from "./document-drive-sTKoi6L4.js";
import { t as parse } from "./parser-CkF6Qt8V.js";
//#region ../reactor/dist/drive-container-types-CAhznKRr.js
/**
* Error thrown when a document model module is not found in the registry.
*/
var ModuleNotFoundError = class extends Error {
	documentType;
	requestedVersion;
	constructor(documentType, version) {
		const versionSuffix = version !== void 0 ? ` version ${version}` : "";
		super(`Document model module not found for type: ${documentType}${versionSuffix}`);
		this.name = "ModuleNotFoundError";
		this.documentType = documentType;
		this.requestedVersion = version;
	}
	static isError(error) {
		return Error.isError(error) && error.name === "ModuleNotFoundError";
	}
};
function driveCollectionId(branch, driveId) {
	return `drive.${branch}.${driveId}`;
}
//#endregion
//#region ../reactor/dist/index.js
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
//#region ../../node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.mjs
var __assign = function() {
	__assign = Object.assign || function __assign(t) {
		for (var s, i = 1, n = arguments.length; i < n; i++) {
			s = arguments[i];
			for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
		}
		return t;
	};
	return __assign.apply(this, arguments);
};
function __rest(s, e) {
	var t = {};
	for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
	if (s != null && typeof Object.getOwnPropertySymbols === "function") {
		for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
	}
	return t;
}
function __spreadArray(to, from, pack) {
	if (pack || arguments.length === 2) {
		for (var i = 0, l = from.length, ar; i < l; i++) if (ar || !(i in from)) {
			if (!ar) ar = Array.prototype.slice.call(from, 0, i);
			ar[i] = from[i];
		}
	}
	return to.concat(ar || Array.prototype.slice.call(from));
}
//#endregion
//#region ../../node_modules/.pnpm/graphql-tag@2.12.6_graphql@16.12.0/node_modules/graphql-tag/lib/index.js
var docCache = /* @__PURE__ */ new Map();
var fragmentSourceMap = /* @__PURE__ */ new Map();
var printFragmentWarnings = true;
var experimentalFragmentVariables = false;
function normalize(string) {
	return string.replace(/[\s,]+/g, " ").trim();
}
function cacheKeyFromLoc(loc) {
	return normalize(loc.source.body.substring(loc.start, loc.end));
}
function processFragments(ast) {
	var seenKeys = /* @__PURE__ */ new Set();
	var definitions = [];
	ast.definitions.forEach(function(fragmentDefinition) {
		if (fragmentDefinition.kind === "FragmentDefinition") {
			var fragmentName = fragmentDefinition.name.value;
			var sourceKey = cacheKeyFromLoc(fragmentDefinition.loc);
			var sourceKeySet = fragmentSourceMap.get(fragmentName);
			if (sourceKeySet && !sourceKeySet.has(sourceKey)) {
				if (printFragmentWarnings) console.warn("Warning: fragment with name " + fragmentName + " already exists.\ngraphql-tag enforces all fragment names across your application to be unique; read more about\nthis in the docs: http://dev.apollodata.com/core/fragments.html#unique-names");
			} else if (!sourceKeySet) fragmentSourceMap.set(fragmentName, sourceKeySet = /* @__PURE__ */ new Set());
			sourceKeySet.add(sourceKey);
			if (!seenKeys.has(sourceKey)) {
				seenKeys.add(sourceKey);
				definitions.push(fragmentDefinition);
			}
		} else definitions.push(fragmentDefinition);
	});
	return __assign(__assign({}, ast), { definitions });
}
function stripLoc(doc) {
	var workSet = new Set(doc.definitions);
	workSet.forEach(function(node) {
		if (node.loc) delete node.loc;
		Object.keys(node).forEach(function(key) {
			var value = node[key];
			if (value && typeof value === "object") workSet.add(value);
		});
	});
	var loc = doc.loc;
	if (loc) {
		delete loc.startToken;
		delete loc.endToken;
	}
	return doc;
}
function parseDocument(source) {
	var cacheKey = normalize(source);
	if (!docCache.has(cacheKey)) {
		var parsed = parse(source, {
			experimentalFragmentVariables,
			allowLegacyFragmentVariables: experimentalFragmentVariables
		});
		if (!parsed || parsed.kind !== "Document") throw new Error("Not a valid GraphQL document.");
		docCache.set(cacheKey, stripLoc(processFragments(parsed)));
	}
	return docCache.get(cacheKey);
}
function gql(literals) {
	var args = [];
	for (var _i = 1; _i < arguments.length; _i++) args[_i - 1] = arguments[_i];
	if (typeof literals === "string") literals = [literals];
	var result = literals[0];
	args.forEach(function(arg, i) {
		if (arg && arg.kind === "Document") result += arg.loc.source.body;
		else result += arg;
		result += literals[i + 1];
	});
	return parseDocument(result);
}
function resetCaches() {
	docCache.clear();
	fragmentSourceMap.clear();
}
function disableFragmentWarnings() {
	printFragmentWarnings = false;
}
function enableExperimentalFragmentVariables() {
	experimentalFragmentVariables = true;
}
function disableExperimentalFragmentVariables() {
	experimentalFragmentVariables = false;
}
var extras = {
	gql,
	resetCaches,
	disableFragmentWarnings,
	enableExperimentalFragmentVariables,
	disableExperimentalFragmentVariables
};
(function(gql_1) {
	gql_1.gql = extras.gql, gql_1.resetCaches = extras.resetCaches, gql_1.disableFragmentWarnings = extras.disableFragmentWarnings, gql_1.enableExperimentalFragmentVariables = extras.enableExperimentalFragmentVariables, gql_1.disableExperimentalFragmentVariables = extras.disableExperimentalFragmentVariables;
})(gql || (gql = {}));
gql["default"] = gql;
//#endregion
//#region ../reactor-drive/dist/index.js
const REACTOR_DRIVE_DOCUMENT_TYPE = "powerhouse/reactor-drive";
const REACTOR_DRIVE_FILE_EXTENSION = "phrd";
function setDriveNameAction(input) {
	return {
		id: generateId(),
		type: "SET_DRIVE_NAME",
		scope: "global",
		timestampUtcMs: (/* @__PURE__ */ new Date()).toISOString(),
		input
	};
}
function setDriveIconAction(input) {
	return {
		id: generateId(),
		type: "SET_DRIVE_ICON",
		scope: "global",
		timestampUtcMs: (/* @__PURE__ */ new Date()).toISOString(),
		input
	};
}
function setSharingTypeAction(input) {
	return {
		id: generateId(),
		type: "SET_SHARING_TYPE",
		scope: "local",
		timestampUtcMs: (/* @__PURE__ */ new Date()).toISOString(),
		input
	};
}
function setAvailableOfflineAction(input) {
	return {
		id: generateId(),
		type: "SET_AVAILABLE_OFFLINE",
		scope: "local",
		timestampUtcMs: (/* @__PURE__ */ new Date()).toISOString(),
		input
	};
}
function addFolderAction(input) {
	return {
		id: generateId(),
		type: "ADD_FOLDER",
		scope: "document",
		timestampUtcMs: (/* @__PURE__ */ new Date()).toISOString(),
		input
	};
}
function updateFolderAction(input) {
	return {
		id: generateId(),
		type: "UPDATE_FOLDER",
		scope: "document",
		timestampUtcMs: (/* @__PURE__ */ new Date()).toISOString(),
		input
	};
}
function removeFolderAction(input) {
	return {
		id: generateId(),
		type: "REMOVE_FOLDER",
		scope: "document",
		timestampUtcMs: (/* @__PURE__ */ new Date()).toISOString(),
		input
	};
}
const reactorDriveActions = {
	setDriveName: setDriveNameAction,
	setDriveIcon: setDriveIconAction,
	setSharingType: setSharingTypeAction,
	setAvailableOffline: setAvailableOfflineAction,
	addFolder: addFolderAction,
	updateFolder: updateFolderAction,
	removeFolder: removeFolderAction
};
const reactorDriveStateReducer = (state, action) => {
	if (isDocumentAction(action)) return state;
	const typedAction = action;
	switch (typedAction.type) {
		case "SET_DRIVE_NAME": {
			const input = typedAction.input;
			state.global.name = input.name;
			return state;
		}
		case "SET_DRIVE_ICON": {
			const input = typedAction.input;
			state.global.icon = input.icon;
			return state;
		}
		case "SET_SHARING_TYPE": {
			const input = typedAction.input;
			state.local.sharingType = input.sharingType;
			return state;
		}
		case "SET_AVAILABLE_OFFLINE": {
			const input = typedAction.input;
			state.local.availableOffline = input.availableOffline;
			return state;
		}
		case "ADD_FOLDER":
		case "UPDATE_FOLDER":
		case "REMOVE_FOLDER": return state;
		default: return state;
	}
};
const initialGlobalState = {
	name: "",
	icon: null
};
const initialLocalState = {
	sharingType: "private",
	availableOffline: false
};
const reactorDriveCreateState = (state) => {
	return {
		...defaultBaseState(),
		global: {
			...initialGlobalState,
			...state?.global
		},
		local: {
			...initialLocalState,
			...state?.local
		}
	};
};
const reactorDriveCreateDocument = (state) => {
	return baseCreateDocument(reactorDriveCreateState, state, REACTOR_DRIVE_DOCUMENT_TYPE);
};
const reactorDriveSaveToFileHandle = (document, input) => {
	return baseSaveToFileHandle(document, input);
};
const reactorDriveLoadFromInput = (input) => {
	return baseLoadFromInput(input, reactorDriveDocumentReducer);
};
const isReactorDriveState = (state) => {
	return typeof state === "object" && state !== null && "global" in state && "local" in state;
};
const assertIsReactorDriveState = (state) => {
	if (!isReactorDriveState(state)) throw new Error("Not a reactor-drive state");
};
const isReactorDriveDocument = (document) => {
	return typeof document === "object" && document !== null && "header" in document && document.header.documentType === "powerhouse/reactor-drive";
};
const assertIsReactorDriveDocument = (document) => {
	if (!isReactorDriveDocument(document)) throw new Error("Not a reactor-drive document");
};
const reactorDriveDocumentReducer = createReducer(reactorDriveStateReducer);
const reactorDriveDocumentGlobalState = {
	id: REACTOR_DRIVE_DOCUMENT_TYPE,
	name: "ReactorDrive",
	extension: REACTOR_DRIVE_FILE_EXTENSION,
	description: "",
	author: {
		name: "Powerhouse Inc",
		website: "https://www.powerhouse.inc/"
	},
	specifications: [{
		version: 1,
		changeLog: [],
		state: {
			global: {
				schema: "type ReactorDriveState {\n  name: String!\n  icon: String\n}",
				initialValue: JSON.stringify(JSON.stringify(initialGlobalState)),
				examples: []
			},
			local: {
				schema: "type ReactorDriveLocalState {\n  sharingType: String!\n  availableOffline: Boolean!\n}",
				initialValue: JSON.stringify(JSON.stringify(initialLocalState)),
				examples: []
			}
		},
		modules: [{
			id: "reactor-drive/base-operations",
			name: "base_operations",
			description: "",
			operations: [
				{
					id: "SET_DRIVE_NAME",
					name: "SET_DRIVE_NAME",
					description: "",
					schema: "input SetDriveNameInput { name: String! }",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "global"
				},
				{
					id: "SET_DRIVE_ICON",
					name: "SET_DRIVE_ICON",
					description: "",
					schema: "input SetDriveIconInput { icon: String }",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "global"
				},
				{
					id: "SET_SHARING_TYPE",
					name: "SET_SHARING_TYPE",
					description: "",
					schema: "input SetSharingTypeInput { sharingType: String! }",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "local"
				},
				{
					id: "SET_AVAILABLE_OFFLINE",
					name: "SET_AVAILABLE_OFFLINE",
					description: "",
					schema: "input SetAvailableOfflineInput { availableOffline: Boolean! }",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "local"
				},
				{
					id: "ADD_FOLDER",
					name: "ADD_FOLDER",
					description: "",
					schema: "input AddFolderInput { folderId: String! parentFolderId: String name: String! }",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "document"
				},
				{
					id: "UPDATE_FOLDER",
					name: "UPDATE_FOLDER",
					description: "",
					schema: "input UpdateFolderInput { folderId: String! name: String parentFolderId: String }",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "document"
				},
				{
					id: "REMOVE_FOLDER",
					name: "REMOVE_FOLDER",
					description: "",
					schema: "input RemoveFolderInput { folderId: String! }",
					template: "",
					reducer: "",
					errors: [],
					examples: [],
					scope: "document"
				}
			]
		}]
	}]
};
const reactorDriveDocumentModelModule = {
	actions: reactorDriveActions,
	reducer: reactorDriveDocumentReducer,
	documentModel: createState(defaultBaseState(), reactorDriveDocumentGlobalState),
	utils: {
		fileExtension: REACTOR_DRIVE_FILE_EXTENSION,
		createState: reactorDriveCreateState,
		createDocument: reactorDriveCreateDocument,
		loadFromInput: reactorDriveLoadFromInput,
		saveToFileHandle: reactorDriveSaveToFileHandle,
		isStateOfType: isReactorDriveState,
		assertIsStateOfType: assertIsReactorDriveState,
		isDocumentOfType: isReactorDriveDocument,
		assertIsDocumentOfType: assertIsReactorDriveDocument
	}
};
gql`
  enum ReactorDriveNodeKind {
    FILE
    FOLDER
  }

  input ReactorDrivePagingInput {
    cursor: String
    limit: Int
  }

  type ReactorDriveFileNode {
    id: ID!
    driveId: ID!
    name: String!
    parentFolder: ID
    documentType: String!
  }

  type ReactorDriveFolderNode {
    id: ID!
    driveId: ID!
    name: String!
    parentFolder: ID
    children(
      paging: ReactorDrivePagingInput
      kind: ReactorDriveNodeKind
    ): ReactorDriveNodePage!
  }

  union ReactorDriveNode = ReactorDriveFileNode | ReactorDriveFolderNode

  type ReactorDriveNodePage {
    results: [ReactorDriveNode!]!
    nextCursor: String
    hasMore: Boolean!
    totalCount: Int
  }

  type ReactorDrive {
    id: ID!
    name: String!
    icon: String
    sharingType: String!
    availableOffline: Boolean!
    rootNodes(
      paging: ReactorDrivePagingInput
      kind: ReactorDriveNodeKind
    ): ReactorDriveNodePage!
  }

  type Query {
    reactorDrive(id: ID!): ReactorDrive
    reactorDriveNode(driveId: ID!, id: ID!): ReactorDriveNode
    reactorDriveDescendants(driveId: ID!, root: ID!): [ReactorDriveNode!]!
  }
`;
//#endregion
export { __spreadArray as a, driveCollectionId as c, __rest as i, gql as n, SyncStatus as o, __assign as r, ModuleNotFoundError as s, reactorDriveDocumentModelModule as t };

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