/* ============== Minassa Cars — data ============== */
/* Real stock car photos via Unsplash CDN (stable IDs). Each card has a
   striped placeholder fallback if a URL fails to load. */

const IMG = (id, w = 900) => `https://images.unsplash.com/${id}?auto=format&fit=crop&w=${w}&q=70`;
/* Prefer a bundled/inlined resource (standalone export) when present, else the live CDN URL. */
const RES = (key, url) => (typeof window !== 'undefined' && window.__resources && window.__resources[key]) || url;

const PHOTOS = {
  landcruiser:  RES('landcruiser', IMG('photo-1519641471654-76ce0107ad1b')),
  prado:        RES('prado', IMG('photo-1605559424843-9e4c228bf1c2')),
  hilux:        RES('hilux', IMG('photo-1559416523-140ddc3d238c')),
  patrol:       RES('patrol', IMG('photo-1612825173281-9a193378527e')),
  mercedes:     RES('mercedes', IMG('photo-1618843479313-40f8afb4b4d8')),
  glc:          RES('glc', IMG('photo-1617469767053-d3b523a0b982')),
  tucson:       RES('tucson', IMG('photo-1533106418989-88406c7cc8ca')),
  corolla:      RES('corolla', IMG('photo-1590362891991-f776e747a588')),
  rav4:         RES('rav4', IMG('photo-1568844293986-8d0400bd4745')),
  duster:       RES('duster', IMG('photo-1568605117036-5fe5e7bab0b7')),
  kangoo:       RES('kangoo', IMG('photo-1549924231-f129b911e442')),
  bmwx5:        RES('bmwx5', IMG('photo-1555215695-3004980ad54e')),
  rangerover:   RES('rangerover', IMG('photo-1606664515524-ed2f786a0bd6')),
  accent:       RES('accent', IMG('photo-1502877338535-766e1452684a')),
};

const VENDORS = {
  sahara:   { name: 'Sahara Motors', tier: 'premium', rating: 4.9, sales: 312, city: 'Nouakchott' },
  atlas:    { name: 'Atlas Auto', tier: 'gold', rating: 4.8, sales: 174, city: 'Nouakchott' },
  nktt:     { name: 'NKTT Cars', tier: 'gold', rating: 4.7, sales: 121, city: 'Nouakchott' },
  ndb:      { name: 'Nouadhibou Auto', tier: 'silver', rating: 4.6, sales: 64, city: 'Nouadhibou' },
  particulier: { name: 'محمد أ. (خاص)', tier: 'bronze', rating: 4.5, sales: 7, city: 'Rosso' },
  desert:   { name: 'Désert Location', tier: 'silver', rating: 4.7, sales: 88, city: 'Atar' },
};

