import type {
  BeaconBindingStatus,
  MachineStateCode,
} from '../model/types'

export function getMachineStateLabel(state: MachineStateCode) {
  if (state === 'IDLE') return 'Стоит'
  if (state === 'ENGINE_ON') return 'Заведена'
  if (state === 'MOVING') return 'В движении'
  if (state === 'NO_DATA') return 'Нет данных'

  return state
}

export function getMachineStateClass(state: MachineStateCode) {
  if (state === 'MOVING') return 'machines-status--blue'
  if (state === 'ENGINE_ON') return 'machines-status--green'
  if (state === 'NO_DATA') return 'machines-status--red'

  return 'machines-status--gray'
}

export function getMachineBindingStatus(beaconId?: number | null): BeaconBindingStatus {
  return beaconId ? 'BOUND' : 'UNBOUND'
}

export function getMachineBindingLabel(status: BeaconBindingStatus) {
  if (status === 'BOUND') return 'Маяк привязан'

  return 'Маяк не привязан'
}

export function getMachineBindingClass(status: BeaconBindingStatus) {
  return status === 'BOUND'
    ? 'machines-status--green'
    : 'machines-status--gray'
}

export function formatMachineDateTime(date?: string | null) {
  if (!date) return 'Нет данных'

  return new Intl.DateTimeFormat('ru-RU', {
    day: '2-digit',
    month: '2-digit',
    year: 'numeric',
    hour: '2-digit',
    minute: '2-digit',
  }).format(new Date(date))
}
