import React, { useState, useRef, useEffect } from 'react'; import confetti from 'canvas-confetti'; import { Brush, Trash2, Download, Sparkles, Heart, Wind, HelpCircle, Shuffle, Check } from 'lucide-react'; import { KINDNESS_CHALLENGES, DISCUSSION_PROMPTS, COLOR_PALETTE } from '../data/storyData'; import { soundManager } from '../utils/audio'; interface ActivityCornerProps { isBedtimeMode: boolean; } export const ActivityCorner: React.FC = ({ isBedtimeMode }) => { // Canvas State const canvasRef = useRef(null); const [isDrawing, setIsDrawing] = useState(false); const [brushColor, setBrushColor] = useState('#60a5fa'); const [brushSize, setBrushSize] = useState(18); const [activeTab, setActiveTab] = useState<'canvas' | 'kindness' | 'breathing' | 'discussion'>('canvas'); // Kindness State const [challengeIndex, setChallengeIndex] = useState(0); const [completedChallenges, setCompletedChallenges] = useState([]); // Breathing State const [breathPhase, setBreathPhase] = useState<'Inhale (Gather Soft Mist)' | 'Hold (Glow with Warmth)' | 'Exhale (Rain Gentle Kindness)'>('Inhale (Gather Soft Mist)'); const [isBreathingActive, setIsBreathingActive] = useState(false); // Initialize Canvas background useEffect(() => { const canvas = canvasRef.current; if (canvas) { const ctx = canvas.getContext('2d'); if (ctx) { ctx.fillStyle = isBedtimeMode ? '#1e1b4b' : '#f0f9ff'; ctx.fillRect(0, 0, canvas.width, canvas.height); } } }, [isBedtimeMode, activeTab]); // Breathing Cycle loop useEffect(() => { let timer: ReturnType; if (isBreathingActive) { const phases: ('Inhale (Gather Soft Mist)' | 'Hold (Glow with Warmth)' | 'Exhale (Rain Gentle Kindness)')[] = [ 'Inhale (Gather Soft Mist)', 'Hold (Glow with Warmth)', 'Exhale (Rain Gentle Kindness)' ]; let idx = 0; setBreathPhase(phases[0]); timer = setInterval(() => { idx = (idx + 1) % phases.length; setBreathPhase(phases[idx]); if (idx === 0) soundManager.playChime(); if (idx === 2) soundManager.playRain(); }, 4000); } return () => clearInterval(timer); }, [isBreathingActive]); // Canvas drawing handlers const startDrawing = (e: React.MouseEvent | React.TouchEvent) => { const canvas = canvasRef.current; if (!canvas) return; const ctx = canvas.getContext('2d'); if (!ctx) return; setIsDrawing(true); const rect = canvas.getBoundingClientRect(); const clientX = 'touches' in e ? e.touches[0].clientX : e.clientX; const clientY = 'touches' in e ? e.touches[0].clientY : e.clientY; const x = (clientX - rect.left) * (canvas.width / rect.width); const y = (clientY - rect.top) * (canvas.height / rect.height); ctx.beginPath(); ctx.moveTo(x, y); ctx.lineCap = 'round'; ctx.lineJoin = 'round'; ctx.strokeStyle = brushColor; ctx.lineWidth = brushSize; }; const draw = (e: React.MouseEvent | React.TouchEvent) => { if (!isDrawing) return; const canvas = canvasRef.current; if (!canvas) return; const ctx = canvas.getContext('2d'); if (!ctx) return; const rect = canvas.getBoundingClientRect(); const clientX = 'touches' in e ? e.touches[0].clientX : e.clientX; const clientY = 'touches' in e ? e.touches[0].clientY : e.clientY; const x = (clientX - rect.left) * (canvas.width / rect.width); const y = (clientY - rect.top) * (canvas.height / rect.height); ctx.lineTo(x, y); ctx.stroke(); }; const stopDrawing = () => { setIsDrawing(false); }; const clearCanvas = () => { soundManager.playFlutter(); const canvas = canvasRef.current; if (!canvas) return; const ctx = canvas.getContext('2d'); if (!ctx) return; ctx.fillStyle = isBedtimeMode ? '#1e1b4b' : '#f0f9ff'; ctx.fillRect(0, 0, canvas.width, canvas.height); }; const downloadCanvas = () => { soundManager.playPop(); const canvas = canvasRef.current; if (!canvas) return; const link = document.createElement('a'); link.download = 'pip-cloud-creation.png'; link.href = canvas.toDataURL(); link.click(); }; // Kindness handlers const handleShuffleKindness = () => { soundManager.playPop(); setChallengeIndex((prev) => (prev + 1) % KINDNESS_CHALLENGES.length); }; const handleCompleteChallenge = (id: number) => { soundManager.playStarCelebration(); setCompletedChallenges((prev) => [...prev, id]); confetti({ particleCount: 50, spread: 60, origin: { y: 0.6 } }); }; const currentChallenge = KINDNESS_CHALLENGES[challengeIndex]; const isChallengeDone = completedChallenges.includes(currentChallenge.id); return (
{/* Header */}
Interactive Activity Studio Creativity • Kindness • Mindfulness • Family Discussion

Pip & Caelum's Creative Meadow

Hands-on interactive experiences designed to extend the storybook's lessons of kindness, self-acceptance, and imaginative problem-solving into real-world family life.

{/* Activity Category Tabs */}
{/* TAB 1: Paint Your Cloud Canvas */} {activeTab === 'canvas' && (

🎨 Paint Your Whispering Cloud Creature

Use Pip's berry pigments to swirl fluffy clouds, raindrops, and flowers!

{/* Canvas Controls */}
{/* Palette picker */}
{COLOR_PALETTE.map((c) => (
{/* Brush Size */}
Size: setBrushSize(parseInt(e.target.value))} className="w-20 accent-amber-500" />
{/* Clear */} {/* Download */}
{/* Drawing Canvas Board */}

Tip: Draw a cloud body, then paint little blushing pink cheeks and golden rainbow drops!

)} {/* TAB 2: Kindness Challenge */} {activeTab === 'kindness' && (
{currentChallenge.icon}
Daily Mission • {currentChallenge.difficulty}

{currentChallenge.title}

"{currentChallenge.description}"

You have completed {completedChallenges.length} of {KINDNESS_CHALLENGES.length} kindness challenges!
)} {/* TAB 3: Bedtime Cloud Breathing */} {activeTab === 'breathing' && (
Mindfulness & Bedtime Regulation

Caelum's Gentle Cloud Breath

Help little bodies settle for sleep or calm down after high-energy emotions.

{/* Rhythmic Expanding/Contracting Breathing Ring */}
☁️ {isBreathingActive ? breathPhase : 'Ready to Breathe'}

Follow the cloud: Breathe in peace, hold warm love, breathe out gentle rain.

)} {/* TAB 4: Family & Educator Discussion Prompts */} {activeTab === 'discussion' && (

Parent, Caregiver & Teacher Circle-Time Guide

Open-ended questions to deepen comprehension and emotional connection

{DISCUSSION_PROMPTS.map((prompt, i) => (
{prompt.category} Q{i + 1}

"{prompt.question}"

Caregiver Guidance: {prompt.guide}
))}
)}
); };