'use client';

import { useRouter } from 'next/navigation';
import { LayoutGrid } from 'lucide-react';
import { IssueCardItem, CollapsibleDashboardCard } from '../components';
import type { TodayIssueItem, TodayIssueSettings } from '../types';

// 라벨 → 설정키 매핑
const LABEL_TO_SETTING_KEY: Record<string, keyof TodayIssueSettings> = {
  '수주': 'orders',
  '채권 추심': 'debtCollection',
  '안전 재고': 'safetyStock',
  '세금 신고': 'taxReport',
  '신규 업체 등록': 'newVendor',
  '연차': 'annualLeave',
  '차량': 'vehicle',
  '장비': 'equipment',
  // '발주': 'purchase',  // [2026-03-03] 비활성화 — transformer에서 필터링됨 (N4 참조)
  '결재 요청': 'approvalRequest',
};

interface StatusBoardSectionProps {
  items: TodayIssueItem[];
  itemSettings?: TodayIssueSettings;
}

export function StatusBoardSection({ items, itemSettings }: StatusBoardSectionProps) {
  const router = useRouter();

  const handleItemClick = (path: string) => {
    if (!path) return;
    router.push(path);
  };

  // 설정에 따라 항목 필터링
  const filteredItems = itemSettings
    ? items.filter((item) => {
        const settingKey = LABEL_TO_SETTING_KEY[item.label];
        return settingKey ? itemSettings[settingKey] : true;
      })
    : items;

  return (
    <CollapsibleDashboardCard
      icon={<LayoutGrid 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-3">
          {filteredItems.map((item) => (
            <IssueCardItem
              key={item.id}
              label={item.label}
              count={item.count}
              subLabel={item.subLabel}
              isHighlighted={item.isHighlighted}
              onClick={() => handleItemClick(item.path)}
            />
          ))}
        </div>
    </CollapsibleDashboardCard>
  );
}
