import type { FinanceBusinessReportPaginationState } from '../../types';

/**
 * 文件职责：经营报表页面筛选与分页行为。
 */
import type { FinanceBusinessReportPeriodType } from '#/api/finance';

interface FilterActionOptions {
  loadReportList: () => Promise<void>;
  pagination: FinanceBusinessReportPaginationState;
  periodType: { value: FinanceBusinessReportPeriodType };
}

/** 创建筛选与分页行为。 */
export function createFilterActions(options: FilterActionOptions) {
  function setPeriodType(value: FinanceBusinessReportPeriodType) {
    options.periodType.value = value || 'daily';
  }

  async function handlePageChange(page: number, pageSize: number) {
    options.pagination.page = page;
    options.pagination.pageSize = pageSize;
    await options.loadReportList();
  }

  return {
    handlePageChange,
    setPeriodType,
  };
}
