<template>
    <div class="row col-md-10 col-md-offset-1">
        <div class="col-md-12">

            <h4 class="text-center">PENGESAHAN KEHADIRAN</h4>
            <hr />

            <h5 class="text-center">
                <a href="https://drive.google.com/file/d/1O5DVDIbGy-w0bejV6RqtJGIty-_5LJD8/view" download>>>Muat Turun Etika Mesyuarat Agung << </a>
            </h5>

            <form @submit.prevent="edit()" id="edit_form">
                <div class="form-group">
                    <label for="name">Nama : </label>
                    <input type="text" name="name" class="form-control" readonly :value="data.user.name" required />
                </div>

                <div class="form-group">
                    <label for="no_kp">No. Kad Pengenalan :</label>
                    <input type="text" name="no_kp" class="form-control" readonly :value="data.user.no_kp" required />
                </div>

                <div class="form-group">
                    <label for="no_anggota">No. Anggota : </label>
                    <input type="text" name="no_anggota" class="form-control" readonly :value="data.user.no_anggota"
                        required />
                </div>

                <div class="form-group">
                    <label for="no_anggota">Unit : </label>
                    <input type="text" name="unit" class="form-control" readonly :value="data.user.unit" required />
                </div>

                <div class="form-group">
                    <label for="role">Kehadiran :</label>
                    <select class="form-control" id="kehadiran" name="kehadiran" value="" required>
                        <option value="1">Fizikal</option>
                        <option value="2">Maya</option>
                    </select>
                </div>

                <div class="mb-2">

                    <p> <i>*Pendaftaran akan dibuka dari <b>jam 7.00 pagi sehingga 10.00 pagi (01 May 2024)</b></i></p>
                    <p> <i>*Di maklumkan juga bahawa <b>elaun kehadiran</b> berjumlah <b>RM300.00 (secara fizikal)</b>
                            akan diberikan secara TUNAI <br>kepada anggota selepas selesai mesyuarat dan <b>RM150
                                (secara atas talian)</b> akan dikreditkan ke akaun anggota yang hadir dari awal hingga
                            tamat.</i></p>
                </div>

                <div class="text-center">
                    <input type="submit" value="SAYA TERIMA" class="btn btn-primary"
                        v-if="data.election.status == 2 && data.user.kehadiran == 0" />
                </div>
               
            </form>
        </div>
    </div>
</template>



<script>
export default {
    data: function () {
        return {
            loading: false,
            userSubmitted: false // Add a flag to track if the user has already submitted
        }
    },

    methods: {
        // refreshUser: function () {

        //     var vm = this;
        //     axios.get(config.API + 'voter/' + this.data.user.id)
        //         .then(response => {
        //             vm.data.user = response.data;
        //             console.log(response.data)
        //         })
        // },



        edit: function () {
            if (this.loading) return;
            this.loading = true;
            var vm = this;
            this.util.notify('Adding Attendance', 'loading');
            axios.put(config.API + 'attendance/' + this.data.user.id, $('#edit_form').serialize())
                .then(response => {
                    $.notifyClose();
                    vm.loading = false;
                    if (vm.util.showResult(response, 'success')) {
                        // vm.refreshUser();
                        location.reload();


                    }
                })
                .catch(error => {
                    $.notifyClose();
                    vm.loading = false;
                    vm.util.showResult(error, 'error')
                })
        }
    }
}
</script>