export type Cat = { key: string; name: string; icon: string; count: number };
export type AdCatT = { key: string; name: string; icon: string; count: number };
export type Tint = [string, string, string];
export type Amenity = { icon: string; label: string };
export type Hour = { d: string; h: string };
export type Listing = {
  id: number;
  slug: string;
  name: string;
  cat: string;
  catName: string;
  area: string;
  city: string;
  rating: number;
  reviews: number;
  price: string;
  unit: string;
  priceLevel: string;
  status: 'open' | 'soon';
  tags: string[];
  desc: string;
  address?: string;
  phone?: string;
  hours: Hour[];
  amenities: Amenity[];
  verified: boolean;
  photos?: string[];
  ownerId?: number;
};
export type Seller = { n: string; t: 'particulier' | 'pro'; r: number; since: string; ads: number };
export type Ad = {
  id: number;
  title: string;
  cat: string;
  icon?: string;
  price: string;
  unit?: string;
  city: string;
  area: string;
  when: string;
  cond: string;
  nego: boolean;
  seller: Seller;
  desc: string;
  photos?: string[];
};

export const CATS: Cat[] = [
  { key: 'restaurants', name: 'Restaurants', icon: 'utensils', count: 1240 },
  { key: 'hotels', name: 'Hôtels & Riads', icon: 'bed', count: 386 },
  { key: 'cafes', name: 'Cafés', icon: 'coffee', count: 712 },
  { key: 'beaute', name: 'Beauté & Coiffure', icon: 'scissors', count: 934 },
  { key: 'spa', name: 'Hammam & Spa', icon: 'spa', count: 211 },
  { key: 'patisseries', name: 'Pâtisseries', icon: 'cake', count: 488 },
  { key: 'fleuristes', name: 'Fleuristes', icon: 'flower', count: 162 },
  { key: 'auto', name: 'Auto & Services', icon: 'car', count: 540 },
  { key: 'mode', name: 'Mode', icon: 'shirt', count: 377 },
  { key: 'epicerie', name: 'Épicerie fine', icon: 'bag', count: 203 },
];

export const TINTS: Record<string, Tint> = {
  restaurants: ['#FCE4DE', '#F4A98E', '#B85230'],
  hotels: ['#E2ECEA', '#A4C8BD', '#2C6B5C'],
  cafes: ['#EFE3D2', '#D4B488', '#8C5E30'],
  beaute: ['#F4E0EC', '#DDA3C2', '#9C467A'],
  spa: ['#E7E9DA', '#BAC299', '#67703E'],
  patisseries: ['#F8E7D2', '#EDBE8E', '#B97E3C'],
  fleuristes: ['#F6DEEA', '#E29DBC', '#A8487A'],
  auto: ['#E2E6EE', '#A6B2C6', '#48566E'],
  mode: ['#EAE4DC', '#C7B49A', '#7C654A'],
  epicerie: ['#ECE8D6', '#CBC089', '#7C7236'],
};

// Les 58 wilayas d'Algérie (chefs-lieux), par ordre alphabétique.
export const CITIES = [
  'Adrar', 'Aïn Defla', 'Aïn Témouchent', 'Alger', 'Annaba', 'Batna', 'Béchar', 'Béjaïa',
  'Béni Abbès', 'Biskra', 'Blida', 'Bordj Badji Mokhtar', 'Bordj Bou Arréridj', 'Bouira',
  'Boumerdès', 'Chlef', 'Constantine', 'Djanet', 'Djelfa', 'El Bayadh', 'El M’Ghair',
  'El Meniaa', 'El Oued', 'El Tarf', 'Ghardaïa', 'Guelma', 'Illizi', 'In Guezzam', 'In Salah',
  'Jijel', 'Khenchela', 'Laghouat', 'M’Sila', 'Mascara', 'Médéa', 'Mila', 'Mostaganem',
  'Naâma', 'Oran', 'Ouargla', 'Ouled Djellal', 'Oum El Bouaghi', 'Relizane', 'Saïda', 'Sétif',
  'Sidi Bel Abbès', 'Skikda', 'Souk Ahras', 'Tamanrasset', 'Tébessa', 'Tiaret', 'Timimoun',
  'Tindouf', 'Tipaza', 'Tissemsilt', 'Tizi Ouzou', 'Tlemcen', 'Touggourt',
];

