<template>
    <div class="row">
        <div class="col bg-white padding-40 b-rad-lg">
            <loading-component style="height: 300px; top: 0;" key="1" color="success" v-show="isLoading" ></loading-component>
            <div class="row justify-content-center" v-show="!isLoading">
                <div class="col">
                    <div class="row m-b-20">
                        <div class="col">
                            <h3 class="all-caps">Are you Sure?</h3>
                            <div class="fs-11">Are you sure you want to try to regenerate the e-invoice for this payment?</div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col p-r-5">
                            <div class="btn btn-sm btn-success btn-block b-rad-none" data-dismiss="modal">Cancel</div>
                        </div>
                        <div class="col p-l-5">
                            <div class="btn btn-sm btn-danger btn-block b-rad-none" @click="submitForm()">Confirm</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { useFormHandler } from '@/composables/useFormHandler';
import { useQueueStore } from '@/stores/queue';
import route from '@/general/functions/router';

const props = defineProps<{
    section: string;
    data: any;
}>();

const { isLoading, parameters, submit, closeModal } = useFormHandler({ section: props.section });
const queueStore = useQueueStore();

const successHandler = () => {
    closeModal();
    queueStore.reloadList({ name: 'bookingDetailSection' });
};

const submitForm = () => {
    parameters.value.normal_invoice = false;
    parameters.value.e_invoice_try = true;
    submit(route('api.booking.einvoice.try.regenerate', props.data.id), 'post', props.section, true, true, parameters.value, { successHandler });
};
</script>
