'use client';

import { useSearchParams } from 'next/navigation';
import { AccountManagement } from '@/components/settings/AccountManagement';
import { AccountDetailForm } from '@/components/settings/AccountManagement/AccountDetailForm';
import { createBankAccount } from '@/components/settings/AccountManagement/actions';
import type { AccountFormData } from '@/components/settings/AccountManagement/types';

export default function AccountsPage() {
  const searchParams = useSearchParams();
  const mode = searchParams.get('mode');

  if (mode === 'new') {
    const handleSubmit = async (data: AccountFormData) => {
      const result = await createBankAccount(data);
      return { success: result.success, error: result.error };
    };

    return <AccountDetailForm mode="create" onSubmit={handleSubmit} />;
  }

  return <AccountManagement />;
}
