<template>
  <div class="intelligence-left-tab-bar">
    <div class="nav-box" :class="{ 'nav-box-show': isNavMenuShow }">
      <div
        v-for="item in navList"
        :key="item.path"
        class="nav-list"
        :class="{ 'on': navPath === item.path }"
        @click="onNavListClick(item.path)"
      >
        <div class="icon" :style="getIconStyle(item.img)"></div>
        <span class="text-tip-1 nav-text">{{ item.name }}</span>
      </div>
    </div>

    <img
      class="show"
      :class="{ 'show-expanded': isNavMenuShow }"
      src="@/assets/icons/muenShow.png"
      alt=""
      @click="onToggleNavMenu"
    />
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import muen1 from '@/assets/icons/tool-item-icon1.png'
import muen2 from '@/assets/icons/tool-item-icon2.png'
import muen3 from '@/assets/icons/tool-item-icon3.png'
import muen4 from '@/assets/icons/tool-item-icon4.png'

const isNavMenuShow = ref(false)
const navPath = ref('')

const navList = ref([
  {
    img: muen1,
    path: '/writtingAsstaint',
    name: '智能写报'
  },
  {
    img: muen2,
    path: '/intelligent-translation',
    name: '智能翻译'
  },
  {
    img: muen3,
    path: '/writtingAsstaint2',
    name: '智能查询'
  },
  {
    img: muen4,
    path: '/writtingAsstaint3',
    name: '智能对话'
  }
])

const route = useRoute()
const router = useRouter()

if (route.path) {
  navPath.value = route.path
}

const getIconStyle = (img) => ({
  background: `url(${img}) no-repeat`,
  backgroundSize: '24px 24px',
  backgroundPosition: '17px 17px'
})

const onToggleNavMenu = () => {
  isNavMenuShow.value = !isNavMenuShow.value
}

const onNavListClick = (path) => {
  if (path === '/writtingAsstaint' || path === '/intelligent-translation') {
    navPath.value = path
    router.push(path)
    return
  }

  ElMessage.error('正在开发中')
}
</script>

<style lang="scss" scoped>
.intelligence-left-tab-bar {
  padding: 5px 0;
  border-right: 1px solid rgb(234, 236, 238);
  position: relative;

  .nav-box {
    height: 100%;
    width: 65px;
    transition: all 0.3s;
    padding: 0 3px;

    .nav-list {
      display: flex;
      align-items: center;
      cursor: pointer;
      border-radius: 8px;
      overflow: hidden;
      height: 60px;

      .icon {
        width: 60px;
        height: 60px;
        flex-shrink: 0;
        border-radius: 10px;
        margin-right: 15px;
      }
    }

    .on {
      background-color: var(--color-primary-10);
      color: var(--color-primary-100);
      font-weight: 700;
    }
  }

  .nav-box-show {
    width: 200px;
    transition: all 0.3s;
  }

  .nav-text {
    white-space: nowrap;
  }

  .show {
    position: absolute;
    width: 24px;
    height: 24px;
    right: 21px;
    bottom: 21px;
    cursor: pointer;
    transform: scaleX(-1);
  }

  .show-expanded {
    transform: scaleX(1);
  }
}
</style>
