|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { Heart, MapPin } from "lucide-react"; |
| 4 | +import { Button } from "@/components/ui/button"; |
| 5 | +import { Card, CardContent, CardFooter } from "@/components/ui/card"; |
| 6 | +import { Hotel } from "@/@types/hotel.entity"; |
| 7 | + |
| 8 | +interface HotelCardProps { |
| 9 | + hotel: Hotel; |
| 10 | + onToggleFavorite: (id: number) => void; |
| 11 | +} |
| 12 | + |
| 13 | +export default function HotelCard({ hotel, onToggleFavorite }: HotelCardProps) { |
| 14 | + return ( |
| 15 | + <Card className="overflow-hidden"> |
| 16 | + <div className="relative"> |
| 17 | + <img |
| 18 | + src={hotel.image || "/placeholder.svg"} |
| 19 | + alt={hotel.name} |
| 20 | + className="w-full h-[150px] object-cover" |
| 21 | + /> |
| 22 | + <Button |
| 23 | + variant="ghost" |
| 24 | + size="icon" |
| 25 | + className="absolute top-2 right-2 bg-white/80 hover:bg-white rounded-full h-8 w-8" |
| 26 | + onClick={() => onToggleFavorite(hotel.id)} |
| 27 | + > |
| 28 | + <Heart |
| 29 | + className={`h-5 w-5 ${hotel.isFavorite ? "fill-red-500 text-red-500" : "text-gray-500"}`} |
| 30 | + /> |
| 31 | + </Button> |
| 32 | + </div> |
| 33 | + <CardContent className="p-4"> |
| 34 | + <h3 className="font-semibold text-lg">{hotel.name}</h3> |
| 35 | + <div className="flex items-center text-sm text-gray-500 mt-1"> |
| 36 | + <MapPin className="h-4 w-4 mr-1" /> |
| 37 | + <span>{hotel.location}</span> |
| 38 | + </div> |
| 39 | + <div className="flex items-center mt-1"> |
| 40 | + <div className="flex"> |
| 41 | + {Array(Math.floor(hotel.stars)) |
| 42 | + .fill(0) |
| 43 | + .map((_, i) => ( |
| 44 | + <svg |
| 45 | + key={i} |
| 46 | + className="w-4 h-4 text-yellow-400" |
| 47 | + fill="currentColor" |
| 48 | + viewBox="0 0 20 20" |
| 49 | + > |
| 50 | + <path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118l-2.8-2.034c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"></path> |
| 51 | + </svg> |
| 52 | + ))} |
| 53 | + {hotel.stars % 1 !== 0 && ( |
| 54 | + <svg |
| 55 | + className="w-4 h-4 text-yellow-400" |
| 56 | + fill="currentColor" |
| 57 | + viewBox="0 0 20 20" |
| 58 | + > |
| 59 | + <defs> |
| 60 | + <linearGradient id="halfStarGradient"> |
| 61 | + <stop offset="50%" stopColor="currentColor" /> |
| 62 | + <stop offset="50%" stopColor="#D1D5DB" /> |
| 63 | + </linearGradient> |
| 64 | + </defs> |
| 65 | + <path |
| 66 | + fill="url(#halfStarGradient)" |
| 67 | + d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118l-2.8-2.034c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" |
| 68 | + ></path> |
| 69 | + </svg> |
| 70 | + )} |
| 71 | + </div> |
| 72 | + <span className="text-sm text-gray-500 ml-1">{hotel.stars}</span> |
| 73 | + </div> |
| 74 | + </CardContent> |
| 75 | + <CardFooter className="p-4 pt-0 flex justify-between items-center"> |
| 76 | + <div> |
| 77 | + <span className="font-bold text-lg">${hotel.price.toFixed(2)}</span> |
| 78 | + <span className="text-sm text-gray-500">/night</span> |
| 79 | + </div> |
| 80 | + </CardFooter> |
| 81 | + </Card> |
| 82 | + ); |
| 83 | +} |
0 commit comments