'use client'

import PropTypes from 'prop-types'
import {createTheme, ThemeProvider} from '@mui/material/styles'
import InitColorSchemeScript from '@mui/material/InitColorSchemeScript'
import CssBaseline from '@mui/material/CssBaseline'

import {grey, green, yellow} from '@mui/material/colors'

import '@fontsource/roboto/300.css'
import '@fontsource/roboto/400.css'
import '@fontsource/roboto/500.css'
import '@fontsource/roboto/700.css'
import '../styles/nprogress.css'

import ChanjeTem from '../components/chanje-tem'
import NextAppDirEmotionCacheProvider from './emotion-cache-provider'

const theme = createTheme({
  cssVariables: {
    colorSchemeSelector: 'class'
  },
  colorSchemes: {
    light: {
      palette: {
        primary: green,
        secondary: {
          main: green[50]
        },
        divider: green[200],
        info: {
          main: grey[900]
        },
        text: {
          primary: grey[900],
          secondary: grey[800],
        },
      }
    },
    dark: {
      palette: {
        primary: {
          main: yellow[500],
          contrastText: '#000'
        },
        secondary: {
          main: yellow[500]
        },
        info: {
          main: '#fff'
        },
        divider: green[700],
        background: {
          default: '#082211',
          paper: '#082211'
        },
        text: {
          primary: '#fff',
          secondary: grey[100]
        }
      }
    }
  }
})

export default function ThemeRegistry(props) {
  const {children} = props

  return (
    <>
      <InitColorSchemeScript attribute='class' />
      <NextAppDirEmotionCacheProvider options={{key: 'mui'}}>
        <ThemeProvider theme={theme}>
          <CssBaseline enableColorScheme />
          <ChanjeTem />
          {children}
        </ThemeProvider>
      </NextAppDirEmotionCacheProvider>
    </>
  )
}

ThemeRegistry.propTypes = {
  children: PropTypes.node.isRequired
}