export const HOURS: Hour[] = [
  { d: 'Lundi', h: '12:00 – 15:00 · 19:00 – 23:30' },
  { d: 'Mardi', h: '12:00 – 15:00 · 19:00 – 23:30' },
  { d: 'Mercredi', h: '12:00 – 15:00 · 19:00 – 23:30' },
  { d: 'Jeudi', h: '12:00 – 15:00 · 19:00 – 00:00' },
  { d: 'Vendredi', h: '19:00 – 00:00' },
  { d: 'Samedi', h: '12:00 – 15:00 · 19:00 – 00:00' },
  { d: 'Dimanche', h: '12:00 – 15:00 · 19:00 – 23:00' },
];

export const AMEN_MAP: Record<string, Amenity> = {
  terrasse: { icon: 'sparkles', label: 'Terrasse' },
  wifi: { icon: 'wifi', label: 'Wi-Fi gratuit' },
  parking: { icon: 'parking', label: 'Parking' },
  card: { icon: 'card', label: 'Carte acceptée' },
  family: { icon: 'users', label: 'Familial' },
  ac: { icon: 'sparkles', label: 'Climatisé' },
  delivery: { icon: 'bag', label: 'Livraison' },
  resa: { icon: 'calendar', label: 'Réservation en ligne' },
};
export const AMEN = (a: string[]): Amenity[] => a.map((x) => AMEN_MAP[x]).filter(Boolean);

const D = (o: Partial<Listing> & Pick<Listing, 'id' | 'slug' | 'name' | 'cat' | 'catName' | 'area' | 'price' | 'unit' | 'tags'>): Listing => ({
  city: 'Alger',
  rating: 4.7,
  reviews: 120,
  priceLevel: '€€',
  status: 'open',
  desc: 'Une adresse incontournable, plébiscitée par la communauté Darsouk pour la qualité de son accueil et de ses prestations.',
  hours: HOURS,
  amenities: AMEN(['resa', 'wifi', 'card', 'parking']),
  verified: true,
  ...o,
});

export const LISTINGS: Listing[] = [];

export const NEIGHBORHOODS = ['Hydra', 'El Biar', 'Sidi Yahia', 'Kouba', 'Bab El Oued', 'Didouche Mourad', 'Ben Aknoun', 'Chéraga', 'Bab Ezzouar', 'Telemly'];

export const byCat = (k: string) => LISTINGS.filter((l) => l.cat === k);
export const byId = (id: number): Listing | undefined => LISTINGS.find((l) => l.id === id);
export const catByKey = (k: string) => CATS.find((c) => c.key === k);

/* ---------- Petites annonces ---------- */
export const AD_CATS: AdCatT[] = [
  { key: 'vehicules', name: 'Véhicules', icon: 'car', count: 8420 },
  { key: 'tel', name: 'Téléphones', icon: 'smartphone', count: 12380 },
  { key: 'info', name: 'Informatique', icon: 'laptop', count: 4510 },
  { key: 'immo', name: 'Immobilier', icon: 'home', count: 6240 },
  { key: 'maison', name: 'Maison & Déco', icon: 'sofa', count: 5170 },
  { key: 'electro', name: 'Électroménager', icon: 'washer', count: 3360 },
  { key: 'mode', name: 'Mode', icon: 'shirt', count: 7290 },
  { key: 'loisirs', name: 'Loisirs', icon: 'gamepad', count: 2880 },
];

export const AD_TINTS: Record<string, Tint> = {
  vehicules: ['#E2E6EE', '#A6B2C6', '#48566E'],
  tel: ['#EBE6F6', '#B7A6E0', '#5E48A8'],
  info: ['#E4E8EC', '#AAB6C0', '#566570'],
  immo: ['#E2ECEA', '#A4C8BD', '#2C6B5C'],
  maison: ['#EFE7DA', '#D2B88E', '#8C6B3C'],
  electro: ['#E2EDEE', '#A4C8CC', '#3C6B70'],
  mode: ['#F4E0EC', '#DDA3C2', '#9C467A'],
  loisirs: ['#F8E7D2', '#EDBE8E', '#B97E3C'],
};
export const adCat = (k: string) => AD_CATS.find((c) => c.key === k);

export const ADS: Ad[] = [];
export const adById = (id: number): Ad | undefined => ADS.find((a) => a.id === id);
