<?php require './partials/head.php';
require '../config/message/error_success.php';
?>

<body>
    <?php require './partials/sidebar.php' ?>

    <main class="dashboard-main">
        <?php require './partials/header.php' ?>

        <div class="dashboard-main-body">
            <div class="d-flex flex-wrap align-items-center justify-content-between gap-3 mb-24">
                <h6 class="fw-semibold mb-0">Manage Edit Shipping Form</h6>
                <ul class="d-flex align-items-center gap-2">
                    <li class="fw-medium">
                        <a href="dashboard" class="d-flex align-items-center gap-1 hover-text-primary">
                            <iconify-icon icon="solar:home-smile-angle-outline" class="icon text-lg"></iconify-icon>
                            Dashboard
                        </a>
                    </li>
                    <li>-</li>
                    <li class="fw-medium">Shipping Form</li>
                </ul>
            </div>
            <?php
            $unique_Id = null;
            if (isset($_GET['unique_Id'])) {
                $unique_Id = $_GET['unique_Id'];
                $query = "SELECT * FROM packages WHERE unique_Id = ?";
                $stmt = $conn->prepare($query);
                $stmt->bind_param("s", $unique_Id);
                $stmt->execute();
                $result = $stmt->get_result();
                $row = $result->fetch_assoc();
                $badgeClass = ($row['status'] == 'active') ? 'bg-success' : 'bg-info';
            } else {
                echo "<div class='alert alert-danger' role='alert'>No Unique Id specified.</div>";
                exit;
            }
            ?>

            <div class="card h-100 p-0 radius-12">
                <div class="card-body p-24">
                    <div class="row">
                        <div class="card-body">
                            <div class="card d-flex">
                                <p><strong>Receiver Name:</strong> <span class="receiver-text"><?= $row['user_name'] ?></span></p>
                            </div>
                            <div class="card d-flex">
                                <p><strong>Receiver Email:</strong> <span class="receiver-text"><?= $row['user_email'] ?></span></p>
                            </div>
                        </div>
                        <style>
                            p {
                                font-family: Arial, sans-serif;
                                font-size: 16px;
                                font-weight: bold;
                            }

                            .receiver-text {
                                font-family: "Courier New", monospace;
                                font-size: 18px;
                                color: #007bff;
                                font-weight: normal;
                            }
                        </style>
                    </div>
                    <div class="row justify-content-center">
                        <div class="col-xxl-6 col-xl-8 col-lg-10">
                            <div class="card border">
                                <div class="card-body">
                                    <form action="../controller/model.php" method="post">
                                        <div class="mb-20">
                                            <label for="current_location" class="form-label fw-semibold text-primary-light text-sm mb-8">Shipping Current Location</label>
                                            <input type="text" value="<?= $row['current_location'] ?>" name="current_location" class="form-control radius-8" id="current_location" placeholder="Enter Shipping Current Location">
                                            <input type="hidden" name="delivery_Id" value="<?= $unique_Id; ?>">
                                        </div>
                                        <div class="mb-20">
                                            <label for="receiver_address" class="form-label fw-semibold text-primary-light text-sm mb-8">Receiver Address</label>
                                            <input type="text" value="<?= $row['receiver_address'] ?>" name="receiver_address" class="form-control radius-8" id="receiver_address" placeholder="Enter Receiver Address">
                                        </div>
                                        <div class="mb-20">
                                            <label for="expected_delivery_date" class="form-label fw-semibold text-primary-light text-sm mb-8">Expected Delivery Date</label>
                                            <input type="date" value="<?= $row['expected_delivery_date'] ?>" name="expected_delivery_date" class="form-control radius-8" id="expected_delivery_date">
                                        </div>
                                        <div class="mb-20">
                                            <label for="pickup_date" class="form-label fw-semibold text-primary-light text-sm mb-8">Pickup Date</label>
                                            <input type="date" value="<?= $row['pickup_date'] ?>" name="pickup_date" class="form-control radius-8" id="pickup_date">
                                        </div>
                                        <div class="mb-20">
                                            <label for="pickup_time" class="form-label fw-semibold text-primary-light text-sm mb-8">Pickup Time</label>
                                            <input type="time" value="<?= $row['pickup_time'] ?>" name="pickup_time" class="form-control radius-8" id="pickup_time">
                                        </div>

                                        <div class="d-flex align-items-center justify-content-center gap-3">
                                            <button type="button" class="border border-danger-600 bg-hover-danger-200 text-danger-600 text-md px-56 py-11 radius-8">
                                                Cancel
                                            </button>
                                            <button type="submit" name="submit_update_shipping" class="btn btn-primary border border-primary-600 text-md px-56 py-12 radius-8">
                                                Save
                                            </button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php require './partials/footer.php' ?>
    </main>
    <?php require './partials/scripts.php' ?>

    <script>
        // ================== Image Upload Js Start ===========================
        function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();
                reader.onload = function(e) {
                    $('#imagePreview').css('background-image', 'url(' + e.target.result + ')');
                    $('#imagePreview').hide();
                    $('#imagePreview').fadeIn(650);
                }
                reader.readAsDataURL(input.files[0]);
            }
        }
        $("#imageUpload").change(function() {
            readURL(this);
        });
        // ================== Image Upload Js End ===========================
    </script>
</body>

</html>