import React from 'react' import { router, usePage } from '@inertiajs/react' import StudioLayout from '../../Layouts/StudioLayout' import { studioSurface, trackStudioEvent } from '../../utils/studioEvents' const kpiItems = [ { key: 'views', label: 'Views', icon: 'fa-eye', color: 'text-emerald-400', bg: 'bg-emerald-500/10' }, { key: 'appreciation', label: 'Reactions', icon: 'fa-heart', color: 'text-pink-400', bg: 'bg-pink-500/10' }, { key: 'shares', label: 'Shares', icon: 'fa-share-nodes', color: 'text-amber-400', bg: 'bg-amber-500/10' }, { key: 'saves', label: 'Saves', icon: 'fa-bookmark', color: 'text-purple-400', bg: 'bg-purple-500/10' }, { key: 'comments', label: 'Comments', icon: 'fa-comment', color: 'text-blue-400', bg: 'bg-blue-500/10' }, { key: 'followers', label: 'Followers', icon: 'fa-user-group', color: 'text-cyan-300', bg: 'bg-cyan-400/10' }, ] const rangeOptions = [7, 14, 30, 60, 90] function formatShortDate(value) { const date = new Date(value) if (Number.isNaN(date.getTime())) return value return date.toLocaleDateString(undefined, { month: 'short', day: 'numeric' }) } function TrendChart({ title, subtitle, points, colorClass, fillClass, icon }) { const values = (points || []).map((point) => Number(point.value || 0)) const maxValue = Math.max(...values, 1) return (

{title}

{subtitle}

{(points || []).map((point) => { const height = `${Math.max(8, Math.round((Number(point.value || 0) / maxValue) * 100))}%` return (
{Number(point.value || 0).toLocaleString()}
{formatShortDate(point.date)}
) })}
) } export default function StudioAnalytics() { const { props } = usePage() const { totals, topContent, moduleBreakdown, recentComments, publishingTimeline, viewsTrend, engagementTrend, comparison, insightBlocks, rangeDays, } = props const updateRange = (days) => { trackStudioEvent('studio_filter_used', { surface: studioSurface(), module: 'analytics', meta: { range_days: days, }, }) router.get(window.location.pathname, { range_days: days }, { preserveScroll: true, preserveState: true, replace: true, }) } return (

Analytics window

Performance over the last {rangeDays || 30} days

This view compares module output, shows views and engagement trends over time, and keeps publishing rhythm in the same window.

{rangeOptions.map((days) => ( ))}
{kpiItems.map((item) => (
{item.label}

{(totals?.[item.key] ?? 0).toLocaleString()}

))}

Module breakdown

{(moduleBreakdown || []).map((item) => (
{item.label}
{Number(item.count || 0).toLocaleString()} items
Open
Views
{Number(item.views || 0).toLocaleString()}
Reactions
{Number(item.appreciation || 0).toLocaleString()}
Comments
{Number(item.comments || 0).toLocaleString()}
Shares
{Number(item.shares || 0).toLocaleString()}
))}

Publishing rhythm

{(publishingTimeline || []).map((point) => (
{new Date(point.date).toLocaleDateString(undefined, { month: 'short', day: 'numeric' })} {point.count}
))}

Module comparison

Last {rangeDays || 30} days
{(comparison || []).map((item) => { const viewMax = Math.max(...(comparison || []).map((entry) => Number(entry.views || 0)), 1) const engagementMax = Math.max(...(comparison || []).map((entry) => Number(entry.engagement || 0)), 1) return (
Views {Number(item.views || 0).toLocaleString()}
Engagement {Number(item.engagement || 0).toLocaleString()}
) })}

Readable insights

{(insightBlocks || []).map((item) => (

{item.title}

{item.body}

{item.cta}
))}

Top content

{(topContent || []).map((item) => ( ))}
Module Title Views Reactions Comments Open
{item.module_label} {item.title} {Number(item.metrics?.views || 0).toLocaleString()} {Number(item.metrics?.appreciation || 0).toLocaleString()} {Number(item.metrics?.comments || 0).toLocaleString()} Open

Recent comments

{(recentComments || []).map((comment) => (

{comment.module_label}

{comment.author_name} on {comment.item_title}

{comment.body}

))}
) }