'use client';

import { Toaster } from 'react-hot-toast';
import { usePathname } from 'next/navigation';

export default function Providers({ children }: { children: React.ReactNode }) {

  const pathname = usePathname();
  const locale = pathname?.split('/')?.[1] || 'ar';
  const isRTL = locale === 'ar';

  return (
    <>
      {children}
      <Toaster
        position={isRTL ? 'top-right' : 'top-left'}
        toastOptions={{
          style: {
            zIndex: 999999,
            borderRadius: '10px',
            fontSize: '14px',
            fontWeight: 500,
            padding: '12px 16px',
            boxShadow: '0 4px 20px rgba(0, 0, 0, 0.12)',
            direction: isRTL ? 'rtl' : 'ltr',
          },
          success: {
            duration: 3000,
            style: {
              background: '#065f46',
              color: '#fff',
            },
            iconTheme: {
              primary: '#34d399',
              secondary: '#fff',
            },
          },
          error: {
            duration: 4500,
            style: {
              background: '#9f1239',
              color: '#fff',
            },
            iconTheme: {
              primary: '#fda4af',
              secondary: '#fff',
            },
          },
        }}
      />
    </>
  );
}
