<template>
    <div style="margin-top:50px;">
        <v-container grid-list-md pa-10 >
            <v-layout row wrap>
                <v-flex md12>
                    <h1>Admin Settings</h1>
                    <br><br>
                    <v-expansion-panels>
                        <v-expansion-panel>
                            <v-expansion-panel-header>General</v-expansion-panel-header>
                            <v-expansion-panel-content>
                                <v-text-field
                                        label="Big Name"
                                        value=""
                                        type="text"
                                        v-model="serverSettings.name_big"
                                ></v-text-field>
                                <v-text-field
                                        label="Big Small"
                                        value=""
                                        type="text"
                                        v-model="serverSettings['name_small']"
                                ></v-text-field>
                                <v-text-field
                                        label="Slogen"
                                        value=""
                                        type="text"
                                        v-model="serverSettings['name_slogen']"
                                ></v-text-field>
                                <v-text-field
                                        label="Frontend URL"
                                        value=""
                                        type="text"
                                        v-model="serverSettings['url']"
                                ></v-text-field>
                            </v-expansion-panel-content>
                        </v-expansion-panel>
                        <v-expansion-panel>
                            <v-expansion-panel-header>Features</v-expansion-panel-header>
                            <v-expansion-panel-content>
                                <v-checkbox
                                        v-model="serverSettings['registration_possible']"
                                        label="Registration possible"
                                ></v-checkbox>
                                <v-checkbox
                                        v-model="serverSettings['invites']"
                                        label="Show invite link on Startpage"
                                ></v-checkbox>
                                <v-checkbox
                                        v-model="serverSettings['startpage']"
                                        label="Startpage"
                                ></v-checkbox>
                            </v-expansion-panel-content>
                        </v-expansion-panel>
                        <v-expansion-panel>
                            <v-expansion-panel-header>SMTP</v-expansion-panel-header>
                            <v-expansion-panel-content>
                                <v-checkbox
                                        v-model="serverSettings['smtp_active']"
                                        label="Send Mails"
                                ></v-checkbox>
                                <v-text-field
                                        label="SMTP Server"
                                        value=""
                                        type="text"
                                        v-model="serverSettings['smtp_host']"
                                ></v-text-field>
                                <v-text-field
                                        label="SMTP Port"
                                        value=""
                                        type="text"
                                        v-model="serverSettings['smtp_port']"
                                ></v-text-field>
                                <v-text-field
                                        label="SMTP Secure"
                                        value="tls"
                                        type="text"
                                        v-model="serverSettings['smtp_secure']"
                                ></v-text-field>
                                <v-checkbox
                                        v-model="serverSettings['smtp_smtpAuth']"
                                        label="SMTP Auth"
                                ></v-checkbox>
                                <v-text-field
                                        label="SMTP Username"
                                        value=""
                                        type="text"
                                        v-model="serverSettings['smtp_username']"
                                ></v-text-field>
                                <v-text-field
                                        label="SMTP Password"
                                        value=""
                                        type="password"
                                        v-model="serverSettings['smtp_password']"
                                ></v-text-field>
                                <v-text-field
                                        label="From Mail"
                                        value=""
                                        type="text"
                                        v-model="serverSettings['smtp_from_mail']"
                                ></v-text-field>
                                <v-text-field
                                        label="From Name"
                                        value=""
                                        type="text"
                                        v-model="serverSettings['smtp_from_name']"
                                ></v-text-field>
                                <v-text-field
                                        label="BCC Mail"
                                        value=""
                                        type="text"
                                        v-model="serverSettings['smtp_bcc']"
                                ></v-text-field>
                            </v-expansion-panel-content>
                        </v-expansion-panel>
                        <v-expansion-panel>
                            <v-expansion-panel-header>reCAPTCHA</v-expansion-panel-header>
                            <v-expansion-panel-content>
                                <v-checkbox
                                        v-model="serverSettings['recaptcha_v2_login']"
                                        label="reCAPTCHA to login"
                                ></v-checkbox>
                                <v-checkbox
                                        v-model="serverSettings['recaptcha_v2_register']"
                                        label="reCAPTCHA to register"
                                ></v-checkbox>
                                <v-text-field
                                        label="Recaptcha V2 Key"
                                        value=""
                                        type="text"
                                        v-model="serverSettings['recaptcha_v2_key']"
                                ></v-text-field>
                                <v-text-field
                                        label="Recaptcha V2 Secret"
                                        value=""
                                        type="password"
                                        v-model="serverSettings['recaptcha_v2_secret']"
                                ></v-text-field>
                            </v-expansion-panel-content>
                        </v-expansion-panel>
                    </v-expansion-panels><br>
                    <v-btn
                            color="success"
                            @click="saveSettings"
                    >Save</v-btn>
                </v-flex>
            </v-layout>
        </v-container>
    </div>
</template>

<script>

    import ServerService from '../../services/Server'
    import AdminService from '../../services/Admin'

    export default {
        data () {
            return {
                nameBig: '',
                nameSmall: '',
                serverSettings: []
            }
        },
        components: {

        },
        methods: {
            getAllSettings: function () {
                ServerService.getAllSettings().then((res) => {
                    let settingsArray = {};
                    for(let i = 0; i < res.data.data.length; i++) {
                        settingsArray[res.data.data[i].name] = res.data.data[i].value;
                    }
                    this.serverSettings = settingsArray;
                });
            },
            saveSettings: function () {
                console.log(this.serverSettings);
                AdminService.saveSettings(this.serverSettings).then(() => {
                    alert("Changed saved");
                }).catch(() => {
                   alert("Something go wrong");
                });
            }
        },
        mounted: function() {
            this.nameBig = this.$store.getters.getSettingValue("name_big");
            this.nameSmall = this.$store.getters.getSettingValue("name_small");
            this.getAllSettings();
        }
    }
</script>

<style>
    .header {
        background-image: url('~@/assets/manhattan-407703_1920.jpg');
        background-repeat: no-repeat;
        margin-top: -100px;
        height: 30vh;
        text-align: center;
    }
    .header h1{
        padding-top: 200px;
        font-size: 56px !important;
        font-weight: 400;
        line-height: 32px !important;
        letter-spacing: normal !important;
    }
    .header h1 .small{
        font-weight: 300 !important;
    }
    .header h2{
        padding-top: 30px;
        font-size: 34px !important;
        font-weight: 300;
        line-height: 32px !important;
        letter-spacing: normal !important;
    }
    h1{
        font-weight: 300;
        line-height: 32px !important;
        letter-spacing: normal !important;
    }
    h2{
        font-weight: 300;
        line-height: 32px !important;
        letter-spacing: normal !important;
    }
</style>
