<?php
session_start();

$user_role = $_SESSION['user_role'] ?? 'user';

if(!isset($_SESSION['user_id'])){
    header("Location: /login.php");
    exit;
}

include("../config/db.php");

header('Content-Type: text/html; charset=utf-8');

$username = $_SESSION['username'] ?? 'Admin';
?>

<!DOCTYPE html>
<html lang="es">

<head>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Dashboard - Wolfxell CRM</title>

    <link rel="stylesheet" href="/assets/css/app.css">
    <link rel="stylesheet" href="/assets/css/sidebar.css">

</head>

<body>

<?php include '../includes/sidebar.php'; ?>

<div class="main">

    <div class="topbar">

        <input type="text" placeholder="Buscar..." class="search-input">

        <div class="topbar-right">

            <button class="primary-btn">
                Nuevo contrato
            </button>

            <div class="avatar">
                <?= strtoupper(substr($username,0,1)); ?>
            </div>

        </div>

    </div>

    <div class="content">

        <div class="page-header">

            <h1>
                Bienvenido, <?= htmlspecialchars($username); ?>
            </h1>

            <p>
                Resumen general del CRM
            </p>

        </div>

        <div class="stats-grid">

            <div class="card stat-card">
                <h3>Contratos</h3>
                <div class="stat-number">127</div>
            </div>

            <div class="card stat-card">
                <h3>Campañas</h3>
                <div class="stat-number">4</div>
            </div>

            <div class="card stat-card">
                <h3>Usuarios</h3>
                <div class="stat-number">12</div>
            </div>

        </div>

        <div class="dashboard-grid">

            <div class="card pipeline-card">

                <h2>
                    Pipeline de contratos
                </h2>

                <div class="pipeline-grid">

                    <div class="pipeline-column">

                        <div class="pipeline-title">
                            Nuevo
                        </div>

                        <div class="pipeline-item">
                            Juan Pérez
                        </div>

                        <div class="pipeline-item">
                            María Gómez
                        </div>

                    </div>

                    <div class="pipeline-column">

                        <div class="pipeline-title">
                            En revisión
                        </div>

                        <div class="pipeline-item">
                            Carlos Ruiz
                        </div>

                    </div>

                    <div class="pipeline-column">

                        <div class="pipeline-title">
                            Aprobado
                        </div>

                        <div class="pipeline-item">
                            Ana Torres
                        </div>

                    </div>

                </div>

            </div>

            <div class="card activity-card">

                <h2>
                    Actividad reciente
                </h2>

                <div class="activity-item">
                    Se creó contrato #127
                </div>

                <div class="activity-item">
                    Contrato #125 aprobado
                </div>

                <div class="activity-item">
                    Nuevo usuario agregado
                </div>

                <div class="activity-item">
                    Nueva campaña creada
                </div>

            </div>

        </div>

    </div>

</div>

</body>
</html>