'use client';

import { useRouter } from 'next/navigation';
import { Gavel, FileWarning, AlertCircle, Scale } from 'lucide-react';
import { AmountCardItem, CheckPointItem, CollapsibleDashboardCard, type SectionColorTheme } from '../components';
import type { DebtCollectionData } from '../types';

// 카드별 아이콘 매핑
const CARD_ICONS = [Scale, FileWarning, AlertCircle, Gavel];
const CARD_THEMES: SectionColorTheme[] = ['red', 'orange', 'amber', 'purple'];

interface DebtCollectionSectionProps {
  data: DebtCollectionData;
}

export function DebtCollectionSection({ data }: DebtCollectionSectionProps) {
  const router = useRouter();

  const handleClick = () => {
    if (data.detailButtonPath) {
      router.push(data.detailButtonPath);
    }
  };

  return (
    <CollapsibleDashboardCard
      icon={<Gavel style={{ color: '#ffffff' }} className="h-5 w-5" />}
      title="채권추심 현황"
      subtitle="채권추심 관리 현황"
    >
      <div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-4 mb-4">
        {data.cards.map((card, idx) => (
          <AmountCardItem
            key={card.id}
            card={card}
            onClick={data.detailButtonPath ? handleClick : undefined}
            icon={CARD_ICONS[idx] || Gavel}
            colorTheme={CARD_THEMES[idx] || 'red'}
            showTrend={!!card.previousLabel}
            trendValue={card.previousLabel}
            trendDirection="down"
            subLabelAsBadge
          />
        ))}
      </div>

      {data.checkPoints.length > 0 && (
        <div className="border-t pt-4 space-y-1">
          {data.checkPoints.map((cp) => (
            <CheckPointItem key={cp.id} checkpoint={cp} />
          ))}
        </div>
      )}
    </CollapsibleDashboardCard>
  );
}
