<?php

header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Authorization");

date_default_timezone_set('Asia/Kolkata');

// ============================================================
// OPTIONS
// ============================================================

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    http_response_code(200);
    exit();
}

// ============================================================
// ERROR HANDLING
// ============================================================

ini_set('display_errors', '0');
error_reporting(E_ALL);

set_exception_handler(function ($e) {

    http_response_code(500);

    echo json_encode([
        "success" => false,
        "message" => "Server PHP error.",
        "error" => $e->getMessage(),
        "file" => basename($e->getFile()),
        "line" => $e->getLine()
    ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);

    exit();
});

// ============================================================
// DATABASE
// ============================================================

require_once '../config.php';

// ============================================================
// RESPONSE
// ============================================================

function sendResponse(
    int $statusCode,
    bool $success,
    string $message,
    array $extra = []
): void {

    http_response_code($statusCode);

    echo json_encode(
        array_merge(
            [
                "success" => $success,
                "message" => $message
            ],
            $extra
        ),
        JSON_UNESCAPED_UNICODE |
        JSON_UNESCAPED_SLASHES
    );

    exit();
}

// ============================================================
// POST ONLY
// ============================================================

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {

    sendResponse(
        405,
        false,
        "Only POST method is allowed."
    );
}

// ============================================================
// READ INPUT
// ============================================================

$rawData = file_get_contents("php://input");

$data = json_decode(
    $rawData,
    true
);

if (!is_array($data)) {
    $data = $_POST;
}

// ============================================================
// USER ID
// IMPORTANT: STRING - SUPPORTS BS01, EMP028 ETC.
// ============================================================

$userId = trim(
    (string)($data['user_id'] ?? '')
);

if ($userId === '') {

    sendResponse(
        400,
        false,
        "Valid user_id is required."
    );
}

$today = date('Y-m-d');

$currentYear = (int)date('Y');

$currentMonth = (int)date('n');

// ============================================================
// VALIDATE USER
// ============================================================

$stmt = $conn->prepare("
    SELECT
        id,
        username,
        role,
        first_name,
        last_name,
        designation,
        photo,
        profile_photo
    FROM users
    WHERE CAST(id AS CHAR) = ?
    LIMIT 1
");

if (!$stmt) {

    sendResponse(
        500,
        false,
        "Unable to prepare user validation query."
    );
}

$stmt->bind_param(
    "s",
    $userId
);

$stmt->execute();

$result = $stmt->get_result();

if ($result->num_rows === 0) {

    $stmt->close();

    sendResponse(
        404,
        false,
        "User not found."
    );
}

$hrUser = $result->fetch_assoc();

$stmt->close();

// ============================================================
// ROLE
// ============================================================

$role = strtolower(
    trim(
        (string)($hrUser['role'] ?? '')
    )
);

// ============================================================
// ALLOWED ROLES
// ============================================================

$allowedRoles = [
    'hr',
    'superadmin',
    'md'
];

if (!in_array(
    $role,
    $allowedRoles,
    true
)) {

    sendResponse(
        403,
        false,
        "Only HR, MD or Superadmin can access this dashboard."
    );
}

// ============================================================
// DISPLAY NAME
// ============================================================

$firstName = trim(
    (string)($hrUser['first_name'] ?? '')
);

$lastName = trim(
    (string)($hrUser['last_name'] ?? '')
);

$fullName = trim(
    $firstName . ' ' . $lastName
);

if ($fullName === '') {

    $fullName = (string)$hrUser['username'];
}

// ============================================================
// MY ATTENDANCE DEFAULT
// ============================================================

$myAttendance = [

    "status" => "not_checked_in",

    "daily_report_id" => null,

    "report_date" => $today,

    "login_time" => null,

    "logout_time" => null,

    "daily_working_hours" => 0,

    "latitude" => null,

    "longitude" => null,

    "login_latitude" => null,

    "login_longitude" => null,

    "logout_latitude" => null,

    "logout_longitude" => null,

    "location_type" => null,

    "location_address" => null,

    "client_name" => null
];

// ============================================================
// MY TODAY ATTENDANCE
// user_id handled as STRING
// ============================================================

$myAttendanceStmt = $conn->prepare("
    SELECT
        id,
        report_date,
        login_time,
        logout_time,
        daily_working_hours,
        latitude,
        longitude,
        logout_latitude,
        logout_longitude,
        location_type,
        location_address,
        client_name
    FROM daily_reports
    WHERE CAST(user_id AS CHAR) = ?
      AND report_date = ?
    ORDER BY id DESC
    LIMIT 1
");

if ($myAttendanceStmt) {

    $myAttendanceStmt->bind_param(
        "ss",
        $userId,
        $today
    );

    $myAttendanceStmt->execute();

    $myAttendanceResult =
        $myAttendanceStmt->get_result();

    if (
        $myAttendanceRow =
        $myAttendanceResult->fetch_assoc()
    ) {

        $myAttendanceStatus =
            "not_checked_in";

        if (!empty(
            $myAttendanceRow['login_time']
        )) {

            $myAttendanceStatus =
                "checked_in";
        }

        if (!empty(
            $myAttendanceRow['logout_time']
        )) {

            $myAttendanceStatus =
                "checked_out";
        }

        // ====================================================
        // CURRENT LOCATION
        // ====================================================

        if (
            $myAttendanceStatus ===
            'checked_out'
        ) {

            $myCurrentLatitude =
                $myAttendanceRow[
                    'logout_latitude'
                ];

            $myCurrentLongitude =
                $myAttendanceRow[
                    'logout_longitude'
                ];

        } else {

            $myCurrentLatitude =
                $myAttendanceRow[
                    'latitude'
                ];

            $myCurrentLongitude =
                $myAttendanceRow[
                    'longitude'
                ];
        }

        $myAttendance = [

            "status" =>
                $myAttendanceStatus,

            "daily_report_id" =>
                (string)$myAttendanceRow[
                    'id'
                ],

            "report_date" =>
                $myAttendanceRow[
                    'report_date'
                ],

            "login_time" =>
                $myAttendanceRow[
                    'login_time'
                ],

            "logout_time" =>
                $myAttendanceRow[
                    'logout_time'
                ],

            "daily_working_hours" =>
                (float)(
                    $myAttendanceRow[
                        'daily_working_hours'
                    ] ?? 0
                ),

            "latitude" =>
                $myCurrentLatitude,

            "longitude" =>
                $myCurrentLongitude,

            "login_latitude" =>
                $myAttendanceRow[
                    'latitude'
                ],

            "login_longitude" =>
                $myAttendanceRow[
                    'longitude'
                ],

            "logout_latitude" =>
                $myAttendanceRow[
                    'logout_latitude'
                ],

            "logout_longitude" =>
                $myAttendanceRow[
                    'logout_longitude'
                ],

            "location_type" =>
                $myAttendanceRow[
                    'location_type'
                ],

            "location_address" =>
                $myAttendanceRow[
                    'location_address'
                ],

            "client_name" =>
                $myAttendanceRow[
                    'client_name'
                ]
        ];
    }

    $myAttendanceStmt->close();
}

// ============================================================
// MY MONTHLY WORKING HOURS
// ============================================================

$myMonthlyWorkingHours = [

    "total_working_hours" => 0,

    "total_working_minutes" => 0,

    "total_working_days" => 0
];

$myMonthlyStmt = $conn->prepare("
    SELECT
        total_working_hours,
        total_working_minutes,
        total_working_days
    FROM monthly_working_hours
    WHERE CAST(user_id AS CHAR) = ?
      AND year = ?
      AND month = ?
    LIMIT 1
");

if ($myMonthlyStmt) {

    $myMonthlyStmt->bind_param(
        "sii",
        $userId,
        $currentYear,
        $currentMonth
    );

    $myMonthlyStmt->execute();

    $myMonthlyResult =
        $myMonthlyStmt->get_result();

    if (
        $myMonthlyRow =
        $myMonthlyResult->fetch_assoc()
    ) {

        $myMonthlyWorkingHours = [

            "total_working_hours" =>
                (float)(
                    $myMonthlyRow[
                        'total_working_hours'
                    ] ?? 0
                ),

            "total_working_minutes" =>
                (int)(
                    $myMonthlyRow[
                        'total_working_minutes'
                    ] ?? 0
                ),

            "total_working_days" =>
                (int)(
                    $myMonthlyRow[
                        'total_working_days'
                    ] ?? 0
                )
        ];
    }

    $myMonthlyStmt->close();
}

// ============================================================
// GET WORKFORCE
// EMPLOYEE + MANAGER
// ============================================================

$employees = [];

$workforceResult = $conn->query("
    SELECT
        id,
        username,
        role,
        first_name,
        last_name,
        designation,
        photo,
        profile_photo
    FROM users
    WHERE LOWER(TRIM(role)) IN (
        'employee',
        'manager'
    )
    ORDER BY username ASC
");

if (!$workforceResult) {

    sendResponse(
        500,
        false,
        "Unable to load workforce."
    );
}

// ============================================================
// LOOP WORKFORCE
// ============================================================

while (
    $employee =
    $workforceResult->fetch_assoc()
) {

    // IMPORTANT: STRING ID

    $employeeId = trim(
        (string)$employee['id']
    );

    // ========================================================
    // EMPLOYEE NAME
    // ========================================================

    $employeeFirstName =
        trim(
            (string)(
                $employee[
                    'first_name'
                ] ?? ''
            )
        );

    $employeeLastName =
        trim(
            (string)(
                $employee[
                    'last_name'
                ] ?? ''
            )
        );

    $employeeName =
        trim(
            $employeeFirstName .
            ' ' .
            $employeeLastName
        );

    if ($employeeName === '') {

        $employeeName =
            (string)$employee[
                'username'
            ];
    }

    // ========================================================
    // DEFAULT ATTENDANCE
    // ========================================================

    $attendance = [

        "status" =>
            "not_checked_in",

        "daily_report_id" =>
            null,

        "report_date" =>
            $today,

        "login_time" =>
            null,

        "logout_time" =>
            null,

        "daily_working_hours" =>
            0,

        "latitude" =>
            null,

        "longitude" =>
            null,

        "login_latitude" =>
            null,

        "login_longitude" =>
            null,

        "logout_latitude" =>
            null,

        "logout_longitude" =>
            null,

        "location_type" =>
            null,

        "location_address" =>
            null,

        "client_name" =>
            null
    ];

    // ========================================================
    // TODAY ATTENDANCE
    // ========================================================

    $attendanceStmt =
        $conn->prepare("
            SELECT
                id,
                report_date,
                login_time,
                logout_time,
                daily_working_hours,
                latitude,
                longitude,
                logout_latitude,
                logout_longitude,
                location_type,
                location_address,
                client_name
            FROM daily_reports
            WHERE CAST(user_id AS CHAR) = ?
              AND report_date = ?
            ORDER BY id DESC
            LIMIT 1
        ");

    if ($attendanceStmt) {

        $attendanceStmt->bind_param(
            "ss",
            $employeeId,
            $today
        );

        $attendanceStmt->execute();

        $attendanceResult =
            $attendanceStmt
                ->get_result();

        if (
            $attendanceRow =
            $attendanceResult
                ->fetch_assoc()
        ) {

            $attendanceStatus =
                "not_checked_in";

            if (!empty(
                $attendanceRow[
                    'login_time'
                ]
            )) {

                $attendanceStatus =
                    "checked_in";
            }

            if (!empty(
                $attendanceRow[
                    'logout_time'
                ]
            )) {

                $attendanceStatus =
                    "checked_out";
            }

            // =================================================
            // CURRENT LOCATION
            // =================================================

            if (
                $attendanceStatus ===
                'checked_out'
            ) {

                $currentLatitude =
                    $attendanceRow[
                        'logout_latitude'
                    ];

                $currentLongitude =
                    $attendanceRow[
                        'logout_longitude'
                    ];

            } else {

                $currentLatitude =
                    $attendanceRow[
                        'latitude'
                    ];

                $currentLongitude =
                    $attendanceRow[
                        'longitude'
                    ];
            }

            $attendance = [

                "status" =>
                    $attendanceStatus,

                "daily_report_id" =>
                    (string)$attendanceRow[
                        'id'
                    ],

                "report_date" =>
                    $attendanceRow[
                        'report_date'
                    ],

                "login_time" =>
                    $attendanceRow[
                        'login_time'
                    ],

                "logout_time" =>
                    $attendanceRow[
                        'logout_time'
                    ],

                "daily_working_hours" =>
                    (float)(
                        $attendanceRow[
                            'daily_working_hours'
                        ] ?? 0
                    ),

                "latitude" =>
                    $currentLatitude,

                "longitude" =>
                    $currentLongitude,

                "login_latitude" =>
                    $attendanceRow[
                        'latitude'
                    ],

                "login_longitude" =>
                    $attendanceRow[
                        'longitude'
                    ],

                "logout_latitude" =>
                    $attendanceRow[
                        'logout_latitude'
                    ],

                "logout_longitude" =>
                    $attendanceRow[
                        'logout_longitude'
                    ],

                "location_type" =>
                    $attendanceRow[
                        'location_type'
                    ],

                "location_address" =>
                    $attendanceRow[
                        'location_address'
                    ],

                "client_name" =>
                    $attendanceRow[
                        'client_name'
                    ]
            ];
        }

        $attendanceStmt->close();
    }

    // ========================================================
    // MONTHLY HOURS
    // ========================================================

    $monthlyWorkingHours = [

        "total_working_hours" =>
            0,

        "total_working_minutes" =>
            0,

        "total_working_days" =>
            0
    ];

    $monthlyStmt =
        $conn->prepare("
            SELECT
                total_working_hours,
                total_working_minutes,
                total_working_days
            FROM monthly_working_hours
            WHERE CAST(user_id AS CHAR) = ?
              AND year = ?
              AND month = ?
            LIMIT 1
        ");

    if ($monthlyStmt) {

        $monthlyStmt->bind_param(
            "sii",
            $employeeId,
            $currentYear,
            $currentMonth
        );

        $monthlyStmt->execute();

        $monthlyResult =
            $monthlyStmt
                ->get_result();

        if (
            $monthlyRow =
            $monthlyResult
                ->fetch_assoc()
        ) {

            $monthlyWorkingHours = [

                "total_working_hours" =>
                    (float)(
                        $monthlyRow[
                            'total_working_hours'
                        ] ?? 0
                    ),

                "total_working_minutes" =>
                    (int)(
                        $monthlyRow[
                            'total_working_minutes'
                        ] ?? 0
                    ),

                "total_working_days" =>
                    (int)(
                        $monthlyRow[
                            'total_working_days'
                        ] ?? 0
                    )
            ];
        }

        $monthlyStmt->close();
    }

    // ========================================================
    // ADD EMPLOYEE
    // ========================================================

    $employees[] = [

        "user_id" =>
            $employeeId,

        "employee_name" =>
            $employeeName,

        "username" =>
            $employee['username'],

        "role" =>
            strtolower(
                trim(
                    (string)$employee[
                        'role'
                    ]
                )
            ),

        "designation" =>
            $employee[
                'designation'
            ] ?? '',

        "photo" =>
            $employee[
                'photo'
            ] ?? '',

        "profile_photo" =>
            $employee[
                'profile_photo'
            ] ?? '',

        "attendance" =>
            $attendance,

        "monthly_working_hours" =>
            $monthlyWorkingHours
    ];
}

// ============================================================
// ATTENDANCE SUMMARY
// ============================================================

$totalEmployees =
    count($employees);

$todayAttendance =
    0;

$currentlyWorking =
    0;

$checkedOut =
    0;

$notCheckedIn =
    0;

foreach (
    $employees as $employee
) {

    $status =
        $employee[
            'attendance'
        ][
            'status'
        ];

    if (
        $status ===
        'checked_in'
    ) {

        $todayAttendance++;

        $currentlyWorking++;

    } elseif (
        $status ===
        'checked_out'
    ) {

        $todayAttendance++;

        $checkedOut++;

    } else {

        $notCheckedIn++;
    }
}

// ============================================================
// PENDING RESPONSIBILITY REVIEWS
// ============================================================

$pendingResponsibilityReviews =
    0;

$responsibilityStmt =
    $conn->prepare("
        SELECT
            COUNT(*) AS total
        FROM daily_responsibility_updates
        WHERE report_date = ?
          AND evening_completed = 1
          AND status = 'evening_submitted'
    ");

if ($responsibilityStmt) {

    $responsibilityStmt->bind_param(
        "s",
        $today
    );

    $responsibilityStmt->execute();

    $pendingResult =
        $responsibilityStmt
            ->get_result();

    if (
        $pendingRow =
        $pendingResult
            ->fetch_assoc()
    ) {

        $pendingResponsibilityReviews =
            (int)(
                $pendingRow[
                    'total'
                ] ?? 0
            );
    }

    $responsibilityStmt->close();
}

// ============================================================
// KPI PENDING VERIFICATION
// ============================================================

$pendingKpiVerification =
    0;

$kpiPendingResult =
    $conn->query("
        SELECT
            COUNT(*) AS total
        FROM kpi_actuals
        WHERE status = 'manager_approved'
          AND manager_approved = 1
    ");

if (
    $kpiPendingResult &&
    $kpiPendingRow =
    $kpiPendingResult
        ->fetch_assoc()
) {

    $pendingKpiVerification =
        (int)(
            $kpiPendingRow[
                'total'
            ] ?? 0
        );
}

// ============================================================
// VERIFIED KPI
// ============================================================

$verifiedKpiCount =
    0;

$verifiedResult =
    $conn->query("
        SELECT
            COUNT(*) AS total
        FROM kpi_actuals
        WHERE status = 'hr_verified'
    ");

if (
    $verifiedResult &&
    $verifiedRow =
    $verifiedResult
        ->fetch_assoc()
) {

    $verifiedKpiCount =
        (int)(
            $verifiedRow[
                'total'
            ] ?? 0
        );
}

// ============================================================
// NOTIFICATIONS - SAFE VERSION
//
// Does NOT assume:
// is_active
// expires_at
//
// Checks actual table columns first.
// ============================================================

$unreadNotifications = 0;

// ============================================================
// CHECK TABLE EXISTS
// ============================================================

$notificationsTableExists =
    false;

$tableCheckResult =
    $conn->query("
        SHOW TABLES LIKE 'notifications'
    ");

if (
    $tableCheckResult &&
    $tableCheckResult->num_rows > 0
) {

    $notificationsTableExists =
        true;
}

// ============================================================
// PROCESS NOTIFICATIONS
// ============================================================

if ($notificationsTableExists) {

    $notificationColumns =
        [];

    $columnResult =
        $conn->query("
            SHOW COLUMNS
            FROM notifications
        ");

    if ($columnResult) {

        while (
            $columnRow =
            $columnResult
                ->fetch_assoc()
        ) {

            $fieldName =
                $columnRow[
                    'Field'
                ] ?? '';

            if ($fieldName !== '') {

                $notificationColumns[] =
                    $fieldName;
            }
        }
    }

    // ========================================================
    // CHECK AVAILABLE COLUMNS
    // ========================================================

    $hasTargetType =
        in_array(
            'target_type',
            $notificationColumns,
            true
        );

    $hasTargetValue =
        in_array(
            'target_value',
            $notificationColumns,
            true
        );

    // ========================================================
    // TARGET BASED NOTIFICATION
    // ========================================================

    if (
        $hasTargetType &&
        $hasTargetValue
    ) {

        $notificationStmt =
            $conn->prepare("
                SELECT
                    COUNT(*) AS total
                FROM notifications
                WHERE
                    target_type = 'all'

                    OR (
                        target_type = 'role'
                        AND LOWER(
                            TRIM(
                                target_value
                            )
                        ) = ?
                    )

                    OR (
                        target_type = 'user'
                        AND TRIM(
                            target_value
                        ) = ?
                    )
            ");

        if ($notificationStmt) {

            $notificationStmt
                ->bind_param(
                    "ss",
                    $role,
                    $userId
                );

            $notificationStmt
                ->execute();

            $notificationResult =
                $notificationStmt
                    ->get_result();

            if (
                $notificationRow =
                $notificationResult
                    ->fetch_assoc()
            ) {

                $unreadNotifications =
                    (int)(
                        $notificationRow[
                            'total'
                        ] ?? 0
                    );
            }

            $notificationStmt
                ->close();
        }

    } else {

        // ====================================================
        // FALLBACK
        // ====================================================

        $notificationResult =
            $conn->query("
                SELECT
                    COUNT(*) AS total
                FROM notifications
            ");

        if (
            $notificationResult &&
            $notificationRow =
            $notificationResult
                ->fetch_assoc()
        ) {

            $unreadNotifications =
                (int)(
                    $notificationRow[
                        'total'
                    ] ?? 0
                );
        }
    }
}

// ============================================================
// EMPLOYEE LOCATIONS
// ============================================================

$employeeLocations =
    [];

foreach (
    $employees as $employee
) {

    $employeeAttendance =
        $employee[
            'attendance'
        ];

    if (
        $employeeAttendance[
            'latitude'
        ] !== null
        &&
        $employeeAttendance[
            'longitude'
        ] !== null
    ) {

        $employeeLocations[] = [

            "user_id" =>
                $employee[
                    'user_id'
                ],

            "employee_name" =>
                $employee[
                    'employee_name'
                ],

            "username" =>
                $employee[
                    'username'
                ],

            "role" =>
                $employee[
                    'role'
                ],

            "attendance_status" =>
                $employeeAttendance[
                    'status'
                ],

            "latitude" =>
                $employeeAttendance[
                    'latitude'
                ],

            "longitude" =>
                $employeeAttendance[
                    'longitude'
                ],

            "login_latitude" =>
                $employeeAttendance[
                    'login_latitude'
                ],

            "login_longitude" =>
                $employeeAttendance[
                    'login_longitude'
                ],

            "logout_latitude" =>
                $employeeAttendance[
                    'logout_latitude'
                ],

            "logout_longitude" =>
                $employeeAttendance[
                    'logout_longitude'
                ],

            "location_type" =>
                $employeeAttendance[
                    'location_type'
                ],

            "location_address" =>
                $employeeAttendance[
                    'location_address'
                ],

            "client_name" =>
                $employeeAttendance[
                    'client_name'
                ]
        ];
    }
}

// ============================================================
// USER DATA
// ============================================================

$userData = [

    "user_id" =>
        (string)$hrUser[
            'id'
        ],

    "username" =>
        $hrUser[
            'username'
        ],

    "name" =>
        $fullName,

    "employee_name" =>
        $fullName,

    "role" =>
        $role,

    "designation" =>
        $hrUser[
            'designation'
        ] ?? '',

    "photo" =>
        $hrUser[
            'photo'
        ] ?? '',

    "profile_photo" =>
        $hrUser[
            'profile_photo'
        ] ?? '',

    "photo_url" =>
        ""
];

// ============================================================
// SUMMARY
// ============================================================

$summary = [

    "total_employees" =>
        $totalEmployees,

    "present_today" =>
        $todayAttendance,

    "absent_today" =>
        $notCheckedIn,

    "checked_out_today" =>
        $checkedOut,

    "currently_working" =>
        $currentlyWorking
];

// ============================================================
// FINAL RESPONSE
// ============================================================

sendResponse(
    200,
    true,
    "HR dashboard loaded successfully.",
    [

        "date" =>
            $today,

        // ====================================================
        // USER
        // ====================================================

        "user" =>
            $userData,

        // ====================================================
        // HR / ADMIN
        // ====================================================

        "hr" => [

            "user_id" =>
                (string)$hrUser[
                    'id'
                ],

            "username" =>
                $hrUser[
                    'username'
                ],

            "role" =>
                $role
        ],

        // ====================================================
        // OWN ATTENDANCE
        // ====================================================

        "my_attendance" =>
            $myAttendance,

        // ====================================================
        // MONTHLY HOURS
        // ====================================================

        "my_monthly_working_hours" =>
            $myMonthlyWorkingHours,

        // ====================================================
        // SUMMARY
        // ====================================================

        "summary" =>
            $summary,

        // ====================================================
        // ATTENDANCE SUMMARY
        // ====================================================

        "attendance_summary" => [

            "total_employees" =>
                $totalEmployees,

            "today_attendance" =>
                $todayAttendance,

            "currently_working" =>
                $currentlyWorking,

            "checked_out" =>
                $checkedOut,

            "not_checked_in" =>
                $notCheckedIn
        ],

        // ====================================================
        // WORK SUMMARY
        // ====================================================

        "work_summary" => [

            "pending_responsibility_reviews" =>
                $pendingResponsibilityReviews,

            "pending_kpi_hr_verification" =>
                $pendingKpiVerification,

            "verified_kpis" =>
                $verifiedKpiCount
        ],

        // ====================================================
        // NOTIFICATION
        // ====================================================

        "unread_notifications" =>
            $unreadNotifications,

        // ====================================================
        // EMPLOYEES
        // ====================================================

        "employees" =>
            $employees,

        // ====================================================
        // LOCATIONS
        // ====================================================

        "employee_locations" =>
            $employeeLocations
    ]
);

?>