export type ListingCondition = "new" | "used";

export interface BuyerListing {
  id: string;
  slug: string;
  title: string;
  price: number;
  /* Available stock from API (get_listing_detail). */
  quantity?: number;
  originalPrice?: number;
  isNegotiable: boolean;
  images: string[];
  category: string;
  subCategory: string;
  condition: ListingCondition;
  city: string;
  area: string;
  pincode: string;
  postedAt: string;
  views: number;
  savedCount: number;
  shareCount: number;
  isFeatured: boolean;
  listingStatus?: "available" | "sold";
  sellerId: string;
  sellerFirebaseId?: string;
  sellerName: string;
  sellerAvatar: string;
  sellerVerified: boolean;
  sellerJoinedDate: string;
  sellerTotalListings: number;
  sellerResponseRate: number;
  description: string;
  specs?: Record<string, string>;
  tags?: string[];
}

const u = (id: string, w = 800, h = 600) =>
  `https://images.unsplash.com/photo-${id}?w=${w}&h=${h}&fit=crop&q=80`;

const av = (id: string) =>
  `https://images.unsplash.com/photo-${id}?w=120&h=120&fit=crop&q=80`;




export const CATEGORIES = [
  { name: "Electronics", emoji: "📱", count: 45 },
  { name: "Vehicles", emoji: "🚗", count: 23 },
  { name: "Property", emoji: "🏠", count: 18 },
  { name: "Fashion", emoji: "👗", count: 31 },
  { name: "Furniture", emoji: "🛋️", count: 14 },
  { name: "Services", emoji: "🔧", count: 8 },
  { name: "Jobs", emoji: "💼", count: 12 },
  { name: "Sports", emoji: "⚽", count: 9 },
];

export const CONDITION_LABELS: Record<string, string> = {
  "new": "Brand New",
  "used": "Used",
};

export function timeAgo(dateStr: string): string {
  const date = new Date(dateStr);
  const now = new Date("2026-06-26T12:00:00Z");
  const diff = Math.floor((now.getTime() - date.getTime()) / 1000);
  if (diff < 60) return "just now";
  if (diff < 3600) return `${Math.floor(diff / 60)}m ago`;
  if (diff < 86400) return `${Math.floor(diff / 3600)}h ago`;
  return `${Math.floor(diff / 86400)}d ago`;
}

export function formatPrice(price: number, currency = "₹"): string {
  if (price >= 100000)
    return `${currency}${(price / 100000).toFixed(price % 100000 === 0 ? 0 : 1)}L`;
  if (price >= 1000)
    return `${currency}${(price / 1000).toFixed(price % 1000 === 0 ? 0 : 1)}K`;
  return `${currency}${price.toLocaleString()}`;
}
