<template>
    <div class="row">
        <div class="col">
            <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 restore this order?</div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col p-r-5">
                            <div class="btn btn-sm btn-default btn-block b-rad-none" data-dismiss="modal">Cancel</div>
                        </div>
                        <div class="col p-l-5">
                            <div class="btn btn-sm btn-success btn-block b-rad-none" @click="submitForm">Restore</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import route from '@/general/functions/router';
import { useComponentHandler } from '@/composables/useComponentHandler';
import { useQueueStore } from '@/stores/queue';
import { useFormHandler } from '@/composables/useFormHandler';

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

const { item } = useComponentHandler(props);
const queueStore = useQueueStore();
const { submit, closeModal } = useFormHandler(props);
const isLoading = ref(false);

const submitForm = async () => {
    isLoading.value = true;

    await submit(
        route('api.booking.restore', item.value.id),
        'put',
        props.section,
        true,
        true,
        undefined,
        {
            successHandler: () => {
                isLoading.value = false;
                closeModal();
                queueStore.reloadList({ name: 'customerTransferListSection' });
                queueStore.reloadList({ name: 'transferSection' });
            },
            errorHandler: () => {
                isLoading.value = false;
            }
        }
    );
};
</script>
