import React, { useMemo } from "react" import { ExternalLink, Copy } from "lucide-react" import { Link } from "react-router-dom" type DealDetailsProps = { title: string price: string store: string link: string postedBy: string postedAgo: string // ISO veya "19 dakika" gibi bir şey gelebilir } function formatTimeAgo(input: string) { if (!input) return "" // Zaten "dakika/saat/gün" gibi geldiyse elleme const looksHuman = /dakika|saat|gün|hafta|ay|yıl|sn|saniye/i.test(input) if (looksHuman) return input const date = new Date(input) if (Number.isNaN(date.getTime())) return input const diffMs = Date.now() - date.getTime() const diffSec = Math.max(0, Math.floor(diffMs / 1000)) if (diffSec < 60) return `${diffSec} sn` const diffMin = Math.floor(diffSec / 60) if (diffMin < 60) return `${diffMin} dk` const diffHour = Math.floor(diffMin / 60) if (diffHour < 24) return `${diffHour} sa` const diffDay = Math.floor(diffHour / 24) if (diffDay < 7) return `${diffDay} gün` const diffWeek = Math.floor(diffDay / 7) if (diffWeek < 4) return `${diffWeek} hf` const diffMonth = Math.floor(diffDay / 30) if (diffMonth < 12) return `${diffMonth} ay` const diffYear = Math.floor(diffDay / 365) return `${diffYear} yıl` } export default function DealDetails({ title, price, store, link, postedBy, postedAgo, }: DealDetailsProps) { const hasLink = Boolean(link && link.trim().length > 0) const timeAgo = useMemo(() => formatTimeAgo(postedAgo), [postedAgo]) return (
{/* Header */}

{title}

{store ? ( {store} ) : null}
{/* Meta: posted by + time */}
Paylaşan{" "} {postedBy ? ( e.stopPropagation()} > {postedBy} ) : ( - )} {timeAgo ? `${timeAgo} önce` : "-"}
{/* Price */}
Fiyat {price} ₺
{/* Actions */}
{ if (!hasLink) e.preventDefault() }} className={[ "inline-flex items-center justify-center gap-2 rounded-xl px-4 py-3 text-sm font-semibold transition", hasLink ? "bg-primary text-[color:var(--color-on-primary)] hover:bg-primary-hover" : "bg-background border border-border text-text-muted cursor-not-allowed", ].join(" ")} > Fırsata Git
) }