import React, { useState, useMemo, useEffect } from 'react';
import { Calendar, User, Users, Edit2, School, Home, ArrowRightLeft, ChevronLeft, ChevronRight } from 'lucide-react';
const KidSchedulePlanner = () => {
const contactPattern = [
// Week 1 (Odd week - Jonno's weekend)
{ week: 1, day: "Monday", workMode: "J Hybrid", dropOff: "H", pickUp: "J", overnight: "J" },
{ week: 1, day: "Tuesday", workMode: "J Hybrid", dropOff: "J", pickUp: "J", overnight: "J" },
{ week: 1, day: "Wednesday", workMode: "", dropOff: "J", pickUp: "H", overnight: "H" },
{ week: 1, day: "Thursday", workMode: "", dropOff: "H", pickUp: "H", overnight: "H" },
{ week: 1, day: "Friday", workMode: "", dropOff: "H", pickUp: "H", overnight: "J" },
{ week: 1, day: "Saturday", workMode: "", dropOff: "J", pickUp: "", overnight: "J" },
{ week: 1, day: "Sunday", workMode: "", dropOff: "J", pickUp: "", overnight: "J" },
// Week 2 (Even week - Hil's weekend)
{ week: 2, day: "Monday", workMode: "J Hybrid", dropOff: "J", pickUp: "J", overnight: "J" },
{ week: 2, day: "Tuesday", workMode: "J Hybrid", dropOff: "J", pickUp: "J", overnight: "J" },
{ week: 2, day: "Wednesday", workMode: "", dropOff: "J", pickUp: "J", overnight: "H" },
{ week: 2, day: "Thursday", workMode: "", dropOff: "H", pickUp: "H", overnight: "H" },
{ week: 2, day: "Friday", workMode: "", dropOff: "H", pickUp: "H", overnight: "H" },
{ week: 2, day: "Saturday", workMode: "", dropOff: "H", pickUp: "", overnight: "H" },
{ week: 2, day: "Sunday", workMode: "", dropOff: "H", pickUp: "", overnight: "H" }
];
const specialDates = {
'2025-12-15': { altered: 'H', notes: '' },
'2025-12-16': { altered: 'J', notes: '' },
'2025-12-17': { altered: 'J', notes: '' },
'2025-12-18': { altered: 'H', notes: '' },
'2025-12-19': { altered: 'H', notes: '' },
'2025-12-20': { altered: 'H', notes: 'Switch routine here. Kids see Hil family' },
'2025-12-21': { altered: 'H', notes: 'Kids see Hil family' },
'2025-12-22': { altered: 'H', notes: 'Hil day off with the kids' },
'2025-12-23': { altered: 'J', notes: 'Jonno day off with the kids' },
'2025-12-24': { altered: 'J', notes: 'Company shutdown - Must book off. Drop kids to Hil evening' },
'2025-12-25': { altered: 'H', notes: 'Bank Holiday - Jonno visit Jesters on Christmas day' },
'2025-12-26': { altered: 'H', notes: 'Jonno pick up to take kids to Norfolk' },
'2025-12-27': { altered: 'J', notes: '' },
'2025-12-28': { altered: 'J', notes: '' },
'2025-12-29': { altered: 'J', notes: 'Company shutdown - Must book off' },
'2025-12-30': { altered: 'J', notes: 'Company shutdown - Must book off' },
'2025-12-31': { altered: 'J', notes: "Company shutdown - Must book off. Hil visit Jib on Eilidh's birthday" },
'2026-01-01': { altered: 'H', notes: 'Bank Holiday' },
'2026-01-02': { altered: 'H', notes: 'Jonno back to work. School holiday' },
'2026-01-03': { altered: 'H', notes: '' },
'2026-01-04': { altered: 'H', notes: '' },
'2026-01-05': { altered: 'H', notes: 'Hil start new job. Inset Day - Dotty and Frank at Jesters to look after the kids' },
'2026-01-06': { altered: 'J', notes: 'Kids back to school' },
'2026-01-07': { altered: 'H', notes: '' },
'2026-01-08': { altered: 'H', notes: '' },
'2026-01-09': { altered: 'H', notes: '' },
'2026-01-10': { altered: 'J', notes: '' },
'2026-01-11': { altered: 'J', notes: '' },
'2026-01-12': { altered: 'J', notes: '' },
'2026-01-13': { altered: 'J', notes: '' },
'2026-01-14': { altered: 'H', notes: '' },
'2026-01-15': { altered: 'H', notes: '' },
'2026-01-16': { altered: 'H', notes: '' },
'2026-01-17': { altered: 'H', notes: '' },
'2026-01-18': { altered: 'H', notes: '' }
};
const schoolTerms2025 = [
{ term: 1, start: '2025-09-03', end: '2025-10-24', days: 38 },
{ term: 2, start: '2025-11-03', end: '2025-12-19', days: 35 },
{ term: 3, start: '2026-01-05', end: '2026-02-13', days: 30 },
{ term: 4, start: '2026-02-23', end: '2026-03-27', days: 25 },
{ term: 5, start: '2026-04-13', end: '2026-05-22', days: 29 },
{ term: 6, start: '2026-06-01', end: '2026-07-22', days: 38 }
];
const schoolHolidays2025 = [
{ name: 'Autumn Half Term', start: '2025-10-27', end: '2025-10-31' },
{ name: 'Christmas', start: '2025-12-22', end: '2026-01-02' },
{ name: 'February Half Term', start: '2026-02-16', end: '2026-02-20' },
{ name: 'Spring/Easter', start: '2026-03-30', end: '2026-04-10' },
{ name: 'May Half Term', start: '2026-05-26', end: '2026-05-29' },
{ name: 'Summer', start: '2026-07-23', end: '2026-08-31' }
];
const ukBankHolidays2026 = [
'2026-01-01', // New Year's Day
'2026-04-03', // Good Friday
'2026-04-06', // Easter Monday
'2026-05-04', // Early May Bank Holiday
'2026-05-25', // Spring Bank Holiday
'2026-08-31', // Summer Bank Holiday
'2026-12-25', // Christmas Day
'2026-12-28' // Boxing Day (substitute)
];
const companyShutdownDates = [
'2025-12-24', // Wed - Christmas Eve
'2025-12-29', // Tue
'2025-12-30', // Wed
'2025-12-31' // Thu - New Year's Eve
];
const generateSchedule = (startDate, endDate) => {
const schedule = [];
const dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const current = new Date(startDate);
const end = new Date(endDate);
const startReference = new Date('2025-10-06');
const daysSinceReference = Math.floor((current - startReference) / (1000 * 60 * 60 * 24));
let patternIndex = ((daysSinceReference % 14) + 14) % 14;
while (current <= end) {
const dateStr = current.toISOString().split('T')[0];
const dayOfWeek = current.getDay();
const dayName = dayNames[dayOfWeek];
const weekNumber = Math.floor(current.getTime() / (1000 * 60 * 60 * 24 * 7));
const is2026OrLater = current.getFullYear() >= 2026;
const adjustedPatternIndex = is2026OrLater ? (patternIndex + 7) % 14 : patternIndex;
const actualPattern = contactPattern[adjustedPatternIndex];
// Determine odd/even week based on pattern
const patternWeek = adjustedPatternIndex < 7 ? 1 : 2;
const isOddWeek = patternWeek === 1;
const override = specialDates[dateStr];
const alteredValue = override ? override.altered : actualPattern.overnight;
const notesValue = override ? override.notes : '';
schedule.push({
week: weekNumber,
day: dayName,
date: dateStr,
current: actualPattern.overnight,
altered: alteredValue,
notes: notesValue,
dropOff: actualPattern.dropOff,
pickUp: actualPattern.pickUp,
overnight: alteredValue,
workMode: actualPattern.workMode,
isOddWeek: isOddWeek,
patternWeek: patternWeek
});
current.setDate(current.getDate() + 1);
patternIndex = (patternIndex + 1) % 14;
}
return schedule;
};
const [scheduleData] = useState(() => generateSchedule('2026-01-01', '2026-12-31'));
const [viewMode, setViewMode] = useState('altered');
const [selectedMonth, setSelectedMonth] = useState(new Date().toISOString().slice(0, 7));
const [editingIndex, setEditingIndex] = useState(null);
const [academicYear, setAcademicYear] = useState('2025-2026');
const [showSchoolInfo, setShowSchoolInfo] = useState(true);
const [showContactPattern, setShowContactPattern] = useState(false);
const [showContactDetails, setShowContactDetails] = useState(false);
// Load saved data from localStorage on mount
const [bookedDaysOff, setBookedDaysOff] = useState(() => {
const saved = localStorage.getItem('kidSchedule_bookedDaysOff');
return saved ? JSON.parse(saved) : {};
});
const [bookedHolidays, setBookedHolidays] = useState(() => {
const saved = localStorage.getItem('kidSchedule_bookedHolidays');
return saved ? JSON.parse(saved) : {};
});
// Save to localStorage whenever bookedDaysOff changes
useEffect(() => {
localStorage.setItem('kidSchedule_bookedDaysOff', JSON.stringify(bookedDaysOff));
}, [bookedDaysOff]);
// Save to localStorage whenever bookedHolidays changes
useEffect(() => {
localStorage.setItem('kidSchedule_bookedHolidays', JSON.stringify(bookedHolidays));
}, [bookedHolidays]);
const currentSchoolTerms = schoolTerms2025;
const currentSchoolHolidays = schoolHolidays2025;
const isSchoolDay = (dateStr) => {
if (!dateStr) return false;
const date = new Date(dateStr);
return currentSchoolTerms.some(term => {
const start = new Date(term.start);
const end = new Date(term.end);
return date >= start && date <= end;
});
};
const isSchoolHoliday = (dateStr) => {
if (!dateStr) return false;
const date = new Date(dateStr);
const holiday = currentSchoolHolidays.find(h => {
const start = new Date(h.start);
const end = new Date(h.end);
return date >= start && date <= end;
});
return holiday ? holiday.name : null;
};
const isBankHoliday = (dateStr) => {
return ukBankHolidays2026.includes(dateStr);
};
const isCompanyShutdown = (dateStr) => {
return companyShutdownDates.includes(dateStr);
};
const filteredData = useMemo(() => {
return scheduleData.filter(d => d.date.startsWith(selectedMonth));
}, [scheduleData, selectedMonth]);
const availableMonths = useMemo(() => {
const months = [...new Set(scheduleData.map(d => d.date.slice(0, 7)))];
return months.sort();
}, [scheduleData]);
const monthStats = useMemo(() => {
const jonno = filteredData.filter(d => d.altered === 'J').length;
const hil = filteredData.filter(d => d.altered === 'H').length;
const school = filteredData.filter(d => isSchoolDay(d.date)).length;
// Company shutdown days (mandatory annual leave)
const shutdownDays = filteredData.filter(d => isCompanyShutdown(d.date));
// Optional days to book off (when Jonno has kids during school holidays)
const optionalDaysOff = filteredData.filter(d => {
const isWeekend = d.day === 'Saturday' || d.day === 'Sunday';
const holidayName = isSchoolHoliday(d.date);
const isBankHol = isBankHoliday(d.date);
const isShutdown = isCompanyShutdown(d.date);
const isFridayWithHilaryPickup = d.day === 'Friday' && d.dropOff === 'H' && d.pickUp === 'H';
return d.altered === 'J' && !isWeekend && holidayName && d.workMode !== 'J Hybrid' && !isFridayWithHilaryPickup && !isBankHol && !isShutdown;
});
// Total days off needed (shutdown + optional)
const totalDaysOff = [...shutdownDays, ...optionalDaysOff];
const holidayDays = filteredData.filter(d => {
const isWeekend = d.day === 'Saturday' || d.day === 'Sunday';
const holidayName = isSchoolHoliday(d.date);
return holidayName && !isWeekend;
});
const bookedCount = totalDaysOff.filter(d => bookedDaysOff[d.date]).length;
const bookedHolidaysCount = holidayDays.filter(d => bookedHolidays[d.date]).length;
return {
jonno,
hil,
total: filteredData.length,
school,
shutdownDays: shutdownDays.length,
optionalDaysOff: optionalDaysOff.length,
potentialDaysOff: totalDaysOff.length,
bookedDaysOff: bookedCount,
daysOffDates: totalDaysOff.map(d => d.date),
holidayDays: holidayDays.length,
bookedHolidaysCount: bookedHolidaysCount
};
}, [filteredData, bookedDaysOff, bookedHolidays]);
const yearStats = useMemo(() => {
// Company shutdown days (mandatory)
const allShutdownDays = scheduleData.filter(d => isCompanyShutdown(d.date));
// Optional days to book off
const allOptionalDaysOff = scheduleData.filter(d => {
const isWeekend = d.day === 'Saturday' || d.day === 'Sunday';
const holidayName = isSchoolHoliday(d.date);
const isBankHol = isBankHoliday(d.date);
const isShutdown = isCompanyShutdown(d.date);
const isFridayWithHilaryPickup = d.day === 'Friday' && d.dropOff === 'H' && d.pickUp === 'H';
return d.altered === 'J' && !isWeekend && holidayName && d.workMode !== 'J Hybrid' && !isFridayWithHilaryPickup && !isBankHol && !isShutdown;
});
// Total days off needed
const allPotentialDaysOff = [...allShutdownDays, ...allOptionalDaysOff];
const allHolidayDays = scheduleData.filter(d => {
const isWeekend = d.day === 'Saturday' || d.day === 'Sunday';
const holidayName = isSchoolHoliday(d.date);
return holidayName && !isWeekend;
});
const bookedCount = allPotentialDaysOff.filter(d => bookedDaysOff[d.date]).length;
const bookedHolidaysCount = allHolidayDays.filter(d => bookedHolidays[d.date]).length;
return {
shutdownDays: allShutdownDays.length,
optionalDays: allOptionalDaysOff.length,
total: allPotentialDaysOff.length,
booked: bookedCount,
remaining: allPotentialDaysOff.length - bookedCount,
holidayTotal: allHolidayDays.length,
holidayBooked: bookedHolidaysCount
};
}, [scheduleData, bookedDaysOff, bookedHolidays]);
const toggleBookedDay = (date) => {
setBookedDaysOff(prev => ({
...prev,
[date]: !prev[date]
}));
};
const toggleBookedHoliday = (date) => {
setBookedHolidays(prev => ({
...prev,
[date]: !prev[date]
}));
};
const clearAllData = () => {
if (confirm('Are you sure you want to clear all saved checkbox data? This cannot be undone.')) {
setBookedDaysOff({});
setBookedHolidays({});
localStorage.removeItem('kidSchedule_bookedDaysOff');
localStorage.removeItem('kidSchedule_bookedHolidays');
}
};
const getParentColor = (parent) => {
if (parent === 'J') return 'bg-blue-100 text-blue-800 border-blue-300';
if (parent === 'H') return 'bg-pink-100 text-pink-800 border-pink-300';
return 'bg-gray-100 text-gray-800 border-gray-300';
};
const navigateMonth = (direction) => {
const currentIndex = availableMonths.indexOf(selectedMonth);
if (direction === 'prev' && currentIndex > 0) {
setSelectedMonth(availableMonths[currentIndex - 1]);
} else if (direction === 'next' && currentIndex < availableMonths.length - 1) {
setSelectedMonth(availableMonths[currentIndex + 1]);
}
};
const currentMonthName = new Date(selectedMonth + '-01').toLocaleDateString('en-GB', {
month: 'long',
year: 'numeric'
});
return (
);
};
export default KidSchedulePlanner;
{/* Header */}
{/* Year Summary */}
{/* Controls */}
{showContactPattern && (
)}
{showSchoolInfo && (
)}
Kid Schedule Planner
Co-parenting made simple
✓ Auto-saves your progress
Year Summary - 2026 Tracking
Company Shutdown
{yearStats.shutdownDays}
Mandatory
Optional Days
{yearStats.optionalDays}
Your choice
Total to Book
{yearStats.total}
Out of 25 days
Booked ✓
{yearStats.booked}
Confirmed
Still to Book
{yearStats.remaining}
Action needed
Contact Pattern (2-2-5-5)
Week 1 Odd - Jonno's Weekend
{contactPattern.slice(0, 7).map((day, idx) => (
{day.day}
{day.overnight}
))}
Week 2 Even - Hil's Weekend
{contactPattern.slice(7, 14).map((day, idx) => (
{day.day}
{day.overnight}
))}
School Year 2025-2026
School Terms
{currentSchoolTerms.map((term, idx) => (
))}
Term {term.term}
{term.days} days
{new Date(term.start).toLocaleDateString('en-GB', { day: 'numeric', month: 'short' })} -
{new Date(term.end).toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric' })}
School Holidays
{currentSchoolHolidays.map((holiday, idx) => (
))}
{holiday.name}
{new Date(holiday.start).toLocaleDateString('en-GB', { day: 'numeric', month: 'short' })} -
{new Date(holiday.end).toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric' })}
| Week | Day | Date | {showSchoolInfo &&School | }Who Has Kids | {showContactDetails && ( <>Drop Off | Pick Up | Work | > )}Day Off? | Holiday? | Notes |
|---|---|---|---|---|---|---|---|---|---|---|
| {item.isOddWeek ? 'Odd' : 'Even'} |
{item.day}
{isShutdown && (
MANDATORY
)}
{isBankHol && !isShutdown && (
BANK HOL
)}
{jonnoNeedsTimeOff && (
BOOK OFF
)}
|
{new Date(item.date).toLocaleDateString('en-GB', { day: 'numeric', month: 'short' })} | {showSchoolInfo && (
{schoolDay ? (
|
)}
{item.altered} | {showContactDetails && ( <>{item.dropOff && {item.dropOff} } | {item.pickUp && {item.pickUp} } | {item.workMode} | > )}{(jonnoNeedsTimeOff || isShutdown) && ( toggleBookedDay(item.date)} className="w-6 h-6 rounded-lg border-2 border-gray-300 text-green-600 focus:ring-4 focus:ring-green-300 cursor-pointer transition-all hover:scale-110" /> )} | {isHolidayDay && ( toggleBookedHoliday(item.date)} className="w-6 h-6 rounded-lg border-2 border-gray-300 text-purple-600 focus:ring-4 focus:ring-purple-300 cursor-pointer transition-all hover:scale-110" /> )} | {item.notes} |
Jonno Days
{monthStats.jonno}
Hil Days
{monthStats.hil}
School Days
{monthStats.school}
Need to Book
{monthStats.potentialDaysOff}
Days Off ✓
{monthStats.bookedDaysOff}
Holidays ✓
{monthStats.bookedHolidaysCount}/{monthStats.holidayDays}

