import { initialRoutine } from './data/index.js' const weekdayKeys = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'] export function localCalendarDate(date) { return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 12) } export function addCalendarDays(date, days) { return new Date(date.getFullYear(), date.getMonth(), date.getDate() + days, 12) } export function startOfWeek(date) { return addCalendarDays(date, -((date.getDay() + 6) % 7)) } export function localDateKey(date) { const pad = (value) => String(value).padStart(2, '0') return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}` } export function routineForDate(date) { return initialRoutine.days[weekdayKeys[date.getDay()]] } function rangeLabel(range) { return range.min === range.max ? String(range.min) : `${range.min}–${range.max}` } function durationLabel(range) { if (range.min % 60 === 0 && range.max % 60 === 0) { return `${rangeLabel({ min: range.min / 60, max: range.max / 60 })} min` } return `${rangeLabel(range)} sec` } export function prescriptionLabel(prescription) { const per = prescription.per ? ` per ${prescription.per}` : '' switch (prescription.kind) { case 'emom': return `${prescription.rounds} min EMOM · ${rangeLabel(prescription.repsPerRound)} reps each minute` case 'repetitions': return prescription.sets ? `${rangeLabel(prescription.sets)} × ${rangeLabel(prescription.reps)} reps${per}` : `${rangeLabel(prescription.reps)} ${prescription.tempo || ''} reps${per}`.replace(/\s+/g, ' ').trim() case 'timed-sets': return prescription.durationSec ? `${rangeLabel(prescription.sets)} × ${durationLabel(prescription.durationSec)}${per}` : `${rangeLabel(prescription.sets)} sets · duration not specified` case 'timed-hold': return `${durationLabel(prescription.durationSec)}${per}` case 'isometric-hold': return `Hold${per}` case 'hanging-practice': return `Goal: ${durationLabel({ min: prescription.goalDurationSec, max: prescription.goalDurationSec })}` default: return '' } } export function restLabel(rest) { if (!rest) return null if (rest.kind === 'remainder-of-interval') return 'Rest: remainder of each minute' if (rest.kind === 'approximate') return `Rest: about ${durationLabel({ min: rest.seconds, max: rest.seconds })}` return `Rest: ${durationLabel(rest.seconds)}` } export function loadLabel(load) { if (!load) return null if (load.bodyweightOnly) return 'Bodyweight only' const parts = [] if ('vestKg' in load) parts.push(load.vestKg === null ? 'Vest load not specified' : `${load.vestKg} kg vest`) if ('dumbbellKg' in load || 'dumbbellKgEach' in load) parts.push('Dumbbell load not specified') if ('ezBarTotalKg' in load) parts.push('EZ-bar load not specified') return parts.join(' · ') }