<template lang="pug">
  .sidebar.flex.flex-col.justify-between.flex-auto.py-6.box-border(:style="bordersStyle")
    .flex.flex-col.gap-y-6
      base-button-sidebar(
        v-for="button in pageSettings.filter((el) => el.id !== 'settings')",
        :path="button.path",
        :id="button.id",
        :active="button.active",
        :change-style-page="changeStylePage"
      )
        q-icon(:name="`app:${button.icon}`", size="36px")
    .flex.text-4xl.flex-col.gap-y-6
      base-button-sidebar(
        :path="getSettings.path",
        :id="getSettings.id",
        :active="getSettings.active",
        :change-style-page="changeStylePage"
      )
        q-icon(:name="`app:${getSettings.icon}`", size="36px")
</template>

<script>
import BaseButtonSidebar from "@/components/base/BaseSidebarButton";

export default {
  name: "TheSidebar",
  components: { BaseButtonSidebar },
  data() {
    return {
      pageSettings: [
        {
          id: "calendar",
          path: "#/calendar",
          active: true,
          icon: "icon-calendar-2",
        },
        {
          id: "user",
          path: "#/clients",
          active: false,
          icon: "icon-person-2",
        },
        {
          id: "settings",
          path: "#/settings",
          icon: "icon-settings",
          active: false,
        },
      ],
      currentPageBorder: true,
    };
  },
  methods: {
    changeStylePage(e) {
      this.pageSettings.forEach((el, index) => {
        el.id === e.currentTarget.id
          ? (this.pageSettings[index].active = true)
          : (this.pageSettings[index].active = false);
      });
    },
  },
  computed: {
    getSettings() {
      return this.pageSettings.find((el) => el.id === "settings");
    },
    bordersStyle() {
      return {
        "border-top-right-radius": this.currentPageBorder ? "0px" : "4px",
        //"border-bottom-right-radius": this.currentPageBorder ? "0px" : "4px",
      };
    },
  },
  mounted() {
    let href = window.location.href.slice(22);
    this.pageSettings.forEach((el, index) => {
      el.path === href.substr(href.lastIndexOf("#"))
        ? (this.pageSettings[index].active = true)
        : (this.pageSettings[index].active = false);
    });
  },
  watch: {
    "$route.path"() {
      if (this.$router.currentRoute._value.fullPath === "/calendar") {
        this.currentPageBorder = true;
        this.pageSettings.forEach((el) =>
          el.path === "#/calendar" ? (el.active = true) : (el.active = false)
        );
      } else this.currentPageBorder = false;
    },
  },
};
</script>

<style lang="sass" scoped>
.sidebar
  max-width: 80px
  min-width: 80px
  background-color: var(--default-white)
</style>
