<template>
    <section :class="['network-information', darkMode ? 'section-darkmode' : 'section-lightmode']">
        <div :class="['label', darkMode ? 'div-darkmode' : 'div-lightmode']" id="network">Network specifications:</div>
        <div class="asset-data">
            <div class="IPv4-MAC">
                <div class="data-field" id="IPv4">
                    <pre :class="['label', darkMode ? 'div-darkmode' : 'div-lightmode']">IPv4:</pre>
                    <pre :class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">{{ inputIPv4 }}</pre>
                </div>
                <div class="data-field" id="MAC">
                    <pre :class="['label', darkMode ? 'div-darkmode' : 'div-lightmode']">MAC:</pre>
                    <pre :class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">{{ item.MAC }}</pre>
                </div>
            </div>
            <div class="IPv6-subnetmask">
                <div class="data-field" id="IPv6">
                    <pre :class="['label', darkMode ? 'div-darkmode' : 'div-lightmode']">IPv6:</pre>
                    <pre :class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">{{ inputIPv6 }}</pre>
                </div>
                <div class="data-field" id="subnetmask">
                    <pre :class="['label', darkMode ? 'div-darkmode' : 'div-lightmode']">Subnetmask:</pre>
                    <pre :class="['data', darkMode ? 'data-darkmode' : 'data-lightmode']">{{ item.subnetmask }}</pre>
                </div>
            </div>
        </div>
    </section>
</template>
    

<script setup>
import { ref, onMounted } from 'vue';
import Axios from '../axios.config.js';
import clientsideConfig from '../../clientsideConfig.js';

const darkMode = ref(true)
const item = ref({});
const networkBoolean = ref(false);
const inputIPv4 = ref('');
const inputIPv6 = ref('');

// get config item from id
const getItemById = async () => {
    // later itemIndex from route params
    let itemIndex = 9;
    try {
        const response = await Axios.get(
            `https://${clientsideConfig.url}:${clientsideConfig.port}/api/getConfigItem/${itemIndex}`
        );
        item.value = response.data;
        if ((item.value.networkBool == 1) && (item.value.IPv4 === (null | "")) && (item.value.IPv6 === (null | "")) && (item.value.subnetmask === (null | "")) && (item.value.MAC === (null | ""))) {
            item.value.networkBool = 0;
            networkBoolean.value = false;
        };
        if (item.value.networkBool == 1) {
            networkBoolean.value = true;
        };

        if (item.value.IPv4 == null) {
            inputIPv4.value = "";
        } else {
            inputIPv4.value = item.value.IPv4;
        }
        if (item.value.IPv6 == null) {
            inputIPv6.value = "";
        } else {
            inputIPv6.value = item.value.IPv6;
        }
    } catch (err) {
        console.log(err.response.statusText);
    }
}

onMounted(() => {
    getItemById();
});
</script>

<script>
export default {
    name: "NetworkSpecifications",
};
</script>          
      
      
<style scoped>
.network-information {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
    padding: 1.25rem 1.875rem;
    border-radius: 0.625rem;
    box-shadow: 0.25rem 0.25rem 0.25rem 0rem rgba(0, 0, 0, 0.25);
}

.section-darkmode {
    background-color: #2c2c2c;
}

.section-lightmode {
    background-color: #fff;
}

.data-field {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    padding: 0 1.875rem;
    gap: 1.25rem;
    border-radius: 0.625rem;
}

.label {
    letter-spacing: 5%;
    font: 400 0.875rem/1.875rem Overpass, sans-serif;
}

.div-darkmode {
    color: #fff;
}

.div-lightmode {
    color: #000;
}

.label#network {
    padding-top: 1rem;
    padding-bottom: 1rem;
}

.data {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    padding: 0 0.625rem;
    border-radius: 0.3125rem;
    box-shadow: 0.0625rem 0.0625rem 0.25rem 0rem rgba(0, 0, 0, 0.25) inset;
    letter-spacing: 5%;
    font: 400 0.75rem/250% Overpass, sans-serif;
}

.data-darkmode {
    background-color: #212121;
    color: #fff;
}

.data-lightmode {
    background-color: #EBEBEB;
    color: #000;
}

.asset-data {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    align-self: stretch;
}

.IPv4-MAC,
.IPv6-subnetmask {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    line-height: normal;
    width: 50%;
    padding: 0 0;
    border-radius: 0.3125rem;
}
</style>