/* type: 'sale' | 'rent' | 'auction' */
const CARS = [
  {
    id: 'lc-300', sponsored: true, featured: true, type: 'sale',
    brand: 'Toyota', model: 'Land Cruiser 300 GR-S', year: 2023,
    price: 12500000, photo: PHOTOS.landcruiser,
    km: 28000, fuel: 'ديزل', gearbox: 'أوتوماتيك', body: 'SUV', city: 'Nouakchott',
    condition: 'مستعمل', vendor: VENDORS.sahara,
  },
  {
    id: 'prado', sponsored: true, featured: true, type: 'sale',
    brand: 'Toyota', model: 'Land Cruiser Prado VXL', year: 2021,
    price: 7900000, photo: PHOTOS.prado,
    km: 61000, fuel: 'ديزل', gearbox: 'أوتوماتيك', body: 'SUV', city: 'Nouakchott',
    condition: 'مستعمل', vendor: VENDORS.atlas,
  },
  {
    id: 'glc', sponsored: true, featured: true, type: 'sale',
    brand: 'Mercedes-Benz', model: 'GLC 250 4MATIC', year: 2020,
    price: 6450000, photo: PHOTOS.glc,
    km: 74000, fuel: 'بنزين', gearbox: 'أوتوماتيك', body: 'SUV', city: 'Nouakchott',
    condition: 'مستعمل', vendor: VENDORS.nktt,
  },
  {
    id: 'hilux', featured: true, type: 'sale',
    brand: 'Toyota', model: 'Hilux Double Cabine', year: 2022,
    price: 5350000, photo: PHOTOS.hilux,
    km: 42000, fuel: 'ديزل', gearbox: 'يدوي', body: 'بيك أب', city: 'Nouadhibou',
    condition: 'مستعمل', vendor: VENDORS.ndb,
  },
  {
    id: 'patrol', featured: true, type: 'sale',
    brand: 'Nissan', model: 'Patrol Y62', year: 2019,
    price: 6100000, photo: PHOTOS.patrol,
    km: 98000, fuel: 'بنزين', gearbox: 'أوتوماتيك', body: 'SUV', city: 'Nouakchott',
    condition: 'مستعمل', vendor: VENDORS.atlas,
  },
  {
    id: 'tucson', type: 'sale',
    brand: 'Hyundai', model: 'Tucson', year: 2021,
    price: 3950000, photo: PHOTOS.tucson,
    km: 55000, fuel: 'بنزين', gearbox: 'أوتوماتيك', body: 'SUV', city: 'Nouakchott',
    condition: 'مستعمل', vendor: VENDORS.nktt,
  },
  {
    id: 'corolla', type: 'sale',
    brand: 'Toyota', model: 'Corolla', year: 2020,
    price: 2750000, photo: PHOTOS.corolla,
    km: 67000, fuel: 'بنزين', gearbox: 'أوتوماتيك', body: 'سيدان', city: 'Rosso',
    condition: 'مستعمل', vendor: VENDORS.particulier,
  },
  {
    id: 'rav4', type: 'sale',
    brand: 'Toyota', model: 'RAV4 Hybrid', year: 2022,
    price: 5200000, photo: PHOTOS.rav4,
    km: 31000, fuel: 'هجين', gearbox: 'أوتوماتيك', body: 'SUV', city: 'Nouakchott',
    condition: 'مستعمل', vendor: VENDORS.sahara,
  },
  {
    id: 'duster', type: 'sale',
    brand: 'Dacia', model: 'Duster', year: 2021,
    price: 2150000, photo: PHOTOS.duster,
    km: 48000, fuel: 'ديزل', gearbox: 'يدوي', body: 'SUV', city: 'Kaédi',
    condition: 'مستعمل', vendor: VENDORS.particulier,
  },
  {
    id: 'accent', type: 'sale',
    brand: 'Hyundai', model: 'Accent', year: 2019,
    price: 1450000, photo: PHOTOS.accent,
    km: 89000, fuel: 'بنزين', gearbox: 'يدوي', body: 'سيدان', city: 'Nouadhibou',
    condition: 'مستعمل', vendor: VENDORS.ndb,
  },
];

/* rental fleet */
const RENTALS = [
  {
    id: 'r-prado', type: 'rent',
    brand: 'Toyota', model: 'Land Cruiser Prado', year: 2022,
    daily: 18000, deposit: 200000, photo: PHOTOS.prado,
    fuel: 'ديزل', gearbox: 'أوتوماتيك', body: 'SUV', seats: 7, city: 'Nouakchott',
    vendor: VENDORS.desert,
  },
  {
    id: 'r-corolla', type: 'rent',
    brand: 'Toyota', model: 'Corolla', year: 2021,
    daily: 7500, deposit: 80000, photo: PHOTOS.corolla,
    fuel: 'بنزين', gearbox: 'أوتوماتيك', body: 'سيدان', seats: 5, city: 'Nouakchott',
    vendor: VENDORS.desert,
  },
  {
    id: 'r-duster', type: 'rent',
    brand: 'Dacia', model: 'Duster', year: 2021,
    daily: 9000, deposit: 100000, photo: PHOTOS.duster,
    fuel: 'ديزل', gearbox: 'يدوي', body: 'SUV', seats: 5, city: 'Atar',
    vendor: VENDORS.desert,
  },
];

