"use client"; import React, { useState, useEffect } from "react"; import DatePicker from "react-datepicker"; import "react-datepicker/dist/react-datepicker.css"; import { Bar } from 'react-chartjs-2'; import { Chart as ChartJS, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend } from 'chart.js'; ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend); interface Block { name: string; description: string; choices: string[]; } interface SavedData { [key: string]: { blocks: Block[]; completedChoices: boolean[][][]; dailyValueCreation: string[]; dailyMeditations: string[]; dailyAffirmations: string; guidingPrinciples: string; }; } export default function Home() { const initialBlocks: Block[] = [ { name: "1. Prime", description: "Build Your Higher Self", choices: ["Rise early", "God First", "Learn", "Exercise", "Meditation", "Nutrition"], }, { name: "2. Prosper", description: "Create and Monetize Value", choices: ["DW#1 TCF", "DW#2 GrowTime AI", "DW#3 BubbleTech"], }, { name: "3. Play", description: "Enjoy the Best Things Life Has to Offer", choices: ["Quality Time With Loved Ones", "Fun", "Plan and Enjoy Transformational Experiences"], }, { name: "4. Purpose", description: "Contribute Locally and Globally", choices: ["Sagetown", "FUNDEMEX"], }, { name: "5. Peace", description: "Wind Down, Rest Well", choices: ["Meditation", "Sleep early"], }, ]; const [blocks, setBlocks] = useState(initialBlocks); const [completedChoices, setCompletedChoices] = useState( initialBlocks.map((block) => block.choices.map(() => Array(7).fill(false))) ); const [dailyValueCreation, setDailyValueCreation] = useState(Array(7).fill("")); const [dailyMeditations, setDailyMeditations] = useState(Array(7).fill("")); const [dailyAffirmations, setDailyAffirmations] = useState(""); const [guidingPrinciples, setGuidingPrinciples] = useState(""); const [week, setWeek] = useState(""); const [selectedDate, setSelectedDate] = useState(new Date()); const [availableWeeks, setAvailableWeeks] = useState([]); useEffect(() => { const today = new Date(); const firstDayOfWeek = new Date(today); firstDayOfWeek.setDate(today.getDate() - today.getDay() + 1); const lastDayOfWeek = new Date(firstDayOfWeek); lastDayOfWeek.setDate(firstDayOfWeek.getDate() + 6); const options: Intl.DateTimeFormatOptions = { month: "long", day: "numeric", year: "numeric" as "numeric" | "2-digit" }; const currentWeek = `${firstDayOfWeek.toLocaleDateString(undefined, options)} - ${lastDayOfWeek.toLocaleDateString( undefined, options )}`; setWeek(currentWeek); loadData(currentWeek); loadAvailableWeeks(); }, []); const loadAvailableWeeks = () => { const weeks = Object.keys(localStorage) .filter(key => key.startsWith('blocks_')) .map(key => key.replace('blocks_', '')); setAvailableWeeks(weeks); }; const loadData = (week: string) => { const savedBlocks = localStorage.getItem(blocks_${week}); const savedCompletedChoices = localStorage.getItem(completedChoices_${week}); const savedDailyValueCreation = localStorage.getItem(dailyValueCreation_${week}); const savedDailyMeditations = localStorage.getItem(dailyMeditations_${week}); const savedDailyAffirmations = localStorage.getItem(dailyAffirmations_${week}); const savedGuidingPrinciples = localStorage.getItem(guidingPrinciples_${week}); if ( savedBlocks && savedCompletedChoices && savedDailyValueCreation && savedDailyMeditations && savedDailyAffirmations && savedGuidingPrinciples ) { setBlocks(JSON.parse(savedBlocks)); setCompletedChoices(JSON.parse(savedCompletedChoices)); setDailyValueCreation(JSON.parse(savedDailyValueCreation)); setDailyMeditations(JSON.parse(savedDailyMeditations)); setDailyAffirmations(JSON.parse(savedDailyAffirmations)); setGuidingPrinciples(savedGuidingPrinciples); } else { setBlocks(initialBlocks); setCompletedChoices(initialBlocks.map((block) => block.choices.map(() => Array(7).fill(false)))); setDailyValueCreation(Array(7).fill("")); setDailyMeditations(Array(7).fill("")); setDailyAffirmations(""); setGuidingPrinciples(""); } }; const handleDateChange = (date: Date) => { setSelectedDate(date); const firstDayOfWeek = new Date(date); firstDayOfWeek.setDate(date.getDate() - date.getDay() + 1); const lastDayOfWeek = new Date(firstDayOfWeek); lastDayOfWeek.setDate(firstDayOfWeek.getDate() + 6); const options: Intl.DateTimeFormatOptions = { month: "long", day: "numeric", year: "numeric" as "numeric" | "2-digit" }; const selectedWeek = `${firstDayOfWeek.toLocaleDateString(undefined, options)} - ${lastDayOfWeek.toLocaleDateString( undefined, options )}`; setWeek(selectedWeek); loadData(selectedWeek); }; const toggleCompletion = (blockIndex: number, choiceIndex: number, dayIndex: number) => { const updatedCompletedChoices = [...completedChoices]; updatedCompletedChoices[blockIndex][choiceIndex][dayIndex] = !updatedCompletedChoices[blockIndex][choiceIndex][dayIndex]; setCompletedChoices(updatedCompletedChoices); }; const handleValueChange = (dayIndex: number, value: string) => { const updatedDailyValueCreation = [...dailyValueCreation]; updatedDailyValueCreation[dayIndex] = value; setDailyValueCreation(updatedDailyValueCreation); }; const handleMeditationChange = (dayIndex: number, value: string) => { const updatedDailyMeditations = [...dailyMeditations]; updatedDailyMeditations[dayIndex] = value; setDailyMeditations(updatedDailyMeditations); }; const handleAffirmationChange = (value: string) => { setDailyAffirmations(value); }; const handleGuidingPrinciplesChange = (value: string) => { setGuidingPrinciples(value); }; const handleAddChoice = (blockIndex: number) => { const updatedBlocks = [...blocks]; updatedBlocks[blockIndex].choices.push("New Choice"); setBlocks(updatedBlocks); const updatedCompletedChoices = [...completedChoices]; updatedCompletedChoices[blockIndex].push(Array(7).fill(false)); setCompletedChoices(updatedCompletedChoices); }; const handleEditChoice = (blockIndex: number, choiceIndex: number, value: string) => { const updatedBlocks = [...blocks]; updatedBlocks[blockIndex].choices[choiceIndex] = value; setBlocks(updatedBlocks); }; const handleDeleteChoice = (blockIndex: number, choiceIndex: number) => { const updatedBlocks = [...blocks]; updatedBlocks[blockIndex].choices.splice(choiceIndex, 1); setBlocks(updatedBlocks); const updatedCompletedChoices = [...completedChoices]; updatedCompletedChoices[blockIndex].splice(choiceIndex, 1); setCompletedChoices(updatedCompletedChoices); }; const calculateStats = (blockIndex: number) => { const blockChoices = completedChoices[blockIndex]; const totalDays = blockChoices.reduce( (sum, choice) => sum + choice.filter((day) => day).length, 0 ); const totalChoices = blockChoices.length * 7; const blockScore = totalChoices > 0 ? Math.round((totalDays / totalChoices) * 100) : 0; return { totalDays, blockScore }; }; const blockScores = blocks.map((_, index) => calculateStats(index).blockScore); const data = { labels: ["Prime", "Prosper", "Play", "Purpose", "Peace"], datasets: [ { label: 'Completion Percentage', data: blockScores, backgroundColor: 'rgba(75, 192, 192, 0.2)', borderColor: 'rgba(75, 192, 192, 1)', borderWidth: 1, }, ], }; const options = { scales: { y: { beginAtZero: true, max: 100, }, }, }; const saveData = () => { localStorage.setItem(blocks_${week}, JSON.stringify(blocks)); localStorage.setItem(completedChoices_${week}, JSON.stringify(completedChoices)); localStorage.setItem(dailyValueCreation_${week}, JSON.stringify(dailyValueCreation)); localStorage.setItem(dailyMeditations_${week}, JSON.stringify(dailyMeditations)); localStorage.setItem(dailyAffirmations_${week}, JSON.stringify(dailyAffirmations)); localStorage.setItem(guidingPrinciples_${week}, guidingPrinciples); alert("Data saved successfully!"); loadAvailableWeeks(); }; return (

Sacred Choices

Daily Architecture for Optimized Performance

{week}

My Path to Greatness

Guiding Principles