<template>
    <section id="content">
        <div id="content-header">
            <router-link to="/issueSlips" class="button" id="issueSlips-button" @click="defaultIssueSlipPage()">
                <h1 :class="[loggedInUserDarkModeBoolean ? 'h1-darkmode' : 'h1-lightmode']" id="page-name">Issue slips
                </h1>
            </router-link>
            &nbsp;
            &nbsp;
            &nbsp;
            &nbsp;
            &nbsp;
            &nbsp;
            &nbsp;
            &nbsp;
            &nbsp;
            &nbsp;
            &nbsp;
            &nbsp;
            &nbsp;
            &nbsp;
            &nbsp;
            &nbsp;
            <router-link to="/issueItems" class="button" id="issues-button" @click="defaultIssuePage()">
                <h1 :class="[loggedInUserDarkModeBoolean ? 'h1-darkmode' : 'h1-lightmode']" id="active-page-name">Issues
                </h1>
            </router-link>
        </div>
        <div id="content-body">
            <IssueStateSearch v-if="onIssueItemList" />
            <IssueTable v-if="onIssueItemList" />
            <Issue v-if="onIssueItem" />
            <IssueVariants v-if="onIssueItem" />
            <IssueVariant v-if="onIssueItemVariant" />
        </div>
    </section>
</template>


<script setup>
import { ref, onMounted, watch } from 'vue';
import IssueStateSearch from "../components/IssueStateSearch.vue";
import IssueTable from "../components/server/IssueTable.vue";
import Issue from "../components/server/Issue.vue";
import IssueVariants from "../components/server/IssueVariants.vue";
import IssueVariant from "../components/server/IssueVariant.vue";
import { useStore } from 'vuex';
import { computed } from 'vue';

const store = useStore();
const modeChanged = computed(() => store.state.updateDarkMode);
const onIssueItemList = computed(() => store.state.onIssueItemList);
const onIssueItem = computed(() => store.state.onIssueItem);
const onIssueItemVariant = computed(() => store.state.onIssueItemVariant);

definePageMeta({
    layout: 'default',
    title: 'Issue Items'
})

const loggedInUserDarkModeBoolean = ref('');

const defaultIssueSlipPage = () => {
    store.commit('resetStore');
    store.commit('changeToIssueSliplist')
}

const defaultIssuePage = () => {
    store.commit('resetStore');
    store.commit('changeToIssueItemList')
}

const getSession = async () => {
    const loggedInUserDarkModeBool = getItem('logged-in-user-darkMode');
    if (loggedInUserDarkModeBool == 1) {
        loggedInUserDarkModeBoolean.value = true;
    } else {
        loggedInUserDarkModeBoolean.value = false;
    }
}

function getItem(item) {
    if (process.client) {
        return localStorage.getItem(item)
    } else {
        return undefined
    }
}

watch(modeChanged, getSession)

onMounted(async () => {
    await getSession();
});
</script>

<script>
export default {
    name: "IssueItemsPage",
}
</script>



<style scoped>
* {
    box-sizing: border-box;
}


#content {
    display: flex;
    flex-direction: column;
    float: left;
    justify-content: stretch;
    align-items: stretch;
    width: 100%;
    flex-grow: 1;
    gap: 0.625rem;
    padding: 0 1.25rem;
}

#content-header {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 3.125rem;
}

#page-name {
    letter-spacing: 5%;
    font: 400 1.5rem/125% Overpass, -apple-system, Roboto, Helvetica,
        sans-serif;
    text-decoration: none;
}

#active-page-name {
    letter-spacing: 5%;
    font: 400 1.5rem/125% Overpass, -apple-system, Roboto, Helvetica,
        sans-serif;
    text-decoration: underline;
}

.button {
    text-decoration: none;
}

.h1-darkmode {
    color: #fff;
}

.h1-lightmode {
    color: #000;
}

#content-body {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 1.25rem;
    margin-bottom: 0.625rem;
    border-radius: 0.625rem;
}
</style>../components/IssueStateSearch.vue