/* live auctions — endsAt computed relative to load so countdowns are live */
const now = Date.now();
const MIN = 60 * 1000, HR = 60 * MIN;
const AUCTIONS = [
  {
    id: 'a-lc200', type: 'auction',
    brand: 'Toyota', model: 'Land Cruiser V8', year: 2018,
    photo: PHOTOS.landcruiser, city: 'Nouakchott',
    km: 112000, fuel: 'ديزل', gearbox: 'أوتوماتيك', body: 'SUV',
    vendor: VENDORS.sahara,
    startBid: 4000000, currentBid: 5350000, increment: 50000, bidders: 23,
    endsAt: now + 2 * HR + 14 * MIN + 30 * 1000,
    feed: [
      { who: 'مزايد #A47', amount: 5350000, ago: 'منذ 22 ث', you: false, lead: true },
      { who: 'أنت', amount: 5300000, ago: 'منذ 1 د', you: true, lead: false },
      { who: 'مزايد #C12', amount: 5250000, ago: 'منذ 2 د', you: false, lead: false },
      { who: 'مزايد #A47', amount: 5150000, ago: 'منذ 4 د', you: false, lead: false },
      { who: 'مزايد #B08', amount: 5050000, ago: 'منذ 6 د', you: false, lead: false },
    ],
  },
  {
    id: 'a-rr', type: 'auction',
    brand: 'Land Rover', model: 'Range Rover Sport', year: 2017,
    photo: PHOTOS.rangerover, city: 'Nouakchott',
    km: 134000, fuel: 'ديزل', gearbox: 'أوتوماتيك', body: 'SUV',
    vendor: VENDORS.atlas,
    startBid: 5000000, currentBid: 6800000, increment: 100000, bidders: 18,
    endsAt: now + 47 * MIN,
    feed: [],
  },
  {
    id: 'a-bmw', type: 'auction',
    brand: 'BMW', model: 'X5 xDrive', year: 2019,
    photo: PHOTOS.bmwx5, city: 'Nouadhibou',
    km: 86000, fuel: 'بنزين', gearbox: 'أوتوماتيك', body: 'SUV',
    vendor: VENDORS.ndb,
    startBid: 4500000, currentBid: 5900000, increment: 50000, bidders: 11,
    endsAt: now + 6 * HR + 5 * MIN,
    feed: [],
  },
  {
    id: 'a-glc', type: 'auction',
    brand: 'Mercedes-Benz', model: 'GLC Coupé', year: 2018,
    photo: PHOTOS.glc, city: 'Nouakchott',
    km: 101000, fuel: 'بنزين', gearbox: 'أوتوماتيك', body: 'SUV',
    vendor: VENDORS.nktt,
    startBid: 3800000, currentBid: 4650000, increment: 50000, bidders: 9,
    endsAt: now + 9 * MIN + 40 * 1000,
    feed: [],
  },
];

const BRANDS = ['Toyota', 'Mercedes-Benz', 'Hyundai', 'Nissan', 'Dacia', 'Land Rover', 'BMW', 'Renault', 'Kia'];
const CITIES = ['Nouakchott', 'Nouadhibou', 'Rosso', 'Kaédi', 'Atar', 'Zouérat', 'Néma'];
const BODIES = ['SUV', 'سيدان', 'بيك أب', 'مدينية', 'شحن'];
const FUELS = ['بنزين', 'ديزل', 'هجين', 'كهربائي'];

Object.assign(window, {
  CARS, RENTALS, AUCTIONS, VENDORS, PHOTOS, IMG,
  BRANDS, CITIES, BODIES, FUELS,
});
