/* ============================================================
   COMMONS — mock data
   ============================================================ */

// Deterministic procedural cover gradients from a seed string.
// Returns a warm, intentional multi-stop gradient + accent dot color.
const COVER_PALETTES = [
  ["#E8482A", "#F4A23C", "#FBE4DC"],   // ember
  ["#2C4A6E", "#4E86B0", "#BFD6E4"],   // cobalt
  ["#5E7355", "#9CB07F", "#E3E9D3"],   // sage
  ["#6B3F5E", "#B06A8E", "#EAD2DF"],   // plum
  ["#B98326", "#E6B45A", "#F6E6C6"],   // gold
  ["#1B1714", "#5A4A3E", "#C9B79F"],   // ink
  ["#A8412B", "#E2762E", "#F7D9B0"],   // clay
  ["#37606B", "#6FA0A6", "#D2E5E3"],   // teal
];

function hashStr(s) {
  let h = 0;
  for (let i = 0; i < s.length; i++) { h = (h * 31 + s.charCodeAt(i)) >>> 0; }
  return h;
}

function coverFor(seed) {
  const h = hashStr(seed);
  const pal = COVER_PALETTES[h % COVER_PALETTES.length];
  const ang = 90 + (h % 140);
  const x = 20 + (h % 50), y = 15 + ((h >> 3) % 60);
  return {
    css: `radial-gradient(120% 120% at ${x}% ${y}%, ${pal[2]} 0%, ${pal[1]} 42%, ${pal[0]} 100%)`,
    angle: ang,
    colors: pal,
  };
}

const EVENTS = [
  { id: "e1", title: "Diljit Dosanjh — Aura World Tour (Finale)", cat: "Music", date: "Sat, Jun 20", time: "7:30 PM", venue: "Chase Center", dist: "San Francisco", price: "$95", going: 18000, host: "Live Nation", hostU: "LN", fav: true,
    blurb: "The closing night of the record-breaking Aura World Tour. The first Punjabi artist to sell out arenas across North America brings it home." },
  { id: "e2", title: "Breaking Borders Festival 2026", cat: "Festival", date: "Thu, Sep 03", time: "4:00 PM", venue: "Ta' Qali Park", dist: "Malta", price: "From £180", going: 25000, host: "Breaking Borders", hostU: "BB", fav: true,
    blurb: "The world's biggest desi destination festival. Karan Aujla headlines Friday & Sunday with two different setlists; AP Dhillon takes Saturday." },
  { id: "e3", title: "Monthly Kirtan Darbar & Langar", cat: "Kirtan", date: "Sun, Jun 21", time: "6:00 PM", venue: "Gurdwara Sahib Dixie", dist: "Brampton", price: "Free", going: 540, host: "Gurdwara Committee", hostU: "GC", fav: false,
    blurb: "An evening of shabad kirtan by visiting raagi jathas, followed by langar in the hall. All sangat welcome." },
  { id: "e4", title: "Southall Summer Mela", cat: "Food", date: "Sat, Jun 27", time: "12:00 PM", venue: "Southall Park", dist: "London", price: "Free", going: 3200, host: "Southall Mela", hostU: "SM", fav: false,
    blurb: "Chaat, jalebi and tandoori everything, three stages of dhol and live singers, and a funfair for the kids. Bring the whole parivaar." },
  { id: "e5", title: "Surrey Kabaddi Cup", cat: "Sports", date: "Sun, Jun 28", time: "10:00 AM", venue: "Newton Athletic Park", dist: "Surrey, BC", price: "$10", going: 2100, host: "Kabaddi Federation", hostU: "KF", fav: false,
    blurb: "Circle-style kabaddi with teams flown in from Punjab. Full day of raids, dhol, and the best jalebi truck in the Lower Mainland." },
  { id: "e6", title: "Bhangra & Giddha Night", cat: "Music", date: "Fri, Jul 03", time: "9:00 PM", venue: "The Roxy", dist: "Melbourne", price: "$25", going: 320, host: "Desi Beats", hostU: "DB", fav: false,
    blurb: "Live dhol, a giddha circle, and a DJ spinning everything from Gurdas Maan to the latest drops. Phulkari dress code encouraged." },
  { id: "e7", title: "Kavi Darbar — Punjabi Poetry Evening", cat: "Community", date: "Wed, Jul 08", time: "7:00 PM", venue: "Punjabi Bhawan", dist: "Wolverhampton", price: "Free", going: 90, host: "Punjabi Sahit Sabha", hostU: "PS", fav: false,
    blurb: "An open mehfil of poetry and prose in Punjabi — from Shiv Kumar Batalvi classics to new diaspora voices. Sign up to read." },
  { id: "e8", title: "Classic Screening: 'Chann Pardesi'", cat: "Film", date: "Fri, Jul 10", time: "8:00 PM", venue: "Rooftop Cinema", dist: "Toronto", price: "$12", going: 140, host: "Reel Punjab", hostU: "RP", fav: true,
    blurb: "The 1981 award-winning classic under the stars, restored and subtitled. A story of land, loyalty and pardes that still hits home." },
];

