// Sample data for the rental admin.
// Vehicles, bookings, and blocked dates.

const VEHICLE_TYPES = ["Sedan", "Hatchback", "SUV", "Minivan"];
const TRANSMISSIONS = ["Automatic", "Manual"];

// Placeholder photo as data URI - simple colored rectangle with car silhouette
const carPhoto = (bg, accent, label) =>
  `data:image/svg+xml;utf8,${encodeURIComponent(`
    <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 240'>
      <rect width='400' height='240' fill='${bg}'/>
      <g transform='translate(60 80)' fill='${accent}' opacity='0.9'>
        <path d='M20 80 L40 30 Q50 15 70 15 L210 15 Q230 15 240 30 L260 80 L280 80 L280 110 L260 110 Q260 130 240 130 Q220 130 220 110 L60 110 Q60 130 40 130 Q20 130 20 110 L0 110 L0 80 Z' />
        <circle cx='40' cy='110' r='14' fill='${bg}'/>
        <circle cx='240' cy='110' r='14' fill='${bg}'/>
        <path d='M55 35 L80 70 L130 70 L130 35 Z' fill='${bg}' opacity='0.6'/>
        <path d='M150 35 L150 70 L210 70 L225 35 Z' fill='${bg}' opacity='0.6'/>
      </g>
      <text x='20' y='225' font-family='ui-sans-serif,system-ui' font-size='11' fill='${accent}' opacity='0.5'>${label}</text>
    </svg>
  `)}`;

const samplePhotos = (bg, accent, label) => [
  carPhoto(bg, accent, label + " — front 3/4"),
  carPhoto(accent, bg, label + " — rear"),
  carPhoto("#1f2937", "#9ca3af", label + " — interior"),
  carPhoto("#374151", "#d1d5db", label + " — side"),
];

const INITIAL_VEHICLES = [
  {
    id: "v1",
    year: 2023,
    make: "Toyota",
    model: "Corolla",
    type: "Sedan",
    price: 65,
    passengers: 5,
    suitcases: 2,
    transmission: "Automatic",
    plate: "A 1284",
    description:
      "Reliable, fuel-efficient sedan. AC, Bluetooth audio, USB charging. Great for couples or small families on island trips.",
    photos: samplePhotos("#e5e7eb", "#1f2937", "Corolla 2023"),
    coverIndex: 0,
    status: "Available",
  },
  {
    id: "v2",
    year: 2022,
    make: "Honda",
    model: "Civic",
    type: "Sedan",
    price: 60,
    passengers: 5,
    suitcases: 2,
    transmission: "Automatic",
    plate: "A 0931",
    description:
      "Sporty handling, excellent on coastal roads. AC, reverse camera, Apple CarPlay.",
    photos: samplePhotos("#dbeafe", "#1e3a8a", "Civic 2022"),
    coverIndex: 0,
    status: "Available",
  },
  {
    id: "v3",
    year: 2024,
    make: "Hyundai",
    model: "Tucson",
    type: "SUV",
    price: 95,
    passengers: 5,
    suitcases: 4,
    transmission: "Automatic",
    plate: "A 1502",
    description:
      "Mid-size SUV with high ground clearance — handles rough roads and beach access tracks well. Roof rails, tow bar, AC.",
    photos: samplePhotos("#1e293b", "#cbd5e1", "Tucson 2024"),
    coverIndex: 0,
    status: "Available",
  },
  {
    id: "v4",
    year: 2021,
    make: "Suzuki",
    model: "Swift",
    type: "Hatchback",
    price: 50,
    passengers: 4,
    suitcases: 1,
    transmission: "Manual",
    plate: "A 0712",
    description:
      "Compact and easy to park in town. Manual transmission, AC, fuel efficient. Best for solo travelers or couples with light luggage.",
    photos: samplePhotos("#fef3c7", "#92400e", "Swift 2021"),
    coverIndex: 0,
    status: "Maintenance",
  },
  {
    id: "v5",
    year: 2023,
    make: "Toyota",
    model: "RAV4",
    type: "SUV",
    price: 105,
    passengers: 5,
    suitcases: 4,
    transmission: "Automatic",
    plate: "A 1799",
    description:
      "Spacious SUV with hybrid engine. Excellent fuel economy, smooth ride. AC, sunroof, leather seats.",
    photos: samplePhotos("#dcfce7", "#14532d", "RAV4 2023"),
    coverIndex: 0,
    status: "Available",
  },
  {
    id: "v6",
    year: 2022,
    make: "Kia",
    model: "Carnival",
    type: "Minivan",
    price: 130,
    passengers: 8,
    suitcases: 6,
    transmission: "Automatic",
    plate: "A 1611",
    description:
      "Large minivan ideal for groups, families, or airport transfers. Three rows, sliding doors, dual AC zones.",
    photos: samplePhotos("#fee2e2", "#7f1d1d", "Carnival 2022"),
    coverIndex: 0,
    status: "Available",
  },
  {
    id: "v7",
    year: 2020,
    make: "Volkswagen",
    model: "Polo",
    type: "Hatchback",
    price: 48,
    passengers: 4,
    suitcases: 1,
    transmission: "Manual",
    plate: "A 0588",
    description: "Economical hatchback. AC, Bluetooth, manual transmission.",
    photos: samplePhotos("#e0e7ff", "#312e81", "Polo 2020"),
    coverIndex: 0,
    status: "Available",
  },
  {
    id: "v8",
    year: 2024,
    make: "Nissan",
    model: "Pathfinder",
    type: "SUV",
    price: 115,
    passengers: 7,
    suitcases: 5,
    transmission: "Automatic",
    plate: "A 1890",
    description:
      "Large 7-seater SUV. Tow capacity 2,700kg. Ideal for adventure trips and larger groups.",
    photos: samplePhotos("#0f172a", "#94a3b8", "Pathfinder 2024"),
    coverIndex: 0,
    status: "Available",
  },
];

