/**
 * 지출 상세 모달 변환 (Purchase, Card, Bill, ExpectedExpense Detail)
 */

import type {
  PurchaseDashboardDetailApiResponse,
  CardDashboardDetailApiResponse,
  BillDashboardDetailApiResponse,
  ExpectedExpenseDashboardDetailApiResponse,
} from '../types';
import type { DateFilterConfig, DetailModalConfig } from '@/components/business/CEODashboard/types';
import type { PurchaseRecord } from '@/components/accounting/PurchaseManagement/types';
import type { CardTransaction } from '@/components/accounting/CardTransactionInquiry/types';
import type { BillRecord } from '@/components/accounting/BillManagement/types';
import { PURCHASE_TYPE_LABELS } from '@/components/accounting/PurchaseManagement/types';
import { getBillStatusLabel } from '@/components/accounting/BillManagement/types';

// 차트 색상 팔레트
const CHART_COLORS = ['#60A5FA', '#34D399', '#F59E0B', '#F87171', '#A78BFA', '#94A3B8'];

// ============================================
// Purchase Dashboard Detail 변환 (me1)
// ============================================

/**
 * Purchase Dashboard Detail API 응답 → DetailModalConfig 변환
 * 매입 상세 모달 설정 생성 (me1)
 */
export function transformPurchaseDetailResponse(api: PurchaseDashboardDetailApiResponse): DetailModalConfig {
  const { summary, monthly_trend, by_type, items } = api;
  const changeRateText = summary.change_rate >= 0
    ? `+${summary.change_rate.toFixed(1)}%`
    : `${summary.change_rate.toFixed(1)}%`;

  return {
    title: '매입 상세',
    summaryCards: [
      { label: '당월 매입액', value: summary.current_month_amount, unit: '원' },
      { label: '전월 대비', value: changeRateText },
    ],
    barChart: {
      title: '월별 매입 추이',
      data: monthly_trend.map(item => ({
        name: item.label,
        value: item.amount,
      })),
      dataKey: 'value',
      xAxisKey: 'name',
      color: '#60A5FA',
    },
    pieChart: {
      title: '유형별 매입 비율',
      data: by_type.map(item => ({
        name: item.type_label,
        value: item.amount,
        percentage: 0, // API에서 계산하거나 프론트에서 계산
        color: item.color,
      })),
    },
    table: {
      title: '매입 내역',
      columns: [
        { key: 'no', label: 'No.', align: 'center' },
        { key: 'date', label: '매입일자', align: 'center', format: 'date' },
        { key: 'vendor', label: '거래처명', align: 'left' },
        { key: 'amount', label: '금액', align: 'right', format: 'currency' },
        { key: 'type', label: '유형', align: 'center' },
      ],
      data: items.map((item, idx) => ({
        no: idx + 1,
        date: item.purchase_date,
        vendor: item.vendor_name,
        amount: item.amount,
        type: item.type_label,
      })),
      filters: [
        {
          key: 'type',
          options: [
            { value: 'all', label: '전체' },
            ...by_type.map(t => ({ value: t.type, label: t.type_label })),
          ],
          defaultValue: 'all',
        },
      ],
      showTotal: true,
      totalLabel: '합계',
      totalValue: items.reduce((sum, item) => sum + item.amount, 0),
      totalColumnKey: 'amount',
    },
  };
}

// ============================================
// Card Dashboard Detail 변환 (me2)
// ============================================

/**
 * Card Dashboard Detail API 응답 → DetailModalConfig 변환
 * 카드 상세 모달 설정 생성 (me2)
 */
