<template>
    <div class="row m-b-20" @keyup.enter="downloadReport()">
        <div class="col">
            <div class="row m-l-0 m-r-0">
                <div class="col p-l-0 p-r-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 p-l-0 p-r-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-0 p-r-0">
                    <div class="btn btn-lg btn-primary fs-11 w-100 h-100 d-flex justify-content-center align-items-center" @click="downloadReport()">
                        <span>
                            Export
                        </span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

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

export default {
    props: {
        section:{
            type: String,
            required: true
        }
    },
    data(){
        return {
            parameters: {
                startDate: '',
                endDate: '',
            },
        }
    },
    validations: {
        parameters: {
            startDate: {
                required
            },
            endDate: {
                required
            },
        }
    },
    methods: {
        downloadReport(){
            var apiRoute = '';
            if(!this.validate()){ return; }
            switch(this.section) {
                case 'pendingPaymentSection':
                    apiRoute = route('paymentTransactions.export', 'pendingPaymentSection');
                    break;
                case 'paidInvoiceSection':
                    apiRoute = route('paymentTransactions.export', 'paidInvoiceSection');
                    break;
                case 'walletsReportSection':
                    apiRoute = route('walletTransactions.export');
                    break;
            }
            window.open(apiRoute + '?startDate=' + this.parameters.startDate + '&endDate=' + this.parameters.endDate, '_blank');
        },
        updateDocumentType(documentType) {
            this.parameters.type = documentType;
            this.selectedDocumentStatus = !this.selectedDocumentStatus
        }
    },
    mixins: [componentHandler]
};
</script>
