<!-- components/ObjectCard.vue -->
<template>
  <div class="card cursor-pointer" @click="$emit('click')">
    <div class="relative">
      <img 
        :src="object.image" 
        :alt="object.title"
        class="w-full h-48 object-cover"
      >
      <div class="absolute top-2 right-2">
        <span class="badge badge-primary">
          {{ getTypeLabel(object.type) }}
        </span>
      </div>
    </div>
    
    <div class="card-body">
      <h3 class="text-lg font-semibold mb-2">{{ object.title }}</h3>
      <p class="text-gray-600 text-sm mb-3 line-clamp-2">
        {{ object.description }}
      </p>
      
      <div class="flex items-center justify-between">
        <div class="flex items-center space-x-1">
          <span class="text-yellow-500">⭐</span>
          <span class="text-sm font-medium">{{ object.rating }}</span>
        </div>
        <div class="text-right">
          <div class="font-bold text-primary-600">
            {{ formatPrice(object.price) }}
          </div>
          <div class="text-xs text-gray-500">за ночь</div>
        </div>
      </div>
      
      <div class="mt-3 flex items-center text-sm text-gray-500">
        <span class="mr-2">📍</span>
        <span>{{ object.city }}</span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
interface ObjectItem {
  id: number
  title: string
  type: string
  city: string
  price: number
  rating: number
  image: string
  description: string
}

interface Props {
  object: ObjectItem
}

defineProps<Props>()
defineEmits<{
  click: []
}>()

const getTypeLabel = (type: string) => {
  const types: Record<string, string> = {
    hotel: 'Отель',
    sanatorium: 'Санаторий',
    guest_house: 'Гостевой дом',
    tour: 'Тур',
    excursion: 'Экскурсия'
  }
  return types[type] || type
}

const formatPrice = (price: number) => {
  return new Intl.NumberFormat('ru-RU', {
    style: 'currency',
    currency: 'RUB',
    minimumFractionDigits: 0
  }).format(price)
}
</script>