<template>
  <div class="navigation">
    <div 
      v-for="(group, index) in sortedGroups" 
      :key="group.name"
      class="group-container"
      :style="{ animationDelay: `${index * 0.1}s` }"
    >
      <div class="group-header">
        <div class="group-icon-wrapper">
          <img 
            v-if="group.icon" 
            :src="group.icon" 
            :alt="group.name"
            class="group-icon"
            @error="handleImageError"
          />
        </div>
        <div class="group-info">
          <h2 class="group-name">{{ group.name }}</h2>
          <p v-if="group.description" class="group-description">{{ group.description }}</p>
        </div>
      </div>
      
      <div class="links-list">
        <a
          v-for="(link, linkIndex) in sortedLinks(group.links)"
          :key="link.name"
          :href="link.url"
          target="_blank"
          rel="noopener noreferrer"
          class="link-item"
          :style="{ animationDelay: `${(index * 0.1) + (linkIndex * 0.03)}s` }"
        >
          <div class="link-icon-wrapper">
            <img 
              v-if="link.icon" 
              :src="link.icon" 
              :alt="link.name"
              class="link-icon"
              @error="handleImageError"
            />
          </div>
          <div class="link-content">
            <div class="link-name">{{ link.name }}</div>
            <div v-if="link.description" class="link-description">{{ link.description }}</div>
          </div>
          <div class="link-arrow">→</div>
        </a>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import navigationData from '../data/navigation.json'

const groups = ref([])

onMounted(() => {
  groups.value = navigationData.groups || []
})

const sortedGroups = computed(() => {
  return [...groups.value].sort((a, b) => (a.sort || 0) - (b.sort || 0))
})

const sortedLinks = (links) => {
  if (!links) return []
  return [...links].sort((a, b) => (a.sort || 0) - (b.sort || 0))
}

const handleImageError = (event) => {
  event.target.style.display = 'none'
}
</script>

<style scoped>
.navigation {
  display: flex;
  flex-direction: column;
  gap: 35px;
}

.group-container {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  padding: 30px;
  box-shadow: 0 2px 15px rgba(0, 0, 0, 0.08);
  animation: slideIn 0.4s ease-out both;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.group-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 25px;
  padding-bottom: 20px;
  border-bottom: 2px solid #e2e8f0;
}

.group-icon-wrapper {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  flex-shrink: 0;
}

.group-icon {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

.group-info {
  flex: 1;
}

.group-name {
  font-size: 28px;
  color: #1a202c;
  margin-bottom: 5px;
  font-weight: 600;
}

.group-description {
  font-size: 16px;
  color: #718096;
  font-weight: 400;
}

.links-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.link-item {
  display: flex;
  align-items: center;
  gap: 20px;
  background: #f7fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 20px 25px;
  text-decoration: none;
  color: inherit;
  transition: all 0.3s ease;
  animation: slideIn 0.4s ease-out both;
}

.link-item:hover {
  background: #ffffff;
  border-color: #667eea;
  transform: translateX(5px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

.link-icon-wrapper {
  width: 50px;
  height: 50px;
  border-radius: 10px;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.link-icon {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.link-content {
  flex: 1;
  min-width: 0;
}

.link-name {
  font-size: 20px;
  color: #2d3748;
  font-weight: 600;
  margin-bottom: 4px;
}

.link-description {
  font-size: 14px;
  color: #718096;
  line-height: 1.4;
}

.link-arrow {
  font-size: 24px;
  color: #667eea;
  opacity: 0.6;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.link-item:hover .link-arrow {
  opacity: 1;
  transform: translateX(5px);
}

@media (max-width: 768px) {
  .group-container {
    padding: 20px;
  }
  
  .group-name {
    font-size: 24px;
  }
  
  .link-item {
    padding: 15px 20px;
  }
  
  .link-name {
    font-size: 18px;
  }
}
</style>

