<template>
    <div class="container-fluid  px-0">
        
        <div class="row">
            <div class="col-sm-12">
                <div class="card border-0 bg-transparent">
                    <div class="card-body border-0 bg-white rounded_8">
                        <div class="mb-3">
                            <a class="page-title text-nowrap">
                                <h5>{{ $t('Cuurency') }}</h5>
                            </a>
                        </div>
                            <div class="table-responsive">
                                <form  method="post">
                                    <!-- <div class="col-sm-12">
                                        <div class="card mb-3 border">
                                            <div class="card-header"> <div class="p-2">អាករ[ VAT(%) ] </div></div>
                                            <div class="card-body">
                                                <div class="p-2">
                                                    <input type="text" v-model="allSetting.vat"  class="form-control number-only">
                                                </div>
                                            </div>
                                        </div>
                                    </div> -->
                                    <div class="card mb-3 border">
                                        <div class="card-header">
                                            <div class="p-2">អត្រា( Rate )</div>
                                        </div>
                                        <div class="card-body">
                                            <div class="p-2">
                                                <input type="text" v-model="form.rate"
                                                    class="form-control number-only">
                                            </div>
                                        </div>
                                    </div>
                                    <!-- <div class="col-sm-12">
                                        <div class="card mb-3 border">
                                            <div class="card-header"> <div class="p-2">ស្តុក( Qty alert )</div></div>
                                            <div class="card-body">
                                                <div class="p-2">
                                                    <input type="text"  v-model="allSetting.qty_alert" class="form-control number-only"  >
                                                </div>
                                            </div>
                                        </div>
                                    </div> -->
                                    <div class="d-flex justify-content-end">
                                        <button type="button" :disabled="form.busy" class="btn btn-primary" @click="funUpdateData()">
                                            <img :src="form.busy ? ' /icons/loading.gif ' : '/icons/save.png'"
                                                alt="">
                                            {{ $t('Submit') }}
                                        </button>
                                    </div>
                                </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            form: new Form({
                id: 1,
                rate: 4000,
            }),
        }
    },
    created() {
        this.funGetAllSetting();
    },

    methods: {
        funGetAllSetting() {
            
            axios.get('admin-api/setting')
                .then((res) => {
                    if (res.data == 'User have not permission for this page access.') {
                        this.$router.push({ name: 'noPermission' });
                    }
                    this.form.fill(res.data);
                    
                });
        },
        funUpdateData() {
            this.form.post("admin-api/setting").then((res) => {
                this.funGetAllSetting();
                this.$toast.success(res.data.message);
            }).catch((error) => {
                console.log(error);
            });
        }
    }
}
</script>