import { useState, useEffect } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Loader2, TrendingUp, Users, CreditCard, Package, ExternalLink, ArrowUpRight } from "lucide-react"; interface Stats { total: number; active: number; pending: number; on_hold: number; cancelled: number; expired: number; monthly_revenue: number; new_this_month: number; subscription_products?: number; } export function OverviewTab() { const [stats, setStats] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { fetchStats(); }, []); const fetchStats = async () => { setLoading(true); try { const apiUrl = window.swiftCommerceData?.apiUrl || '/wp-json/swift-commerce/v1'; const response = await fetch( `${apiUrl}/subscriptions/stats`, { headers: { 'X-WP-Nonce': window.swiftCommerceData?.restNonce || '', }, } ); const data = await response.json(); if (data.success) { setStats(data.stats); } } catch (error) { console.error('Failed to fetch stats:', error); // Set default stats if API fails setStats({ total: 0, active: 0, pending: 0, on_hold: 0, cancelled: 0, expired: 0, monthly_revenue: 0, new_this_month: 0, }); } finally { setLoading(false); } }; const createSubscriptionProduct = () => { window.open('/wp-admin/post-new.php?post_type=product', '_blank'); }; if (loading) { return (
); } return (
{/* Quick Stats */}
Total Subscriptions
{stats?.total || 0}

All time subscriptions created

Active Subscriptions
{stats?.active || 0}

Currently active subscribers

New This Month
{stats?.new_this_month || 0}

Subscriptions started this month

Subscription Products
{stats?.subscription_products || 0}

Products with subscription pricing

{/* Quick Actions */} Quick Actions Common subscription management tasks
); }