<template>
  <v-card class="product-card">
    <v-row no-gutters align="center" class="w-100 py-3 px-2">
      <v-col cols="12" md="3" class="d-flex justify-center">
        <v-img :src="product.img" class="product-img" contain></v-img>
      </v-col>

      <v-col cols="12" md="5">
        <v-card-title class="product-name">{{ product.name }}</v-card-title>
        <v-card-subtitle class="product-description">{{ product.description }}</v-card-subtitle>
        <div class="prices mt-3">
          <div class="price-unit">
            <span class="price-label">Precio unitario</span>
            <span class="price-value">{{ currency(product.price) }}</span>
          </div>
          <div class="price-total">
            <span class="price-label">Precio total</span>
            <span class="price-value total">{{ currency(product.price * product.quantity) }}</span>
          </div>
        </div>
      </v-col>

      <v-col cols="12" md="4" class="d-flex align-center justify-md-end justify-center mt-3 mt-md-0">
        <div class="quantity-controls">
          <v-btn icon small class="qty-btn" @click="decrease(product)">
            <v-icon small>mdi-minus</v-icon>
          </v-btn>
          <v-text-field
            v-model.number="product.quantity"
            type="number"
            min="0"
            class="quantity-input"
            dense
            outlined
            hide-details
            aria-label="Cantidad"
            @input="handleQuantityChange"
          />
          <v-btn icon small class="qty-btn qty-btn-add" @click="handleIncrease">
            <v-icon small>mdi-plus</v-icon>
          </v-btn>
        </div>
      </v-col>
    </v-row>
  </v-card>
</template>

<script>
export default {
  props: {
    product: {
      type: Object,
      required: true
    },
    increase: {
      type: Function,
      required: true
    },
    decrease: {
      type: Function,
      required: true
    },
    currency: {
      type: Function,
      required: true
    },
    updateQuantity: {
      type: Function,
      required: true
    }
  },
  methods: {
    handleIncrease() {
      this.increase(this.product);
      this.$emit('add-to-cart', this.product);
    },
    handleQuantityChange(value) {
      this.updateQuantity(this.product);
      if (this.product.quantity > 0) {
        this.$emit('add-to-cart', this.product);
      }
    }
  }
}
</script>

<style scoped>
.product-card {
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  transition: all 0.3s ease;
}
.product-card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  transform: translateY(-2px);
  border-color: #bdbdbd;
}
.product-img {
  width: 120px;
  height: 120px;
  border-radius: 10px;
  object-fit: cover;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.product-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: #2c3e50;
  line-height: 1.3;
  padding: 0 0 4px 0;
}
.product-description {
  font-size: 0.85rem;
  color: #7f8c8d;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.prices {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.price-unit, .price-total {
  display: flex;
  align-items: center;
  gap: 8px;
}
.price-label {
  font-size: 0.75rem;
  color: #95a5a6;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.price-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: #2c3e50;
}
.price-value.total {
  color: #27ae60;
  font-size: 1.1rem;
}
.quantity-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #f5f5f5;
  border-radius: 25px;
  padding: 4px;
}
.quantity-input {
  max-width: 70px;
}
.quantity-input input {
  text-align: center;
  font-weight: 600;
}
.qty-btn {
  min-width: 32px !important;
  height: 32px !important;
  border-radius: 50% !important;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.qty-btn:hover {
  background: #e0e0e0;
}
.qty-btn-add {
  background: #27ae60;
  color: white;
}
.qty-btn-add:hover {
  background: #219a52 !important;
}
@media (max-width: 960px) {
  .product-img {
    width: 100px;
    height: 100px;
  }
}
@media (max-width: 600px) {
  .product-card {
    border-radius: 8px;
  }
  .product-img {
    width: 80px;
    height: 80px;
  }
  .product-name {
    font-size: 1rem;
    text-align: center;
  }
  .prices {
    align-items: center;
  }
}
</style>
