<?php
session_start();

if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit();
}
$is_admin_or_manager = in_array($_SESSION['user_role'], ['Admin', 'Manager']);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Performance Guide - Digify OS</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
</head>
<body class="bg-gray-100">
    <div class="flex flex-col md:flex-row min-h-screen" x-data="{ sidebarOpen: false }">
        <!-- Sidebar -->
        <div :class="{'translate-x-0': sidebarOpen, '-translate-x-full': !sidebarOpen}" class="w-64 bg-gray-800 text-white p-4 fixed inset-y-0 left-0 transform md:relative md:translate-x-0 transition-transform duration-200 ease-in-out z-30">
            <h1 class="text-2xl font-bold mb-10">Digify OS</h1>
            <nav>
                <?php if ($is_admin_or_manager): ?>
                    <a href="dashboard.php" class="flex items-center gap-3 py-2.5 px-4 rounded hover:bg-gray-700">Dashboard</a>
                    <a href="employees.php" class="flex items-center gap-3 mt-2 py-2.5 px-4 rounded hover:bg-gray-700">Employees</a>
                    <a href="reports.php" class="flex items-center gap-3 mt-2 py-2.5 px-4 rounded hover:bg-gray-700">Reports</a>
                    <a href="leave-management.php" class="flex items-center gap-3 mt-2 py-2.5 px-4 rounded hover:bg-gray-700">Leave Management</a>
                <?php else: ?>
                    <a href="employee-profile.php?id=<?php echo $_SESSION['user_id']; ?>" class="flex items-center gap-3 py-2.5 px-4 rounded hover:bg-gray-700">My Profile</a>
                <?php endif; ?>
                <a href="leave-request.php" class="flex items-center gap-3 mt-2 py-2.5 px-4 rounded hover:bg-gray-700">Leave Request</a>
                <a href="change-password.php" class="flex items-center gap-3 mt-2 py-2.5 px-4 rounded hover:bg-gray-700">Change Password</a>
                <a href="logout.php" class="flex items-center gap-3 mt-2 py-2.5 px-4 rounded hover:bg-gray-700">Logout</a>
                <a href="guide.php" class="flex items-center gap-3 mt-4 border-t border-gray-700 pt-4 py-2.5 px-4 rounded bg-gray-700">Guide</a>
            </nav>
        </div>

        <!-- Main Content -->
        <div class="flex-1">
            <header class="bg-white shadow-sm p-4 flex justify-between items-center">
                <button class="md:hidden" @click.stop="sidebarOpen = !sidebarOpen">
                    <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" /></svg>
                </button>
                <h2 class="text-xl font-bold text-gray-800">Performance Guide</h2>
                <div class="text-sm"><?php echo htmlspecialchars($_SESSION['user_name']); ?></div>
            </header>
            <main class="p-6 md:p-10">
                <div class="max-w-4xl mx-auto bg-white p-8 rounded-lg shadow">
                    <h1 class="text-3xl font-bold text-center mb-2">Digify OS - Employee Performance Guide 🚀</h1>
                    <p class="text-center text-gray-600 mb-8">Hello Team, yeh guide aapko naya performance system samajhne mein madad karegi.</p>

                    <div class="space-y-8">
                        <!-- Rating Score Section -->
                        <div>
                            <h2 class="text-2xl font-semibold text-gray-800 border-b pb-2 mb-4">1. Rating Score (5 mein se) ⭐</h2>
                            <p class="text-gray-700 mb-4">Yeh aapka overall performance score hai, jo aapki daily performance aur attendance par depend karta hai.</p>
                            <ul class="list-disc list-inside space-y-2">
                                <li><strong>Present (Kaam par ઉપસ્થિત):</strong> Aapki rating aapke kaam ke production ke aadhar par 0 se 5 ke beech mein calculate ki jayegi. <br><span class="text-sm text-gray-500 font-mono">Formula: (Kiye gaye tasks / Assign kiye gaye tasks) * 5</span></li>
                                <li><strong>CL (Casual Leave):</strong> Agar aap CL par hain, to aapki us din ki rating automatically <strong>4.5 / 5</strong> maani jayegi.</li>
                                <li><strong>Absent (Anupasthit):</strong> Agar aap Absent hain, to aapki us din ki rating <strong>0 / 5</strong> maani jayegi.</li>
                            </ul>
                        </div>

                        <!-- Production Score Section -->
                        <div>
                            <h2 class="text-2xl font-semibold text-gray-800 border-b pb-2 mb-4">2. Production Score (%) 🎯</h2>
                            <p class="text-gray-700 mb-4">Yeh score batata hai ki aapne aapko assign kiye gaye kaam ka kitna pratishat (%) poora kiya hai. Yeh score sirf aapke <strong>kaam karne waale dino</strong> (Working Days) par hi calculate hota hai.</p>
                             <ul class="list-disc list-inside space-y-2">
                                <li><strong>Working Days kya hain?</strong> Jin dino aap ya to <strong>Present</strong> the ya <strong>CL</strong> par the. "Absent" waale din is calculation mein nahi gine jaate.</li>
                                <li><strong>Kaise Calculate Hota Hai?</strong> Hum poore mahine mein aapko assign kiye gaye saare tasks ko jodte hain, aur phir aapke dwara poore kiye gaye tasks se divide karte hain. <br><span class="text-sm text-gray-500 font-mono">Formula: (Poore kiye gaye tasks / Assign kiye gaye tasks) * 100</span></li>
                            </ul>
                        </div>

                        <!-- Quality Score Section -->
                        <div>
                            <h2 class="text-2xl font-semibold text-gray-800 border-b pb-2 mb-4">3. Quality Score (%) ✨</h2>
                            <p class="text-gray-700 mb-4">Yeh score aapki kaam ki quality aur time management ko darshata hai. Iska seedha sambandh aapke pending kaam se hai.</p>
                            <ul class="list-disc list-inside space-y-2">
                                <li><strong>Kaise Calculate Hota Hai?</strong> Har employee mahine ki shuruaat <strong>100%</strong> Quality Score ke saath karta hai. Aapke dwara chhode gaye har ek pending task ke liye, aapke mahine ke Quality Score se <strong>1%</strong> kam ho jayega.</li>
                                <li><strong>Important Note:</strong> Yeh score sirf un dino ke liye calculate hota hai jab aap <strong>Present</strong> the. Agar aapne poore mahine kaam nahi kiya, to yeh <strong>N/A</strong> (Not Applicable) dikhega.</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </main>
        </div>
    </div>
</body>
</html>
