<script setup lang="ts">
import type { Component } from 'vue'
import { Coin, Discount, Grid, Key, Moon, Present } from '@element-plus/icons-vue'

interface ZoneOption {
  key: string
  label: string
  hint: string
  count: number
}

interface Props {
  zones: ZoneOption[]
  activeZone: string
}

defineProps<Props>()

const emit = defineEmits<{
  'update:activeZone': [value: string]
}>()

const zoneIcons: Record<string, Component> = {
  all: Grid,
  sale: Discount,
  gift: Present,
  night: Moon,
  password: Key,
  highCoin: Coin,
}

function selectZone(key: string) {
  emit('update:activeZone', key)
}
</script>

<template>
  <div class="zone-tabs">
    <button
      v-for="zone in zones"
      :key="zone.key"
      type="button"
      class="zone-tab"
      :class="{ active: activeZone === zone.key }"
      @click="selectZone(zone.key)"
    >
      <span class="zone-icon" aria-hidden="true">
        <el-icon><component :is="zoneIcons[zone.key] || Grid" /></el-icon>
      </span>
      <span class="zone-title">
        <strong>{{ zone.label }}</strong>
        <span class="zone-count" :class="{ 'is-empty': zone.count === 0 }">{{ zone.count }}</span>
      </span>
      <small>{{ zone.hint }}</small>
    </button>
  </div>
</template>

<style scoped>
.zone-tabs {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}

.zone-tab {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 14px;
  border: 1px solid #eef1f5;
  border-radius: 14px;
  background: #ffffff;
  cursor: pointer;
  text-align: left;
  transition:
    border-color 0.18s ease,
    background-color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease;
}

.zone-tab:hover {
  border-color: #ffd4b0;
  background: #fffaf5;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(255, 106, 0, 0.08);
}

.zone-tab.active {
  border-color: #ff6a00;
  background: #fff7ed;
  box-shadow: 0 6px 16px rgba(255, 106, 0, 0.1);
}

.zone-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: #f3f5f9;
  color: #94a3b8;
  font-size: 18px;
  transition:
    background-color 0.18s ease,
    color 0.18s ease;
}

.zone-tab:hover .zone-icon,
.zone-tab.active .zone-icon {
  background: #ffe6d2;
  color: #ff6a00;
}

.zone-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.zone-title strong {
  overflow: hidden;
  font-size: 15px;
  font-weight: 700;
  color: #17233d;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zone-count {
  flex-shrink: 0;
  font-size: 15px;
  font-weight: 800;
  color: #ff6a00;
  font-variant-numeric: tabular-nums;
}

.zone-count.is-empty {
  color: #c0c8d4;
  font-weight: 700;
}

.zone-tab small {
  overflow: hidden;
  font-size: 12px;
  color: #7b8798;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .zone-tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .zone-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
</style>
