<template>
  <ScreenLayout :show-back-btn="true" back-text="返回菜单" back-target="/menu">
    <div class="page-navigation">
      <h1 class="page-title">路线引导</h1>
      <p class="page-subtitle">请选择您要去的地方</p>

      <div class="destinations-grid">
        <div
          v-for="dest in destinations"
          :key="dest.destinationId"
          class="destination-card"
          @click="selectDestination(dest)"
        >
          <div class="dest-icon" :style="{ background: getCategoryColor(dest.category) }">
            <component :is="getCategoryIcon(dest.category)" />
          </div>
          <div class="dest-info">
            <h3>{{ dest.name }}</h3>
            <p>{{ dest.floor }} · {{ dest.description }}</p>
          </div>
          <div class="dest-time">
            <span>约{{ dest.estimatedTime }}</span>
          </div>
        </div>
      </div>
    </div>
  </ScreenLayout>
</template>

<script setup>
import { ref, onMounted, h } from 'vue'
import { useRouter } from 'vue-router'
import { useNavigationStore } from '@/stores/navigation'
import ScreenLayout from '@/layouts/ScreenLayout.vue'

const router = useRouter()
const navigationStore = useNavigationStore()

const destinations = ref([])

// 图标组件
const ReceptionIcon = () => h('svg', { viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', 'stroke-width': '2' }, [
  h('rect', { x: '2', y: '3', width: '20', height: '18', rx: '2' }),
  h('line', { x1: '8', y1: '12', x2: '16', y2: '12' })
])

const LobbyIcon = () => h('svg', { viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', 'stroke-width': '2' }, [
  h('path', { d: 'M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z' }),
  h('polyline', { points: '9 22 9 12 15 12 15 22' })
])

const MeetingIcon = () => h('svg', { viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', 'stroke-width': '2' }, [
  h('path', { d: 'M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2' }),
  h('circle', { cx: '9', cy: '7', r: '4' }),
  h('path', { d: 'M23 21v-2a4 4 0 0 0-3-3.87' }),
  h('path', { d: 'M16 3.13a4 4 0 0 1 0 7.75' })
])

const ExhibitionIcon = () => h('svg', { viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', 'stroke-width': '2' }, [
  h('rect', { x: '3', y: '3', width: '18', height: '18', rx: '2' }),
  h('circle', { cx: '8.5', cy: '8.5', r: '1.5' }),
  h('polyline', { points: '21 15 16 10 5 21' })
])

const RestIcon = () => h('svg', { viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', 'stroke-width': '2' }, [
  h('path', { d: 'M18 8h1a4 4 0 0 1 0 8h-1' }),
  h('path', { d: 'M2 8h16v9a4 4 0 0 1-4 4H6a4 4 0 0 1-4-4V8z' }),
  h('line', { x1: '6', y1: '1', x2: '6', y2: '4' }),
  h('line', { x1: '10', y1: '1', x2: '10', y2: '4' }),
  h('line', { x1: '14', y1: '1', x2: '14', y2: '4' })
])

const ToiletIcon = () => h('svg', { viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', 'stroke-width': '2' }, [
  h('circle', { cx: '12', cy: '4', r: '2' }),
  h('path', { d: 'M12 6v6' }),
  h('path', { d: 'M8 22v-6a4 4 0 0 1 8 0v6' })
])

const OtherIcon = () => h('svg', { viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', 'stroke-width': '2' }, [
  h('circle', { cx: '12', cy: '12', r: '10' }),
  h('line', { x1: '12', y1: '8', x2: '12', y2: '12' }),
  h('line', { x1: '12', y1: '16', x2: '12.01', y2: '16' })
])

const getCategoryIcon = (category) => {
  const icons = {
    '服务': ReceptionIcon,
    '公共': LobbyIcon,
    '会议': MeetingIcon,
    '展示': ExhibitionIcon,
    '设施': RestIcon,
    '卫生间': ToiletIcon
  }
  return icons[category] || OtherIcon
}

const getCategoryColor = (category) => {
  const colors = {
    '服务': 'linear-gradient(135deg, #2f8ee5 0%, #1a6fc9 100%)',
    '公共': 'linear-gradient(135deg, #20b7c7 0%, #0ea5a5 100%)',
    '会议': 'linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%)',
    '展示': 'linear-gradient(135deg, #f59e0b 0%, #d97706 100%)',
    '设施': 'linear-gradient(135deg, #10b981 0%, #059669 100%)',
    '卫生间': 'linear-gradient(135deg, #ec4899 0%, #db2777 100%)'
  }
  return colors[category] || colors['公共']
}

const selectDestination = async (dest) => {
  await navigationStore.startNavigation(dest)
  router.push('/navigation/status')
}

onMounted(async () => {
  await navigationStore.fetchDestinations()
  destinations.value = navigationStore.destinations
})
</script>

<style scoped>
.page-navigation {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.page-title {
  font-size: 32px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  margin: 0;
}

.page-subtitle {
  font-size: 18px;
  color: var(--text-muted);
  text-align: center;
  margin: 8px 0 32px;
}

.destinations-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  overflow-y: auto;
  padding: 0 16px;
}

.destination-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.destination-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.destination-card:active {
  transform: translateY(-2px);
}

.dest-icon {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  color: white;
  flex-shrink: 0;
}

.dest-icon svg {
  width: 28px;
  height: 28px;
}

.dest-info {
  flex: 1;
  min-width: 0;
}

.dest-info h3 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 4px;
}

.dest-info p {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dest-time {
  flex-shrink: 0;
}

.dest-time span {
  font-size: 14px;
  color: var(--primary);
  padding: 6px 12px;
  background: var(--primary-soft);
  border-radius: var(--radius-full);
}
</style>
