<template>
  <div class="mobiliari-details">
    <!-- Sección 1: Información del Servicio -->
    <div class="section">
      <h3>Información del Servicio</h3>
      <div class="detail-row">
        <img :src="iconMobiliari" alt="Mobiliario" class="icon-img" />
        <strong>Tipología:</strong>
        <span>{{ formatTipologia(service.mobiliari_decoracio.tipologia) }}</span>
      </div>
      <div class="detail-row" v-if="service.mobiliari_decoracio.subtipologia">
        <i class="bi bi-tags"></i>
        <strong>Subtipología:</strong>
        <span>{{ service.mobiliari_decoracio.subtipologia }}</span>
      </div>
      <div class="detail-row">
        <i class="bi bi-basket"></i>
        <strong>Tipo de servicio:</strong>
        <span>{{ service.mobiliari_decoracio.is_rental ? 'Alquiler' : 'Venta' }}</span>
      </div>
      <div class="detail-row">
        <i class="bi bi-box"></i>
        <strong>Cantidad disponible:</strong>
        <span>{{ service.mobiliari_decoracio.cantidad_min }} - {{ service.mobiliari_decoracio.cantidad_max }} unidades</span>
      </div>
    </div>

    <!-- Sección 2: Detalles -->
    <div class="section">
      <h3>Detalles del servicio</h3>
      <div class="detail-row" v-if="service.mobiliari_decoracio.forma">
        <i class="bi bi-square"></i>
        <strong>Forma:</strong>
        <span>{{ service.mobiliari_decoracio.forma }}</span>
      </div>
      <div class="detail-row" v-if="service.mobiliari_decoracio.modality">
        <i class="bi bi-gear"></i>
        <strong>Modalidad:</strong>
        <span>{{ service.mobiliari_decoracio.modality }}</span>
      </div>
      <div class="detail-row" v-if="service.mobiliari_decoracio.color && service.mobiliari_decoracio.color.length">
        <i class="bi bi-palette"></i>
        <strong>Colores:</strong>
      </div>
      <div class="caracteristicas-list" v-if="service.mobiliari_decoracio.color && service.mobiliari_decoracio.color.length">
        <span v-for="(color, idx) in service.mobiliari_decoracio.color" :key="idx" class="tagger">
          {{ color }}
        </span>
      </div>
      <div class="detail-row" v-if="service.mobiliari_decoracio.material && service.mobiliari_decoracio.material.length">
        <i class="bi bi-tools"></i>
        <strong>Materiales:</strong>
      </div>
      <div class="caracteristicas-list" v-if="service.mobiliari_decoracio.material && service.mobiliari_decoracio.material.length">
        <span v-for="(material, idx) in service.mobiliari_decoracio.material" :key="idx" class="tagger">
          {{ material }}
        </span>
      </div>
      <div class="detail-row" v-if="service.mobiliari_decoracio.style">
        <i class="bi bi-palette2"></i>
        <strong>Estilo:</strong>
        <span>{{ service.mobiliari_decoracio.style }}</span>
      </div>
      <div class="detail-row" v-if="service.mobiliari_decoracio.size">
        <i class="bi bi-arrows-angle-expand"></i>
        <strong>Tamaño:</strong>
        <span>{{ service.mobiliari_decoracio.size }}</span>
      </div>
      <div class="detail-row" v-if="service.mobiliari_decoracio.dimensions">
        <i class="bi bi-rulers"></i>
        <strong>Dimensiones:</strong>
        <span>{{ formatDimensions(service.mobiliari_decoracio.dimensions) }}</span>
      </div>
      <div class="detail-row" v-if="service.mobiliari_decoracio.caracteristicas && service.mobiliari_decoracio.caracteristicas.length">
        <i class="bi bi-stars"></i>
        <strong>Características:</strong>
      </div>
      <div class="caracteristicas-list" v-if="service.mobiliari_decoracio.caracteristicas && service.mobiliari_decoracio.caracteristicas.length">
        <span v-for="(caracteristica, idx) in service.mobiliari_decoracio.caracteristicas" :key="idx" class="tagger">
          {{ caracteristica }}
        </span>
      </div>

      <div class="detail-row" v-if="service.mobiliari_decoracio.complement">
        <i class="bi bi-plus-circle"></i>
        <strong>Complementos:</strong>
        <span>{{ service.mobiliari_decoracio.complement }}</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>
import iconMobiliari from '@/assets/icon_mobiliari2.png'

export default {
  name: 'DetallesMobiliari',
  props: {
    service: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      iconMobiliari
    }
  },
  methods: {
    formatTipologia (tipologia) {
      return tipologia
        .replace(/_/g, ' ')
        .replace(/([A-Z])/g, ' $1')
        .replace(/^./, str => str.toUpperCase())
    },
    formatDimensions (dimensions) {
      if (!dimensions) return ''
      const { width, height, depth } = dimensions
      return `${width} x ${height} x ${depth} cm`
    },
    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>
.mobiliari-details {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.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: center;
  gap: 0.5rem;
  margin-top: 1rem;
}

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

.detail-row i {
  color: #333;
  font-size: 1.1rem;
  flex-shrink: 0;
}

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

.detail-row span {
  color: #666;
}

.caracteristicas-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-left: 1.5rem;
  margin-top: 0.2rem;
}

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

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

.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;
}

.icon-img {
  width: 1.1rem;
  height: 1.1rem;
  object-fit: contain;
}
</style>
