<template>
  <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
    <h1 class="text-3xl sm:text-4xl font-bold mb-2" style="color: var(--text)">Referenzen</h1>
    <p class="mb-8" style="color: var(--secondary)">Ausgewählte Projekte aus unserer Veranstaltungstechnik-Praxis.</p>
    <div class="flex flex-wrap gap-2 mb-8" role="tablist" aria-label="Referenz-Filter">
      <button v-for="cat in categories" :key="cat" @click="filter = cat" :class="['hms-chip', filter === cat ? 'active' : '']" role="tab" :aria-selected="filter === cat">{{ cat === 'alle' ? 'Alle' : cat }}</button>
    </div>
    <div v-if="loading">
      <div class="hms-gallery">
        <div v-for="i in 6" :key="i" class="hms-card overflow-hidden">
          <div class="hms-skeleton aspect-[4/3]" style="border-radius:0"></div>
          <div class="p-4 space-y-2"><div class="hms-skeleton h-4 w-3/4"></div><div class="hms-skeleton h-3 w-1/3"></div></div>
        </div>
      </div>
    </div>
    <ErrorState v-else-if="error" title="Referenzen konnten nicht geladen werden" message="Bitte versuchen Sie es in Kürze erneut." @retry="retry" />
    <div v-else class="hms-gallery">
      <article v-for="img in filteredImages" :key="img.id" class="hms-card overflow-hidden group cursor-pointer">
        <div class="aspect-[4/3] relative overflow-hidden">
          <img :src="img.img" :alt="img.title" loading="lazy" class="absolute inset-0 w-full h-full object-cover transition-transform duration-500 group-hover:scale-110" />
          <div class="absolute inset-0 bg-gradient-to-t from-black/50 to-transparent opacity-0 group-hover:opacity-100 transition-opacity"></div>
          <span class="hms-badge hms-badge-primary absolute top-3 left-3">{{ img.category }}</span>
        </div>
        <div class="p-4"><h3 class="font-semibold text-sm" style="color: var(--text)">{{ img.title }}</h3><p class="text-xs mt-1" style="color: var(--secondary)">{{ img.date }}</p></div>
      </article>
    </div>
    <EmptyState v-if="!loading && !error && filteredImages.length === 0" icon="📭" title="Keine Referenzen" message="Für diese Kategorie liegen aktuell keine Referenzen vor." action-label="Alle anzeigen" @action="filter = 'alle'" />
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'

const loading = ref(true)
const error = ref(false)
const filter = ref('alle')
const categories = ['alle', 'Open-Air', 'Indoor', 'Rigging', 'Event']
const allImages = [
  { id: 1, title: 'Open-Air Veranstaltung', category: 'Open-Air', date: '2017', img: 'img/ref1.jpg' },
  { id: 2, title: 'Bühnenaufbau', category: 'Rigging', date: '2016', img: 'img/ref2.jpg' },
  { id: 3, title: 'Donautal Radelspass', category: 'Event', date: '2019', img: 'img/ref3.jpg' },
  { id: 4, title: 'Traversenaufbau', category: 'Rigging', date: '2019', img: 'img/ref4.jpg' },
  { id: 5, title: 'Veranstaltungstechnik vor Ort', category: 'Event', date: '2019', img: 'img/ref5.jpg' },
  { id: 6, title: 'Indoor Beschallung', category: 'Indoor', date: '2016', img: 'img/ref6.jpg' },
  { id: 7, title: 'Bühnentechnik Setup', category: 'Rigging', date: '2019', img: 'img/ref7.jpg' },
  { id: 8, title: 'Event-Aufbau', category: 'Event', date: '2019', img: 'img/ref8.jpg' },
  { id: 9, title: 'Großbühne Aufbau', category: 'Open-Air', date: '2016', img: 'img/ref9.jpg' }
]
const filteredImages = computed(() => {
  if (filter.value === 'alle') return allImages
  return allImages.filter(i => i.category === filter.value)
})
onMounted(() => { setTimeout(() => { loading.value = false }, 1000) })
function retry() { loading.value = true; error.value = false; setTimeout(() => { loading.value = false }, 800) }
</script>
