import type { ReactNode } from "react";
import type { Adapters } from "../contexts/adapter-context.js";
import { AdapterProvider } from "../contexts/adapter-context.js";
import {
	BestiaryProvider,
	BulkImportProvider,
	EncounterProvider,
	InitiativeRollsProvider,
	PlayerCharactersProvider,
	RulesEditionProvider,
	SidePanelProvider,
	ThemeProvider,
} from "../contexts/index.js";
import { createTestAdapters } from "./adapters/in-memory-adapters.js";

export function AllProviders({
	adapters,
	children,
}: {
	adapters?: Adapters;
	children: ReactNode;
}) {
	const resolved = adapters ?? createTestAdapters();
	return (
		<AdapterProvider adapters={resolved}>
			<ThemeProvider>
				<RulesEditionProvider>
					<EncounterProvider>
						<BestiaryProvider>
							<PlayerCharactersProvider>
								<BulkImportProvider>
									<SidePanelProvider>
										<InitiativeRollsProvider>
											{children}
										</InitiativeRollsProvider>
									</SidePanelProvider>
								</BulkImportProvider>
							</PlayerCharactersProvider>
						</BestiaryProvider>
					</EncounterProvider>
				</RulesEditionProvider>
			</ThemeProvider>
		</AdapterProvider>
	);
}
