<template>
  <div
    v-if="settingsStore.settings.ui.navigationMode !== 'hidden'"
    class="fixed bottom-0 left-0 right-0 h-16 group md:h-16"
  >
    <!-- Invisible hover trigger area for desktop (only for hover mode) -->
    <div
      v-if="settingsStore.settings.ui.navigationMode === 'hover'"
      class="absolute inset-0 hidden md:block"
    ></div>
    <!-- Navigation bar -->
    <nav
      class="absolute bottom-0 left-0 right-0 bg-white md:bg-transparent border-t md:border-t-0 border-gray-200 md:shadow-none shadow-lg"
      :class="getNavigationClasses()"
    >
      <UserIcon />
      <div class="flex justify-center md:pb-4 pb-2">
        <ul
          class="flex space-x-4 md:space-x-8 md:bg-white md:rounded-lg md:shadow-md px-6 py-3 w-full md:w-auto justify-around md:justify-center"
        >
          <li>
            <router-link
              to="/"
              class="flex flex-col items-center font-medium"
              :class="
                $route.name === 'home' ? 'text-blue-600' : 'text-gray-600 hover:text-blue-600'
              "
            >
              <svg class="w-6 h-6 mb-1" fill="currentColor" viewBox="0 0 24 24">
                <path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z" />
              </svg>
              <span class="text-xs">Dashboard</span>
            </router-link>
          </li>
          <li>
            <router-link
              to="/sensors"
              class="flex flex-col items-center font-medium"
              :class="
                $route.name === 'sensors'
                  ? 'text-orange-600'
                  : 'text-gray-600 hover:text-orange-600'
              "
            >
              <svg class="w-6 h-6 mb-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path
                  stroke-linecap="round"
                  stroke-linejoin="round"
                  stroke-width="2"
                  d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z"
                />
              </svg>
              <span class="text-xs">Sensors</span>
            </router-link>
          </li>
          <li>
            <router-link
              to="/models"
              class="flex flex-col items-center font-medium"
              :class="
                $route.name === 'models' ? 'text-purple-600' : 'text-gray-600 hover:text-purple-600'
              "
            >
              <IconEcosystem />
              <span class="text-xs">Models</span>
            </router-link>
          </li>
          <li>
            <router-link
              to="/analytics"
              class="flex flex-col items-center font-medium"
              :class="
                $route.name === 'analytics'
                  ? 'text-indigo-600'
                  : 'text-gray-600 hover:text-indigo-600'
              "
            >
              <svg class="w-6 h-6 mb-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path
                  stroke-linecap="round"
                  stroke-linejoin="round"
                  stroke-width="2"
                  d="M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2z"
                />
              </svg>
              <span class="text-xs">Analytics</span>
            </router-link>
          </li>
          <li>
            <router-link
              to="/settings"
              class="flex flex-col items-center font-medium"
              :class="
                $route.name === 'settings' ? 'text-green-700' : 'text-gray-600 hover:text-green-700'
              "
            >
              <svg class="w-6 h-6 mb-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path
                  stroke-linecap="round"
                  stroke-linejoin="round"
                  stroke-width="2"
                  d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"
                />
                <path
                  stroke-linecap="round"
                  stroke-linejoin="round"
                  stroke-width="2"
                  d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
                />
              </svg>
              <span class="text-xs">Settings</span>
            </router-link>
          </li>
        </ul>
      </div>
    </nav>
  </div>
</template>

<script setup lang="ts">
import { onMounted } from 'vue'
import { useSettingsStore } from '@/stores/settings'
import UserIcon from './UserIcon.vue'
import IconEcosystem from '../icons/IconEcosystem.vue'
const settingsStore = useSettingsStore()

// Compute navigation classes based on settings
const getNavigationClasses = () => {
  const mode = settingsStore.settings.ui.navigationMode

  if (mode === 'always') {
    // Always visible - no transform on desktop
    return 'transform-none md:transform-none'
  } else if (mode === 'hover') {
    // Hover mode - original behavior
    return 'transform-none md:transform md:translate-y-full md:group-hover:translate-y-0 md:transition-transform md:duration-300 md:ease-in-out'
  }

  // Default fallback
  return 'transform-none md:transform md:translate-y-full md:group-hover:translate-y-0 md:transition-transform md:duration-300 md:ease-in-out'
}

// Initialize settings store
onMounted(() => {
  if (!settingsStore.lastSaved) {
    settingsStore.initialize()
  }
})
</script>
