import type { PaymentOrder, SellerStats } from "./types";

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

export const MOCK_ORDERS: PaymentOrder[] = [
  {
    id: "ord-001",
    listingId: "bl1",
    listingSlug: "iphone-14-pro-max-256gb-deep-purple",
    listingTitle: "iPhone 14 Pro Max 256GB Deep Purple",
    listingImage: img("1510557880182-3d4d3cba35a5"),
    listingCondition: "Like New",
    sellerId: "s1",
    sellerName: "Rahul Sharma",
    sellerAvatar: av("1535713875002-d1d0cf377fde"),
    sellerVerified: true,
    buyerId: "me",
    buyerInfo: {
      name: "Keyur Ramani",
      email: "keyur@divinetechs.com",
      phone: "+91 98765 43210",
      address: "42, Sunrise Apartments, Andheri West",
      city: "Mumbai",
      pincode: "400053",
    },
    quantity: 1,
    listingPrice: 68000,
    serviceFee: 680,
    deliveryFee: 0,
    discount: 0,
    tax: 1224,
    totalAmount: 69904,
    paymentMethod: "paypal",
    paymentStatus: "paid",
    orderStatus: "completed",
    transactionId: "PAY-8XK7293N5B",
    paypalOrderId: "PP-ORD-29284910",
    createdAt: "2026-06-24T14:30:00Z",
    updatedAt: "2026-06-24T14:35:00Z",
  },
  {
    id: "ord-002",
    listingId: "bl2",
    listingSlug: "macbook-air-m2-13inch-midnight",
    listingTitle: "MacBook Air M2 13-inch — Midnight",
    listingImage: img("1517336714731-489689fd1ca8"),
    listingCondition: "Like New",
    sellerId: "s2",
    sellerName: "Priya Mehta",
    sellerAvatar: av("1494790108377-be9c29b29330"),
    sellerVerified: true,
    buyerId: "me",
    buyerInfo: {
      name: "Keyur Ramani",
      email: "keyur@divinetechs.com",
      phone: "+91 98765 43210",
      address: "42, Sunrise Apartments, Andheri West",
      city: "Mumbai",
      pincode: "400053",
    },
    quantity: 1,
    listingPrice: 70000,
    serviceFee: 700,
    deliveryFee: 0,
    discount: 0,
    tax: 1260,
    totalAmount: 71960,
    paymentMethod: "paypal",
    paymentStatus: "refunded",
    orderStatus: "refunded",
    transactionId: "PAY-3RK5821M9C",
    paypalOrderId: "PP-ORD-38291010",
    createdAt: "2026-06-25T09:00:00Z",
    updatedAt: "2026-06-26T10:00:00Z",
    refundStatus: "processed",
    refundReason: "Item condition did not match description",
  },
  {
    id: "ord-003",
    listingId: "bl5",
    listingSlug: "canon-eos-r50-mirrorless-kit",
    listingTitle: "Canon EOS R50 + 18-45mm Kit Lens",
    listingImage: img("1502920917128-1aa500764cbd"),
    listingCondition: "Like New",
    sellerId: "me",
    sellerName: "Keyur Ramani",
    sellerAvatar: av("1535713875002-d1d0cf377fde"),
    sellerVerified: false,
    buyerId: "b1",
    buyerInfo: {
      name: "Arjun Nair",
      email: "arjun@example.com",
      phone: "+91 91234 56789",
      address: "15, Palm Grove, Bandra",
      city: "Mumbai",
      pincode: "400050",
    },
    quantity: 1,
    listingPrice: 40000,
    serviceFee: 400,
    deliveryFee: 0,
    discount: 0,
    tax: 720,
    totalAmount: 41120,
    paymentMethod: "cod",
    paymentStatus: "pending",
    orderStatus: "awaiting_confirmation",
    createdAt: "2026-06-26T10:00:00Z",
    updatedAt: "2026-06-26T10:00:00Z",
  },
  {
    id: "ord-004",
    listingId: "bl3",
    listingSlug: "sony-wh1000xm5-noise-cancelling",
    listingTitle: "Sony WH-1000XM5 Headphones",
    listingImage: img("1505740420928-5e560c06d30e"),
    listingCondition: "Good",
    sellerId: "me",
    sellerName: "Keyur Ramani",
    sellerAvatar: av("1535713875002-d1d0cf377fde"),
    sellerVerified: false,
    buyerId: "b2",
    buyerInfo: {
      name: "Meera Joshi",
      email: "meera@example.com",
      phone: "+91 99887 76655",
      address: "8, Rose Garden, Lajpat Nagar",
      city: "Delhi",
      pincode: "110024",
    },
    quantity: 1,
    listingPrice: 22000,
    serviceFee: 220,
    deliveryFee: 0,
    discount: 0,
    tax: 396,
    totalAmount: 22616,
    paymentMethod: "cod",
    paymentStatus: "paid",
    orderStatus: "completed",
    transactionId: "COD-8821-DL",
    createdAt: "2026-06-25T14:00:00Z",
    updatedAt: "2026-06-25T20:00:00Z",
  },
  {
    id: "ord-005",
    listingId: "bl6",
    listingSlug: "samsung-galaxy-s23-ultra",
    listingTitle: "Samsung Galaxy S23 Ultra 512GB",
    listingImage: img("1610945415114-8c7a3b36b9aa"),
    listingCondition: "Good",
    sellerId: "s3",
    sellerName: "Deepak Patel",
    sellerAvatar: av("1472099645785-5658abf4ff4e"),
    sellerVerified: true,
    buyerId: "me",
    buyerInfo: {
      name: "Keyur Ramani",
      email: "keyur@divinetechs.com",
      phone: "+91 98765 43210",
      address: "42, Sunrise Apartments, Andheri West",
      city: "Mumbai",
      pincode: "400053",
    },
    quantity: 1,
    listingPrice: 52000,
    serviceFee: 520,
    deliveryFee: 0,
    discount: 2000,
    tax: 900,
    totalAmount: 51420,
    paymentMethod: "paypal",
    paymentStatus: "failed",
    orderStatus: "cancelled",
    transactionId: undefined,
    createdAt: "2026-06-23T11:00:00Z",
    updatedAt: "2026-06-23T11:05:00Z",
    failureReason: "Payment declined by bank",
  },
];

