/**
 * TabataFit Typography System
 * SF Pro (system font) — premium native iOS feel
 *
 * Uses Apple's Dynamic Type scale with system font.
 * No custom fonts loaded — SF Pro is the default on iOS.
 * fontWeight controls the visual weight; no fontFamily needed for SF Pro.
 *
 * For data/timer: system monospaced via fontVariant: ['tabular-nums']
 */

import { Platform, TextStyle } from 'react-native'

// ═══════════════════════════════════════════════════════════════════════════
// FONT FAMILIES — System font (SF Pro on iOS, Roboto on Android)
// ═══════════════════════════════════════════════════════════════════════════

/**
 * On iOS, omitting fontFamily uses SF Pro automatically.
 * On Android, omitting fontFamily uses Roboto.
 * We use 'System' as a semantic marker — React Native resolves it to the
 * platform system font.
 */
export const FONT_FAMILY = {
  // System font — no fontFamily needed (undefined = system font in RN)
  SANS: undefined,
  SANS_MEDIUM: undefined,
  SANS_SEMIBOLD: undefined,
  SANS_BOLD: undefined,
  // Serif — iOS has New York via serif fontFamily
  SERIF: Platform.OS === 'ios' ? 'Georgia' : 'serif',
  SERIF_ITALIC: Platform.OS === 'ios' ? 'Georgia' : 'serif',
  // Monospace — system mono (SF Mono on iOS, Roboto Mono on Android)
  MONO: Platform.OS === 'ios' ? 'Menlo' : 'monospace',
  MONO_MEDIUM: Platform.OS === 'ios' ? 'Menlo' : 'monospace',
} as const

// Font alias object — maps to FONT_FAMILY values
const FONT = {
  SANS: FONT_FAMILY.SANS,
  SANS_MEDIUM: FONT_FAMILY.SANS_MEDIUM,
  SANS_SEMIBOLD: FONT_FAMILY.SANS_SEMIBOLD,
  SANS_BOLD: FONT_FAMILY.SANS_BOLD,
  SERIF: FONT_FAMILY.SERIF,
  SERIF_ITALIC: FONT_FAMILY.SERIF_ITALIC,
  MONO: FONT_FAMILY.MONO,
  MONO_MEDIUM: FONT_FAMILY.MONO_MEDIUM,
  // Backward compat
  REGULAR: FONT_FAMILY.SANS,
  MEDIUM: FONT_FAMILY.SANS_MEDIUM,
  SEMIBOLD: FONT_FAMILY.SANS_SEMIBOLD,
  BOLD: FONT_FAMILY.SANS_BOLD,
  BLACK: FONT_FAMILY.SANS_BOLD,
} as const

// ═══════════════════════════════════════════════════════════════════════════
// TYPE SCALE — matches Apple HIG Dynamic Type defaults
// ═══════════════════════════════════════════════════════════════════════════

