<template>
  <div class="dashboard">
    <div class="settings-views">
      <div
        v-for="setting in settings"
        :key="setting.id + '-main'"
        :id="setting.id + '-main'"
        :class="{
          active: active(setting.id + '-main'),
          clickable: !active(setting.id + '-main'),
        }"
        @click="!active(setting.id + '-main') && setView(setting.id + '-main')"
      >
        <!-- Dynamically render the component based on the setting -->
        <component :is="setting.component"></component>
      </div>
    </div>

    <div v-if="loading">
      <h2 class="message delayed">
        <div class="spinner">
          <div class="bounce1"></div>
          <div class="bounce2"></div>
          <div class="bounce3"></div>
        </div>
        <span>{{ $t("files.loading") }}</span>
      </h2>
    </div>
  </div>
</template>

<script>
import { state, getters, mutations } from "@/store";
import { settings } from "@/utils/constants";
import GlobalSettings from "@/views/settings/Global.vue";
import UserDefaultSettings from "@/views/settings/UserDefaults.vue";
import UserColumnSettings from "@/views/settings/UserColumn.vue";
import ProfileSettings from "@/views/settings/Profile.vue";
import SharesSettings from "@/views/settings/Shares.vue";

export default {
  name: "settings",
  components: {
    GlobalSettings,
    UserDefaultSettings,
    UserColumnSettings,
    ProfileSettings,
    SharesSettings,
  },
  data() {
    return {
      settings, // Initialize the settings array in data
    };
  },
  computed: {
    loading() {
      return getters.isLoading();
    },
    user() {
      return state.user;
    },
    currentHash() {
      return getters.currentHash();
    },
  },
  mounted() {
    mutations.setActiveSettingsView(getters.currentHash());
  },
  methods: {
    active(id) {
      return state.activeSettingsView === id;
    },
    setView(view) {
      if (state.activeSettingsView === view) return;
      mutations.setActiveSettingsView(view);
    },
  },
};
</script>

<style>
.dashboard {
  display: flex;
  flex-direction: column;
  height: 100%;
  align-items: center;
}
.settings-views {
  max-width: 1000px;
  padding-bottom: 35vh;
}
.settings-views > .active > .card {
  border-style: solid;
  opacity: 1;
}
.settings-views .card {
  opacity: 0.3;
}
</style>
