<script setup>
import { defineProps } from 'vue'
const props = defineProps(['invoice_id'])
import { authenticatedRequest } from "@/components/session/authenticatedRequest.vue";
import LoadButtonWhileAwait from "@/components/request/LoadButtonWhileAwait.vue";
import { handleEconomicError } from "@/components/request/HandleEconomicError.vue";
import { ref } from "vue";

const getOrderPDF = async () => {
  await authenticatedRequest('/invoices/pdf?id=' + props.invoice_id,
      'GET',{
  }) .then((response) => {
    // Open the PDF in a new tab
    window.open(response.data.data.url, '_blank');
  }).catch((error) => {
    handleEconomicError(error);
  });
};
</script>

<template>
  <LoadButtonWhileAwait class="is-dark" :loadFunction="getOrderPDF" icon="fas fa-file-pdf"> Hent faktura PDF </LoadButtonWhileAwait>
</template>

<style scoped>

</style>