<template>
  <div class="musica-details">
    <!-- Información del Servicio -->
    <div class="section">
      <h3>Información del Servicio</h3>
      <div class="detail-row">
        <i class="bi bi-music-note-beamed"></i>
        <strong>Tipo de música:</strong>
        <span>{{ formatMusicaType(service.musica.musica_type) }}</span>
      </div>
      <div class="detail-row">
        <i class="bi bi-music-note-list"></i>
        <strong>Tipo de canciones:</strong>
        <span>{{ formatCanciones(service.musica.canciones) }}</span>
      </div>
      <div class="detail-row">
        <i class="bi bi-clock"></i>
        <strong>Duración:</strong>
        <span>{{ service.musica.duracion }} horas</span>
      </div>
      <div class="detail-row" v-if="service.musica.generos && service.musica.generos.length">
        <i class="bi bi-music-note"></i>
        <strong>Géneros:</strong>
        <span>{{ service.musica.generos.map(g => formatGenero(g)).join(', ') }}</span>
      </div>
      <div class="detail-row" v-if="service.musica.instrumentos && service.musica.instrumentos.length">
        <img :src="iconInstrumento" alt="Instrument" class="icon-img" />
        <strong>Instrumentos:</strong>
        <span>{{ service.musica.instrumentos.map(i => formatInstrumento(i)).join(', ') }}</span>
      </div>
      <div class="detail-row" v-if="service.musica.caracteristicas && service.musica.caracteristicas.length">
        <i class="bi bi-stars"></i>
        <strong>Características:</strong>
      </div>
      <div class="caracteristicas-list" v-if="service.musica.caracteristicas && service.musica.caracteristicas.length">
        <span v-for="(caracteristica, idx) in service.musica.caracteristicas" :key="idx" class="tagger">
          {{ caracteristica }}
        </span>
      </div>
    </div>

    <!-- Raider -->
    <div class="section" v-if="service.musica.raider">
      <h3>Raider</h3>
      <div class="detail-row">
        <i class="bi bi-people"></i>
        <strong>Número de integrantes:</strong>
        <span>{{ service.musica.raider.num_integrantes }}</span>
      </div>
      <div class="detail-row" v-if="service.musica.raider.equipo && service.musica.raider.equipo.length">
        <i class="bi bi-person-lines-fill"></i>
        <strong>Equipo:</strong>
      </div>
      <div class="equipo-table" v-if="service.musica.raider.equipo && service.musica.raider.equipo.length">
        <div class="equipo-header">
          <span>Nombre</span>
          <span>Rol</span>
        </div>
        <div v-for="(miembro, idx) in service.musica.raider.equipo" :key="idx" class="equipo-row">
          <span>{{ miembro.nombre }}</span>
          <span>{{ miembro.rol }}</span>
        </div>
      </div>
      <div class="detail-row">
        <i class="bi bi-music-note"></i>
        <strong>Solicitar canción nueva:</strong>
        <span>{{ service.musica.raider.solicitar_cancion_nueva ? 'Sí' : 'No' }}</span>
      </div>
      <div class="detail-row">
        <i class="bi bi-speaker"></i>
        <strong>Equipo propio:</strong>
        <span>{{ service.musica.raider.equipo_propio ? 'Sí' : 'No' }}</span>
      </div>
      <div class="detail-row">
        <i class="bi bi-rulers"></i>
        <strong>Dimensiones del escenario:</strong>
        <span>
          {{ getDimensionesEscenario() }}
        </span>
      </div>
      <div class="detail-row" v-if="service.musica.raider.condiciones && service.musica.raider.condiciones.length">
        <i class="bi bi-exclamation-triangle"></i>
        <strong>Condiciones especiales:</strong>
      </div>
      <div class="conditions-list" v-if="service.musica.raider.condiciones && service.musica.raider.condiciones.length">
        <span v-for="(condicion, idx) in service.musica.raider.condiciones" :key="idx" class="condition">
          {{ condicion }}
        </span>
      </div>
    </div>

    <!-- 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>
import iconInstrumento from '@/assets/icono_instrument.png'
export default {
  name: 'DetallesMusica',
  props: {
    service: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      iconInstrumento
    }
  },
  methods: {
    getDimensionesEscenario () {
      const dims = this.service.musica.raider.dimensiones_escenario
      if (!dims) return '-'

      const ancho = dims.ancho || dims.width
      const alto = dims.alto || dims.height
      const profundidad = dims.profundidad || dims.depth

      if (!ancho && !alto && !profundidad) return '-'

      const partes = []
      if (ancho) partes.push(`${ancho}m`)
      if (alto) partes.push(`${alto}m`)
      if (profundidad) partes.push(`${profundidad}m`)

      return partes.join(' x ')
    },
    formatMusicaType (type) {
      return type
        .replace(/_/g, ' ')
        .replace(/([A-Z])/g, ' $1')
        .replace(/^./, str => str.toUpperCase())
    },
    formatCanciones (type) {
      return type
        .replace(/_/g, ' ')
        .replace(/([A-Z])/g, ' $1')
        .replace(/^./, str => str.toUpperCase())
    },
    formatGenero (genero) {
      return genero
        .replace(/_/g, ' ')
        .replace(/([A-Z])/g, ' $1')
        .replace(/^./, str => str.toUpperCase())
    },
    formatInstrumento (instrumento) {
      return instrumento
        .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>
.musica-details {
  display: flex;
  flex-direction: column;
  gap: 0rem;
}
.icon-img {
  width: 25px;
  height: 25px;
  object-fit: contain;
  margin-right: -0.4rem;
}

.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-left: 1.7rem;
  margin-top: -0.5rem;
  margin-bottom: 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;
}

.equipo-table {
  width: 100%;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  overflow: hidden;
  margin-left: 1.7rem;
  margin-top: -0.5rem;
  margin-bottom: 1rem;
}

.equipo-header {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #f8f9fa;
  padding: 0.8rem;
  font-weight: 600;
  color: #333;
  border-bottom: 1px solid #e9ecef;
}

.equipo-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 0.8rem;
  border-bottom: 1px solid #e9ecef;
}

.equipo-row:last-child {
  border-bottom: none;
}

.equipo-row span:first-child {
  font-weight: 500;
  color: #333;
}

.equipo-row span:last-child {
  color: #666;
  font-style: italic;
}

.conditions-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  width: 100%;
  margin-left: 1.7rem;
  margin-top: -0.5rem;
  margin-bottom: 1rem;
}

.condition {
  background-color: #fff3e0;
  color: #e65100;
  border: 1px solid #ffe0b2;
  border-radius: 6px;
  padding: 0.25rem 0.7rem;
  font-size: 0.9em;
  display: inline-block;
}

.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;
  }
  .equipo-header,
  .equipo-row {
    grid-template-columns: 1fr;
    gap: 0.3rem;
  }
  .equipo-header span:last-child,
  .equipo-row span:last-child {
    border-top: 1px solid #e9ecef;
    padding-top: 0.3rem;
  }
}
</style>