const CATEGORIES = ["All", "Music", "Festival", "Food", "Sports", "Comedy", "Community", "Film"];
const DAYS = ["Any day", "This weekend", "This month", "Upcoming"];

const COMMUNITIES = [
  { id: "c1", name: "askpunjab", members: "52.4k", color: "#E8482A", desc: "Diaspora life, sorted." },
  { id: "c2", name: "punjabimusic", members: "78.1k", color: "#6B3F5E", desc: "New drops & live shows." },
  { id: "c3", name: "langar", members: "34.6k", color: "#B98326", desc: "Recipes & where to eat." },
  { id: "c4", name: "pind2city", members: "21.3k", color: "#2C4A6E", desc: "Immigration & settling in." },
  { id: "c5", name: "kabaddi", members: "12.9k", color: "#5E7355", desc: "Khel, teams & tournaments." },
  { id: "c6", name: "gurbani", members: "29.0k", color: "#37606B", desc: "Kirtan, paath & seva." },
];

const POSTS = [
  { id: "p1", sub: "langar", author: "amritsari_tadka", time: "3h", title: "Found a dhaba in Brampton doing proper Amritsari kulcha — chole like my biji's",
    body: "Tucked behind the plaza on Airport Rd. The chole are slow-cooked overnight and the kulcha comes out of a real tandoor. Cash only, go before 1pm or they sell out.",
    votes: 284, comments: 56, tag: "Recommendation", img: true },
  { id: "p2", sub: "askpunjab", author: "newin_brampton", time: "6h", title: "Just landed from Jalandhar on a work permit — what's the one thing nobody tells you about settling here?",
    body: "Already learned that everything shuts early and you need a car for everything. What else am I missing as a fresh-off-the-plane Punjabi?",
    votes: 512, comments: 218, tag: "Discussion", img: false },
  { id: "p3", sub: "punjabimusic", author: "8pm_vibes", time: "1h", title: "Karan Aujla doing TWO different setlists at Breaking Borders is wild — what are we hoping he opens with?",
    body: "Friday and Sunday, completely different shows. I'm praying for 'Tauba Tauba' energy one night and the old 'Don't Look' deep cuts the other. AP on Saturday is just the cherry on top.",
    votes: 431, comments: 96, tag: "Discussion", img: true },
  { id: "p4", sub: "pind2city", author: "study_visa_2026", time: "9h", title: "PSA: post-grad work permit rules changed again — here's what actually applies for 2026 intakes",
    body: "Spent two hours with a consultant so you don't have to. Short version: check your program's eligibility list BEFORE you pay tuition. Details + links inside.",
    votes: 173, comments: 41, tag: "Advice", img: false },
  { id: "p5", sub: "kabaddi", author: "stopper_singh", time: "12h", title: "Surrey Kabaddi Cup draw is out — defending champions land in the group of death",
    body: "Brackets just dropped. Two teams flown in straight from Ludhiana. If you've never seen circle-style live, this is the year to go.",
    votes: 96, comments: 28, tag: "Match report", img: true },
];

