<template>
    <div class="row m-b-15">
        <div class="col-12">
            <div class="row">
                <div class="col-12">
                    <div class="row m-l-0 m-r-0">
                        <div class="col mb-2 mb-md-0 p-l-3 p-r-3 p-md-0">
                            <validation-wrapper-component selectable :validator="$v.parameters.supplier">
                                <label>Supplier</label>
                                <selectable-component :disableOnFetch="true" :endpoint="route('api.company.list')  + '?filters=' + JSON.stringify({'business_type': 3, 'status_in': [1, 2, 0]})" section="exportSupplierFilterSection" valueColumn="id" :labelColumn="['name']" v-model="parameters.supplier"></selectable-component>
                            </validation-wrapper-component>
                        </div>
                        <div class="col mb-2 mb-md-0 p-l-3 p-r-3 p-md-0">
                            <validation-wrapper-component :validator="$v.parameters.startDate">
                                <label class="all-caps">Start Date</label>
                                <date-picker-component :parameters="parameters" v-model.lazy="parameters.startDate"></date-picker-component>
                            </validation-wrapper-component>
                        </div>
                        <div class="col mb-2 mb-md-0 p-l-3 p-r-3 p-md-0">
                            <validation-wrapper-component :validator="$v.parameters.endDate">
                                <label class="all-caps">End Date</label>
                                <date-picker-component :parameters="parameters" v-model.lazy="parameters.endDate"></date-picker-component>
                            </validation-wrapper-component>
                        </div>
                        <div class="col-auto p-l-3 p-r-3 p-md-0">
                            <div class="btn btn-lg btn-primary fs-11 w-100 h-100 d-flex justify-content-center align-items-center" @click="bulkDownloadWhiteForm()">
                                <span>
                                    Export
                                </span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row align-items-center justify-content-center bg-white p-t-50 p-b-50 p-l-15 p-r-15 margin-15" v-if="returnData">
                <div class="col-10">
                    <div class="row align-items-center justify-content-center  hint-text">
                        <div class="col-4 hint-text"><img src="/images/not-found-illustration.png" class="w-100 hint-text" /></div>
                    </div>
                    <div class="row text-center">
                        <div class="col">
                            <div class="row m-t-20">
                                <div class="col">
                                    <p class="all-caps no-margin fs-11" :class="[{'text-danger': returnData.status == 'Error'}]" style="letter-spacing: 2px;">{{ returnData.message }}</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import componentHandler from "../../../general/mixins/componentHandler";
import { required } from "vuelidate/lib/validators";

export default {
    data(){
        return {
            returnData: null,
            parameters: {
                startDate: '',
                endDate: '',
                supplier: ''
            },
        }
    },
    validations: {
        parameters: {
            supplier: {
                required
            },
            startDate: {
                required
            },
            endDate: {
                required
            },
        }
    },
    methods: {
        bulkDownloadWhiteForm(){
            this.submit(this.route('api.suppliers.white_forms'), 'post', this.section, false, false);
        },
        successHandler(response) {
            this.isLoading = false;
            if (response.message) {
                this.returnData = response;
            } else {
                this.returnData = null;
            }
        },
    },
    mixins: [componentHandler]
};
</script>
