'use client';

import { PrivyProvider } from '@privy-io/react-auth';
import { ReactNode , useEffect  } from 'react';

export function Providers({ children }: { children: ReactNode }) {
  useEffect(() => {
    localStorage.removeItem('privy:embedded-wallet:iframe-ready');
    localStorage.removeItem('privy:embedded-wallet:ready');
  }, []);

  return (
    <PrivyProvider 
        appId={process.env.NEXT_PUBLIC_PRIVY_APP_ID || ''}
        config={{
        "appearance": {
          "accentColor": "#6A6FF5",
          "theme":"#FFFFFF",
          "showWalletLoginFirst": false,
          "logo": "https://auth.privy.io/logos/privy-logo.png",
          "walletChainType": 'ethereum-only',
          "walletList": ['metamask', 'wallet_connect', 'coinbase_wallet', 'rabby_wallet', 'cryptocom','safe']
        },
        "loginMethods": [
          "email",
          "wallet"
        ],
        "embeddedWallets": {
          "createOnLogin": "all-users",
          "requireUserPasswordOnCreate": false,
          "showWalletUIs": true
        },
        "mfa": {
          "noPromptOnMfaRequired": false
        },
        "networkConfigs": {
          defaultNetwork: 56,
          supportedNetworks: [
            {
              chainId: 56,
              name: 'BNB Smart Chain',
              rpcUrl: 'https://bsc-dataseed.binance.org/',
              blockExplorerUrl: 'https://bscscan.com'
            }
          ]
        }
      }}
      >
        {children}
      </PrivyProvider>
  );
}