/* route-data.jsx — REAL Sofia route geometry (from OSRM/OpenStreetMap), baked in so the
   prototype always shows genuine street-following routes. Coords are [lat, lng].
   START = ул. Димитър Хаджикоцев (Лозенец) → DEST = Народен театър „Иван Вазов". */

// — Direct corridor: Хаджикоцев → Арсеналски → Черни връх → Раковски (≈2.6 км) —
const GEO_DIRECT = [[42.67702,23.31988],[42.67636,23.31856],[42.67606,23.31797],[42.67564,23.31716],[42.67582,23.31701],[42.676,23.31687],[42.6761,23.31678],[42.67621,23.31669],[42.67627,23.31664],[42.67636,23.3168],[42.67697,23.31798],[42.67732,23.31864],[42.67768,23.31932],[42.67773,23.31943],[42.67789,23.31973],[42.67802,23.32007],[42.67812,23.32039],[42.67824,23.32076],[42.67843,23.32138],[42.67844,23.32143],[42.67847,23.32157],[42.67847,23.32178],[42.67865,23.32182],[42.67885,23.3218],[42.68194,23.32116],[42.68214,23.32112],[42.68237,23.32104],[42.68259,23.32097],[42.68274,23.32093],[42.68292,23.32087],[42.68303,23.32085],[42.68317,23.32082],[42.68318,23.32082],[42.68334,23.32081],[42.68342,23.3208],[42.68346,23.3208],[42.68355,23.3208],[42.68368,23.32082],[42.68384,23.32085],[42.68426,23.32094],[42.68464,23.32101],[42.68467,23.32113],[42.68487,23.32181],[42.68499,23.32221],[42.68525,23.3231],[42.68527,23.32316],[42.68533,23.32314],[42.68571,23.32297],[42.68574,23.32296],[42.68577,23.32295],[42.68591,23.32288],[42.68614,23.32279],[42.68615,23.32278],[42.68621,23.32276],[42.68625,23.32276],[42.68636,23.32276],[42.68643,23.32277],[42.68664,23.32281],[42.6867,23.32282],[42.68701,23.32287],[42.68706,23.32288],[42.68731,23.32292],[42.68736,23.32293],[42.68758,23.32296],[42.68762,23.32297],[42.68765,23.32297],[42.68796,23.32302],[42.68829,23.32308],[42.68845,23.3231],[42.68852,23.32311],[42.68862,23.32313],[42.6887,23.32314],[42.68877,23.32316],[42.68888,23.32318],[42.68925,23.32324],[42.68928,23.32325],[42.68988,23.32336],[42.69062,23.32347],[42.69065,23.32348],[42.69067,23.32352],[42.6907,23.32356],[42.69102,23.32422],[42.6913,23.32476],[42.69137,23.32491],[42.69138,23.32492],[42.69141,23.32497],[42.69142,23.32499],[42.69143,23.325],[42.69144,23.32503],[42.69145,23.32503],[42.69148,23.32508],[42.69177,23.3255],[42.69203,23.32588],[42.69205,23.32591],[42.69207,23.32593],[42.69232,23.3263]];

