import { View, Text, Pressable } from "react-native";
import { Link } from "expo-router";
import { Ionicons } from "@expo/vector-icons";
import { useTheme } from "./theme";
import { Badge } from "./ui/badge";
import { Rating } from "./ui/rating";
import { getCategoryName, CATEGORIES } from "../lib/constants";
interface AdCardProps {
ad: {
_id: string;
title: string;
category: string;
location: string;
priceRange?: string;
ratingAvg?: number;
reviewCount: number;
};
}
function getCategoryIcon(slug: string): string {
return CATEGORIES.find((c) => c.slug === slug)?.icon ?? "construct-outline";
}
function getCategoryColor(slug: string): string {
const colors = ["#D4764A", "#4A8C6F", "#2B5797", "#C47A4A", "#8B5CF6", "#E07B5A",
"#3B82F6", "#7C3AED", "#06B6D4", "#D97706", "#059669", "#6B7280"];
const idx = slug.split("").reduce((a, c) => a + c.charCodeAt(0), 0);
return colors[idx % colors.length];
}
export function AdCard({ ad }: AdCardProps) {
const theme = useTheme();
const categoryName = getCategoryName(ad.category);
const iconName = getCategoryIcon(ad.category);
const catColor = getCategoryColor(ad.category);
return (
[
{
backgroundColor: theme.colors.surface,
borderRadius: theme.radius.lg,
padding: theme.spacing.md,
borderWidth: 1,
borderColor: theme.colors.border,
...theme.shadows.xs,
},
pressed && { opacity: 0.82, transform: [{ scale: 0.995 }] },
]}
>
{ad.title}
{ad.location}
{ad.ratingAvg != null && ad.ratingAvg > 0 && (
)}
{ad.priceRange && (
{ad.priceRange}
)}
);
}