/**
 * Late slips preview (legacy CI slips/preview_list).
 */
import { apiFetch } from './http'

export type SlipPreviewRow = Record<string, unknown>

export async function fetchSlipPreviewList(params?: {
  school_year?: string
  semester?: string
}): Promise<{ rows?: SlipPreviewRow[]; school_year?: string; semester?: string }> {
  const qs = new URLSearchParams()
  if (params?.school_year) qs.set('school_year', params.school_year)
  if (params?.semester) qs.set('semester', params.semester)
  const suffix = qs.toString() ? `?${qs}` : ''
  const res = await apiFetch<{ ok: boolean; logs?: SlipPreviewRow[] }>(
    `/api/v1/reports/slips/logs${suffix}`,
  )
  return { rows: res.logs ?? [] }
}