// — Calm corridor: Черни връх → Левски → Цар Иван Шишман → Патриарх Евтимий → Раковски (≈3.8 км) —
const GEO_CALM = [[42.67702,23.31988],[42.67636,23.31856],[42.67606,23.31797],[42.67564,23.31716],[42.67582,23.31701],[42.676,23.31687],[42.6761,23.31678],[42.67621,23.31669],[42.67627,23.31664],[42.67636,23.3168],[42.67697,23.31798],[42.67732,23.31864],[42.67768,23.31932],[42.67773,23.31943],[42.67789,23.31973],[42.67802,23.32007],[42.67812,23.32039],[42.67824,23.32076],[42.67843,23.32138],[42.67844,23.32143],[42.67847,23.32157],[42.67847,23.32178],[42.67865,23.32182],[42.67885,23.3218],[42.68194,23.32116],[42.68214,23.32112],[42.68237,23.32104],[42.68259,23.32097],[42.68274,23.32093],[42.68292,23.32087],[42.68303,23.32085],[42.68317,23.32082],[42.68318,23.32082],[42.68334,23.32081],[42.68342,23.3208],[42.68346,23.3208],[42.68355,23.3208],[42.68368,23.32082],[42.68384,23.32085],[42.68426,23.32094],[42.68464,23.32101],[42.68528,23.32115],[42.68542,23.32117],[42.68578,23.32123],[42.68585,23.32125],[42.68585,23.32133],[42.68603,23.32214],[42.68615,23.32262],[42.68618,23.32269],[42.68621,23.32276],[42.68623,23.32282],[42.6863,23.32297],[42.68639,23.32332],[42.6865,23.32375],[42.68663,23.32431],[42.68675,23.32477],[42.68676,23.32482],[42.68678,23.32491],[42.68682,23.32506],[42.68689,23.32535],[42.68707,23.32609],[42.68718,23.32608],[42.68735,23.32611],[42.68751,23.32614],[42.68777,23.32618],[42.68819,23.32626],[42.68823,23.32627],[42.68833,23.32629],[42.68839,23.3263],[42.68842,23.3263],[42.68845,23.32631],[42.68866,23.32634],[42.68884,23.32661],[42.68932,23.32734],[42.68934,23.32737],[42.68936,23.32739],[42.68936,23.32741],[42.68938,23.32743],[42.68939,23.32744],[42.6894,23.32745],[42.68944,23.32752],[42.68953,23.32764],[42.68966,23.32783],[42.6897,23.32788],[42.68972,23.32791],[42.68993,23.3282],[42.68995,23.32823],[42.68996,23.32826],[42.68993,23.3283],[42.68969,23.32862],[42.68955,23.32881],[42.68902,23.32953],[42.68894,23.32964],[42.68892,23.32966],[42.68891,23.32969],[42.68883,23.32979],[42.68845,23.32932],[42.68825,23.32909],[42.68823,23.329],[42.68822,23.32896],[42.68821,23.32895],[42.68818,23.3289],[42.68817,23.32889],[42.68816,23.32887],[42.68814,23.32883],[42.68813,23.32877],[42.68812,23.32868],[42.68813,23.32861],[42.68825,23.32725],[42.68828,23.32689],[42.6883,23.32668],[42.68833,23.32637],[42.68833,23.32629],[42.68836,23.32597],[42.6884,23.32561],[42.68844,23.32512],[42.68845,23.325],[42.68851,23.32432],[42.68854,23.324],[42.68861,23.32324],[42.68861,23.32321],[42.68862,23.32313],[42.6887,23.32314],[42.68877,23.32316],[42.68888,23.32318],[42.68925,23.32324],[42.68928,23.32325],[42.68988,23.32336],[42.69062,23.32347],[42.69065,23.32348],[42.69067,23.32352],[42.6907,23.32356],[42.69102,23.32422],[42.6913,23.32476],[42.69137,23.32491],[42.69138,23.32492],[42.69141,23.32497],[42.69142,23.32499],[42.69143,23.325],[42.69144,23.32503],[42.69145,23.32503],[42.69148,23.32508],[42.69177,23.3255],[42.69203,23.32588],[42.69205,23.32591],[42.69207,23.32593],[42.69232,23.3263]];

