<template>
    <div>

        <div class="row justify-content-center">
            <div class="col-md-6 text-center mb-2">
                <h2 class="heading-section">ĐĂNG NHẬP</h2>
            </div>
        </div>
        <div class="row justify-content-center">
            <div class="col-md-8 col-lg-4">
                <div class="card">

                    <div class="card-body">
                        <div class="login-wrap p-md-3">
                            <div class="text-danger validation-summary-errors text-center"
                                v-show="authStore.errorMessage">
                                <ul>
                                    <li>{{ authStore.errorMessage }}</li>
                                </ul>
                            </div>
                            <Form @submit="onSubmit" :validation-schema="schema" v-slot="{ errors, isSubmitting }">
                                <div class="form-group mb-3">
                                    <label>Tên đăng nhập</label>
                                    <Field name="username" type="text" class="form-control" placeholder="tên đăng nhập"
                                        :class="{ 'is-invalid': errors.username }" />
                                    <div class="invalid-feedback">{{ errors.username }}</div>


                                </div>
                                <div class="form-group mb-3">
                                    <label>Mật khẩu</label>
                                    <Field name="password" type="password" placeholder="mật khẩu" class="form-control"
                                        :class="{ 'is-invalid': errors.password }" />
                                    <div class="invalid-feedback">{{ errors.password }}</div>
                                </div>
                                <!-- <div class="form-group">
                                    <div class="w-50 text-left">
                                        <label class="checkbox-wrap checkbox-primary mb-0">
                                            <input type="checkbox" checked="">
                                            <span class="checkmark"></span>
                                            Ghi nhớ thông tin đăng nhập
                                        </label>
                                    </div>
                                </div> -->
                                <div class="form-group">
                                    <button type="submit" class="btn btn-main-primary btn-block"
                                        :disabled="isSubmitting">
                                        <span v-show="isSubmitting" class="spinner-border spinner-border-sm"></span>
                                        Đăng nhập

                                    </button>

                                </div>

                            </form>
                        </div>
                    </div>

                </div>

            </div>
        </div>
    </div>
</template>
<script setup>
import { Form, Field } from 'vee-validate';
import * as Yup from 'yup';
import { useUserStore } from '@/stores';
const authStore = useUserStore();



const schema = Yup.object().shape({
    username: Yup.string().required('Tên đăng nhập không để trống'),
    password: Yup.string().required('Mật khẩu không để trống')
});

async function onSubmit(values) {

    const { username, password } = values;

    await authStore.login(username, password);
}




</script>