<script>
import { authenticatedRequest } from "@/components/session/authenticatedRequest.vue";
import axios from "axios";
import {API_URL} from "@/main.js";
import { SessionUser } from "@/components/session/token/SessionUser.vue";
import Swal from "sweetalert2";

export const downloadWashCertificate = async (id) => {
  // Create a download link
  return authenticatedRequest('/bookings/download_pdf', 'post', {
    id
  });
};

export const showDownloadWashCertificate = async (id) => {
  download(id);
}

const download = (booking_id) => {
  SessionUser.objects.bookings.functions.download(booking_id).then(async (response) => {
    console.log(response, 'success');
    const href = response.data.data.link;
    window.open(href, '_blank');
  }).catch((error) => {
    console.log(error, 'error');
    Swal.fire({
      icon: "error",
      title: "Fejl",
      text: "Der skete en fejl under download af vaskecertifikatet",
      footer: error
    });
  });
}
</script>