<template>
  <div
    class="menu-side"
    :class="{ 'menu-side--collapsed': collapsed }"
  >
    <div class="menu-side__fixed">
      <div class="menu-side__logo">
        <img
          v-if="!collapsed"
          :src="configApp.logoDark"
          class="menu-side__logo-img"
        >
        <img
          v-else
          :src="configApp.logo"
          class="menu-side__logo-icon"
        >
      </div>

      <div
        v-if="getIsAuthed"
        class="menu-side__user"
      >
        <div class="menu-side__avatar">
          <i
            class="fa fa-user-circle"
            aria-hidden="true"
          />
        </div>
        <div
          v-if="!collapsed"
          class="menu-side__user-info"
        >
          <b class="menu-side__username">{{ getUsername }}</b>
          <span class="menu-side__plan">{{ $t("USER_PLAN", { plan: getUserPlan }) }}</span>
          <span
            class="menu-side__expired"
          >
            {{ getTimeExpried }}
          </span>
        </div>
      </div>
    </div>

    <div class="menu-side__scroll">
      <div class="menu-side__list">
        <div
          v-for="menu in getListMenu"
          :key="menu.key"
          v-tooltip="collapsed ? menu.label : ''"
          class="menu-side__item"
          :class="{ 'menu-side__item--active': getMenuActive === menu.key }"
          @click="openMenu(menu)"
        >
          <div
            v-if="getMenuActive === menu.key"
            class="menu-side__indicator"
          />
          <div class="menu-side__item-inner">
            <div class="menu-side__icon-wrap">
              <img
                v-if="menu.image"
                :src="menu.image"
                class="menu-side__item-image"
              >
              <i
                v-else
                :class="menu.icon"
                class="menu-side__item-icon"
                aria-hidden="true"
              />
              <span
                v-if="menu.key === 'setting' && hasNotify"
                class="menu-side__badge"
              />
            </div>
            <span
              v-if="!collapsed"
              class="menu-side__item-label"
            >{{ menu.label }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import mixin from '@/vue/mixin/menu';

export default {
  name: 'MenuSide',
  props: {
    collapsed: {
      type: Boolean,
      default: false,
    },
    hasNotify: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      isSideMenu: true,
    };
  },
  mixins: [mixin],
  computed: {
    getListMenu() {
      return this.listMenu.filter((item) => item.isShow);
    },
  },
};
</script>

<style scoped>
.menu-side {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.menu-side__fixed {
  flex-shrink: 0;
}

.menu-side__logo {
  padding: 14px 16px;
  margin: 0 8px;
  border-bottom: 1px solid #f0f0f0;
  text-align: center;
}

.menu-side__logo-img {
  height: 36px;
}

.menu-side__logo-icon {
  height: 28px;
  width: 28px;
  object-fit: contain;
}

.menu-side__user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  margin: 8px 8px 0;
  background: #f6f8fa;
  border-radius: 8px;
  cursor: default;
}

.menu-side--collapsed .menu-side__user {
  justify-content: center;
  padding: 10px;
  margin: 8px 4px 0;
}

.menu-side__avatar {
  font-size: 28px;
  color: #1890ff;
  line-height: 1;
  flex-shrink: 0;
}

.menu-side--collapsed .menu-side__avatar {
  font-size: 22px;
}

.menu-side__user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.menu-side__username {
  font-size: 13px;
  color: #1d2129;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-side__plan {
  font-size: 11px;
  color: #8c8c8c;
}

.menu-side__expired {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  margin-top: 2px;
}

.menu-side__scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
}

.menu-side__scroll::-webkit-scrollbar {
  width: 4px;
}

.menu-side__scroll::-webkit-scrollbar-track {
  background: transparent;
}

.menu-side__scroll::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
}

.menu-side__scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.2);
}

.menu-side__list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
}

.menu-side--collapsed .menu-side__list {
  padding: 0 4px;
}

.menu-side__item {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  color: #595959;
  font-size: 13px;
  overflow: hidden;
}

.menu-side__item:hover {
  background: #f0f5ff;
  color: #1890ff;
}

.menu-side__item--active {
  background: #e6f7ff;
  color: #1890ff;
  font-weight: 600;
}

.menu-side__indicator {
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: #1890ff;
  border-radius: 0 3px 3px 0;
}

.menu-side__item-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  width: 100%;
}

.menu-side--collapsed .menu-side__item-inner {
  justify-content: center;
  padding: 10px;
}

.menu-side__icon-wrap {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.menu-side__item-icon {
  width: 18px;
  text-align: center;
  font-size: 14px;
}

.menu-side--collapsed .menu-side__item-icon {
  font-size: 16px;
}

.menu-side__item-image {
  height: 18px;
  width: 18px;
  object-fit: contain;
}

.menu-side__badge {
  position: absolute;
  top: -3px;
  right: -4px;
  width: 8px;
  height: 8px;
  background: #f5222d;
  border-radius: 50%;
  border: 1.5px solid #fff;
  animation: badge-pulse 2s infinite;
}

@keyframes badge-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(245, 34, 45, 0.4);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(245, 34, 45, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(245, 34, 45, 0);
  }
}

.menu-side__item-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
