import React from 'react'
import { usePage } from '@inertiajs/react'
import StudioLayout from '../../Layouts/StudioLayout'
import { studioSurface, trackStudioEvent } from '../../utils/studioEvents'
const kpiConfig = [
{ key: 'total_content', label: 'Total content', icon: 'fa-solid fa-table-cells-large' },
{ key: 'views_30d', label: 'Views', icon: 'fa-solid fa-eye' },
{ key: 'appreciation_30d', label: 'Reactions', icon: 'fa-solid fa-heart' },
{ key: 'shares_30d', label: 'Shares / Saves', icon: 'fa-solid fa-share-nodes' },
{ key: 'comments_30d', label: 'Comments', icon: 'fa-solid fa-comments' },
{ key: 'followers', label: 'Followers', icon: 'fa-solid fa-user-group' },
]
function KpiCard({ config, value }) {
return (
{typeof value === 'number' ? value.toLocaleString() : value}
)
}
function QuickCreateCard({ item }) {
return (
trackStudioEvent('studio_quick_create_used', {
surface: studioSurface(),
module: item.key,
meta: {
href: item.url,
label: item.label,
},
})}
className="rounded-[24px] border border-sky-300/20 bg-sky-300/10 p-4 text-sky-100 transition hover:border-sky-300/35 hover:bg-sky-300/15"
>
New {item.label}
Jump straight into the dedicated {item.label.toLowerCase()} creation workflow.
)
}
function RecentPublishCard({ item }) {
return (
{item.module_label}
{item.title}
Published {new Date(item.published_at || item.updated_at).toLocaleDateString()}
)
}
function ContinueWorkingCard({ item }) {
return (
{item.module_label}
{item.title}
Updated {new Date(item.updated_at || item.created_at).toLocaleDateString()}
)
}
function ScheduledItemCard({ item }) {
return (
{item.module_label}
{item.title}
Scheduled {new Date(item.scheduled_at || item.published_at).toLocaleString()}
)
}
function ActivityRow({ item }) {
return (
{item.title}
{item.module_label}
{item.body}
)
}
function GrowthHint({ item }) {
return (
{item.title}
{item.body}
{item.label}
)
}
function ChallengeWidget({ challenge }) {
return (
{challenge.official ? 'Official challenge' : 'Community challenge'}
{challenge.title}
{challenge.status}
{challenge.prompt || challenge.description}
{Number(challenge.entries_count || 0).toLocaleString()} entries
{challenge.is_joined ? `${challenge.submission_count} submitted` : 'Not joined'}
)
}
function FeaturedStatusCard({ item }) {
return (
{item.module_label}
{item.title}
{item.subtitle || item.visibility || 'Selected for profile presentation'}
)
}
function CommandCenterColumn({ title, items = [], empty, renderItem }) {
return (
{title}
{items.length > 0 ? items.map(renderItem) :
{empty}
}
)
}
function InsightBlock({ item }) {
const toneClasses = {
positive: 'border-emerald-400/20 bg-emerald-400/10 text-emerald-100',
warning: 'border-amber-400/20 bg-amber-400/10 text-amber-100',
action: 'border-sky-400/20 bg-sky-400/10 text-sky-100',
neutral: 'border-white/10 bg-white/[0.03] text-slate-200',
}
return (
trackStudioEvent('studio_insight_clicked', {
surface: studioSurface(),
module: 'overview',
meta: {
insight_key: item.key,
href: item.href,
},
})}
className={`block rounded-[24px] border p-4 transition hover:border-white/20 ${toneClasses[item.tone] || toneClasses.neutral}`}
>
{item.title}
{item.body}
{item.cta}
)
}
function TopPerformerCard({ item }) {
return (
{item.image_url && (

)}
{item.module_label}
{item.title}
{item.subtitle || item.visibility}
{Number(item.metrics?.views || 0).toLocaleString()} views
{Number(item.metrics?.appreciation || 0).toLocaleString()} reactions
{Number(item.metrics?.comments || 0).toLocaleString()} comments
)
}
function RecentComment({ comment }) {
return (
{comment.author_name}
{' '}on{' '}
{comment.item_title}
{comment.body}
{new Date(comment.created_at).toLocaleDateString()}
)
}
export default function StudioDashboard() {
const { props } = usePage()
const overview = props.overview || {}
const analytics = props.analytics || {}
const kpis = overview.kpis || {}
const widgetVisibility = overview.preferences?.widget_visibility || {}
const showWidget = (key) => widgetVisibility[key] !== false
return (
{kpiConfig.map((config) => (
))}
Readable insights
{(overview.insight_blocks || []).map((item) => (
))}
{showWidget('module_summaries') &&
{(overview.module_summaries || []).map((item) => (
{item.label}
{Number(item.count || 0).toLocaleString()}
{Number(item.published_count || 0).toLocaleString()} published
{Number(item.trend_value || 0).toLocaleString()} {item.trend_label || 'recent'}
{Number(item.draft_count || 0).toLocaleString()} drafts
{Number(item.archived_count || 0).toLocaleString()} archived
))}
}
Quick create
Start with any module
{(overview.quick_create || []).map((item) => (
))}
{showWidget('active_challenges') &&
{(overview.active_challenges?.items || []).map((item) => )}
}
{showWidget('featured_status') &&
{overview.featured_status?.selected_count || 0}/{overview.featured_status?.target_count || 4}
modules have a selected featured item
{(overview.featured_status?.missing_modules || []).length} missing
{(overview.featured_status?.items || []).slice(0, 3).map((item) => )}
}
{showWidget('creator_health') &&
{overview.creator_health?.score || 0}
blended workflow health score
}
{showWidget('continue_working') &&
{(overview.continue_working || []).map((item) => )}
}
{showWidget('scheduled_items') &&
{(overview.scheduled_items || []).slice(0, 4).map((item) => )}
}
{overview.top_performers?.length > 0 ? (
{overview.top_performers.map((item) => (
))}
) : (
Nothing has enough activity yet to rank here.
)}
{showWidget('draft_reminders') &&
}
{showWidget('recent_activity') &&
Recent publishes
{(overview.recent_publishes || []).slice(0, 4).map((item) => (
))}
Inbox feed
{(overview.recent_activity || []).slice(0, 4).map((item) => (
))}
}
Growth hints
{(overview.growth_hints || []).map((item) => (
))}
{(overview.recent_comments || []).length > 0 ? (
overview.recent_comments.map((comment) =>
)
) : (
No comments yet
)}
Momentum
{[
['Views', analytics.totals?.views],
['Reactions', analytics.totals?.appreciation],
['Shares', analytics.totals?.shares],
['Comments', analytics.totals?.comments],
].map(([label, value]) => (
{label}
{Number(value || 0).toLocaleString()}
))}
{showWidget('stale_drafts') &&
{(overview.stale_drafts || []).map((item) => )}
}
)
}