import React from 'react';
import { TamaguiProvider, Theme } from '@tamagui/core';
import { RouterProvider } from 'react-router-dom';
import tamaguiConfig from '../../../tamagui.config';
import { router } from './router';
import { ConsentProvider } from '@/contexts/consent';
import { AppearanceProvider } from '@/hooks/use-appearance';
import { useAppearance } from '@/hooks/use-appearance';

export default function App() {
  return (
    <TamaguiProvider config={tamaguiConfig} defaultTheme="guestLight" themeClassNameOnRoot>
      <AppearanceProvider>
        <ConsentProvider>
          <AppThemeRouter />
        </ConsentProvider>
      </AppearanceProvider>
    </TamaguiProvider>
  );
}

function AppThemeRouter() {
  const { resolved } = useAppearance();
  const themeName = resolved === 'dark' ? 'guestNight' : 'guestLight';

  return (
    <Theme name={themeName}>
      <RouterProvider router={router} />
    </Theme>
  );
}
