<template>
  <section :class="['dashboard', darkMode ? 'section-darkmode' : 'section-lightmode']">
    <h2 :class="['heading', darkMode ? 'heading-darkmode' : 'heading-lightmode']">My tasks</h2>
    <div class="shortcuts">
      <nuxt-link to="/maintenanceVisits" id="nuxt-link" class="button"
        :class="[darkMode ? 'button-darkmode' : 'button-lightmode', darkMode ? 'nuxt-link-darkmode' : 'nuxt-link-lightmode']"
        @click="goToMVIList()">
        <button :class="[darkMode ? 'input-darkmode' : 'input-lightmode']" type="button" id="maintenance-visits">My
          Maintenance Visits</button>
      </nuxt-link>
      <nuxt-link to="/productionOrders" id="nuxt-link" class="button"
        :class="[darkMode ? 'button-darkmode' : 'button-lightmode', darkMode ? 'nuxt-link-darkmode' : 'nuxt-link-lightmode']"
        @click="goToPOIList()">
        <button :class="[darkMode ? 'input-darkmode' : 'input-lightmode']" type="button" id="production-orders">My
          Production Orders</button>
      </nuxt-link>
      <!-- <input :class="[darkMode ? 'input-darkmode' : 'input-lightmode']" type="button" id="solutions"
        value="My Solutions">
      <input :class="[darkMode ? 'input-darkmode' : 'input-lightmode']" type="button" id="issue-slips"
        value="My Issue Slips"> -->
    </div>
  </section>
</template>


<script setup>
import { ref, onMounted, watch } from 'vue';
import { useStore } from 'vuex';
import { computed } from 'vue';

const store = useStore();
const modeChanged = computed(() => store.state.updateDarkMode);
const modeChangedLocalstorage = computed(() => store.state.modeDashboard);
const darkMode = ref('');
const loggedInUsername = ref('');

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

const goToMVIList = () => {
  store.commit('activateFilteredUserTerm');
  store.commit('activateFiltered');
  store.commit('changeToInstancelist');
};

const goToPOIList = () => {
  store.commit('activateFilteredUserTerm');
  store.commit('activateFiltered'); 
  store.commit('changeToInstancelist');
};

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

watch(modeChanged, getSession)
watch(modeChangedLocalstorage, getSession)

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

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


<style scoped>
.dashboard {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  align-self: stretch;
  width: 100%;
  padding: 1.875rem 3.125rem 3.125rem;
  gap: 1.25rem;
  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;
}

.heading {
  letter-spacing: 5%;
  text-decoration-line: underline;
  font: 400 1rem/2rem Overpass, sans-serif;
}

.heading-darkmode {
  color: #fff;
}

.heading-lightmode {
  color: #000;
}

.shortcuts {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-content: center;
  padding: 0.625rem 2.5rem;
  gap: 2.5rem;
}

input,
button {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  width: 15rem;
  height: 4rem;
  border-radius: 0.625rem;
  padding: 0.9375rem 1.25rem;
  border: none;
  text-align: center;
  letter-spacing: 5%;
  font: 400 0.875rem/2rem Overpass, sans-serif;
}

button:hover {
  cursor: pointer;
}

.input-darkmode {
  color: #fff;
  background-color: #343434;
}

.input-lightmode {
  color: #000;
  background-color: #E4E4E4;
}
</style>