<?php
session_start();
$message = "";
$shift_status = "";

$curent_date = (new DateTime())->format('Y-m-d H:i:s');  
if (isset($_POST['clock_in'])) {
    $clock_no = $_POST['clock_no'];
    $sql = "SELECT * FROM admin WHERE clock_no = '$clock_no' AND id='".$_SESSION['user_id']."'";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        $user = $result->fetch_assoc();
        $_SESSION['engineer_id'] = $user['id'];
        header("Location: index?page=dashboard");
        exit();
    } else {
        $message = "Incorrect ID Code.";
    }
}
?>

<div class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-12">
                <h1 class="m-0 text-primary"><?=$page_header;?></h1>
            </div>
        </div>
    </div>
</div>

<section class="content">
    <div class="container-fluid">
        <div class="row justify-content-center">
            <div class="col-lg-6">
                <div class="form-container">
                    <h2>Clock In/  Clock Out</h2>
                    <form method="POST" action="">
                        <input type="text" name="clock_no" placeholder="Enter ID Code" required>
                        <?php if ($shift_status != "active" && $shift_status != "paused"): ?>
                            <button type="submit" name="clock_in">Log In</button>
                        <?php endif; ?>
                    </form>
                    <p class="error-message"><?= $message; ?></p>
                </div>
            </div>
        </div>
    </div>
</section>

<style>
   
    .form-container {
        background: white;
        padding: 30px;
        border-radius: 10px;
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
        text-align: center;
        max-width: 400px;
        width: 100%;
        animation: fadeIn 1s ease-in-out;
    }
    @keyframes fadeIn {
        from { opacity: 0; transform: translateY(-20px); }
        to { opacity: 1; transform: translateY(0); }
    }
    h2 {
        color: #D81B60;
        font-size: 28px;
        font-weight: 600;
        text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
    }
    input[type="text"] {
        width: 100%;
        padding: 12px;
        margin: 10px 0;
        font-size: 16px;
        border: 2px solid #D81B60;
        border-radius: 5px;
        text-align: center;
        transition: 0.3s;
    }
    input[type="text"]:focus {
        border-color: #1E88E5;
        outline: none;
    }
    button {
        width: 100%;
        padding: 12px;
        font-size: 16px;
        background: #1E88E5;
        color: #fff;
        border: none;
        border-radius: 5px;
        cursor: pointer;
        transition: 0.3s;
    }
    button:hover {
        background: #1565C0;
    }
    .error-message {
        margin-top: 10px;
        color: red;
        font-weight: bold;
    }
</style>
