68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
/**
|
|
* Generador de Prueba Social Dinámica, Variable y Determinística para Calzado Deportivo
|
|
* Produce calificaciones realistas (4.8 - 5.0), conteo de reviews (38 - 186) y pedidos (+75 a +340)
|
|
* únicos por modelo para maximizar la confianza del comprador sin generar dudas ni patrones repetitivos.
|
|
*/
|
|
|
|
export interface SocialProofData {
|
|
rating: number;
|
|
reviewsCount: number;
|
|
salesCount: number;
|
|
badge: string;
|
|
}
|
|
|
|
export function getProductSocialProof(product: {
|
|
id?: string;
|
|
name?: string;
|
|
brand?: string;
|
|
rating?: number;
|
|
reviewsCount?: number;
|
|
salesCount?: number;
|
|
originBadge?: string;
|
|
}): SocialProofData {
|
|
const seedStr = `${product.id || ''}-${product.name || 'sneaker'}-${product.brand || 'brand'}`;
|
|
let hash = 0;
|
|
for (let i = 0; i < seedStr.length; i++) {
|
|
hash = (hash << 5) - hash + seedStr.charCodeAt(i);
|
|
hash |= 0;
|
|
}
|
|
const positiveHash = Math.abs(hash);
|
|
|
|
// Calificaciones variables realistas entre 4.7 y 5.0
|
|
const ratingVariations = [4.8, 4.9, 4.9, 4.8, 5.0, 4.9, 4.8, 4.9, 5.0, 4.8];
|
|
const calculatedRating =
|
|
product.rating && product.rating > 0
|
|
? product.rating
|
|
: ratingVariations[positiveHash % ratingVariations.length];
|
|
|
|
// Número de reseñas variable entre 38 y 186
|
|
const calculatedReviews =
|
|
product.reviewsCount && product.reviewsCount > 0
|
|
? product.reviewsCount
|
|
: 38 + (positiveHash % 148);
|
|
|
|
// Contador de ventas variable entre 75 y 340 pedidos
|
|
const calculatedSales =
|
|
product.salesCount && product.salesCount > 0
|
|
? product.salesCount
|
|
: 75 + ((positiveHash * 13) % 265);
|
|
|
|
const badges = [
|
|
'★ Drop Exclusivo',
|
|
'🔥 Top Ventas',
|
|
'⚡ Más Pedido',
|
|
'✨ Tendencia Nacional',
|
|
'🚀 Lanzamiento 2026',
|
|
'💎 Edición Premium',
|
|
'🌟 Calidad G5',
|
|
];
|
|
const calculatedBadge = product.originBadge || badges[positiveHash % badges.length];
|
|
|
|
return {
|
|
rating: calculatedRating,
|
|
reviewsCount: calculatedReviews,
|
|
salesCount: calculatedSales,
|
|
badge: calculatedBadge,
|
|
};
|
|
}
|