'use client';

import { useSearchParams } from 'next/navigation';
import { CardManagement } from '@/components/hr/CardManagement';
import { IntegratedDetailTemplate } from '@/components/templates/IntegratedDetailTemplate';
import { cardConfig } from '@/components/hr/CardManagement/cardConfig';
import { createCard } from '@/components/hr/CardManagement/actions';
import type { CardFormData } from '@/components/hr/CardManagement/types';

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

  // mode=new일 때 등록 화면 표시
  if (mode === 'new') {
    const handleSubmit = async (data: Record<string, unknown>) => {
      const result = await createCard(data as CardFormData);
      return { success: result.success, error: result.error };
    };

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

  return <CardManagement />;
}
