import type { MediaItem, MediaType } from '@/types/domain'
import { formatRuntime } from '@/utils/format'

export const mediaTypeLabel = (type: MediaType): string =>
  type === 'movie' ? 'Movie' : type === 'show' ? 'Show' : 'Game'

export const mediaBadgeVariant = (type: MediaType): 'accent' | 'secondary' | 'neutral' =>
  type === 'movie' ? 'accent' : type === 'show' ? 'secondary' : 'neutral'

export const mediaMeta = (item: MediaItem): string =>
  item.type === 'game' && item.platforms.length > 0
    ? item.platforms.slice(0, 2).join(' • ')
    : formatRuntime(item.runtimeMinutes, item.type)

export const mediaYear = (isoDate: string): string => String(new Date(isoDate).getFullYear())

export const mediaMonogram = (title: string): string =>
  title
    .split(/\s+/)
    .filter(Boolean)
    .slice(0, 2)
    .map((part) => part[0]?.toUpperCase() ?? '')
    .join('')
    .slice(0, 2) || 'SN'