// — Scenic: along Борисова градина via Цар Освободител & Евлоги и Хр. Георгиеви (≈4.5 км) —
const GEO_SCENIC = [[42.67702,23.31988],[42.67636,23.31856],[42.67606,23.31797],[42.67564,23.31716],[42.67582,23.31701],[42.676,23.31687],[42.6761,23.31678],[42.67621,23.31669],[42.67627,23.31664],[42.67636,23.3168],[42.67697,23.31798],[42.67732,23.31864],[42.67768,23.31932],[42.67773,23.31943],[42.67789,23.31973],[42.67802,23.32007],[42.67812,23.32039],[42.67824,23.32076],[42.67843,23.32138],[42.67844,23.32143],[42.67847,23.32157],[42.67847,23.32178],[42.67865,23.32182],[42.67885,23.3218],[42.68194,23.32116],[42.68214,23.32112],[42.68237,23.32104],[42.68259,23.32097],[42.68274,23.32093],[42.68292,23.32087],[42.68303,23.32085],[42.68317,23.32082],[42.68318,23.32082],[42.68334,23.32081],[42.68342,23.3208],[42.68346,23.3208],[42.68355,23.3208],[42.68368,23.32082],[42.68384,23.32085],[42.68426,23.32094],[42.68464,23.32101],[42.68528,23.32115],[42.68542,23.32117],[42.68578,23.32123],[42.68585,23.32125],[42.68585,23.32133],[42.68603,23.32214],[42.68615,23.32262],[42.68618,23.32269],[42.68621,23.32276],[42.68623,23.32282],[42.6863,23.32297],[42.68639,23.32332],[42.6865,23.32375],[42.68663,23.32431],[42.68675,23.32477],[42.68676,23.32482],[42.68678,23.32491],[42.68682,23.32506],[42.68689,23.32535],[42.68707,23.32609],[42.68728,23.32692],[42.68749,23.32779],[42.68754,23.328],[42.6876,23.32826],[42.68762,23.32831],[42.68765,23.32835],[42.68788,23.32866],[42.68804,23.32891],[42.68806,23.32894],[42.68807,23.32896],[42.68809,23.32898],[42.6881,23.32899],[42.68814,23.32906],[42.68815,23.32906],[42.68825,23.32909],[42.68845,23.32932],[42.68883,23.32979],[42.68943,23.33053],[42.68995,23.33116],[42.69008,23.33132],[42.69011,23.33136],[42.69053,23.33188],[42.69105,23.33251],[42.69156,23.33312],[42.6917,23.3333],[42.69221,23.33392],[42.69228,23.334],[42.69236,23.33406],[42.69244,23.33411],[42.69253,23.33414],[42.69267,23.33427],[42.69273,23.33433],[42.69277,23.33439],[42.69278,23.33441],[42.69279,23.33444],[42.6928,23.33448],[42.6928,23.3345],[42.6928,23.33456],[42.69278,23.33466],[42.69271,23.3348],[42.69237,23.33521],[42.69143,23.33631],[42.69089,23.33699],[42.69085,23.33704],[42.6907,23.33723],[42.69061,23.33701],[42.69053,23.33688],[42.69033,23.33654],[42.6896,23.33539],[42.68935,23.33499],[42.68892,23.33431],[42.68883,23.33417],[42.68874,23.33404],[42.68871,23.334],[42.68863,23.33385],[42.68869,23.33374],[42.68871,23.33371],[42.68921,23.33287],[42.68932,23.33268],[42.68934,23.33263],[42.68966,23.3321],[42.68968,23.33207],[42.68998,23.33154],[42.69008,23.33132],[42.69015,23.33115],[42.69018,23.33109],[42.69022,23.33102],[42.69044,23.33062],[42.69099,23.32964],[42.69103,23.32958],[42.69104,23.32955],[42.69105,23.32954],[42.69108,23.32949],[42.69111,23.32943],[42.69114,23.32938],[42.69115,23.32937],[42.69128,23.32913],[42.69158,23.3286],[42.69195,23.32794],[42.692,23.32785],[42.69203,23.3278],[42.69219,23.32751],[42.6922,23.32748],[42.69255,23.32688],[42.69257,23.32685],[42.69264,23.32675],[42.69258,23.32668],[42.69257,23.32666],[42.6924,23.32642],[42.69232,23.3263]];

const STEPS_DIRECT = [
  { icon: 'IconStraight', text: 'Тръгнете', street: 'ул. Димитър Хаджикоцев', start: 270 },
  { icon: 'IconArrowTurnR', text: 'Завийте надясно', street: 'ул. Църноок', start: 80 },
  { icon: 'IconArrowTurnR', text: 'Завийте надясно', street: 'бул. Арсеналски', start: 490 },
  { icon: 'IconArrowTurnL', text: 'Завийте наляво', street: 'бул. Черни връх', start: 550 },
  { icon: 'IconStraight', text: 'Продължете направо', street: 'проф. Фритьоф Нансен', start: 150 },
  { icon: 'IconArrowTurnR', text: 'Завийте надясно', street: 'ул. Любен Каравелов', start: 190 },
  { icon: 'IconArrowTurnL', text: 'Завийте наляво', street: 'ул. Г. С. Раковски', start: 900 },
  { icon: 'IconPin', text: 'Пристигане', street: 'Народен театър', start: 40 },
];
const STEPS_CALM = [
  { icon: 'IconStraight', text: 'Тръгнете', street: 'ул. Димитър Хаджикоцев', start: 270 },
  { icon: 'IconArrowTurnR', text: 'Завийте надясно', street: 'бул. Арсеналски', start: 490 },
  { icon: 'IconArrowTurnL', text: 'Завийте наляво', street: 'бул. Черни връх', start: 300 },
  { icon: 'IconArrowTurnR', text: 'Завийте надясно', street: 'бул. Васил Левски', start: 420 },
  { icon: 'IconArrowTurnL', text: 'Завийте наляво', street: 'ул. Цар Иван Шишман', start: 360 },
  { icon: 'IconArrowTurnR', text: 'Завийте надясно', street: 'бул. Патриарх Евтимий', start: 300 },
  { icon: 'IconArrowTurnL', text: 'Завийте наляво', street: 'ул. Г. С. Раковски', start: 220 },
  { icon: 'IconPin', text: 'Пристигане', street: 'Народен театър', start: 40 },
];
const STEPS_SCENIC = [
  { icon: 'IconStraight', text: 'Тръгнете', street: 'ул. Димитър Хаджикоцев', start: 270 },
  { icon: 'IconArrowTurnL', text: 'Завийте наляво', street: 'бул. Черни връх', start: 300 },
  { icon: 'IconArrowTurnR', text: 'Завийте надясно', street: 'бул. Цар Освободител', start: 260 },
  { icon: 'IconStraight', text: 'Продължете направо', street: 'бул. Евлоги и Хр. Георгиеви', start: 900 },
  { icon: 'IconArrowTurnL', text: 'Покрай Борисова градина', street: 'към Орлов мост', start: 500 },
  { icon: 'IconArrowTurnL', text: 'Завийте наляво', street: 'ул. Ген. Гурко', start: 360 },
  { icon: 'IconArrowTurnR', text: 'Завийте надясно', street: 'ул. Г. С. Раковски', start: 220 },
  { icon: 'IconPin', text: 'Пристигане', street: 'Народен театър', start: 40 },
];

