"use client";

import { ShieldAlert, Users, Activity } from "lucide-react";
import { LogStats } from "./AdminActivityLogsDashboard";

type Props = {
    stats: LogStats | null;
    loading: boolean;
};

export default function ActivityStatsPanel({ stats, loading }: Props) {
    if (loading || !stats) {
        return (
            <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
                {[...Array(3)].map((_, i) => (
                    <div key={i} className="bg-white border border-slate-200 rounded-xl p-5 shadow-sm animate-pulse h-[116px]"></div>
                ))}
            </div>
        );
    }

    return (
        <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
            <div className="bg-white border border-slate-200 rounded-xl p-5 shadow-sm">
                <div className="flex items-start justify-between">
                    <div>
                        <p className="text-sm font-medium text-slate-500 mb-1">Total Actions (24h)</p>
                        <h3 className="text-2xl font-bold text-slate-800">{stats.last24h.totalActions.toLocaleString()}</h3>
                    </div>
                    <div className="p-2.5 bg-blue-50 text-blue-600 rounded-lg">
                        <Activity className="w-5 h-5" />
                    </div>
                </div>
                <p className="text-xs text-slate-500 mt-3 pt-3 border-t border-slate-100">
                    Platform-wide administrative operations
                </p>
            </div>

            <div className="bg-white border border-slate-200 rounded-xl p-5 shadow-sm">
                <div className="flex items-start justify-between">
                    <div>
                        <p className="text-sm font-medium text-slate-500 mb-1">Active Admins (24h)</p>
                        <h3 className="text-2xl font-bold text-slate-800">{stats.last24h.uniqueAdmins}</h3>
                    </div>
                    <div className="p-2.5 bg-indigo-50 text-indigo-600 rounded-lg">
                        <Users className="w-5 h-5" />
                    </div>
                </div>
                <p className="text-xs text-slate-500 mt-3 pt-3 border-t border-slate-100">
                    Unique admin accounts performing actions
                </p>
            </div>

            <div className={`bg-white border rounded-xl p-5 shadow-sm ${stats.last24h.suspiciousEvents > 0 ? 'border-amber-200 bg-amber-50/30' : 'border-slate-200'}`}>
                <div className="flex items-start justify-between">
                    <div>
                        <p className={`text-sm font-medium mb-1 ${stats.last24h.suspiciousEvents > 0 ? 'text-amber-700' : 'text-slate-500'}`}>
                            Suspicious Events (24h)
                        </p>
                        <h3 className={`text-2xl font-bold ${stats.last24h.suspiciousEvents > 0 ? 'text-amber-800' : 'text-slate-800'}`}>
                            {stats.last24h.suspiciousEvents}
                        </h3>
                    </div>
                    <div className={`p-2.5 rounded-lg ${stats.last24h.suspiciousEvents > 0 ? 'bg-amber-100 text-amber-600' : 'bg-slate-50 text-slate-400'}`}>
                        <ShieldAlert className="w-5 h-5" />
                    </div>
                </div>
                <p className={`text-xs mt-3 pt-3 border-t ${stats.last24h.suspiciousEvents > 0 ? 'text-amber-600 font-medium border-amber-100' : 'text-slate-500 border-slate-100'}`}>
                    {stats.last24h.suspiciousEvents > 0 ? "Requires immediate review" : "No critical events detected"}
                </p>
            </div>
        </div>
    );
}
