"use client";

import { createComponentDefinition } from "../../utils/createComponentDefinition";
import { ComponentCategory } from "@/types/component";
import { AggregationWidgetWrapper } from "./AggregationWidgetComponent";
import { V2AggregationWidgetConfigPanel } from "@/components/v2/config-panels/V2AggregationWidgetConfigPanel";
import type { AggregationWidgetConfig } from "./types";

/**
 * AggregationWidget 컴포넌트 정의
 * 데이터 집계 (합계, 평균, 개수 등)를 표시하는 위젯
 */
export const V2AggregationWidgetDefinition = createComponentDefinition({
  id: "v2-aggregation-widget",
  name: "집계 위젯",
  nameEng: "Aggregation Widget",
  description: "데이터의 합계, 평균, 개수 등 집계 결과를 표시하는 위젯 (필터링 지원)",
  category: ComponentCategory.DISPLAY,
  webType: "text",
  component: AggregationWidgetWrapper,
  defaultConfig: {
    dataSourceType: "table", // 기본값: 테이블에서 직접 조회
    items: [],
    filters: [], // 필터 조건
    filterLogic: "AND",
    layout: "horizontal",
    showLabels: true,
    showIcons: true,
    gap: "16px",
    backgroundColor: "#f8fafc",
    borderRadius: "6px",
    padding: "12px",
    autoRefresh: false,
    refreshOnFormChange: true, // 폼 변경 시 자동 새로고침
  } as Partial<AggregationWidgetConfig>,
  defaultSize: { width: 400, height: 60 },
  configPanel: V2AggregationWidgetConfigPanel,
  icon: "Calculator",
  tags: ["집계", "합계", "평균", "개수", "통계", "데이터", "필터"],
  version: "1.1.0",
  author: "개발팀",
});

// 타입 내보내기
export type {
  AggregationWidgetConfig,
  AggregationItem,
  AggregationType,
  AggregationResult,
  DataSourceType,
  FilterCondition,
  FilterOperator,
  FilterValueSourceType,
} from "./types";

