<script setup lang="ts">
/**
 * 文件职责：经营报表批量导出确认弹窗。
 */
import type { FinanceBusinessReportPeriodType } from '#/api/finance';

import { computed } from 'vue';

import { Modal } from 'ant-design-vue';

import { resolvePeriodTypeLabel } from '../composables/report-page/helpers';

interface PaginationState {
  page: number;
  pageSize: number;
  total: number;
}

interface Props {
  currentPageCount: number;
  open: boolean;
  pagination: PaginationState;
  periodType: FinanceBusinessReportPeriodType;
  selectedStoreName: string;
  submitting: boolean;
}

const props = defineProps<Props>();

const emit = defineEmits<{
  (event: 'close'): void;
  (event: 'confirm'): void;
}>();

const periodText = computed(() => resolvePeriodTypeLabel(props.periodType));
const pageSizeText = computed(() => `${props.pagination.pageSize} 条/页`);

const pageRangeText = computed(() => {
  const pageSize = Math.max(1, Number(props.pagination.pageSize || 20));
  const page = Math.max(1, Number(props.pagination.page || 1));
  const currentCount = Math.max(0, Number(props.currentPageCount || 0));

  if (currentCount === 0) {
    return '当前页暂无数据';
  }

  const start = (page - 1) * pageSize + 1;
  const end = start + currentCount - 1;
  return `${start}-${end}`;
});
</script>

<template>
  <Modal
    :open="props.open"
    title="批量导出经营报表"
    ok-text="确认导出"
    cancel-text="取消"
    :confirm-loading="props.submitting"
    @ok="emit('confirm')"
    @cancel="emit('close')"
  >
    <div class="frp-batch-modal">
      <p class="frp-batch-desc">
        将按当前门店、当前周期和当前分页范围导出 ZIP 文件（包含 PDF 与 Excel）。
      </p>

      <div class="frp-batch-list">
        <div class="frp-batch-line">
          <span class="frp-batch-label">门店</span>
          <span class="frp-batch-value">{{ props.selectedStoreName }}</span>
        </div>
        <div class="frp-batch-line">
          <span class="frp-batch-label">报表周期</span>
          <span class="frp-batch-value">{{ periodText }}</span>
        </div>
        <div class="frp-batch-line">
          <span class="frp-batch-label">当前页</span>
          <span class="frp-batch-value">第 {{ props.pagination.page }} 页</span>
        </div>
        <div class="frp-batch-line">
          <span class="frp-batch-label">分页大小</span>
          <span class="frp-batch-value">{{ pageSizeText }}</span>
        </div>
        <div class="frp-batch-line">
          <span class="frp-batch-label">导出范围</span>
          <span class="frp-batch-value">{{ pageRangeText }}</span>
        </div>
        <div class="frp-batch-line is-total">
          <span class="frp-batch-label">总报表数</span>
          <span class="frp-batch-value">{{ props.pagination.total }} 条</span>
        </div>
      </div>
    </div>
  </Modal>
</template>