// Helpers for date keys
const dateKey = (d) => {
  const yr = d.getFullYear();
  const mo = String(d.getMonth() + 1).padStart(2, "0");
  const dy = String(d.getDate()).padStart(2, "0");
  return `${yr}-${mo}-${dy}`;
};

const today = new Date();
today.setHours(0, 0, 0, 0);
const addDays = (d, n) => {
  const r = new Date(d);
  r.setDate(r.getDate() + n);
  return r;
};

// Generate sample bookings (customer rentals) and blocks (admin-blocked dates)
function generateSampleBookings() {
  const bookings = {};
  const blocks = {};

  // v1 — booked next week for 5 days
  bookings["v1"] = [
    {
      id: "b1",
      customer: "Marcus Chen",
      start: dateKey(addDays(today, 4)),
      end: dateKey(addDays(today, 9)),
      ref: "RES-2841",
    },
    {
      id: "b2",
      customer: "Sofia Alvarez",
      start: dateKey(addDays(today, 22)),
      end: dateKey(addDays(today, 26)),
      ref: "RES-2855",
    },
  ];

  bookings["v2"] = [
    {
      id: "b3",
      customer: "James O'Connor",
      start: dateKey(addDays(today, 1)),
      end: dateKey(addDays(today, 7)),
      ref: "RES-2837",
    },
  ];

  bookings["v3"] = [
    {
      id: "b4",
      customer: "Linnea Karlsson",
      start: dateKey(addDays(today, 10)),
      end: dateKey(addDays(today, 17)),
      ref: "RES-2849",
    },
    {
      id: "b5",
      customer: "Ravi Mehta",
      start: dateKey(addDays(today, 35)),
      end: dateKey(addDays(today, 42)),
      ref: "RES-2860",
    },
  ];

  bookings["v5"] = [
    {
      id: "b6",
      customer: "Patricia Hill",
      start: dateKey(addDays(today, 14)),
      end: dateKey(addDays(today, 21)),
      ref: "RES-2851",
    },
  ];

  bookings["v6"] = [
    {
      id: "b7",
      customer: "The Watanabe family (8)",
      start: dateKey(addDays(today, 6)),
      end: dateKey(addDays(today, 13)),
      ref: "RES-2843",
    },
  ];

  bookings["v8"] = [
    {
      id: "b8",
      customer: "Daniel Beauchamp",
      start: dateKey(addDays(today, 2)),
      end: dateKey(addDays(today, 5)),
      ref: "RES-2840",
    },
    {
      id: "b9",
      customer: "Amelia Foster",
      start: dateKey(addDays(today, 28)),
      end: dateKey(addDays(today, 34)),
      ref: "RES-2858",
    },
  ];

  // Admin-blocked dates (maintenance, owner use, etc.)
  blocks["v4"] = [
    { start: dateKey(addDays(today, 0)), end: dateKey(addDays(today, 11)), reason: "Transmission service" },
  ];
  blocks["v1"] = [
    { start: dateKey(addDays(today, 18)), end: dateKey(addDays(today, 19)), reason: "Cleaning + detailing" },
  ];
  blocks["v3"] = [
    { start: dateKey(addDays(today, 50)), end: dateKey(addDays(today, 52)), reason: "Tire rotation" },
  ];

  return { bookings, blocks };
}

const SAMPLE = generateSampleBookings();

window.RENTAL_DATA = {
  VEHICLE_TYPES,
  TRANSMISSIONS,
  INITIAL_VEHICLES,
  INITIAL_BOOKINGS: SAMPLE.bookings,
  INITIAL_BLOCKS: SAMPLE.blocks,
  dateKey,
  addDays,
  carPhoto,
  samplePhotos,
};
