import { unpackProxyObject } from "@scalar/workspace-store/helpers/unpack-proxy";
//#region src/v2/features/modal/helpers/restore-workspace-state.ts
/**
* Restores the state of a workspace document by reverting its state
* to the specified import, while preserving certain live properties
* such as servers, security schemes, and selected server.
*/
var restoreWorkspaceState = ({ workspaceStore, workspaceState, name }) => {
	if (!workspaceStore) return {
		ok: false,
		error: "Workspace store is not available"
	};
	const currentDocument = unpackProxyObject(workspaceStore.workspace.documents[name]);
	if (!currentDocument) return {
		ok: false,
		error: "Current document not found in workspace store"
	};
	const importingDocument = workspaceState.documents[name];
	if (!importingDocument) return {
		ok: false,
		error: "Importing document not found in workspace state"
	};
	const persistedProperties = {
		selectedServer: currentDocument["x-scalar-selected-server"],
		securitySchemes: currentDocument.components?.securitySchemes,
		servers: currentDocument.servers
	};
	workspaceStore.loadWorkspace({
		meta: {},
		documents: { [name]: importingDocument },
		intermediateDocuments: {},
		originalDocuments: {},
		overrides: {},
		history: {},
		auth: {}
	});
	const newDocument = unpackProxyObject(workspaceStore.workspace.documents[name]);
	if (!newDocument) return {
		ok: false,
		error: "New document not found in workspace store"
	};
	newDocument["x-scalar-selected-server"] = persistedProperties.selectedServer;
	newDocument.servers = persistedProperties.servers;
	newDocument.components ??= {};
	newDocument.components.securitySchemes = persistedProperties.securitySchemes;
	return { ok: true };
};
//#endregion
export { restoreWorkspaceState };

//# sourceMappingURL=restore-workspace-state.js.map