<?php
session_start();

if (!isset($_SESSION['clinic_logged_in']) || $_SESSION['clinic_logged_in'] !== true) {
    header('Location: index.php');
    exit;
}

include 'dbconn.php';

// Logged-in clinic ID
$admin_id = $_SESSION['clinic_id'];

// Clinics (no status filtering shown originally)
$clinicTotalCount = $mysqli->query("SELECT COUNT(*) as total FROM clinics")->fetch_assoc()['total'];

// Basic Information
$basicInfoTotal = $mysqli->query("SELECT COUNT(*) as total FROM basic_information")->fetch_assoc()['total'];
$basicInfoPending = $mysqli->query("
    SELECT COUNT(*) as total 
    FROM basic_information 
    WHERE status = 'Pending' AND clinic_id = '$admin_id'
")->fetch_assoc()['total'];

// Investigational Products
$investigationalTotal = $mysqli->query("SELECT COUNT(*) as total FROM investigational_products")->fetch_assoc()['total'];
$investigationalPending = $mysqli->query("
    SELECT COUNT(*) as total 
    FROM investigational_products 
    WHERE status = 'Pending' AND clinic_id = '$admin_id'
")->fetch_assoc()['total'];


// Principal Investigators
$principalTotal = $mysqli->query("SELECT COUNT(*) as total FROM principal_investigators")->fetch_assoc()['total'];
$principalPending = $mysqli->query("
    SELECT COUNT(*) as total 
    FROM principal_investigators 
    WHERE status = 'Pending' AND clinic_id = $admin_id
")->fetch_assoc()['total'];


// Recruitment Data
$recruitmentTotal = $mysqli->query("SELECT COUNT(*) as total FROM recruitment_data")->fetch_assoc()['total'];
$recruitmentPending = $mysqli->query("
    SELECT COUNT(*) as total 
    FROM recruitment_data 
    WHERE status = 'Pending' AND clinic_id = $admin_id
")->fetch_assoc()['total'];

// Site Facilities
$siteTotal = $mysqli->query("SELECT COUNT(*) as total FROM site_facilities")->fetch_assoc()['total'];
$sitePending = $mysqli->query("
    SELECT COUNT(*) as total 
    FROM site_facilities 
    WHERE status = 'Pending' AND clinic_id = $admin_id
")->fetch_assoc()['total'];

// Study Design
$studyDesignTotal = $mysqli->query("SELECT COUNT(*) as total FROM study_design")->fetch_assoc()['total'];
$studyDesignPending = $mysqli->query("
    SELECT COUNT(*) as total 
    FROM study_design 
    WHERE status = 'Pending' AND clinic_id = $admin_id
")->fetch_assoc()['total'];

?>

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CRA - Clinical Research Analysis
    </title>

    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Nunito:wght@300;400;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="assets/css/bootstrap.css">

    <link rel="stylesheet" href="assets/vendors/iconly/bold.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <link rel="stylesheet" href="assets/vendors/perfect-scrollbar/perfect-scrollbar.css">
    <link rel="stylesheet" href="assets/vendors/bootstrap-icons/bootstrap-icons.css">
    <link rel="stylesheet" href="assets/css/app.css">
    <link rel="shortcut icon" href="assets/images/favicon.svg" type="image/x-icon">
    
</head>
<body>
    <div id="app">
        <div id="sidebar" class="active">
            <div class="sidebar-wrapper active">
                <div class="sidebar-header">
                    <div class="d-flex justify-content-between">
                        <div class="logo">
                            <a href="dashboard.php"><img src="img/logo.png" alt="Logo" style="width: 150px; height:50px" srcset=""></a>
                        </div>
                        <div class="toggler">
                            <a href="#" class="sidebar-hide d-xl-none d-block"><i class="bi bi-x bi-middle"></i></a>
                        </div>
                    </div>
                </div>
                <div class="sidebar-menu">
                    <ul class="menu">
                      
                        <li class="sidebar-item active ">
                            <a href="dashboard.php" class='sidebar-link'>
                                <i class="bi bi-grid-fill"></i>
                                <span>Dashboard</span>
                            </a>
                        </li>

                        <li class="sidebar-item  ">
                            <a href="basic_information.php" class='sidebar-link'>
                                <i class="bi bi-collection-fill"></i>
                                <span>Basic Information</span>
                            </a>
                           
                        </li>

                        <li class="sidebar-item ">
                            <a href="principal_investigators.php" class='sidebar-link'>
                                <i class="bi bi-grid-1x2-fill"></i>
                                <span>Principal Investigator</span>
                            </a>
                        </li>
                        <li class="sidebar-item  ">
                            <a href="study_design.php" class='sidebar-link'>
                                <i class="bi bi-hexagon-fill"></i>
                                <span>Study Design</span>
                            </a>
                        </li>

                        <li class="sidebar-item  ">
                            <a href="site_facility.php" class='sidebar-link'>
                                <i class="bi bi-file-earmark-medical-fill"></i>
                                <span>Site & Facility</span>
                            </a>
                        </li>

                        <li class="sidebar-item  ">
                            <a href="investigational_products.php" class='sidebar-link'>
                                <i class="bi bi-pen-fill"></i>
                                <span>Investigational Product</span>
                            </a>
                        </li>

                        <li class="sidebar-item  ">
                            <a href="requirement_datacollection.php" class='sidebar-link'>
                                <i class="bi bi-grid-1x2-fill"></i>
                                <span>Recruitment & Data<br> Collection</span>
                            </a>
                        </li>
                        
                        <li class="sidebar-item  ">
                            <a href="logout.php" class='sidebar-link'>
                                <i class="bi bi-x-octagon-fill"></i>
                                <span>Log Out</span>
                            </a>
                           
                        </li>

                        

                    </ul>
                </div>
                <button class="sidebar-toggler btn x"><i data-feather="x"></i></button>
            </div>
        </div>
        <div id="main">
            <header class="mb-3">
                <a href="#" class="burger-btn d-block d-xl-none">
                    <i class="bi bi-justify fs-3"></i>
                </a>
            </header>

            <div class="page-heading">
                <h3>Clinics Admin</h3>
            </div>
            <div class="page-content">
             <section class="row">
    <div class="col-12">
        <div class="row">
            <!-- Basic Information -->
            <div class="col-6 col-lg-3 col-md-6">
                <a href="basic_information.php" class="text-decoration-none">
                    <div class="card position-relative">
                       <?php if ($basicInfoPending > 0): ?>
                            <span class="badge bg-danger position-absolute top-0 end-0 m-2"><?= $basicInfoPending ?> Pending</span>
                        <?php endif; ?>
                        <div class="card-body px-3 py-4-5">
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="stats-icon red">
                                        <i class="fas fa-info-circle"></i>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <h6 class="text-muted font-semibold">Basic Information</h6>
                                    <h6 class="font-extrabold mb-0"><?= $basicInfoTotal ?></h6>
                                </div>
                            </div>
                        </div>
                    </div>
                </a>
            </div>

            <!-- Principal Investigator -->
            <div class="col-6 col-lg-3 col-md-6">
                <a href="principal_investigators.php">
                    <div class="card position-relative">
                        <?php if ($principalPending > 0): ?>
                            <span class="badge bg-danger position-absolute top-0 end-0 m-2"><?= $principalPending ?> Pending</span>
                        <?php endif; ?>
                        <div class="card-body px-3 py-4-5">
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="stats-icon purple">
                                        <i class="fas fa-user-md"></i>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <h6 class="text-muted font-semibold">Principal Investigator</h6>
                                    <h6 class="font-extrabold mb-0"><?= $principalTotal ?></h6>
                                </div>
                            </div>
                        </div>
                    </div>
                </a>
            </div>

            <!-- Study Design -->
            <div class="col-6 col-lg-3 col-md-6">
                <a href="study_design.php">
                    <div class="card position-relative">
                        <?php if ($studyDesignPending > 0): ?>
                            <span class="badge bg-danger position-absolute top-0 end-0 m-2"><?= $studyDesignPending ?> Pending</span>
                        <?php endif; ?>
                        <div class="card-body px-3 py-4-5">
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="stats-icon blue">
                                        <i class="fas fa-project-diagram"></i>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <h6 class="text-muted font-semibold">Study Design</h6>
                                    <h6 class="font-extrabold mb-0"><?= $studyDesignTotal ?></h6>
                                </div>
                            </div>
                        </div>
                    </div>
                </a>
            </div>

            <!-- Site & Facility -->
            <div class="col-6 col-lg-3 col-md-6">
                <a href="site_facility.php">
                    <div class="card position-relative">
                        <?php if ($sitePending > 0): ?>
                            <span class="badge bg-danger position-absolute top-0 end-0 m-2"><?= $sitePending ?> Pending</span>
                        <?php endif; ?>
                        <div class="card-body px-3 py-4-5">
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="stats-icon green">
                                        <i class="fas fa-building"></i>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <h6 class="text-muted font-semibold">Site & Facility</h6>
                                    <h6 class="font-extrabold mb-0"><?= $siteTotal ?></h6>
                                </div>
                            </div>
                        </div>
                    </div>
                </a>
            </div>

            <!-- Investigational Product -->
            <div class="col-6 col-lg-3 col-md-6">
                <a href="investigational_products.php">
                    <div class="card position-relative">
                         <?php if ($investigationalPending > 0): ?>
                            <span class="badge bg-danger position-absolute top-0 end-0 m-2"><?= $investigationalPending ?> Pending</span>
                        <?php endif; ?>
                        <div class="card-body px-3 py-4-5">
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="stats-icon red">
                                        <i class="fas fa-pills"></i>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <h6 class="text-muted font-semibold">Investigational Product</h6>
                                    <h6 class="font-extrabold mb-0"><?= $investigationalTotal ?></h6>
                                </div>
                            </div>
                        </div>
                    </div>
                </a>
            </div>

            <!-- Recruitment & Data Collection -->
            <div class="col-6 col-lg-3 col-md-6">
                <a href="requirement_datacollection.php">
                    <div class="card position-relative">
                       <?php if ($recruitmentPending > 0): ?>
                            <span class="badge bg-danger position-absolute top-0 end-0 m-2"><?= $recruitmentPending ?> Pending</span>
                        <?php endif; ?>
                        <div class="card-body px-3 py-4-5">
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="stats-icon purple">
                                        <i class="fas fa-users"></i>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <h6 class="text-muted font-semibold">Recruitment & Data Collection</h6>
                                    <h6 class="font-extrabold mb-0"><?= $recruitmentTotal ?></h6>
                                </div>
                            </div>
                        </div>
                    </div>
                </a>
            </div>

        </div>
    </div>
</section>

            </div>

            <footer>
                <div class="footer clearfix mb-0 text-muted">
                    <div class="float-start">
                        <p>2025 &copy; Phaseon Clinical Research</p>
                    </div>
                    <div class="float-end">
                        <p>Design by PoojaInfotech</p>
                    </div>
                </div>
            </footer>
        </div>
    </div>
    <script src="assets/vendors/perfect-scrollbar/perfect-scrollbar.min.js"></script>
    <script src="assets/js/bootstrap.bundle.min.js"></script>

    <script src="assets/vendors/apexcharts/apexcharts.js"></script>
    <script src="assets/js/pages/dashboard.js"></script>

    <script src="assets/js/main.js"></script>
</body>

</html>