import type { TableColumnCtx } from 'element-plus'

type FormatterFn = (
  row: any,
  column: TableColumnCtx<any>,
  cellValue: any,
  index: number,
) => string

export const priceFormatter: FormatterFn = (
  _row,
  _column,
  cellValue,
) => `¥${Number(cellValue).toLocaleString()}`

export const booleanFormatter = (
  truthyText = '启用',
  falsyText = '禁用',
): FormatterFn => (_row, _column, cellValue) =>
  cellValue ? truthyText : falsyText

export const mapFormatter = (
  mapping: Record<string, string>,
  fallback = '',
): FormatterFn => (_row, _column, cellValue) =>
  mapping[String(cellValue)] ?? fallback
