/**
 * 품목 목록 페이지 (Server Component)
 *
 * Next.js 15 App Router
 * 서버에서 데이터 fetching 후 Client Component로 전달
 */

import { Suspense } from 'react';
import ItemListClient from '@/components/items/ItemListClient';
import type { ItemMaster } from '@/types/item';

// Mock 데이터 (API 연동 전 임시)
const mockItems: ItemMaster[] = [
  {
    id: '1',
    itemCode: 'KD-FG-001',
    itemName: '스크린 제품 A',
    itemType: 'FG',
    unit: 'EA',
    specification: '2000x2000',
    isActive: true,
    category1: '본체부품',
    category2: '가이드시스템',
    salesPrice: 150000,
    purchasePrice: 100000,
    productCategory: 'SCREEN',
    lotAbbreviation: 'KD',
    currentRevision: 0,
    isFinal: false,
    createdAt: '2025-01-10T00:00:00Z',
  },
  {
    id: '2',
    itemCode: 'KD-PT-001',
    itemName: '가이드레일(벽면형)',
    itemType: 'PT',
    unit: 'EA',
    specification: '2438mm',
    isActive: true,
    category1: '본체부품',
    category2: '가이드시스템',
    category3: '가이드레일',
    salesPrice: 50000,
    purchasePrice: 35000,
    partType: 'ASSEMBLY',
    partUsage: 'GUIDE_RAIL',
    installationType: '벽면형',
    assemblyType: 'M',
    assemblyLength: '2438',
    currentRevision: 0,
    isFinal: false,
    createdAt: '2025-01-10T00:00:00Z',
  },
  {
    id: '3',
    itemCode: 'KD-PT-002',
    itemName: '절곡품 샘플',
    itemType: 'PT',
    unit: 'EA',
    specification: 'EGI 1.55T',
    isActive: true,
    partType: 'BENDING',
    material: 'EGI 1.55T',
    length: '2000',
    salesPrice: 30000,
    currentRevision: 0,
    isFinal: false,
    createdAt: '2025-01-10T00:00:00Z',
  },
  {
    id: '4',
    itemCode: 'KD-RM-001',
    itemName: 'SPHC-SD',
    itemType: 'RM',
    unit: 'KG',
    specification: '1.6T x 1219 x 2438',
    isActive: true,
    category1: '철강재',
    purchasePrice: 1500,
    material: 'SPHC-SD',
    currentRevision: 0,
    isFinal: false,
    createdAt: '2025-01-10T00:00:00Z',
  },
  {
    id: '5',
    itemCode: 'KD-SM-001',
    itemName: '볼트 M6x20',
    itemType: 'SM',
    unit: 'EA',
    specification: 'M6x20',
    isActive: true,
    category1: '구조재/부속품',
    category2: '볼트/너트',
    purchasePrice: 50,
    currentRevision: 0,
    isFinal: false,
    createdAt: '2025-01-10T00:00:00Z',
  },
  {
    id: '6',
    itemCode: 'KD-CS-001',
    itemName: '절삭유',
    itemType: 'CS',
    unit: 'L',
    specification: '20L',
    isActive: true,
    purchasePrice: 30000,
    currentRevision: 0,
    isFinal: false,
    createdAt: '2025-01-10T00:00:00Z',
  },
  {
    id: '7',
    itemCode: 'KD-FG-002',
    itemName: '철재 제품 B',
    itemType: 'FG',
    unit: 'SET',
    specification: '3000x2500',
    isActive: false,
    category1: '본체부품',
    salesPrice: 200000,
    productCategory: 'STEEL',
    lotAbbreviation: 'KD',
    currentRevision: 0,
    isFinal: false,
    createdAt: '2025-01-09T00:00:00Z',
  },
];

/**
 * 품목 목록 조회 함수
 * TODO: API 연동 시 fetchItems()로 교체
 */
async function getItems(): Promise<ItemMaster[]> {
  // API 연동 전 mock 데이터 반환
  // const items = await fetchItems();
  return mockItems;
}

/**
 * 품목 목록 페이지
 */
export default async function ItemsPage() {
  const items = await getItems();

  return (
    <Suspense fallback={<div className="text-center py-8">로딩 중...</div>}>
      <ItemListClient />
    </Suspense>
  );
}

/**
 * 메타데이터 설정
 */
export const metadata = {
  title: '품목 관리',
  description: '품목 목록 조회 및 관리',
};