"use client";

import {
    RocketLaunchIcon,
    ChartBarIcon,
    BriefcaseIcon,
    LifebuoyIcon,
    CreditCardIcon,
    DocumentTextIcon,
    FolderIcon,
    ShareIcon,
    ArrowTrendingUpIcon,
    ArrowTrendingDownIcon,
    CheckCircleIcon,
    ClockIcon,
} from '@heroicons/react/24/outline';

export default function DashboardPage() {
    const overviewStats = [
        { name: 'Receita Total (Mês)', value: 'R$ 124.500', change: '+12%', changeType: 'increase', icon: ChartBarIcon, color: 'green' },
        { name: 'Novos Leads', value: '45', change: '+5%', changeType: 'increase', icon: RocketLaunchIcon, color: 'blue' },
        { name: 'Projetos Ativos', value: '12', change: '-1', changeType: 'decrease', icon: BriefcaseIcon, color: 'purple' },
        { name: 'Chamados Abertos', value: '3', change: '-2', changeType: 'decrease', icon: LifebuoyIcon, color: 'orange' },
    ];

    const modules = [
        {
            title: 'CRM & Vendas',
            icon: RocketLaunchIcon,
            color: 'blue',
            stats: [
                { label: 'Propostas Enviadas', value: '8' },
                { label: 'Aguardando Aprovação', value: '3' },
                { label: 'Taxa de Conversão', value: '24%' },
            ]
        },
        {
            title: 'Financeiro & ERP',
            icon: ChartBarIcon,
            color: 'green',
            stats: [
                { label: 'A Receber', value: 'R$ 45.200' },
                { label: 'A Pagar', value: 'R$ 12.800' },
                { label: 'Fluxo de Caixa', value: 'Positivo' },
            ]
        },
        {
            title: 'Projetos & Tarefas',
            icon: BriefcaseIcon,
            color: 'purple',
            stats: [
                { label: 'Em Andamento', value: '12' },
                { label: 'Atrasados', value: '1' },
                { label: 'Concluídos (Mês)', value: '4' },
            ]
        },
        {
            title: 'Helpdesk',
            icon: LifebuoyIcon,
            color: 'orange',
            stats: [
                { label: 'Novos Chamados', value: '3' },
                { label: 'Tempo Médio Resposta', value: '2h' },
                { label: 'Satisfação', value: '4.8/5' },
            ]
        },
        {
            title: 'Documentos & Contratos',
            icon: DocumentTextIcon,
            color: 'indigo',
            stats: [
                { label: 'Contratos Ativos', value: '28' },
                { label: 'A Vencer (30 dias)', value: '2' },
                { label: 'Docs Armazenados', value: '1.2GB' },
            ]
        },
        {
            title: 'Redes Sociais',
            icon: ShareIcon,
            color: 'pink',
            stats: [
                { label: 'Posts Agendados', value: '14' },
                { label: 'Engajamento', value: '+8.5%' },
                { label: 'Novos Seguidores', value: '120' },
            ]
        }
    ];

    return (
        <div className="p-6 h-full overflow-auto">
            <div className="space-y-8">
                {/* Header */}
                <div>
                    <h1 className="text-2xl font-bold text-gray-900 dark:text-white">
                        Visão Geral da Agência
                    </h1>
                    <p className="mt-1 text-sm text-gray-600 dark:text-gray-400">
                        Acompanhe o desempenho de todos os módulos em tempo real
                    </p>
                </div>

                {/* Top Stats */}
                <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
                    {overviewStats.map((stat) => {
                        const Icon = stat.icon;
                        return (
                            <div
                                key={stat.name}
                                className="relative overflow-hidden rounded-xl bg-white dark:bg-zinc-900 p-4 border border-gray-200 dark:border-zinc-800 shadow-sm"
                            >
                                <div className="flex items-center justify-between">
                                    <div className={`rounded-lg p-2 bg-${stat.color}-50 dark:bg-${stat.color}-900/20`}>
                                        <Icon className={`h-6 w-6 text-${stat.color}-600 dark:text-${stat.color}-400`} />
                                    </div>
                                    <div className={`flex items-baseline text-sm font-semibold ${stat.changeType === 'increase' ? 'text-green-600' : 'text-red-600'
                                        }`}>
                                        {stat.changeType === 'increase' ? (
                                            <ArrowTrendingUpIcon className="h-4 w-4 mr-1" />
                                        ) : (
                                            <ArrowTrendingDownIcon className="h-4 w-4 mr-1" />
                                        )}
                                        {stat.change}
                                    </div>
                                </div>
                                <div className="mt-4">
                                    <p className="text-sm font-medium text-gray-500 dark:text-gray-400">{stat.name}</p>
                                    <p className="text-2xl font-bold text-gray-900 dark:text-white">{stat.value}</p>
                                </div>
                            </div>
                        );
                    })}
                </div>

                {/* Modules Grid */}
                <div>
                    <h2 className="text-lg font-semibold text-gray-900 dark:text-white mb-4">
                        Performance por Módulo
                    </h2>
                    <div className="grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3">
                        {modules.map((module) => {
                            const Icon = module.icon;
                            return (
                                <div
                                    key={module.title}
                                    className="rounded-xl bg-white dark:bg-zinc-900 border border-gray-200 dark:border-zinc-800 p-6 hover:border-gray-200 dark:hover:border-zinc-700 transition-colors"
                                >
                                    <div className="flex items-center gap-3 mb-6">
                                        <div className={`p-2 rounded-lg bg-${module.color}-50 dark:bg-${module.color}-900/20`}>
                                            <Icon className={`h-5 w-5 text-${module.color}-600 dark:text-${module.color}-400`} />
                                        </div>
                                        <h3 className="font-semibold text-gray-900 dark:text-white">
                                            {module.title}
                                        </h3>
                                    </div>
                                    <div className="space-y-4">
                                        {module.stats.map((stat, idx) => (
                                            <div key={idx} className="flex items-center justify-between text-sm">
                                                <span className="text-gray-500 dark:text-gray-400">{stat.label}</span>
                                                <span className="font-medium text-gray-900 dark:text-white">{stat.value}</span>
                                            </div>
                                        ))}
                                    </div>
                                </div>
                            );
                        })}
                    </div>
                </div>
            </div>
        </div>
    );
}
