import { Row } from '@tanstack/react-table'

import DepositCapCell from 'components/DepositCapCell'
import Loading from 'components/Loading'

export const DEPOSIT_CAP_META = { accessorKey: 'cap', header: 'Deposit Cap' }

interface Props {
  vault: Vault | DepositedVault
  isLoading: boolean
}

export const depositCapSortingFn = (
  a: Row<Vault> | Row<DepositedVault>,
  b: Row<Vault> | Row<DepositedVault>,
): number => {
  const depositCapA = a.original.cap.max
  const depositCapB = b.original.cap.max
  return depositCapA.minus(depositCapB).toNumber()
}

export default function DepositCap(props: Props) {
  const { vault } = props

  if (props.isLoading) return <Loading />

  return <DepositCapCell depositCap={vault.cap} />
}
