<script setup>
import { defineProps } from 'vue'
const props = defineProps(['order_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";
import { useRouter } from "vue-router";

const router = useRouter();

const exportOrderToInvoice = async () => {
  await authenticatedRequest('/economic/invoice/export','post',{
    order_id: props.order_id
  }) .then((response) => {
    // Get the department id from the route
    const departmentId = router.currentRoute.value.params.departmentId;
    // Send the user to the department dashboard
    location.href = '/admin/' + departmentId + '/';
  }).catch((error) => {
    handleEconomicError(error);
  });
};
</script>

<template>
  <LoadButtonWhileAwait class="is-success is-inverted" :loadFunction="exportOrderToInvoice" icon="fas fa-file-invoice"> Gennemfør </LoadButtonWhileAwait>
</template>

<style scoped>

</style>