/**
 * 기본 데스크톱 목록 템플릿
 * 
 * 품목관리 화면을 기반으로 한 재사용 가능한 데스크톱 목록 템플릿입니다.
 * - PageLayout
 * - PageHeader  
 * - StatCards (통계 카드)
 * - SearchFilter (검색/필터)
 * - DataTable (데이터 테이블)
 * - Pagination (페이지네이션)
 */

import { ReactNode } from "react";
import { LucideIcon } from "lucide-react";
import { PageLayout } from "../organisms/PageLayout";
import { PageHeader } from "../organisms/PageHeader";
import { StatCards, StatCardProps } from "../organisms/StatCards";
import { SearchFilter } from "../organisms/SearchFilter";
import { DataTable, Column } from "../organisms/DataTable";
import { Card, CardContent, CardHeader, CardTitle } from "../ui/card";

export interface BasicDesktopListTemplateProps<T> {
  // 페이지 헤더
  title: string;
  description?: string;
  icon?: LucideIcon;
  headerActions?: ReactNode;
  
  // 통계 카드
  stats?: StatCardProps[];
  
  // 검색 및 필터
  searchValue?: string;
  onSearchChange?: (value: string) => void;
  searchPlaceholder?: string;
  extraFilters?: ReactNode;
  
  // 데이터 테이블
  columns: Column<T>[];
  data: T[];
  keyField: keyof T;
  onRowClick?: (row: T) => void;
  
  // 카드 제목
  cardTitle?: string;
  
  // 페이지네이션
  pagination?: {
    currentPage: number;
    totalPages: number;
    onPageChange: (page: number) => void;
    showInfo?: boolean;
  };
  
  // 테이블 옵션
  striped?: boolean;
  hoverable?: boolean;
  emptyMessage?: string;
  
  // 레이아웃
  maxWidth?: "sm" | "md" | "lg" | "xl" | "full";
}

export function BasicDesktopListTemplate<T>({
  title,
  description,
  icon,
  headerActions,
  stats,
  searchValue,
  onSearchChange,
  searchPlaceholder = "검색...",
  extraFilters,
  columns,
  data,
  keyField,
  onRowClick,
  cardTitle,
  pagination,
  striped = true,
  hoverable = true,
  emptyMessage = "데이터가 없습니다",
  maxWidth = "full",
}: BasicDesktopListTemplateProps<T>) {
  return (
    <PageLayout maxWidth={maxWidth}>
      {/* 페이지 헤더 */}
      <PageHeader
        title={title}
        description={description}
        icon={icon}
        actions={headerActions}
      />

      {/* 통계 카드 */}
      {stats && stats.length > 0 && <StatCards stats={stats} />}

      {/* 검색 및 필터 */}
      {(onSearchChange || extraFilters) && (
        <Card>
          <CardContent className="p-4 md:p-6">
            <SearchFilter
              searchValue={searchValue || ""}
              onSearchChange={onSearchChange || (() => {})}
              searchPlaceholder={searchPlaceholder}
              filterButton={false}
              extraActions={extraFilters}
            />
          </CardContent>
        </Card>
      )}

      {/* 데이터 테이블 */}
      <Card>
        {cardTitle && (
          <CardHeader>
            <CardTitle className="text-sm md:text-base">{cardTitle}</CardTitle>
          </CardHeader>
        )}
        <CardContent>
          <DataTable
            columns={columns}
            data={data}
            keyField={keyField as string}
            onRowClick={onRowClick}
            pagination={pagination}
            striped={striped}
            hoverable={hoverable}
            emptyMessage={emptyMessage}
          />
        </CardContent>
      </Card>
    </PageLayout>
  );
}
