<template>
    <nav class="custom-tabbar">
      <div
        v-for="item in tabs"
        :key="item.path"
        :class="['tabbar-item', { active: route.path === item.path }]"
        @click="onTabClick(item.path)"
      >
        <span class="tabbar-icon">

          <icon :name="route.path === item.path ? item.iconActive : item.icon" />
        </span>
        <span class="tabbar-label">{{ item.label }}</span>
      </div>
    </nav>
  </template>

  <script setup lang="ts">
  import { useI18n } from 'vue-i18n'
  import { useRouter, useRoute } from 'vue-router'

  const { t } = useI18n()
  const router = useRouter()
  const route = useRoute()

  const tabs = [
    {
      label: t('tabs.wallet'),
      path: '/',
      icon: 'icon_wallet',
      iconActive: 'icon_wallet',
    },
    {
      label: t('tabs.cards'),
      path: '/cards',
      icon: 'icon_card',
      iconActive: 'icon_card',
    },
  //   {
  //     label: t('tabs.finance'),
  //     path: '/finance',
  //     icon: 'gold-coin-o',
  //     iconActive: 'gold-coin',
  //   },
    {
      label: t('tabs.mine'),
      path: '/mine',
      icon: 'icon_my',
      iconActive: 'icon_my',
    },
  ]

  function onTabClick(path: string) {
    if (route.path !== path) {
      router.replace(path)
    }
  }
  </script>

  <style scoped>
  .custom-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 60px;
    background: var(--main-bg);
    border-radius: 18px 18px 0 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -2px 16px rgba(0,0,0,0.12);
    z-index: 100;
    margin: 0 8px 0px 8px;
  }
  .tabbar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-size: var(--font-size-12);
    font-weight: 600;
    border-radius: 12px;
    line-height: 16px;
    padding: 8px 0;
    cursor: pointer;
  }
  .tabbar-item.active {
    color: var(--main-yellow);
  }
  .tabbar-icon {
    margin-bottom: 4px;
    font-size: var(--font-size-24);
  }
  .tabbar-icon-active {
    color: var(--main-yellow);
  }
  .tabbar-label {
    font-weight: 500;
    line-height: 1.2;
    letter-spacing: 1px;
  }
  </style>
