<template>
  <div class="general-event-service-card">
    <div class="card-content">
      <!-- Columna de imagen -->
      <div class="image-column">
        <img :src="mainImage" alt="Imagen del servicio" class="service-image" />
      </div>
      <!-- Columna de información -->
      <div class="info-column">
        <div class="info-header">
          <div class="service-title">
            <strong>{{ reserva.service.name }}</strong>
            <span v-if="serviceTypeLabel">({{ serviceTypeLabel }})</span>
          </div>
          <div class="action-buttons">
            <button class="details-btn" @click="goToDetails">
              <i class="bi bi-eye"></i>
              Ver
            </button>
          </div>
        </div>
        <div class="service-info">
          <div><strong>Fecha inicio:</strong> {{ formatDate(reserva.data_inicio) }}</div>
          <div><strong>Fecha fin:</strong> {{ formatDate(reserva.data_fin) }}</div>
          <div><strong>Cantidad:</strong> {{ reserva.cantidad }}</div>
          <div><strong>Precio total:</strong> {{ reserva.price_total }} €</div>
          <div v-if="reserva.service.address">
            <strong>Dirección:</strong> {{ formatAddress(reserva.service.address) }}
          </div>
          <div v-if="caracteristicas && caracteristicas.length">
            <strong>Características:</strong> {{ caracteristicas.join(', ') }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ReadOnlyEventServiceCard',
  props: {
    reserva: { type: Object, required: true }
  },
  computed: {
    mainImage () {
      return this.reserva.service.images && this.reserva.service.images.length > 0
        ? this.reserva.service.images[0]
        : 'https://via.placeholder.com/300x200?text=Sin+imagen'
    },
    serviceTypeLabel () {
      return this.reserva.service.type || ''
    },
    caracteristicas () {
      if (this.reserva.service.espai && this.reserva.service.espai.caracteristiques) {
        return this.reserva.service.espai.caracteristiques
      }
      return []
    }
  },
  methods: {
    goToDetails () {
      this.$router.push({ name: 'detallesService', params: { id: this.reserva.service.id } })
    },
    formatDate (dateStr) {
      if (!dateStr) return '-'
      const d = new Date(dateStr)
      return d.toLocaleString('es-ES', { dateStyle: 'short', timeStyle: 'short' })
    },
    formatAddress (addr) {
      if (!addr) return ''
      return `${addr.direccion}, ${addr.ciudad} (${addr.codigo_postal})`
    }
  }
}
</script>

<style scoped>
.general-event-service-card {
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  margin-bottom: 24px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  overflow: hidden;
}
.card-content {
  display: flex;
  flex-direction: row;
}
.image-column {
  flex: 0 0 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f7f7f7;
}
.service-image {
  width: 240px;
  height: 180px;
  object-fit: cover;
  border-radius: 8px;
}
.info-column {
  flex: 1;
  padding: 24px 24px 16px 24px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  position: relative;
  text-align: left;
}
.info-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}
.service-title {
  font-size: 1.2em;
  font-weight: bold;
}
.action-buttons {
  display: flex;
  gap: 8px;
}
.details-btn {
  background: #fff;
  border: 1px solid #1976d2;
  color: #1976d2;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.95em;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.details-btn:hover {
  background: #e3f2fd;
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.service-info {
  margin-bottom: 18px;
}
</style>