export function transformCardDetailResponse(api: CardDashboardDetailApiResponse): DetailModalConfig {
  const { summary, monthly_trend, by_user, items } = api;
  const changeRate = summary.previous_month_total > 0
    ? ((summary.current_month_total - summary.previous_month_total) / summary.previous_month_total * 100)
    : 0;
  const changeRateText = changeRate >= 0
    ? `+${changeRate.toFixed(1)}%`
    : `${changeRate.toFixed(1)}%`;

  return {
    title: '카드 사용 상세',
    summaryCards: [
      { label: '당월 사용액', value: summary.current_month_total, unit: '원' },
      { label: '전월 대비', value: changeRateText },
      { label: '당월 건수', value: summary.current_month_count, unit: '건' },
    ],
    barChart: {
      title: '월별 카드 사용 추이',
      data: monthly_trend.map(item => ({
        name: item.label,
        value: item.amount,
      })),
      dataKey: 'value',
      xAxisKey: 'name',
      color: '#34D399',
    },
    pieChart: {
      title: '사용자별 사용 비율',
      data: by_user.map(item => ({
        name: item.user_name,
        value: item.amount,
        percentage: 0,
        color: item.color,
      })),
    },
    table: {
      title: '카드 사용 내역',
      columns: [
        { key: 'no', label: 'No.', align: 'center' },
        { key: 'cardName', label: '카드명', align: 'left' },
        { key: 'user', label: '사용자', align: 'center' },
        { key: 'date', label: '사용일자', align: 'center', format: 'date' },
        { key: 'store', label: '가맹점명', align: 'left' },
        { key: 'amount', label: '사용금액', align: 'right', format: 'currency' },
        { key: 'usageType', label: '사용항목', align: 'center' },
      ],
      data: items.map((item, idx) => ({
        no: idx + 1,
        cardName: item.card_name,
        user: item.user_name,
        date: item.transaction_date,
        store: item.merchant_name,
        amount: item.amount,
        usageType: item.usage_type,
      })),
      filters: [
        {
          key: 'user',
          options: [
            { value: 'all', label: '전체' },
            ...by_user.map(u => ({ value: u.user_name, label: u.user_name })),
          ],
          defaultValue: 'all',
        },
      ],
      showTotal: true,
      totalLabel: '합계',
      totalValue: items.reduce((sum, item) => sum + item.amount, 0),
      totalColumnKey: 'amount',
    },
  };
}

// ============================================
// Bill Dashboard Detail 변환 (me3)
// ============================================

/**
 * Bill Dashboard Detail API 응답 → DetailModalConfig 변환
 * 발행어음 상세 모달 설정 생성 (me3)
 */
export function transformBillDetailResponse(api: BillDashboardDetailApiResponse): DetailModalConfig {
  const { summary, monthly_trend, by_vendor, items } = api;
  const changeRateText = summary.change_rate >= 0
    ? `+${summary.change_rate.toFixed(1)}%`
    : `${summary.change_rate.toFixed(1)}%`;

  // 거래처별 가로 막대 차트 데이터
  const horizontalBarData = by_vendor.map(item => ({
    name: item.vendor_name,
    value: item.amount,
  }));

  return {
    title: '발행어음 상세',
    summaryCards: [
      { label: '당월 발행어음', value: summary.current_month_amount, unit: '원' },
      { label: '전월 대비', value: changeRateText },
    ],
    barChart: {
      title: '월별 발행어음 추이',
      data: monthly_trend.map(item => ({
        name: item.label,
        value: item.amount,
      })),
      dataKey: 'value',
      xAxisKey: 'name',
      color: '#F59E0B',
    },
    horizontalBarChart: {
      title: '거래처별 발행어음',
      data: horizontalBarData,
      dataKey: 'value',
      yAxisKey: 'name',
      color: '#8B5CF6',
    },
    table: {
      title: '발행어음 내역',
      columns: [
        { key: 'no', label: 'No.', align: 'center' },
        { key: 'vendor', label: '거래처명', align: 'left' },
        { key: 'issueDate', label: '발행일', align: 'center', format: 'date' },
        { key: 'dueDate', label: '만기일', align: 'center', format: 'date' },
        { key: 'amount', label: '금액', align: 'right', format: 'currency' },
        { key: 'status', label: '상태', align: 'center' },
      ],
      data: items.map((item, idx) => ({
        no: idx + 1,
        vendor: item.vendor_name,
        issueDate: item.issue_date,
        dueDate: item.due_date,
        amount: item.amount,
        status: item.status_label,
      })),
      filters: [
        {
          key: 'vendor',
          options: [
            { value: 'all', label: '전체' },
            ...by_vendor.map(v => ({ value: v.vendor_name, label: v.vendor_name })),
          ],
          defaultValue: 'all',
        },
        {
          key: 'status',
          options: [
            { value: 'all', label: '전체' },
            { value: 'pending', label: '대기중' },
            { value: 'paid', label: '결제완료' },
            { value: 'overdue', label: '연체' },
          ],
          defaultValue: 'all',
        },
      ],
      showTotal: true,
      totalLabel: '합계',
      totalValue: items.reduce((sum, item) => sum + item.amount, 0),
      totalColumnKey: 'amount',
    },
  };
}

