'use client';

import { useSearchParams } from 'next/navigation';
import { AccountManagement } from '@/components/settings/AccountManagement';
import { IntegratedDetailTemplate } from '@/components/templates/IntegratedDetailTemplate';
import { accountConfig } from '@/components/settings/AccountManagement/accountConfig';
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: Record<string, unknown>) => {
      const result = await createBankAccount(data as AccountFormData);
      return { success: result.success, error: result.error };
    };

    return (
      <IntegratedDetailTemplate
        config={accountConfig}
        mode="create"
        onSubmit={handleSubmit}
      />
    );
  }

  return <AccountManagement />;
}
