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 { getCategoryName, CATEGORIES } from "../lib/constants";
interface PostCardProps {
post: {
_id: string;
title: string;
description: string;
category?: string;
location?: string;
budget?: string;
status: string;
createdAt: number;
};
}
function getCategoryIcon(slug?: string): string {
if (!slug) return "document-text-outline";
return CATEGORIES.find((c) => c.slug === slug)?.icon ?? "document-text-outline";
}
function getCategoryColor(slug?: string): string {
if (!slug) return "#6B7280";
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 PostCard({ post }: PostCardProps) {
const theme = useTheme();
const categoryName = post.category ? getCategoryName(post.category) : null;
const iconName = getCategoryIcon(post.category);
const catColor = getCategoryColor(post.category);
const isOpen = post.status === "open";
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 }] },
]}
>
{post.title}
{post.description}
{categoryName && }
{post.location && (
{post.location}
)}
{post.budget && (
{post.budget}
)}
);
}