<template>
  <div class="home">
    <div class="content">
      <router-view v-slot="{ Component }">
        <transition
          appear
          enter-active-class="animate__animated animate__fadeInRight"
          leact-active-class="animate__animated animate__fadeOutRight"
        >
          <component :is="Component"></component>
        </transition>
      </router-view>
    </div>
    <div v-show="footStore.showFooter" class="footer">
      <div
        v-for="(item, index) in footerItem"
        :key="index"
        :class="[
          'footer-item',
          {
            active: route.path === item.routerPath,
            'ai-button': item.title == 'AI助手'
          }
        ]"
        @click="goPage(item.routerPath)"
      >
        <img :src="route.path === item.routerPath ? item.iconActive : item.icon" alt="" />
        <span>{{ item.title }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
  import { getIconUrl } from '@/utils/utils'
  import { useRoute, useRouter } from 'vue-router'
  import useShowFooterStore from '@/store/modules/showFooter'
  const footStore = useShowFooterStore()
  const router = useRouter()
  const route = useRoute()
  const footerItem = [
    {
      icon: getIconUrl('label_home_gray'),
      iconActive: getIconUrl('label_home_color'),
      title: '首页',
      routerPath: '/layout'
    },
    {
      icon: getIconUrl('label_message_gray'),
      iconActive: getIconUrl('label_message_color'),
      title: '消息',
      routerPath: '/message'
    },
    {
      icon: getIconUrl('label_ai_color'),
      iconActive: getIconUrl('label_ai_color'),
      title: 'AI助手',
      routerPath: '/ai'
    },
    {
      icon: getIconUrl('label_circle_gray'),
      iconActive: getIconUrl('label_circle_color'),
      title: '警事圈',
      routerPath: '/warningCircle'
    },
    {
      icon: getIconUrl('label_my_gray'),
      iconActive: getIconUrl('label_my_color'),
      title: '我的',
      routerPath: '/mine'
    }
  ]

  const goPage = path => {
    router.push({
      path,
      replace: true
    })
  }
</script>

<style lang="scss" scoped>
  .home {
    width: 100%;
    height: 100vh;
    .content {
      width: 100%;
      height: 100%;
    }
    .footer {
      position: fixed;
      bottom: 0;
      z-index: 999;
      height: calc(70px + env(safe-area-inset-bottom));
      padding-bottom: env(safe-area-inset-bottom);
      background: url('@/assets/icons/bj_label.png') no-repeat;
      background-size: 100% 100%;
      width: 100%;
      display: grid;
      grid-template-columns: repeat(5, 1fr);
      filter: drop-shadow(0 5px 5px rgba(0, 0, 0, 0.5));

      .footer-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
        padding-top: 15px;

        img {
          width: 24px;
          height: 24px;
          transition: all 0.3s;
          /* 解决高分辨率屏幕下图标模糊问题 */
          image-rendering: pixelated;
          transform: translateZ(0);
          backface-visibility: hidden;
        }

        span {
          font-size: 12px;
          color: #999;
          margin-top: 4px;
          transition: all 0.3s;
        }

        &.active {
          span {
            color: #2979ff;
          }
        }

        &.ai-button {
          img {
            width: 55px;
            height: 44px;
            margin-top: -10px;
          }
          span {
            margin-top: -5px;
          }
        }
      }
    }
  }
</style>
