<template>
    <div class="row">
        <div class="col bg-white padding-40 b-rad-lg">
            <loading-component style="height: 50px; top: 0;" key="1" color="success" v-show="$store.getters.isLoading(section)"></loading-component>
            <div class="row" v-show="!$store.getters.isLoading(section)">
                <div class="col">
                    <div class="row m-b-5 animate__animated animate__fadeInUpBig animate__fast" v-if="error">
                        <div class="col">
                            <small class="bold fs-10 text-danger">{{error}}</small>
                        </div>
                    </div>
                    <div class="row m-b-20">
                        <div class="col-12 col-md-8">
                            <validation-wrapper-component selectable class="m-b-15" :validator="$v.parameters.question_set">
                                <label class="text-primary">Question Set</label>
                                <select-component :options="[{'id': 1, 'text': 'Customer Support Satisfaction Survey'}, {'id': 2, 'text': 'First Order Experience Feedback'}, {'id': 3, 'text': 'Sales Inquiry Experience'}]" v-model="parameters.question_set"></select-component>
                            </validation-wrapper-component>
                        </div>

                        <div class="col-12 col-md-8">
                            <validation-wrapper-component selectable class="m-b-15" :validator="$v.parameters.system">
                                <label class="text-primary">System</label>
                                <select-component :options="[{'id': 1, 'text': 'IZYIM'}, {'id': 2, 'text': 'Exchange'}, {'id': 3, 'text': 'Lite'}]" v-model="parameters.system"></select-component>
                            </validation-wrapper-component>
                        </div>

                        <div class="col-12 m-b-15 col-md-8">
                            <validation-wrapper-component :validator="$v.parameters.customer_marking">
                                <label>Customer Marking</label>
                                <input type="text" class="form-control" v-model="parameters.customer_marking" @input="formTouched = true">
                            </validation-wrapper-component>
                        </div>

                        <div class="col-12 m-b-15 col-md-8">
                            <validation-wrapper-component :validator="$v.parameters.email">
                                <label>Email</label>
                                <input type="text" class="form-control" v-model="parameters.email" @input="formTouched = true">
                            </validation-wrapper-component>
                        </div>

                    </div>
                </div>
            </div>
            <div class="row" v-show="!$store.getters.isLoading(section)">
                <div class="col-md-8">
                    <div class="btn btn-sm btn-primary btn-block b-rad-none" :disabled="!$v.$dirty || !$v.$valid" @click="formTouched = true; submitForm()">Generate URL</div>
                </div>
            </div>
            <div class="row m-b-20 m-t-10" v-show="url">
                <div class="col-12 col-md-8">
                    URL Generated: <a target="_blank" :href="'/feedback/' + url">Click here to open at new tab</a>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    import { required } from "vuelidate/lib/validators";
    export default {
        data(){
            return {
                section: 'generateFeedbackLinkForm',
                url: '',
                error: null,
                parameters: {
                    system: '',
                    customer_marking:'',
                    email: '',
                    question_set: '',
                }
            }
        },
        validations: {
            parameters: {
                system: { required },
                customer_marking: { required },
                email: { required },
                question_set: { required },
            }
        },
        methods: {
            successHandler(response){
                this.url = response.payload.data.token;
                this.reset();
            },
            submitForm() {
                this.url = '';
                this.submit(this.route('api.helpmenu.feedback.url.generate'), 'post', this.section, true, true);
            },
            reset(){
                this.parameters.system = '';
                this.parameters.customer_marking = '';
                this.parameters.email = '';
                this.parameters.question_set = '';
                this.$v.$reset();
            }
        }
    }
</script>