// ============================================
// Expected Expense Dashboard Detail 변환 (me1~me4 통합)
// ============================================

// cardId별 제목 및 차트 설정 매핑
const EXPENSE_CARD_CONFIG: Record<string, {
  title: string;
  tableTitle: string;
  summaryLabel: string;
  barChartTitle: string;
  pieChartTitle?: string;
  horizontalBarChartTitle?: string;
  hasBarChart: boolean;
  hasPieChart: boolean;
  hasHorizontalBarChart: boolean;
  dateFilter?: DateFilterConfig;
}> = {
  me1: {
    title: '당월 매입 상세',
    tableTitle: '일별 매입 내역',
    summaryLabel: '당월 매입',
    barChartTitle: '월별 매입 추이',
    pieChartTitle: '거래처별 매입 비율',
    hasBarChart: true,
    hasPieChart: true,
    hasHorizontalBarChart: false,
    dateFilter: { enabled: true, defaultPreset: '당월', showSearch: true },
  },
  me2: {
    title: '당월 카드 상세',
    tableTitle: '일별 카드 사용 내역',
    summaryLabel: '당월 카드 사용',
    barChartTitle: '월별 카드 사용 추이',
    pieChartTitle: '거래처별 카드 사용 비율',
    hasBarChart: true,
    hasPieChart: true,
    hasHorizontalBarChart: false,
    dateFilter: { enabled: true, defaultPreset: '당월', showSearch: true },
  },
  me3: {
    title: '당월 발행어음 상세',
    tableTitle: '일별 발행어음 내역',
    summaryLabel: '당월 발행어음 사용',
    barChartTitle: '월별 발행어음 추이',
    horizontalBarChartTitle: '당월 거래처별 발행어음',
    hasBarChart: true,
    hasPieChart: false,
    hasHorizontalBarChart: true,
    dateFilter: { enabled: true, presets: ['당해년도', '전전월', '전월', '당월', '어제'], defaultPreset: '당월', showSearch: true },
  },
  me4: {
    title: '당월 지출 예상 상세',
    tableTitle: '당월 지출 승인 내역서',
    summaryLabel: '당월 지출 예상',
    barChartTitle: '',
    hasBarChart: false,
    hasPieChart: false,
    hasHorizontalBarChart: false,
  },
};

/**
 * ExpectedExpense Dashboard Detail API 응답 → DetailModalConfig 변환
 * 카드별 지출 상세 모달 설정 생성 (me1: 매입, me2: 카드, me3: 발행어음, me4: 전체)
 *
 * @param api API 응답 데이터
 * @param cardId 카드 ID (me1~me4), 기본값 me4
 */
