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

<body>
    <?php require './partials/sidebar.php'; ?>
    <main class="dashboard-main fade-in">
        <?php require './partials/header.php'; ?>
        <div class="dashboard-main-body">
            <?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();
                $receiverDetaials = $result->fetch_assoc();
                $badgeClass = ($receiverDetaials['status'] == 'active') ? 'bg-success' : 'bg-info';
            } else {
                echo "<div class='alert alert-danger' role='alert'>No user specified.</div>";
                exit;
            }
            ?>
            <div class="row">
                <p><strong>User Details</strong></p>
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-header ">
                            <div class="row">
                                <div class="col-md-7"></div>
                                <div class="col-md-12">
                                    <?php
                                    $status = $receiverDetaials['status'];
                                    ?>
                                    <a href="javascript:void(0)<?= $unique_Id ?>"
                                        class="btn btn text-white-50 me-2 mb-2 deletereceiverDetaialsButton"
                                        style="background-color: black;">User Rent History</a>

                                    <?php if ($status == 'pending') : ?>
                                        <button type="button"
                                            id="pendingBtn<?= $unique_Id; ?>"
                                            class="btn btn-info me-2 mb-2 deletereceiverDetaialsButton"
                                            data-id="<?= $unique_Id; ?>"
                                            onclick="showPendingModal(<?= $unique_Id; ?>)">
                                            <i class="fas fa-hourglass-half"></i> Pending
                                        </button>
                                        <button type="button"
                                            class="btn btn-warning me-2 mb-2"
                                            data-id="<?= $unique_Id; ?>"
                                            onclick="confirmProcessing('<?= $unique_Id; ?>')">
                                            <i class="fas fa-shipping-fast"></i> Confirm Processing
                                        </button>
                                    <?php endif; ?>

                                    <?php if ($status == 'processing') : ?>
                                        <button type="button"
                                            class="btn btn-success me-2 mb-2"
                                            data-id="<?= $unique_Id; ?>"
                                            onclick="confirmCompleted('<?= $unique_Id; ?>')">
                                            <i class="fas fa-check"></i> Mark as Completed
                                        </button>
                                    <?php endif; ?>

                                    <button type="button" class="btn btn-primary me-2 mb-2" onclick="redirectToEditPage('<?= $unique_Id; ?>')" <?= $status == 'completed' ? 'disabled' : ''; ?>>
                                        <i class="fas fa-edit"></i> Edit Shipping Location
                                    </button>
                                    <script>
                                        function redirectToEditPage(unique_Id) {
                                            window.location.href = `edit-shipping-location?unique_Id=${unique_Id}`;
                                        }
                                    </script>
                                    <!-- Delete Button -->
                                    <button type="button"
                                        class="btn btn-danger me-2 mb-2"
                                        data-id="<?= $unique_Id; ?>"
                                        onclick="confirmDeleteUser('<?= $unique_Id; ?>')">
                                        <i class="fas fa-trash"></i> Delete
                                    </button>
                                </div>
                            </div>
                        </div>

                        <style>
                            .card {
                                margin-top: 20px;
                            }

                            .card-img-top {
                                padding-left: 10px;
                            }

                            .cardd {
                                padding-left: 15px;
                                padding-right: 15px;
                                background-color: white;
                            }

                            .fade-in {
                                opacity: 0;
                                animation: fadeIn 2s 1s forwards;
                            }

                            @keyframes fadeIn {
                                to {
                                    opacity: 1;
                                }
                            }
                        </style>
                        <div class="background-container fade-in">
                            <div class="row">
                                <div class="col-lg-3 col-md-3">
                                    <div class="card cardd fade-in">
                                        <img class="card-img-top img-thumbnail" src="./KycImg/profile.png" alt="Card image cap">
                                    </div>
                                </div>
                                <div class="col-lg-9 col-md-9">
                                    <div class="card">
                                        <div class="card-header fade-in">
                                            <h3 class="animate__animated animate__fadeInTopLeft animate__delay-1s">Shipping Details</h3>
                                        </div>
                                        <div class="card-body">
                                            <div class="table-responsive">
                                                <table id="mainTable" class="table table-hover m-b-0">
                                                    <thead>
                                                        <tr class="fade-in">
                                                            <th>Details</th>
                                                            <th>Information</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <tr>
                                                            <th>User Name</th>
                                                            <td><?= $receiverDetaials['user_name'] ?></td>
                                                        </tr>
                                                        <tr>
                                                            <th>User Email</th>
                                                            <td><?= $receiverDetaials['user_email'] ?></td>
                                                        </tr>
                                                        <tr>
                                                            <th>Phone Number</th>
                                                            <td><?= $receiverDetaials['user_number']; ?></td>
                                                        </tr>
                                                        <tr>
                                                            <th>Package Name</th>
                                                            <td><?= $receiverDetaials['package_name']; ?></td>
                                                        </tr>
                                                        <tr>
                                                            <th>Current Location</th>
                                                            <td><?= $receiverDetaials['current_location']; ?></td>
                                                        </tr>
                                                        <tr>
                                                            <th>Receiver Address</th>
                                                            <td><?= $receiverDetaials['receiver_address']; ?></td>
                                                        </tr>
                                                        <tr>
                                                            <th>Origin</th>
                                                            <td><?= $receiverDetaials['origin']; ?></td>
                                                        </tr>
                                                        <tr>
                                                            <th>Destination</th>
                                                            <td><?= $receiverDetaials['destination']; ?></td>
                                                        </tr>
                                                        <tr>
                                                            <th>Shipping Type</th>
                                                            <td><?= $receiverDetaials['shipping_type']; ?></td>
                                                        </tr>
                                                        <tr>
                                                            <th>Quality</th>
                                                            <td><?= $receiverDetaials['quality']; ?> Quality</td>
                                                        </tr>
                                                        <tr>
                                                            <th>Weight</th>
                                                            <td><?= $receiverDetaials['weight']; ?> Kg</td>
                                                        </tr>

                                                        <tr>
                                                            <th>Payment Mode</th>
                                                            <td><?= $receiverDetaials['payment_mode']; ?></td>
                                                        </tr>
                                                        <tr>
                                                            <th>Expected Delivery Date</th>
                                                            <td><?= formatDate($receiverDetaials['expected_delivery_date']) ?></td>
                                                        </tr>
                                                        <tr>
                                                            <th>Pickup Date</th>
                                                            <td><?= formatDate($receiverDetaials['pickup_date']) ?></td>
                                                        </tr>
                                                        <tr>
                                                            <th>Pickup Time</th>
                                                            <td><?= date('h:i A', strtotime($receiverDetaials['pickup_time'])) ?></td>
                                                        </tr>
                                                        </tr>
                                                        <tr>
                                                            <th>Amount</th>
                                                            <td><?= formatCurrency($receiverDetaials['amount']); ?></td>
                                                        </tr>
                                                        <tr>
                                                            <th>Comment</th>
                                                            <td colspan="2"><?= $receiverDetaials['comment']; ?></td>
                                                        </tr>
                                                        <tr>
                                                            <th>Status</th>
                                                            <td>
                                                                <?php
                                                                $textClass = '';
                                                                $textLabel = '';
                                                                switch ($receiverDetaials['status']) {
                                                                    case 'completed':
                                                                        $textClass = 'text-success';
                                                                        $textLabel = 'Mark As Completed';
                                                                        break;

                                                                    case 'processing':
                                                                        $textClass = 'text-info';
                                                                        $textLabel = 'Mark As Processing';
                                                                        break;
                                                                    case 'pending':
                                                                    default:
                                                                        $textClass = 'text-warning';
                                                                        $textLabel = 'Pending';
                                                                        break;
                                                                }
                                                                ?>
                                                                <span class="<?= $textClass; ?>">
                                                                    <?= $textLabel; ?>
                                                                </span>
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php require './partials/footer.php'; ?>
        <?php require '../config/message/error_success.php' ?>
    </main>
    <?php require './partials/scripts.php'; ?>
</body>

</html>