<template>
    <section>
        <schema-field v-model="valueCopy.name" :schema="schema.properties.name"></schema-field>
        <schema-field v-model="valueCopy.idStr" :schema="schema.properties.idStr"></schema-field>
        <schema-field v-model="valueCopy.expirationDate" :schema="schema.properties.expirationDate"></schema-field>
        <schema-field v-model="totalVouchers" :schema="schema.properties.totalVouchers"></schema-field>
        <schema-field v-model="valueCopy.totalClaimedVouchers" :schema="schema.properties.totalClaimedVouchers"></schema-field>

        <hr />

        <check-voucher-code :action-id="valueCopy.idStr" :verify-url="`/action/check-voucher`" v-if="valueCopy.totalVouchers > 0"></check-voucher-code>
        <upload-voucher-codes :action-id="valueCopy.id" :upload-url="`/action/import-voucher-codes/${valueCopy.id}`" v-if="valueCopy.id" @updateTotalVoucher="updateTotalVoucher"></upload-voucher-codes>
        <div class="alert alert-info mb-0" role="alert" v-else>Klik op opslaan om hier een csv met voucher codes te uploaden</div>
    </section>
</template>
  
<script>
    import customEditorExtends from '../shared/custom-editor-extends.vue';
    import UploadVoucherCodes from "./upload-voucher-codes.vue";
    import CheckVoucherCode from "./check-voucher-code.vue";

    export default {
    extends: customEditorExtends,
    components: {
        CheckVoucherCode,
        UploadVoucherCodes,
    },
    data() {
        return {
        totalVouchers : this.$props.value.totalVouchers
        };
    },
    methods:{
        updateTotalVoucher(newTotal) {
        this.totalVouchers = newTotal;
        } 
    }
    }
</script>
      