import { NostrLoginProvider } from "@nostrify/react/login";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { createHead, UnheadProvider } from "@unhead/react/client";
import { BrowserRouter } from "react-router-dom";
import { AppProvider } from "@/components/AppProvider";
import NostrProvider from "@/components/NostrProvider";
import type { AppConfig } from "@/contexts/AppContext";

interface TestAppProps {
  children: React.ReactNode;
}

export function TestApp({ children }: TestAppProps) {
  const head = createHead();

  const queryClient = new QueryClient({
    defaultOptions: {
      queries: { retry: false },
      mutations: { retry: false },
    },
  });

  const defaultConfig: AppConfig = {
    appName: "Eranos",
    appId: "eranos",
    homePage: "feed",
    theme: "light",
    useAppRelays: true,
    useUserRelays: false,
    relayMetadata: {
      relays: [{ url: "wss://relay.primal.net", read: true, write: true }],
      updatedAt: 0,
    },
    feedSettings: {
      feedIncludePosts: true,
      feedIncludeComments: true,
      feedIncludeReposts: true,
      feedIncludeGenericReposts: true,
      feedIncludeReactions: false,
      feedIncludeArticles: false,
      showArticles: false,
      showHighlights: false,
      feedIncludeHighlights: false,
      showEvents: false,
      feedIncludeEvents: false,
      showVines: true,
      showPolls: false,
      showTreasures: false,
      showTreasureGeocaches: true,
      showTreasureFoundLogs: true,
      showColors: false,
      showPeopleLists: true,
      feedIncludeVines: false,
      feedIncludePolls: false,
      feedIncludeTreasureGeocaches: false,
      feedIncludeTreasureFoundLogs: false,
      feedIncludeColors: false,
      feedIncludePeopleLists: false,
      showDecks: false,
      feedIncludeDecks: false,
      feedIncludeVoiceMessages: false,
      showCustomEmojis: true,
      showEmojiPacks: false,
      feedIncludeEmojiPacks: false,
      showPhotos: true,
      feedIncludePhotos: true,
      showVideos: true,
      feedIncludeNormalVideos: true,
      feedIncludeShortVideos: true,
      showUserStatuses: true,
      showMusic: false,
      feedIncludeMusicTracks: false,
      feedIncludeMusicPlaylists: false,
      showPodcasts: false,
      feedIncludePodcastEpisodes: false,
      feedIncludePodcastTrailers: false,
      showDevelopment: false,
      feedIncludeDevelopment: false,
      showCommunities: false,
      feedIncludeCommunities: false,
      showBadges: false,
      showBadgeDefinitions: true,
      showProfileBadges: true,
      showBadgeAwards: true,
      feedIncludeBadgeDefinitions: false,
      feedIncludeProfileBadges: false,
      feedIncludeBadgeAwards: false,
      feedIncludeVanish: true,
      showBirdstar: false,
      feedIncludeBirdDetections: false,
      feedIncludeBirdex: false,
      feedIncludeConstellations: false,
      followsFeedShowReplies: true,
    },
    sidebarOrder: [],
    nip85StatsPubkey:
      "5f68e85ee174102ca8978eef302129f081f03456c884185d5ec1c1224ab633ea",
    blossomServerMetadata: {
      servers: [],
      updatedAt: 0,
    },
    useAppBlossomServers: true,
    faviconUrl: "https://ditto.pub/api/favicon/{hostname}",
    linkPreviewUrl: "https://ditto.pub/api/link-preview/{url}",
    corsProxy: "https://proxy.shakespeare.diy/?url={href}",
    contentWarningPolicy: "blur",
    sentryDsn: "",
    sentryEnabled: false,
    plausibleDomain: "",
    plausibleEndpoint: "",
    savedFeeds: [],
    autoplayVideos: false,
    imageQuality: 'compressed',
    imageProxy: '',
    lowBandwidthMode: false,
    torEnabled: false,
    sidebarWidgets: [],
    aiBaseURL: 'https://ai.shakespeare.diy/v1',
    aiApiKey: '',
    aiModel: 'google/gemma-4-26b',
    aiSystemPrompt: '',
    translateWorkerUrl: '',
  };

  return (
    <UnheadProvider head={head}>
      <AppProvider storageKey="test-app-config" defaultConfig={defaultConfig}>
        <QueryClientProvider client={queryClient}>
          <NostrLoginProvider storageKey="test-login">
            <NostrProvider>
              <BrowserRouter>{children}</BrowserRouter>
            </NostrProvider>
          </NostrLoginProvider>
        </QueryClientProvider>
      </AppProvider>
    </UnheadProvider>
  );
}

export default TestApp;
