import { Feather } from "@expo/vector-icons"; import * as Haptics from "expo-haptics"; import React, { useRef } from "react"; import { Alert, Animated, StyleSheet, Text, TouchableOpacity, View, } from "react-native"; import { Swipeable } from "react-native-gesture-handler"; import { useColors } from "@/hooks/useColors"; import { PostizPost } from "@/context/PostizContext"; import { StatusBadge } from "./StatusBadge"; interface PostCardProps { post: PostizPost; onDelete: (id: string) => Promise; onLongPress: (post: PostizPost) => void; onReschedule?: (post: PostizPost) => void; } function formatDate(dateStr: string): string { try { const d = new Date(dateStr); return d.toLocaleDateString("en-US", { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit", }); } catch { return dateStr; } } function getNetworkIcon(type?: string): React.ComponentProps["name"] { const t = (type ?? "").toLowerCase(); if (t.includes("twitter") || t.includes("x")) return "twitter"; if (t.includes("linkedin")) return "linkedin"; if (t.includes("instagram")) return "instagram"; if (t.includes("facebook")) return "facebook"; if (t.includes("youtube")) return "youtube"; return "globe"; } export function PostCard({ post, onDelete, onLongPress, onReschedule }: PostCardProps) { const colors = useColors(); const swipeRef = useRef(null); const handleDelete = () => { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium); Alert.alert("Delete Post", "Are you sure you want to delete this post?", [ { text: "Cancel", style: "cancel", onPress: () => swipeRef.current?.close(), }, { text: "Delete", style: "destructive", onPress: async () => { await onDelete(post.id); }, }, ]); }; const renderRightActions = ( _progress: Animated.AnimatedInterpolation, dragX: Animated.AnimatedInterpolation ) => { const scale = dragX.interpolate({ inputRange: [-80, 0], outputRange: [1, 0.8], extrapolate: "clamp", }); return ( ); }; const renderLeftActions = post.state === "QUEUE" && onReschedule ? ( _progress: Animated.AnimatedInterpolation, dragX: Animated.AnimatedInterpolation ) => { const scale = dragX.interpolate({ inputRange: [0, 80], outputRange: [0.8, 1], extrapolate: "clamp", }); return ( { swipeRef.current?.close(); onReschedule(post); }} activeOpacity={0.8} > ); } : undefined; const integrations = post.integrations ?? (post.integration ? [post.integration] : []); const truncatedContent = post.content.length > 140 ? post.content.slice(0, 140) + "…" : post.content; return ( onLongPress(post)} delayLongPress={400} style={[ styles.card, { backgroundColor: colors.card, borderBottomColor: colors.border }, ]} > {integrations.slice(0, 3).map((intg) => ( ))} {integrations.length > 3 && ( +{integrations.length - 3} )} {truncatedContent} {integrations.length > 0 && ( <> {integrations .slice(0, 2) .map((i) => i.name || i.identifier || "") .filter(Boolean) .join(", ")} {integrations.length > 2 ? ` +${integrations.length - 2}` : ""} · )} {formatDate(post.publishDate)} ); } const styles = StyleSheet.create({ card: { paddingHorizontal: 20, paddingVertical: 14, borderBottomWidth: StyleSheet.hairlineWidth, gap: 8, }, header: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", }, integrations: { flexDirection: "row", alignItems: "center", gap: 4, }, networkIcon: { width: 22, height: 22, borderRadius: 11, alignItems: "center", justifyContent: "center", }, moreText: { fontSize: 11, fontFamily: "Inter_500Medium", }, content: { fontSize: 14, fontFamily: "Inter_400Regular", lineHeight: 20, }, footer: { flexDirection: "row", alignItems: "center", gap: 4, }, date: { fontSize: 12, fontFamily: "Inter_400Regular", }, accountName: { fontSize: 12, fontFamily: "Inter_400Regular", flexShrink: 1, }, dot: { fontSize: 12, marginHorizontal: 3, }, deleteAction: { width: 72, alignItems: "center", justifyContent: "center", }, rescheduleAction: { width: 72, alignItems: "center", justifyContent: "center", }, });