import { ThemeOptions , createTheme , Theme } from '@material-ui/core/styles' ; import useTheme from '@material-ui/core/styles/useTheme' ; import { IThemeWeb , themes } from '../../Themes' ; const parserToString = ( theme ) => Object . entries ( theme ) . sort ( ) . toString ( ) ; const isEqual = ( providedTheme , defaultTheme ) => parserToString ( providedTheme ) === parserToString ( defaultTheme ) ; export const getDefaultTheme = ( providerTheme ) => { const parsedProviderTheme = JSON . parse ( JSON . stringify ( providerTheme ) ) ; const parsedDefaultTheme = JSON . parse ( JSON . stringify ( createTheme ( { } ) ) ) ; if ( isEqual ( parsedProviderTheme , parsedDefaultTheme ) ) { return createTheme ( themes . natura . light as ThemeOptions ) ; } return providerTheme as Theme ; } ; export const useDefaultTheme = ( ) => { const providerTheme = useTheme ( ) ; return getDefaultTheme ( providerTheme ) ; } ; export default useDefaultTheme ;