'use client' import { useSearchParams, useRouter } from 'next/navigation' import { useEffect, useState, useMemo } from 'react' import { RequireAuth } from '@/components/auth/RequireAuth' import { ProfileCard } from '@/components/profile/ProfileCard' import { ProfileSettings } from '@/components/profile/ProfileSettings' import { Header } from '@/components/header' import { Footer } from '@/components/footer' function ProfileContent() { const searchParams = useSearchParams() const router = useRouter() const [activeTab, setActiveTab] = useState('profile') const [paymentResult, setPaymentResult] = useState<{ type: 'success' | 'failed' message: string amount?: string txn?: string paymentType?: string } | null>(null) const validTabs = useMemo(() => ['profile', 'balance', 'billing', 'services', 'security', 'danger'], []) useEffect(() => { const tab = searchParams.get('tab') if (tab && validTabs.includes(tab)) { setActiveTab(tab) } else if (tab && !validTabs.includes(tab)) { // Handle invalid tab parameter by redirecting to default const params = new URLSearchParams(searchParams.toString()) params.delete('tab') router.replace(`/profile${params.toString() ? `?${params.toString()}` : ''}`) } // Handle payment result notifications const payment = searchParams.get('payment') const paymentType = searchParams.get('type') const amount = searchParams.get('amount') const txn = searchParams.get('txn') const reason = searchParams.get('reason') const message = searchParams.get('message') if (payment === 'success') { setPaymentResult({ type: 'success', message: paymentType === 'balance' ? `Balance successfully added! ₹${amount ? parseFloat(amount).toLocaleString('en-IN') : '0'} has been credited to your account.` : `Payment successful! Your service payment has been processed.`, amount, txn, paymentType }) // If it's balance addition, switch to balance tab if (paymentType === 'balance') { setActiveTab('balance') } } else if (payment === 'failed') { const failureMessages: Record = { 'insufficient-funds': 'Payment failed due to insufficient funds.', 'card-declined': 'Your card was declined. Please try a different payment method.', 'timeout': 'Payment timed out. Please try again.', 'user-cancelled': 'Payment was cancelled.', 'invalid-details': 'Invalid payment details. Please check and try again.', 'unknown': 'Payment failed due to an unexpected error.' } setPaymentResult({ type: 'failed', message: message ? decodeURIComponent(message) : (failureMessages[reason || 'unknown'] || 'Payment failed. Please try again.'), amount, txn, paymentType }) } // Clean up URL parameters after handling payment result if (payment) { setTimeout(() => { const params = new URLSearchParams(searchParams.toString()) params.delete('payment') params.delete('type') params.delete('amount') params.delete('txn') params.delete('reason') params.delete('message') params.delete('warning') const queryString = params.toString() router.replace(`/profile${queryString ? `?${queryString}` : ''}`, { scroll: false }) }, 100) // Small delay to ensure state is set } }, [searchParams, router, validTabs]) const handleTabChange = (tab: string) => { if (!validTabs.includes(tab)) return setActiveTab(tab) const params = new URLSearchParams(searchParams.toString()) if (tab === 'profile') { // Remove tab parameter for default tab to keep URLs clean params.delete('tab') } else { params.set('tab', tab) } const queryString = params.toString() router.push(`/profile${queryString ? `?${queryString}` : ''}`) } return (

Profile

Manage your account settings and preferences

{/* Payment Result Notification */} {paymentResult && (
{paymentResult.type === 'success' ? ( ) : ( )}

{paymentResult.message}

{paymentResult.txn && (

Transaction ID: {paymentResult.txn}

)}
)}
) } export default function ProfilePage() { return (
) }