export function transformExpectedExpenseDetailResponse(
  api: ExpectedExpenseDashboardDetailApiResponse,
  cardId: string = 'me4'
): DetailModalConfig {
  const { summary, monthly_trend, vendor_distribution, items, footer_summary } = api;
  const changeRateText = summary.change_rate >= 0
    ? `+${summary.change_rate.toFixed(1)}%`
    : `${summary.change_rate.toFixed(1)}%`;

  // cardId별 설정 가져오기 (기본값: me4)
  const config = EXPENSE_CARD_CONFIG[cardId] || EXPENSE_CARD_CONFIG.me4;

  // 거래처 필터 옵션 생성
  const vendorOptions = [{ value: 'all', label: '전체' }];
  const uniqueVendors = [...new Set(items.map(item => item.vendor_name).filter(Boolean))];
  uniqueVendors.forEach(vendor => {
    vendorOptions.push({ value: vendor, label: vendor });
  });

  // 결과 객체 생성
  const result: DetailModalConfig = {
    title: config.title,
    ...(config.dateFilter && { dateFilter: config.dateFilter }),
    summaryCards: [
      { label: config.summaryLabel, value: summary.total_amount, unit: '원' },
      { label: '전월 대비', value: changeRateText },
      { label: '지출 후 예상 잔액', value: summary.remaining_balance, unit: '원' },
    ],
    table: {
      title: config.tableTitle,
      columns: [
        { key: 'no', label: 'No.', align: 'center' },
        { key: 'paymentDate', label: '결제예정일', align: 'center', format: 'date' },
        { key: 'item', label: '항목', align: 'left' },
        { key: 'amount', label: '금액', align: 'right', format: 'currency' },
        { key: 'vendor', label: '거래처', align: 'left' },
        { key: 'account', label: '계정과목', align: 'center' },
      ],
      data: items.map((item, idx) => ({
        no: idx + 1,
        paymentDate: item.payment_date,
        item: item.item_name,
        amount: item.amount,
        vendor: item.vendor_name,
        account: item.account_title,
      })),
      filters: [
        {
          key: 'vendor',
          options: vendorOptions,
          defaultValue: 'all',
        },
      ],
      showTotal: true,
      totalLabel: '합계',
      totalValue: footer_summary.total_amount,
      totalColumnKey: 'amount',
      footerSummary: [
        { label: `총 ${footer_summary.item_count}건`, value: footer_summary.total_amount },
      ],
    },
  };

  // barChart 추가 (me1, me2, me3)
  if (config.hasBarChart && monthly_trend && monthly_trend.length > 0) {
    result.barChart = {
      title: config.barChartTitle,
      data: monthly_trend.map(item => ({
        name: item.label,
        value: item.amount,
      })),
      dataKey: 'value',
      xAxisKey: 'name',
      color: '#60A5FA',
    };
  }

  // pieChart 추가 (me1, me2)
  if (config.hasPieChart && vendor_distribution && vendor_distribution.length > 0) {
    result.pieChart = {
      title: config.pieChartTitle || '분포',
      data: vendor_distribution.map(item => ({
        name: item.name,
        value: item.value,
        percentage: item.percentage,
        color: item.color,
      })),
    };
  }

  // horizontalBarChart 추가 (me3)
  if (config.hasHorizontalBarChart && vendor_distribution && vendor_distribution.length > 0) {
    result.horizontalBarChart = {
      title: config.horizontalBarChartTitle || '거래처별 분포',
      data: vendor_distribution.map(item => ({
        name: item.name,
        value: item.value,
      })),
      color: '#60A5FA',
    };
  }

  return result;
}

// ============================================
// 기존 페이지 서버 액션 응답 → DetailModalConfig 변환
// (dashboard-detail API 대신 실제 페이지 API 사용)
// ============================================

/** 거래처별 그룹핑 → 상위 5개 + 기타 */
function groupByVendor(
  records: { vendorName: string; amount: number }[],
  limit: number = 5,
): { name: string; value: number; percentage: number; color: string }[] {
  const vendorMap = new Map<string, number>();
  let total = 0;
  for (const r of records) {
    const name = r.vendorName || '미지정';
    vendorMap.set(name, (vendorMap.get(name) || 0) + r.amount);
    total += r.amount;
  }
  const sorted = [...vendorMap.entries()].sort((a, b) => b[1] - a[1]);
  const top = sorted.slice(0, limit);
  const otherTotal = sorted.slice(limit).reduce((sum, [, v]) => sum + v, 0);
  if (otherTotal > 0) top.push(['기타', otherTotal]);

  return top.map(([name, value], idx) => ({
    name,
    value,
    percentage: total > 0 ? Math.round((value / total) * 1000) / 10 : 0,
    color: CHART_COLORS[idx % CHART_COLORS.length],
  }));
}

/**
 * PurchaseRecord[] → DetailModalConfig (me1 매입)
 */
