// Learning levels per block — identical to the backend (learning.py LEVELS).
// Floor in % of cap_final (cap_final = all subblocks × 25).
// green=Beginner 20% · blue=Advanced 40% · purple=Expert 60% · gold=Master 100%.
export const LEVELS = [
  { key: 'beginner', label: 'Beginner', kurz: '✓', floor: 0.2, farbe: 'var(--level-beginner)' },
  { key: 'advanced', label: 'Advanced', kurz: '✓✓', floor: 0.4, farbe: 'var(--level-advanced)' },
  { key: 'expert', label: 'Expert', kurz: '✓✓✓', floor: 0.6, farbe: 'var(--level-expert)' },
  { key: 'master', label: 'Master', kurz: '★', floor: 1.0, farbe: 'var(--level-master)' },
]

export function schwelle(floor, cap) {
  return Math.round(floor * cap)
}

// Highest reached level (object) or null (below Beginner, <20%).
export function stufeFuer(score, cap) {
  let s = null
  for (const st of LEVELS) if (score >= schwelle(st.floor, cap)) s = st
  return s
}

// Error-penalty display by progress (against cap_aktuell): ≤25%→−5 · ≤50%→−10 · ≤75%→−15 · >75%→−20.
export function malusRegel(score, cap) {
  const pct = cap ? score / cap : 0
  if (pct <= 0.25) return '−5'
  if (pct <= 0.5) return '−10'
  if (pct <= 0.75) return '−15'
  return '−20'
}

// Reached badge level (LEVELS key) → view level 1..4, so unlocked SUBS match the badge:
// Advanced-Badge → advanced subs visible. Same threshold as stufeFuer, no drift.
export const BADGE_VIEW_RANK = { beginner: 1, advanced: 2, expert: 3, master: 4 }

// Sub-level tag (from the guide markers) → view level 1..4 (A/F/E/V).
export const SUB_RANK = { beginner: 1, advanced: 2, expert: 3, peripheral: 4, einfach: 1, mittel: 2, schwer: 3 }
export const VIEW_KURZ = { 1: 'A', 2: 'F', 3: 'E', 4: 'V' }
export const VIEW_FARBE = {
  1: 'var(--level-beginner)', 2: 'var(--level-advanced)',
  3: 'var(--level-expert)', 4: 'var(--level-master)',
}
