<?php
require_once __DIR__ . '/../config/database.php';

$userId = $_SESSION['user_id'] ?? null;

if (!$userId) {
    header("Location: login.php");
    exit;
}

/* ===============================
   COUNT ASSIGNED JOBS
=================================*/
$stmt = $pdo->prepare("
    SELECT COUNT(*) 
    FROM operations_tickets
    WHERE assigned_to = ? 
    AND status = 'OPEN'
");
$stmt->execute([$userId]);
$openJobs = $stmt->fetchColumn();

/* ===============================
   COUNT COMPLETED JOBS
=================================*/
$stmt = $pdo->prepare("
    SELECT COUNT(*) 
    FROM operations_tickets
    WHERE assigned_to = ? 
    AND status = 'CLOSED'
");
$stmt->execute([$userId]);
$completedJobs = $stmt->fetchColumn();
?>

<div class="main-content">

    <div class="page-header">
        <h2>Installer Dashboard</h2>
        <p class="page-subtitle">
            Welcome, <?= htmlspecialchars($_SESSION['full_name']) ?>
        </p>
    </div>

    <div class="card">
        <h4>My Open Jobs</h4>
        <p><?= (int)$openJobs ?></p>
    </div>

    <div class="card">
        <h4>Completed Jobs</h4>
        <p><?= (int)$completedJobs ?></p>
    </div>

</div>