<template>
    <div class="row">
        <div class="col p-r-0">
            <div class="row no-margin">
                <div class="col">
                    <div class="row m-b-20 animated fadeInUpBig fast" v-if="error">
                        <div class="col p-l-50">
                            <small class="bold fs-10 text-danger" >{{error}}</small>
                        </div>
                    </div>
                    <div class="row animated fadeInDownBig">
                        <div class="col b-t b-b b-grey animated" :class="[{'shake': $v.parameters.password.$error}]"  :style="[$v.parameters.password.$error ? {'border-bottom': 'solid 2px red !important'} : {}]">
                            <div class="row align-items-center">
                                <div class="col no-padding bg-white ">
                                    <div class="input-group transparent">
                                        <span class="input-group-addon no-border">
                                            <i class="fa fa-lock fa-fw p-l-15 p-t-20" style="padding-right: 18px;"></i>
                                        </span>
                                        <input v-model="parameters.password" placeholder="New Password" type="password" class="form-control no-border bg-white p-t-35 p-b-35 p-l-0 p-r-0">
                                        <validation-error-component :validator="$v.parameters.password" class="absolute fs-12" style=" top: 10px; right: 15px; z-index: 99;"></validation-error-component>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row animated fadeInUpBig">
                        <div class="col b-t b-b b-grey animated" :class="[{'shake': $v.parameters.confirmPassword.$error}]"  :style="[$v.parameters.confirmPassword.$error ? {'border-bottom': 'solid 2px red !important'} : {}]">
                            <div class="row align-items-center">
                                <div class="col no-padding bg-white ">
                                    <div class="input-group transparent">
                                        <span class="input-group-addon no-border">
                                            <i class="fa fa-lock fa-fw p-l-15 p-t-20" style="padding-right: 18px;"></i>
                                        </span>
                                        <input v-model="parameters.confirmPassword" placeholder="Confirm Password" type="password" class="form-control no-border bg-white p-t-35 p-b-35 p-l-0 p-r-0">
                                        <validation-error-component :validator="$v.parameters.confirmPassword" class="absolute fs-12" style=" top: 10px; right: 15px; z-index: 99;"></validation-error-component>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row m-t-30 align-items-center m-r-0">
                <div class="col-auto animated fadeInLeftBig slower">
                    <a :href="route('login')" @click="$store.dispatch('toggleLoading', {name: 'resetPasswordSection', status: true})">
                        <div class="b-t b-b b-r b-grey all-caps muted p-t-15 p-b-15 p-l-30 p-r-20 font-lato pointer fs-12" style="letter-spacing: 2px;"><i class="fa fa-angle-left" style="padding-right: 18px;"></i>Go to login</div>
                    </a>
                </div>
                <div class="col-auto ml-auto p-r-0 animated fadeInRightBig slow">
                    <div class="bg-success all-caps text-white p-t-15 p-b-15 p-l-50 p-r-20 bold font-lato pointer fs-12" style="letter-spacing: 4px;" @click="submit(route('api.account.authentication.password.reset'), 'post', section, false , false)">Change Password</div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>

    import { required, minLength, sameAs } from "vuelidate/lib/validators";
    import request from '../../../mixins/requestMixin'
    export default {
        props: {
            section: {
                type: String,
                required: true
            },
            token: {
                type: String,
                required: true
            }
        },
        data() {
            return {
                error: '',
                parameters: {
                    token: this.token,
                    password: '',
                    confirmPassword: ''
                }
            };
        },
        validations: {
            parameters: {
                password: {
                    required,
                    minLength: minLength(6)
                },
                confirmPassword: {
                    sameAs: sameAs('password')
                }
            }
        },
        methods:{
            successHandler(){
                this.$store.dispatch('toggleSection', {name: 'resetPasswordSuccess', status: true});
            },
            errorHandler(error){
                this.error = error.message;
            }
        },
        mixins: [request]
    }

</script>