'use client'; import { motion } from 'framer-motion'; import { useEffect, useState } from 'react'; // Mock data structure for retention cohort const COHORT_DATA = [ { week: 'Week 1', users: '2,543', retention: [100, 84, 73, 67, 62, 58], }, { week: 'Week 2', users: '2,148', retention: [100, 80, 69, 63, 59, 55], }, { week: 'Week 3', users: '1,958', retention: [100, 82, 71, 64, 60, 56], }, { week: 'Week 4', users: '2,034', retention: [100, 83, 72, 65, 61, 57], }, { week: 'Week 5', users: '1,987', retention: [100, 81, 70, 64, 60, 56], }, { week: 'Week 6', users: '2,245', retention: [100, 85, 74, 68, 64, 60], }, { week: 'Week 7', users: '2,108', retention: [100, 82, 71, 65, 61], }, { week: 'Week 8', users: '1,896', retention: [100, 83, 72, 66], }, { week: 'Week 9', users: '2,156', retention: [100, 81, 70], }, ]; const COHORT_DATA_ALT = [ { week: 'Week 1', users: '2,876', retention: [100, 79, 76, 70, 65, 61], }, { week: 'Week 2', users: '2,543', retention: [100, 85, 73, 67, 62, 58], }, { week: 'Week 3', users: '2,234', retention: [100, 79, 75, 68, 63, 59], }, { week: 'Week 4', users: '2,456', retention: [100, 88, 77, 69, 65, 61], }, { week: 'Week 5', users: '2,321', retention: [100, 77, 73, 67, 54, 42], }, { week: 'Week 6', users: '2,654', retention: [100, 91, 83, 69, 66, 62], }, { week: 'Week 7', users: '2,432', retention: [100, 93, 88, 72, 64], }, { week: 'Week 8', users: '2,123', retention: [100, 78, 76, 69], }, { week: 'Week 9', users: '2,567', retention: [100, 70, 64], }, ]; function RetentionCell({ percentage }: { percentage: number }) { // Calculate color intensity based on percentage const getBackgroundColor = (value: number) => { if (value === 0) return 'bg-transparent'; // Using CSS color mixing to create a gradient from light to dark blue return `rgb(${Math.round(239 - value * 1.39)} ${Math.round(246 - value * 1.46)} ${Math.round(255 - value * 0.55)})`; }; return (
{percentage}%
); } export function ProductAnalyticsFeature() { const [currentData, setCurrentData] = useState(COHORT_DATA); useEffect(() => { const interval = setInterval(() => { setCurrentData((current) => current === COHORT_DATA ? COHORT_DATA_ALT : COHORT_DATA, ); }, 3000); return () => clearInterval(interval); }, []); return (
{/* Header row */}
Cohort
{/* Week numbers - changed length to 6 */}
{Array.from({ length: 6 }).map((_, i) => (
W{i + 1}
))}
{/* Data rows */}
{currentData.map((cohort, rowIndex) => (
{cohort.week}
{cohort.retention.map((value, cellIndex) => ( ))} {/* Fill empty cells - changed length to 6 */} {Array.from({ length: 6 - cohort.retention.length }).map( (_, i) => (
), )}
))}
); }