<template>
  <div class="espai-details">
    <!-- Sección 1: Información del Servicio -->
    <div class="section">
      <h3>Información del Servicio</h3>
      <div class="detail-row">
        <i class="bi bi-building"></i>
        <strong>Tipo de espacio:</strong>
        <span>{{ formatEspaiType(service.espai.espai_type) }}</span>
      </div>
      <div class="detail-row">
        <i class="bi bi-people"></i>
        <strong>Capacidad:</strong>
        <span>{{ service.espai ? `${service.espai.capacitat_min} - ${service.espai.capacitat_max} personas` : '-' }}</span>
      </div>
      <div class="detail-row" v-if="service.espai && service.espai.caracteristicas && service.espai.caracteristicas.length">
        <i class="bi bi-stars"></i>
        <strong>Características:</strong>
      </div>
      <div class="caracteristicas-list">
        <span v-for="(caracteristica, idx) in service.espai.caracteristicas" :key="idx" class="tagger">
          {{ caracteristica }}
        </span>
      </div>
    </div>

    <!-- Sección 3: Servicios Incluidos -->
    <div class="section" v-if="service && service.service_include">
      <h3>Servicios Incluidos</h3>
      <div class="services-included-list">
        <div v-for="(value, key) in service.service_include" :key="key" class="detail-row">
          <i class="bi bi-check-circle-fill"></i>
          <strong>{{ formatServiceIncludeKey(key) }}:</strong>
          <span>{{ formatServiceValue(value) }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetallesEspai',
  props: {
    service: {
      type: Object,
      required: true
    }
  },
  methods: {
    formatEspaiType (type) {
      return type
        .replace(/_/g, ' ')
        .replace(/([A-Z])/g, ' $1')
        .replace(/^./, str => str.toUpperCase())
    },
    formatServiceIncludeKey (key) {
      return key
        .replace(/_/g, ' ')
        .replace(/([A-Z])/g, ' $1')
        .replace(/^./, str => str.toUpperCase())
    },
    formatServiceValue (value) {
      if (typeof value === 'boolean') {
        return value ? 'Sí' : 'No'
      }
      if (Array.isArray(value)) {
        return value.join(', ')
      }
      if (typeof value === 'string') {
        return value.replace(/^["']|["']$/g, '')
      }
      return String(value)
    }
  }
}
</script>

<style scoped>
.espai-details {
  display: flex;
  flex-direction: column;
  gap: 0rem;
}

.section {
  background: #fff;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.section h3 {
  color: #800020;
  margin: 0 0 1rem 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.detail-row {
  font-size: 1rem;
  color: #333;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.detail-row:last-child {
  margin-bottom: 0;
}

.detail-row i {
  color:rgb(19, 19, 19);
  font-size: 1.1rem;
  flex-shrink: 0;
  margin-top: 0.2rem;
}

.detail-row strong {
  color: #333;
  font-weight: 700;
  flex-shrink: 0;
  margin-right: 0.2rem;
}

.detail-row span {
  color: #666;
  text-align: left;
  flex: 1;
}

.caracteristicas-list {
  display: flex;
  flex-wrap: wrap;
  margin-top: 0.1rem;
}

.tagger {
  background: rgb(213, 213, 213);
  color: #2C3E50;
  border-radius: 6px;
  padding: 0.25rem 0.7rem;
  font-size: 0.9em;
  display: inline-block;
  margin-right: 0.5rem;
  margin-bottom: 0.5rem;
}

.services-included-list {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  width: 100%;
}

.services-included-list .detail-row {
  background: #f8f9fa;
  border-radius: 6px;
  padding: 0.8rem;
  border: 1px solid #e9ecef;
  margin-bottom: 0;
}

.services-included-list .detail-row i {
  color: #28a745;
}

@media (max-width: 768px) {
  .detail-row {
    flex-wrap: wrap;
  }
  .detail-row span {
    width: 100%;
    margin-left: 1.7rem;
  }
}
</style>
