<template>
    <div class="row" @keyup.enter="submitForm">
        <div class="col">
            <loading-component style="height: 200px; top: 0;" key="1" color="success" v-show="isLoading"></loading-component>
            <div class="row" v-show="!isLoading">
                <div class="col">
                    <div class="row">
                        <div class="col">
                            <file-input-component :validator="v$.files" v-model="parameters.files">
                                <template #label>
                                    <div class="font-heading fs-11 text-primary all-caps">Purchase Order PDF</div>
                                </template>
                            </file-input-component>
                        </div>
                    </div>
                    <div class="row m-t-20">
                        <div class="col">
                            <div class="row">
                                <div class="col">
                                    <button type="button" class="btn btn-sm btn-block p-t-10 p-b-10 p-r-35 p-l-35 btn-success b-rad-none" @click="submitForm">Upload</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { useFormHandler } from '@/composables/useFormHandler';
import { required } from '@vuelidate/validators';
import useVuelidate from '@vuelidate/core';
import route from '@/general/functions/router';

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

const { isLoading, parameters, submit } = useFormHandler(props);

parameters.value = {
    files: []
};

const rules = {
    files: { required }
};

const v$ = useVuelidate(rules, parameters);

const submitForm = () => {
    submit(route('api.booking.po.pdf', props.data.id), 'post', props.section, true, false);
};
</script>