export function transformPurchaseRecordsToModal(
  records: PurchaseRecord[],
  dateFilter?: DateFilterConfig,
): DetailModalConfig {
  const totalAmount = records.reduce((sum, r) => sum + r.totalAmount, 0);
  const totalSupply = records.reduce((sum, r) => sum + r.supplyAmount, 0);
  const totalVat = records.reduce((sum, r) => sum + r.vat, 0);

  const vendorData = groupByVendor(
    records.map(r => ({ vendorName: r.vendorName, amount: r.totalAmount })),
  );

  return {
    title: '당월 매입 상세',
    dateFilter: dateFilter ?? { enabled: true, defaultPreset: '당월', showSearch: true },
    summaryCards: [
      { label: '총 매입액', value: totalAmount, unit: '원' },
      { label: '공급가액', value: totalSupply, unit: '원' },
      { label: '부가세', value: totalVat, unit: '원' },
      { label: '건수', value: records.length, unit: '건' },
    ],
    pieChart: vendorData.length > 0 ? {
      title: '거래처별 매입 비율',
      data: vendorData,
    } : undefined,
    table: {
      title: '매입 내역',
      columns: [
        { key: 'no', label: 'No.', align: 'center' },
        { key: 'purchaseDate', label: '매입일자', align: 'center', format: 'date' },
        { key: 'vendorName', label: '거래처명', align: 'left' },
        { key: 'supplyAmount', label: '공급가액', align: 'right', format: 'currency' },
        { key: 'vat', label: '부가세', align: 'right', format: 'currency' },
        { key: 'totalAmount', label: '합계', align: 'right', format: 'currency' },
        { key: 'purchaseType', label: '유형', align: 'center' },
      ],
      data: records.map((r, idx) => ({
        no: idx + 1,
        purchaseDate: r.purchaseDate,
        vendorName: r.vendorName,
        supplyAmount: r.supplyAmount,
        vat: r.vat,
        totalAmount: r.totalAmount,
        purchaseType: PURCHASE_TYPE_LABELS[r.purchaseType] || r.purchaseType,
      })),
      showTotal: true,
      totalLabel: '합계',
      totalValue: totalAmount,
      totalColumnKey: 'totalAmount',
      footerSummary: [
        { label: `총 ${records.length}건`, value: totalAmount, format: 'currency' },
      ],
    },
  };
}

/**
 * CardTransaction[] → DetailModalConfig (me2 카드)
 */
export function transformCardTransactionsToModal(
  records: CardTransaction[],
  dateFilter?: DateFilterConfig,
): DetailModalConfig {
  const totalAmount = records.reduce((sum, r) => sum + r.totalAmount, 0);

  const vendorData = groupByVendor(
    records.map(r => ({ vendorName: r.merchantName || r.vendorName, amount: r.totalAmount })),
  );

  return {
    title: '당월 카드 상세',
    dateFilter: dateFilter ?? { enabled: true, defaultPreset: '당월', showSearch: true },
    summaryCards: [
      { label: '총 사용액', value: totalAmount, unit: '원' },
      { label: '건수', value: records.length, unit: '건' },
    ],
    pieChart: vendorData.length > 0 ? {
      title: '가맹점별 카드 사용 비율',
      data: vendorData,
    } : undefined,
    table: {
      title: '카드 사용 내역',
      columns: [
        { key: 'no', label: 'No.', align: 'center' },
        { key: 'usedAt', label: '사용일자', align: 'center', format: 'date' },
        { key: 'cardName', label: '카드명', align: 'left' },
        { key: 'user', label: '사용자', align: 'center' },
        { key: 'merchantName', label: '가맹점명', align: 'left' },
        { key: 'totalAmount', label: '사용금액', align: 'right', format: 'currency' },
      ],
      data: records.map((r, idx) => ({
        no: idx + 1,
        usedAt: r.usedAt,
        cardName: r.cardName,
        user: r.user,
        merchantName: r.merchantName,
        totalAmount: r.totalAmount,
      })),
      showTotal: true,
      totalLabel: '합계',
      totalValue: totalAmount,
      totalColumnKey: 'totalAmount',
      footerSummary: [
        { label: `총 ${records.length}건`, value: totalAmount, format: 'currency' },
      ],
    },
  };
}

/**
 * BillRecord[] → DetailModalConfig (me3 발행어음)
 */