export const TYPOGRAPHY = {
  // Display / Hero — bold system font for emotional moments
  DISPLAY: {
    fontFamily: FONT.SERIF,
    fontSize: 28,
    fontWeight: '700' as const,
    lineHeight: 34,
    letterSpacing: 0.36,
  } as TextStyle,

  HERO: {
    fontFamily: FONT.SERIF,
    fontSize: 34,
    fontWeight: '700' as const,
    lineHeight: 41,
    letterSpacing: 0.37,
  } as TextStyle,

  // Large Title — iOS native large title
  LARGE_TITLE: {
    fontSize: 34,
    fontWeight: '700' as const,
    lineHeight: 41,
    letterSpacing: 0.37,
  } as TextStyle,

  // Heading 1
  HEADING_1: {
    fontSize: 28,
    fontWeight: '700' as const,
    lineHeight: 34,
    letterSpacing: 0.36,
  } as TextStyle,

  // Title 1
  TITLE_1: {
    fontSize: 28,
    fontWeight: '400' as const,
    lineHeight: 34,
    letterSpacing: 0.36,
  } as TextStyle,

  // Heading 2 — exercise titles, program cards
  HEADING_2: {
    fontSize: 22,
    fontWeight: '700' as const,
    lineHeight: 28,
    letterSpacing: 0.35,
  } as TextStyle,

  TITLE_2: {
    fontSize: 22,
    fontWeight: '400' as const,
    lineHeight: 28,
    letterSpacing: 0.35,
  } as TextStyle,

  TITLE_3: {
    fontSize: 20,
    fontWeight: '400' as const,
    lineHeight: 25,
    letterSpacing: 0.38,
  } as TextStyle,

  // Headline
  HEADLINE: {
    fontSize: 17,
    fontWeight: '600' as const,
    lineHeight: 22,
    letterSpacing: -0.41,
  } as TextStyle,

  // Body
  BODY: {
    fontSize: 17,
    fontWeight: '400' as const,
    lineHeight: 22,
    letterSpacing: -0.41,
  } as TextStyle,

  BODY_BOLD: {
    fontSize: 17,
    fontWeight: '600' as const,
    lineHeight: 22,
    letterSpacing: -0.41,
  } as TextStyle,

  // Callout
  CALLOUT: {
    fontSize: 16,
    fontWeight: '400' as const,
    lineHeight: 21,
    letterSpacing: -0.32,
  } as TextStyle,

  // Subheadline
  SUBHEADLINE: {
    fontSize: 15,
    fontWeight: '400' as const,
    lineHeight: 20,
    letterSpacing: -0.24,
  } as TextStyle,

  // Label — small uppercase for tags, metadata
  LABEL: {
    fontSize: 12,
    fontWeight: '500' as const,
    lineHeight: 16,
    letterSpacing: 0.5,
    textTransform: 'uppercase' as const,
  } as TextStyle,

  // Footnote
  FOOTNOTE: {
    fontSize: 13,
    fontWeight: '400' as const,
    lineHeight: 18,
    letterSpacing: -0.08,
  } as TextStyle,

  // Caption
  CAPTION_1: {
    fontSize: 12,
    fontWeight: '400' as const,
    lineHeight: 16,
    letterSpacing: 0,
  } as TextStyle,

  CAPTION_2: {
    fontSize: 11,
    fontWeight: '400' as const,
    lineHeight: 13,
    letterSpacing: 0.07,
  } as TextStyle,

  // ─────────────────────────────────────────────────────────────────────────
  // SPECIAL: TIMER — Monospaced, readable from 2 meters
  // ─────────────────────────────────────────────────────────────────────────

  TIMER_NUMBER: {
    fontFamily: FONT.MONO,
    fontSize: 88,
    fontWeight: '300' as const,
    lineHeight: 88,
    letterSpacing: -2,
    fontVariant: ['tabular-nums'],
  } as TextStyle,

  TIMER_NUMBER_COMPACT: {
    fontFamily: FONT.MONO,
    fontSize: 72,
    fontWeight: '300' as const,
    lineHeight: 72,
    letterSpacing: -1.5,
    fontVariant: ['tabular-nums'],
  } as TextStyle,

  TIMER_PHASE: {
    fontSize: 13,
    fontWeight: '600' as const,
    lineHeight: 18,
    letterSpacing: 1.5,
    textTransform: 'uppercase' as const,
  } as TextStyle,

  TIMER_ROUND: {
    fontFamily: FONT.MONO,
    fontSize: 17,
    fontWeight: '500' as const,
    lineHeight: 22,
    letterSpacing: 0,
    fontVariant: ['tabular-nums'],
  } as TextStyle,

  EXERCISE_NAME: {
    fontSize: 28,
    fontWeight: '700' as const,
    lineHeight: 34,
    letterSpacing: 0.36,
    textAlign: 'center' as const,
  } as TextStyle,

  // ─────────────────────────────────────────────────────────────────────────
  // SPECIAL: BUTTON
  // ─────────────────────────────────────────────────────────────────────────

  BUTTON_LARGE: {
    fontSize: 17,
    fontWeight: '600' as const,
    lineHeight: 22,
    letterSpacing: -0.41,
  } as TextStyle,

  BUTTON_MEDIUM: {
    fontSize: 15,
    fontWeight: '600' as const,
    lineHeight: 20,
    letterSpacing: -0.24,
  } as TextStyle,

  BUTTON_SMALL: {
    fontSize: 14,
    fontWeight: '600' as const,
    lineHeight: 18,
    letterSpacing: -0.15,
  } as TextStyle,

  // ─────────────────────────────────────────────────────────────────────────
  // SPECIAL: CARD
  // ─────────────────────────────────────────────────────────────────────────

  CARD_TITLE: {
    fontSize: 17,
    fontWeight: '600' as const,
    lineHeight: 22,
    letterSpacing: -0.41,
  } as TextStyle,

  CARD_SUBTITLE: {
    fontSize: 15,
    fontWeight: '400' as const,
    lineHeight: 20,
    letterSpacing: -0.24,
  } as TextStyle,

  CARD_METADATA: {
    fontSize: 13,
    fontWeight: '500' as const,
    lineHeight: 18,
    letterSpacing: -0.08,
  } as TextStyle,

  // ─────────────────────────────────────────────────────────────────────────
  // SPECIAL: STATS — Monospaced numerals
  // ─────────────────────────────────────────────────────────────────────────

  STAT_VALUE: {
    fontFamily: FONT.MONO,
    fontSize: 34,
    fontWeight: '300' as const,
    lineHeight: 41,
    letterSpacing: -0.5,
    fontVariant: ['tabular-nums'],
  } as TextStyle,

  STAT_LABEL: {
    fontSize: 12,
    fontWeight: '500' as const,
    lineHeight: 16,
    letterSpacing: 0.5,
    textTransform: 'uppercase' as const,
  } as TextStyle,

  // ─────────────────────────────────────────────────────────────────────────
  // SPECIAL: OVERLINE / SECTION HEADER
  // ─────────────────────────────────────────────────────────────────────────

  OVERLINE: {
    fontSize: 12,
    fontWeight: '500' as const,
    lineHeight: 16,
    letterSpacing: 0.5,
    textTransform: 'uppercase' as const,
  } as TextStyle,

} as const

export { FONT }

// Named exports for backward compatibility with player components
export const FONT_FAMILY_SANS_SEMIBOLD = FONT_FAMILY.SANS_SEMIBOLD
export const FONT_FAMILY_SANS_BOLD = FONT_FAMILY.SANS_BOLD
