11import { Link , useNavigate } from "react-router" ;
2+ import { useState } from "react" ;
23
34import type { Product } from "@/models/product.model" ;
45import { Button } from "@/components/ui" ;
@@ -10,17 +11,24 @@ interface ProductCardProps {
1011
1112export function ProductCard ( { product, categorySlug } : ProductCardProps ) {
1213 const navigate = useNavigate ( ) ;
14+ const [ hoveredPrice , setHoveredPrice ] = useState < number | null > ( null ) ;
1315 let variantTitle : string | null = null ;
1416 let variants : string [ ] = [ ] ;
1517 let variantParamName : "size" | "measure" | null = null ;
1618
19+ const variantMap : Record < string , string > = {
20+ "3*3" : "3*3" ,
21+ "5*5" : "5*5" ,
22+ "10*10" : "10*10"
23+ } ;
24+
1725 if ( categorySlug === "polos" ) {
1826 variantTitle = "Elige la talla" ;
1927 variants = [ "Small" , "Medium" , "Large" ] ;
2028 variantParamName = "size" ;
2129 } else if ( categorySlug === "stickers" ) {
2230 variantTitle = "Elige la medida" ;
23- variants = [ "3*3" , "5*5" , "10*10" ] ;
31+ variants = [ "3*3" , "5*5" , "10*10" ] ;
2432 variantParamName = "measure" ;
2533 }
2634
@@ -37,6 +45,23 @@ export function ProductCard({ product, categorySlug }: ProductCardProps) {
3745 }
3846 } ;
3947
48+ const hoverVariantClick = ( variant : string ) => {
49+ if ( variantParamName === "measure" ) {
50+ if ( product . stickersVariants && product . stickersVariants . length > 0 ) {
51+ const variantPrice = product . stickersVariants . find (
52+ ( v ) => v . measure === variant
53+ ) ?. price ;
54+ setHoveredPrice ( variantPrice || null ) ;
55+ } else {
56+ setHoveredPrice ( null ) ;
57+ }
58+ }
59+ } ;
60+
61+ const handleMouseLeave = ( ) => {
62+ setHoveredPrice ( null ) ;
63+ } ;
64+
4065 return (
4166 < Link
4267 to = { `/products/${ product . id } ` }
@@ -59,6 +84,8 @@ export function ProductCard({ product, categorySlug }: ProductCardProps) {
5984 < Button
6085 key = { variant }
6186 onClick = { ( e ) => handleVariantClick ( e , variant ) }
87+ onMouseEnter = { ( ) => hoverVariantClick ( variant ) }
88+ onMouseLeave = { handleMouseLeave }
6289 >
6390 { variant }
6491 </ Button >
@@ -70,7 +97,9 @@ export function ProductCard({ product, categorySlug }: ProductCardProps) {
7097 < div className = "flex grow flex-col gap-2 p-4" >
7198 < h2 className = "text-sm font-medium" > { product . title } </ h2 >
7299 < p className = "text-sm text-muted-foreground" > { product . description } </ p >
73- < p className = "mt-auto text-base font-medium" > S/{ product . price } </ p >
100+ < p className = "mt-auto text-base font-medium" >
101+ S/{ hoveredPrice !== null ? hoveredPrice : product . price }
102+ </ p >
74103 </ div >
75104 { product . isOnSale && (
76105 < span className = "absolute top-0 right-0 rounded-bl-xl bg-primary px-2 py-1 text-sm font-medium text-primary-foreground" >
0 commit comments