// Pediatric guidelines for baby routines by age
// Based on AAP recommendations

export interface Guideline {
  minAgeMonths: number;
  maxAgeMonths: number;
  label: string;
  feeds: { times: number; notes: string };
  sleep: { totalHours: number; notes: string };
  diapers: { count: number; notes: string };
}

export const guidelines: Guideline[] = [
  {
    minAgeMonths: 0,
    maxAgeMonths: 1,
    label: "Newborn (0-1 mo)",
    feeds: { times: 8, notes: "On demand, every 2-3 hours" },
    sleep: { totalHours: 16, notes: "Short naps throughout day" },
    diapers: { count: 8, notes: "Wet and dirty" },
  },
  {
    minAgeMonths: 1,
    maxAgeMonths: 3,
    label: "Infant (1-3 mo)",
    feeds: { times: 7, notes: "Every 3-4 hours" },
    sleep: { totalHours: 15, notes: "3-4 naps/day" },
    diapers: { count: 6, notes: "Dirty diapers reduce" },
  },
  {
    minAgeMonths: 3,
    maxAgeMonths: 6,
    label: "Older Infant (3-6 mo)",
    feeds: { times: 6, notes: "Ready for solids around 6 mo" },
    sleep: { totalHours: 14, notes: "2-3 naps/day" },
    diapers: { count: 4, notes: "May start solid foods" },
  },
  {
    minAgeMonths: 6,
    maxAgeMonths: 9,
    label: "Baby (6-9 mo)",
    feeds: { times: 4, notes: "3 meals + 2 snacks" },
    sleep: { totalHours: 13, notes: "2 naps/day" },
    diapers: { count: 4, notes: "Solid foods started" },
  },
  {
    minAgeMonths: 9,
    maxAgeMonths: 12,
    label: "Baby (9-12 mo)",
    feeds: { times: 4, notes: "3 meals + 2 snacks + formula/breast milk" },
    sleep: { totalHours: 14, notes: "2 naps/day, 10-12h night" },
    diapers: { count: 4, notes: "4-6 wet diapers expected" },
  },
  {
    minAgeMonths: 12,
    maxAgeMonths: 18,
    label: "Toddler (12-18 mo)",
    feeds: { times: 3, notes: "3 meals + 2 snacks" },
    sleep: { totalHours: 13, notes: "1 nap + 11h night (11-14h total)" },
    diapers: { count: 4, notes: "4-6 wet diapers" },
  },
  {
    minAgeMonths: 18,
    maxAgeMonths: 24,
    label: "Toddler (18-24 mo)",
    feeds: { times: 3, notes: "3 meals + 2 snacks" },
    sleep: { totalHours: 12, notes: "1 nap + 10-11h night (11-14h total)" },
    diapers: { count: 3, notes: "3-5 wet, potty training begins" },
  },
];

export function getGuideline(birthDate: string): Guideline {
  const birth = new Date(birthDate);
  const now = new Date();
  const months = (now.getTime() - birth.getTime()) / (1000 * 60 * 60 * 24 * 30);

  return (
    guidelines.find((g) => months >= g.minAgeMonths && months < g.maxAgeMonths) ||
    guidelines[guidelines.length - 1]
  );
}

export function getAgeInMonths(birthDate: string): number {
  const birth = new Date(birthDate);
  const now = new Date();
  return Math.floor((now.getTime() - birth.getTime()) / (1000 * 60 * 60 * 24 * 30));
}