"use client";

import ReportEngine, { ReportConfig } from "@/components/admin/report/ReportEngine";

const config: ReportConfig = {
  key: "sales_report_v2",
  title: "영업 리포트",
  description: "다중 조건 비교 분석",
  apiEndpoint: "/sales-report/data",
  metrics: [
    { id: "orderAmt", name: "수주금액", unit: "원", color: "#3b82f6" },
    { id: "orderQty", name: "수주수량", unit: "EA", color: "#10b981" },
    { id: "shipQty", name: "출하수량", unit: "EA", color: "#ef4444" },
    { id: "unitPrice", name: "단가", unit: "원", color: "#8b5cf6" },
    { id: "orderCount", name: "수주건수", unit: "건", color: "#f59e0b" },
  ],
  groupByOptions: [
    { id: "customer", name: "거래처별" },
    { id: "item", name: "품목별" },
    { id: "status", name: "상태별" },
    { id: "monthly", name: "월별" },
    { id: "quarterly", name: "분기별" },
    { id: "weekly", name: "주별" },
    { id: "daily", name: "일별" },
  ],
  defaultGroupBy: "customer",
  defaultMetrics: ["orderAmt"],
  thresholds: [
    { id: "low", label: "목표 미달 ≤", defaultValue: 80, unit: "%" },
    { id: "high", label: "목표 초과 ≥", defaultValue: 120, unit: "%" },
  ],
  filterFieldDefs: [
    { id: "customer", name: "거래처", type: "select", optionKey: "customers" },
    { id: "item", name: "품목", type: "select", optionKey: "items" },
    { id: "status", name: "상태", type: "select", optionKey: "statuses" },
    { id: "orderAmt", name: "수주금액", type: "number" },
    { id: "orderQty", name: "수주수량", type: "number" },
  ],
  drilldownColumns: [
    { id: "date", name: "날짜", format: "date" },
    { id: "order_no", name: "수주번호" },
    { id: "customer", name: "거래처" },
    { id: "item", name: "품목" },
    { id: "status", name: "상태", format: "badge" },
    { id: "orderQty", name: "수주수량", align: "right", format: "number" },
    { id: "unitPrice", name: "단가", align: "right", format: "number" },
    { id: "orderAmt", name: "수주금액", align: "right", format: "number" },
    { id: "shipQty", name: "출하수량", align: "right", format: "number" },
  ],
  rawDataColumns: [
    { id: "date", name: "날짜", format: "date" },
    { id: "order_no", name: "수주번호" },
    { id: "customer", name: "거래처" },
    { id: "part_code", name: "품목코드" },
    { id: "item", name: "품목명" },
    { id: "status", name: "상태", format: "badge" },
    { id: "orderQty", name: "수주수량", align: "right", format: "number" },
    { id: "unitPrice", name: "단가", align: "right", format: "number" },
    { id: "orderAmt", name: "수주금액", align: "right", format: "number" },
    { id: "shipQty", name: "출하수량", align: "right", format: "number" },
  ],
  emptyMessage: "수주 데이터가 없습니다",
};

export default function SalesReportPage() {
  return <ReportEngine config={config} />;
}