window.VR_SRC = [
  { coords: GEO_DIRECT, steps: STEPS_DIRECT },
  { coords: GEO_CALM, steps: STEPS_CALM },
  { coords: GEO_SCENIC, steps: STEPS_SCENIC },
];
window.VR_ENDPOINTS = { start: [42.67702, 23.31988], dest: [42.69232, 23.3263] };

// — Community-contributed map data (the crowdsourced safety layer) —
// Categories drive marker color + icon + the filterable legend.
const VR_CATS = {
  safe:     { label: 'Безопасни улици',  group: 'line',    color: 'safe',     glyph: 'shield' },
  danger:   { label: 'Опасни участъци',  group: 'line',    color: 'danger',   glyph: 'warn' },
  pothole:  { label: 'Дупки и паваж',    group: 'hazard',  color: 'moderate', glyph: 'warn' },
  traffic:  { label: 'Опасно движение',  group: 'hazard',  color: 'danger',   glyph: 'car' },
  blocked:  { label: 'Блокирани алеи',   group: 'hazard',  color: 'moderate', glyph: 'bike' },
  lighting: { label: 'Лошо осветление',  group: 'hazard',  color: 'navline',  glyph: 'bulb' },
  parking:  { label: 'Велопаркинги',     group: 'amenity', color: 'navline',  glyph: 'park' },
  water:    { label: 'Чешми',            group: 'amenity', color: 'safe',     glyph: 'drop' },
  repair:   { label: 'Сервиз / помпа',   group: 'amenity', color: 'brand',    glyph: 'wrench' },

  // VELOSOFIZE route network imported from the official KMZ (kmz-data.jsx).
  // group 'velo' = curated route lines; 'transit'/'velopark' = imported POIs.
  bikelane:        { label: 'Велоалеи',            group: 'velo',     color: 'route-lane',     glyph: 'bike' },
  bikelane_shared: { label: 'Неотделени велоалеи', group: 'velo',     color: 'route-lane',     glyph: 'bike' },
  comfort:         { label: '„Удобни“ улици',      group: 'velo',     color: 'moderate',       glyph: 'bike' },
  rough:           { label: 'Неасфалтирани',       group: 'velo',     color: 'route-rough',    glyph: 'warn' },
  sidewalk:        { label: 'Широки тротоари',     group: 'velo',     color: 'route-sidewalk', glyph: 'bike' },
  untested:        { label: 'Неизпробвани',        group: 'velo',     color: 'route-untested', glyph: 'bike' },
  transit:         { label: 'Обществен транспорт', group: 'transit',  color: 'navline',        glyph: 'train' },
  crossing:        { label: 'Места за пресичане',  group: 'transit',  color: 'safe',           glyph: 'cross' },
  poi:             { label: 'Други места',         group: 'transit',  color: 'route-untested', glyph: 'pin' },
};

// Default map filter — on first load show ONLY bike lanes + crossing places; everything else is
// off but toggleable. The map reads on(cat) = commFilter[cat] !== false, so default-OFF categories
// are stored as false and the default-ON ones as true.
const VR_DEFAULT_ON = ['bikelane', 'bikelane_shared', 'comfort', 'crossing'];
window.VR_DEFAULT_FILTER = (() => {
  const f = {};
  Object.keys(VR_CATS).forEach((k) => { f[k] = VR_DEFAULT_ON.includes(k); });
  return f;
})();

const cmt = (by, ago, text) => ({ by, ago, text });

// The map now draws ONLY real data: the VELOSOFIZE (KMZ) layer (kmz-data.jsx) + any live
// crowdsourced reports hydrated from Supabase (community-live.jsx concats onto these arrays).
// The former mock seed (demo hazards/amenities/safe-danger lines) was removed — hazards now
// come from the real KMZ `rough` (unpaved) routes already fed into the safety engine.
window.VR_COMMUNITY = {
  cats: VR_CATS,
  segments: [],
  points: [],
};
