<script>
  function confirmProcessing(uniqueId) {
    Swal.fire({
      title: 'Are you sure?',
      text: "Do you want to confirm processing for this shipment?",
      icon: 'warning',
      showCancelButton: true,
      confirmButtonColor: '#3085d6',
      cancelButtonColor: '#d33',
      confirmButtonText: 'Yes, confirm it!'
    }).then((result) => {
      if (result.isConfirmed) {
        // Send AJAX request to update the status to processing
        fetch('update_status.php', {
            method: 'POST',
            headers: {
              'Content-Type': 'application/json'
            },
            body: JSON.stringify({
              unique_Id: uniqueId,
              status: 'processing'
            })
          })
          .then(response => response.json())
          .then(data => {
            if (data.success) {
              Swal.fire(
                'Confirmed!',
                'The shipment has been confirmed as processing.',
                'success'
              ).then(() => {
                location.reload();
              });
            } else {
              Swal.fire(
                'Error!',
                'Failed to update the status.',
                'error'
              );
            }
          })
          .catch(error => {
            console.error('Error:', error);
            Swal.fire(
              'Error!',
              'An error occurred while updating the status.',
              'error'
            );
          });
      }
    });
  }

  function confirmCompleted(uniqueId) {
    Swal.fire({
      title: 'Are you sure?',
      text: "Do you want to mark this shipment as completed?",
      icon: 'warning',
      showCancelButton: true,
      confirmButtonColor: '#3085d6',
      cancelButtonColor: '#d33',
      confirmButtonText: 'Yes, mark it!'
    }).then((result) => {
      if (result.isConfirmed) {
        // Send AJAX request to update the status to completed
        fetch('update_status.php', {
            method: 'POST',
            headers: {
              'Content-Type': 'application/json'
            },
            body: JSON.stringify({
              unique_Id: uniqueId,
              status: 'completed'
            })
          })
          .then(response => response.json())
          .then(data => {
            if (data.success) {
              Swal.fire(
                'Completed!',
                'The shipment has been marked as completed.',
                'success'
              ).then(() => {
                location.reload();
              });
            } else {
              Swal.fire(
                'Error!',
                'Failed to update the status.',
                'error'
              );
            }
          })
          .catch(error => {
            console.error('Error:', error);
            Swal.fire(
              'Error!',
              'An error occurred while updating the status.',
              'error'
            );
          });
      }
    });
  }

  function confirmDeleteUser(uniqueId) {
    Swal.fire({
      title: 'Are you sure?',
      text: "Do you want to delete this user?",
      icon: 'warning',
      showCancelButton: true,
      confirmButtonColor: '#3085d6',
      cancelButtonColor: '#d33',
      confirmButtonText: 'Yes, delete it!'
    }).then((result) => {
      if (result.isConfirmed) {
        // Send AJAX request to delete the user
        fetch('delete_user', {
            method: 'POST',
            headers: {
              'Content-Type': 'application/json'
            },
            body: JSON.stringify({
              unique_Id: uniqueId
            })
          })
          .then(response => response.json())
          .then(data => {
            if (data.success) {
              Swal.fire(
                'Deleted!',
                'The user has been deleted.',
                'success'
              ).then(() => {
                // location.reload(shipping_user_details);
                window.location.assign('manage-shipping');
              });
            } else {
              Swal.fire(
                'Error!',
                'Failed to delete the user.',
                'error'
              );
            }
          })
          .catch(error => {
            console.error('Error:', error);
            Swal.fire(
              'Error!',
              'An error occurred while deleting the user.',
              'error'
            );
          });
      }
    });
  }


  function showPendingModal(uniqueId) {
    Swal.fire({
      title: 'Pending',
      text: "This shipment is currently pending.",
      icon: 'info',
      confirmButtonText: 'OK'
    });
  }
</script>









<script src="assets/js/lib/jquery-3.7.1.min.js"></script>
<!-- Bootstrap js -->
<script src="assets/js/lib/bootstrap.bundle.min.js"></script>
<!-- Apex Chart js -->
<script src="assets/js/lib/apexcharts.min.js"></script>
<!-- Data Table js -->
<script src="assets/js/lib/dataTables.min.js"></script>
<!-- Iconify Font js -->
<script src="assets/js/lib/iconify-icon.min.js"></script>
<!-- jQuery UI js -->
<script src="assets/js/lib/jquery-ui.min.js"></script>
<!-- Vector Map js -->
<script src="assets/js/lib/jquery-jvectormap-2.0.5.min.js"></script>
<script src="assets/js/lib/jquery-jvectormap-world-mill-en.js"></script>
<!-- Popup js -->
<script src="assets/js/lib/magnifc-popup.min.js"></script>
<!-- Slick Slider js -->
<script src="assets/js/lib/slick.min.js"></script>
<!-- prism js -->
<script src="assets/js/lib/prism.js"></script>
<!-- file upload js -->
<script src="assets/js/lib/file-upload.js"></script>
<!-- audioplayer -->
<script src="assets/js/lib/audioplayer.js"></script>

<!-- main js -->
<script src="assets/js/app.js"></script>

<script src="assets/js/homeTwoChart.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>