import { createStoreCollections, extendedCollectionDataFactory } from "./collections.js";
import { createStoreCookies } from "./cookies.js";
import { createStoreEnvironments, extendedEnvironmentDataFactory } from "./environment.js";
import { createStoreEvents } from "./events.js";
import { importSpecFileFactory } from "./import-spec.js";
import { createStoreRequestExamples, extendedExampleDataFactory } from "./request-example.js";
import { createStoreRequests, extendedRequestDataFactory } from "./requests.js";
import { createStoreSecuritySchemes, extendedSecurityDataFactory } from "./security-schemes.js";
import { createStoreServers, extendedServerDataFactory } from "./servers.js";
import { createStoreTags, extendedTagDataFactory } from "./tags.js";
import { createStoreWorkspaces, extendedWorkspaceDataFactory } from "./workspace.js";
import { inject, reactive, ref, toRaw } from "vue";
import { useModal } from "@scalar/components";
//#region src/store/store.ts
/**
* Factory function for creating the centralized store for the API client.
*
* This store manages all data and state for the application.
* It should be instantiated once and injected into the app's root component.
*/
var createWorkspaceStore = ({ useLocalStorage = true, showSidebar = true, proxyUrl, theme, hideClientButton = false, _integration }) => {
	const { collections, collectionMutators } = createStoreCollections(useLocalStorage);
	const { tags, tagMutators } = createStoreTags(useLocalStorage);
	const { requests, requestMutators } = createStoreRequests(useLocalStorage);
	const { requestExamples, requestExampleMutators } = createStoreRequestExamples(useLocalStorage);
	const { cookies, cookieMutators } = createStoreCookies(useLocalStorage);
	const { environments, environmentMutators } = createStoreEnvironments(useLocalStorage);
	const { servers, serverMutators } = createStoreServers(useLocalStorage);
	const { securitySchemes, securitySchemeMutators } = createStoreSecuritySchemes(useLocalStorage);
	const { workspaces, workspaceMutators } = createStoreWorkspaces(useLocalStorage);
	const storeContext = {
		collections,
		collectionMutators,
		tags,
		tagMutators,
		requests,
		requestMutators,
		requestExamples,
		requestExampleMutators,
		cookies,
		cookieMutators,
		environments,
		environmentMutators,
		servers,
		serverMutators,
		securitySchemes,
		securitySchemeMutators,
		workspaces,
		workspaceMutators
	};
	const { addTag, deleteTag } = extendedTagDataFactory(storeContext);
	const { addRequest, deleteRequest, findRequestParents } = extendedRequestDataFactory(storeContext, addTag);
	const { deleteEnvironment } = extendedEnvironmentDataFactory(storeContext);
	const { addServer, deleteServer } = extendedServerDataFactory(storeContext);
	const { addCollection, deleteCollection } = extendedCollectionDataFactory(storeContext);
	const { addRequestExample, deleteRequestExample } = extendedExampleDataFactory(storeContext);
	const { addWorkspace, deleteWorkspace } = extendedWorkspaceDataFactory(storeContext);
	const { addSecurityScheme, deleteSecurityScheme } = extendedSecurityDataFactory(storeContext);
	const { addCollectionEnvironment, removeCollectionEnvironment } = extendedCollectionDataFactory(storeContext);
	/** Running request history list */
	const requestHistory = reactive([]);
	const { importSpecFile, importSpecFromUrl } = importSpecFileFactory(storeContext);
	/** Helper function to manage the sidebar width */
	const sidebarWidth = ref((useLocalStorage ? localStorage?.getItem("sidebarWidth") : void 0) || "280px");
	const setSidebarWidth = (width) => {
		sidebarWidth.value = width;
		if (useLocalStorage) localStorage?.setItem("sidebarWidth", width);
	};
	/** This state is to be used by the API Client Modal component to control the modal */
	const modalState = useModal();
	Object.values(workspaces).forEach(({ uid }) => {
		if (proxyUrl) workspaceMutators.edit(uid, "proxyUrl", proxyUrl);
		if (theme) workspaceMutators.edit(uid, "themeId", theme);
	});
	/**
	* For debugging purposes, expose this method for dumping the data stores
	*/
	if (typeof window !== "undefined") window.dataDump = () => ({
		collections: toRaw(collections),
		cookies: toRaw(cookies),
		environments: toRaw(environments),
		requestExamples: toRaw(requestExamples),
		requests: toRaw(requests),
		securitySchemes: toRaw(securitySchemes),
		servers: toRaw(servers),
		tags: toRaw(tags),
		workspaces: toRaw(workspaces)
	});
	return {
		workspaces,
		collections,
		tags,
		cookies,
		environments,
		requestExamples,
		requests,
		servers,
		securitySchemes,
		modalState,
		events: createStoreEvents(),
		sidebarWidth,
		setSidebarWidth,
		proxyUrl,
		hideClientButton,
		showSidebar,
		integration: _integration,
		importSpecFile,
		importSpecFromUrl,
		cookieMutators,
		collectionMutators: {
			...collectionMutators,
			rawAdd: collectionMutators.add,
			add: addCollection,
			delete: deleteCollection,
			addEnvironment: addCollectionEnvironment,
			removeEnvironment: removeCollectionEnvironment
		},
		environmentMutators: {
			...environmentMutators,
			delete: deleteEnvironment
		},
		requestMutators: {
			...requestMutators,
			rawAdd: requestMutators.add,
			add: addRequest,
			delete: deleteRequest
		},
		findRequestParents,
		requestExampleMutators: {
			...requestExampleMutators,
			rawAdd: requestExampleMutators.add,
			add: addRequestExample,
			delete: deleteRequestExample
		},
		requestHistory,
		securitySchemeMutators: {
			...securitySchemeMutators,
			rawAdd: securitySchemeMutators.add,
			add: addSecurityScheme,
			delete: deleteSecurityScheme
		},
		serverMutators: {
			...serverMutators,
			rawAdd: serverMutators.add,
			add: addServer,
			delete: deleteServer
		},
		tagMutators: {
			...tagMutators,
			rawAdd: tagMutators.add,
			add: addTag,
			delete: deleteTag
		},
		workspaceMutators: {
			...workspaceMutators,
			rawAdd: workspaceMutators.add,
			add: addWorkspace,
			delete: deleteWorkspace
		},
		addCollectionEnvironment,
		removeCollectionEnvironment
	};
};
/** Set as a string so that different instances of api-client can reference inject the same store */
var WORKSPACE_SYMBOL = "WORKSPACE_SYMBOL";
/**
* Global hook which contains the store for the whole app
*
* The rawAdd methods are the mutator.add methods. Some add methods have been replaced when we need some side effects
* ex: add examples when adding a request
*/
var useWorkspace = () => {
	const store = inject(WORKSPACE_SYMBOL);
	if (!store) throw new Error("Workspace store not provided");
	return store;
};
//#endregion
export { WORKSPACE_SYMBOL, createWorkspaceStore, useWorkspace };

//# sourceMappingURL=store.js.map