export const CHECKOUT_ITEM: Omit<
  PaymentOrder,
  "id" | "paymentMethod" | "paymentStatus" | "orderStatus" | "createdAt" | "updatedAt" | "buyerId"
> = {
  listingId: "bl7",
  listingSlug: "iphone-14-pro-max-256gb-deep-purple",
  listingTitle: "iPhone 14 Pro Max 256GB Deep Purple",
  listingImage: img("1510557880182-3d4d3cba35a5"),
  listingCondition: "Like New",
  sellerId: "s1",
  sellerName: "Rahul Sharma",
  sellerAvatar: av("1535713875002-d1d0cf377fde"),
  sellerVerified: true,
  buyerInfo: {
    name: "Keyur Ramani",
    email: "keyur@divinetechs.com",
    phone: "+91 98765 43210",
    address: "42, Sunrise Apartments, Andheri West",
    city: "Mumbai",
    pincode: "400053",
  },
  quantity: 1,
  listingPrice: 68000,
  serviceFee: 680,
  deliveryFee: 0,
  discount: 0,
  tax: 1224,
  totalAmount: 69904,
};

export const SELLER_STATS: SellerStats = {
  totalEarnings: 63736,
  pendingAmount: 41120,
  completedAmount: 22616,
  refundedAmount: 0,
  totalOrders: 3,
  averageOrderValue: 28570,
  monthlyData: [
    { month: "Jan", amount: 12000, orders: 1 },
    { month: "Feb", amount: 18500, orders: 2 },
    { month: "Mar", amount: 9200, orders: 1 },
    { month: "Apr", amount: 31000, orders: 3 },
    { month: "May", amount: 22616, orders: 2 },
    { month: "Jun", amount: 41120, orders: 1 },
  ],
};

export function formatPrice(n: number): string {
  if (n >= 100000) return `₹${(n / 100000).toFixed(1).replace(/\.0$/, "")}L`;
  if (n >= 1000) return `₹${(n / 1000).toFixed(1).replace(/\.0$/, "")}K`;
  return `₹${n.toLocaleString("en-IN")}`;
}

export function formatPriceFull(n: number): string {
  return `₹${n.toLocaleString("en-IN")}`;
}

export function formatDate(iso: string): string {
  return new Date(iso).toLocaleDateString("en-IN", {
    day: "numeric",
    month: "short",
    year: "numeric",
    hour: "2-digit",
    minute: "2-digit",
    hour12: true,
  });
}