export function transformBillRecordsToModal(
  records: BillRecord[],
  dateFilter?: DateFilterConfig,
): DetailModalConfig {
  const totalAmount = records.reduce((sum, r) => sum + r.amount, 0);

  const vendorBarData = groupByVendor(
    records.map(r => ({ vendorName: r.vendorName, amount: r.amount })),
  );

  return {
    title: '당월 발행어음 상세',
    dateFilter: dateFilter ?? {
      enabled: true,
      presets: ['당해년도', '전전월', '전월', '당월', '어제'],
      defaultPreset: '당월',
      showSearch: true,
    },
    summaryCards: [
      { label: '총 발행어음', value: totalAmount, unit: '원' },
      { label: '건수', value: records.length, unit: '건' },
    ],
    horizontalBarChart: vendorBarData.length > 0 ? {
      title: '거래처별 발행어음',
      data: vendorBarData.map(d => ({ name: d.name, value: d.value })),
      dataKey: 'value',
      yAxisKey: 'name',
      color: '#8B5CF6',
    } : undefined,
    table: {
      title: '발행어음 내역',
      columns: [
        { key: 'no', label: 'No.', align: 'center' },
        { key: 'billNumber', label: '어음번호', align: 'center' },
        { key: 'vendorName', label: '거래처명', align: 'left' },
        { key: 'issueDate', label: '발행일', align: 'center', format: 'date' },
        { key: 'maturityDate', label: '만기일', align: 'center', format: 'date' },
        { key: 'amount', label: '금액', align: 'right', format: 'currency' },
        { key: 'status', label: '상태', align: 'center' },
      ],
      data: records.map((r, idx) => ({
        no: idx + 1,
        billNumber: r.billNumber,
        vendorName: r.vendorName,
        issueDate: r.issueDate,
        maturityDate: r.maturityDate,
        amount: r.amount,
        status: getBillStatusLabel(r.billType, r.status),
      })),
      showTotal: true,
      totalLabel: '합계',
      totalValue: totalAmount,
      totalColumnKey: 'amount',
      footerSummary: [
        { label: `총 ${records.length}건`, value: totalAmount, format: 'currency' },
      ],
    },
  };
}

/**
 * 3개 합산 → DetailModalConfig (me4 총 예상 지출)
 */
export function transformAllExpensesToModal(
  purchases: PurchaseRecord[],
  cards: CardTransaction[],
  bills: BillRecord[],
): DetailModalConfig {
  const purchaseTotal = purchases.reduce((sum, r) => sum + r.totalAmount, 0);
  const cardTotal = cards.reduce((sum, r) => sum + r.totalAmount, 0);
  const billTotal = bills.reduce((sum, r) => sum + r.amount, 0);
  const grandTotal = purchaseTotal + cardTotal + billTotal;
  const totalCount = purchases.length + cards.length + bills.length;

  // 3개 소스를 하나의 테이블로 합침
  type UnifiedRow = { date: string; type: string; vendorName: string; amount: number };
  const allRows: UnifiedRow[] = [
    ...purchases.map(r => ({
      date: r.purchaseDate,
      type: '매입',
      vendorName: r.vendorName,
      amount: r.totalAmount,
    })),
    ...cards.map(r => ({
      date: r.usedAt?.split(' ')[0] || r.usedAt, // 'YYYY-MM-DD HH:mm' → 'YYYY-MM-DD'
      type: '카드',
      vendorName: r.merchantName || r.vendorName,
      amount: r.totalAmount,
    })),
    ...bills.map(r => ({
      date: r.issueDate,
      type: '어음',
      vendorName: r.vendorName,
      amount: r.amount,
    })),
  ];
  // 날짜순 정렬
  allRows.sort((a, b) => a.date.localeCompare(b.date));

  return {
    title: '당월 지출 예상 상세',
    summaryCards: [
      { label: '총 지출 예상액', value: grandTotal, unit: '원' },
      { label: '매입', value: purchaseTotal, unit: '원' },
      { label: '카드', value: cardTotal, unit: '원' },
      { label: '어음', value: billTotal, unit: '원' },
    ],
    table: {
      title: '당월 지출 승인 내역서',
      columns: [
        { key: 'no', label: 'No.', align: 'center' },
        { key: 'date', label: '일자', align: 'center', format: 'date' },
        { key: 'type', label: '유형', align: 'center' },
        { key: 'vendorName', label: '거래처명', align: 'left' },
        { key: 'amount', label: '금액', align: 'right', format: 'currency' },
      ],
      data: allRows.map((r, idx) => ({
        no: idx + 1,
        date: r.date,
        type: r.type,
        vendorName: r.vendorName,
        amount: r.amount,
      })),
      filters: [
        {
          key: 'type',
          options: [
            { value: 'all', label: '전체' },
            { value: '매입', label: '매입' },
            { value: '카드', label: '카드' },
            { value: '어음', label: '어음' },
          ],
          defaultValue: 'all',
        },
      ],
      showTotal: true,
      totalLabel: '합계',
      totalValue: grandTotal,
      totalColumnKey: 'amount',
      footerSummary: [
        { label: `총 ${totalCount}건`, value: grandTotal, format: 'currency' },
      ],
    },
  };
}