const ARTICLES = [
  { id: "a1", kicker: "History", title: "Bhangra: from the harvest fields to the world's dancefloors",
    dek: "How a Punjabi farmers' dance for Vaisakhi became a global sound — by way of Southall, Birmingham and a drum machine.",
    author: "Harleen Kaur", authorU: "HK", read: "8 min", date: "Jun 11", feat: true, cat: "Culture" },
  { id: "a2", kicker: "Geography", title: "Panj-āb: the five rivers that named a people",
    dek: "Jhelum, Chenab, Ravi, Beas, Sutlej — what the 'land of five waters' means, and why two of them now run through another country.",
    author: "Gurpreet Singh", authorU: "GS", read: "6 min", date: "Jun 9", feat: false, cat: "History" },
  { id: "a3", kicker: "Diaspora", title: "Komagata Maru: the ship that tested an empire",
    dek: "In 1914, 376 Punjabis sailed to Vancouver to claim their rights as British subjects. What happened next still echoes.",
    author: "Ravinder Dhillon", authorU: "RD", read: "11 min", date: "Jun 6", feat: false, cat: "History" },
  { id: "a4", kicker: "Profile", title: "Sidhu Moose Wala and the sound that outlived him",
    dek: "Four years on, the Moosewala catalogue keeps breaking records. A look at how a boy from Moosa became a movement.",
    author: "Simran Gill", authorU: "SG", read: "9 min", date: "Jun 2", feat: false, cat: "Music" },
  { id: "a5", kicker: "Guide", title: "A worldwide map of Vaisakhi: where the diaspora gathers each April",
    dek: "From the Surrey Nagar Kirtan — the largest outside India — to Southall, Yuba City and beyond. Where to be, and when.",
    author: "Manpreet Brar", authorU: "MB", read: "5 min", date: "May 30", feat: false, cat: "Guide" },
];

const ARTICLE_BODY = [
  "It began, like so much of Punjab, in the fields.",
  "Bhangra was the dance of the harvest — performed at Vaisakhi each April when the wheat came in golden and the year's hardest work was finally done. To the heartbeat of the dhol, farmers in Punjab's villages leapt and stamped and threw their arms to the sky, a release of joy after months bent over the earth. There were no stages and no tickets; there was a field, a drum, and a reason to celebrate.",
  "For generations it stayed that way — regional, rural, tied to the rhythm of the land. Then, in the 1970s and 80s, Punjabis carried it onto airplanes. In the back rooms of Southall and the dance halls of Birmingham, the children of immigrants found that the dhol could share a stage with a synthesiser, and that a giddha boliyan could ride a drum machine without losing its soul.",
  "“We weren't trying to preserve anything in a museum,” one early UK bhangra producer recalled. “We were trying to make something our parents recognised and our friends could rave to. Both at once.”",
  "What followed was an explosion. Daytimer gigs filled because British-Asian kids couldn't get into night clubs; cassette labels pressed records out of garages; and a sound born in Punjabi villages became the heartbeat of a generation growing up between two worlds. By the 2000s it had bled into hip-hop, pop and Bollywood alike.",
  "Today a Diljit Dosanjh sells out arenas where bhangra rhythms shake the rafters, and a wedding in Melbourne or a mela in Toronto moves to the same beat a farmer kept in a Doaba field a century ago. The harvest dance never really left home. It just taught the whole world the steps.",
];

// Prefer real data injected by the server (window.__DATA__); fall back to the
// mock data above when running as a static file.
const _D = (typeof window !== "undefined" && window.__DATA__) || {};
Object.assign(window, {
  coverFor, CATEGORIES, DAYS, ARTICLE_BODY,
  EVENTS: Array.isArray(_D.events) ? _D.events : EVENTS,
  COMMUNITIES: Array.isArray(_D.communities) && _D.communities.length ? _D.communities : COMMUNITIES,
  POSTS: Array.isArray(_D.posts) ? _D.posts : POSTS,
  ARTICLES: Array.isArray(_D.articles) && _D.articles.length ? _D.articles : ARTICLES,
});
