// Mock data + utilities

const PROFILE_LABELS = ["Profile A","Profile B","Profile C","Profile D","Profile E","Profile F","Profile G","Profile H"];
const REGIONS = [
  {market:"US Northeast", region:"US", flag:"🇺🇸"}, {market:"US South", region:"US", flag:"🇺🇸"}, {market:"US West", region:"US", flag:"🇺🇸"},
  {market:"UK Market", region:"UK", flag:"🇬🇧"}, {market:"DACH Market", region:"EU", flag:"🇩🇪"}, {market:"Canada Market", region:"CA", flag:"🇨🇦"},
  {market:"Benelux Market", region:"EU", flag:"🇳🇱"}, {market:"France Market", region:"EU", flag:"🇫🇷"}, {market:"Iberia Market", region:"EU", flag:"🇪🇸"},
  {market:"Nordics Market", region:"EU", flag:"🇸🇪"}, {market:"Ireland Market", region:"EU", flag:"🇮🇪"}, {market:"US Southeast", region:"US", flag:"🇺🇸"}
];
const CATEGORIES = ["Beauty","Apparel","Home","Wellness","Outdoor","Pet","Food & Bev","Footwear","Electronics","Kids"];
const SEGMENTS = ["High-LTV","Repeat","Premium","Lapsed-30","Discount-Affinity","Subscription","First-Party","Affluent"];

const rand = (a) => a[Math.floor(Math.random()*a.length)];
const randInt = (lo, hi) => Math.floor(lo + Math.random()*(hi-lo+1));

function genProfile(seed) {
  const label = PROFILE_LABELS[seed % PROFILE_LABELS.length];
  const r = REGIONS[(seed*3) % REGIONS.length];
  return {
    id: "",
    label,
    market: r.market,
    region: r.region,
    flag: r.flag,
    ageBucket: rand(["25-34","35-44","45-54","55-64"]),
    income: rand(["$60-80k","$80-120k","$120-180k","$180k+"]),
    industry: rand(["Beauty","Fashion","Supplements"]),
    platform: rand(["Meta","Google","TikTok"]),
    legalBasis: seed % 2 === 0 ? "Consent" : "Contract",
    noPurchaseData: seed % 2 === 0,
    ltv: seed % 2 === 0 ? null : randInt(380, 4200),
    segments: seed % 2 === 0
      ? ["Consent-Verified", SEGMENTS[(seed+2) % SEGMENTS.length]]
      : [SEGMENTS[seed % SEGMENTS.length], SEGMENTS[(seed+2) % SEGMENTS.length]],
    score: randInt(72, 96),
    optOut: false,
  };
}

const CONSENT_ONLY_PROFILE = {
  id: "SAMPLE_004",
  label: "Profile E",
  market: "US West",
  region: "US",
  flag: "🇺🇸",
  ageBucket: "35-44",
  income: "$80-120k",
  industry: "Beauty",
  platform: "Meta",
  ltv: null,
  segments: ["First-Party", "Consent-Verified"],
  score: 81,
  optOut: false,
  legalBasis: "Consent",
  noPurchaseData: true,
};

// Ticker pre-rolled deterministic so server-render matches
const TICKER_PLATFORMS = ["Meta","Google","TikTok","Meta","Google","TikTok"];
const TICKER_ITEMS = Array.from({length: 18}, (_, i) => {
  const r = REGIONS[(i*5) % REGIONS.length];
  const cat = CATEGORIES[(i*3) % CATEGORIES.length];
  const amt = (40 + (i*13) % 220).toFixed(2);
  const platform = TICKER_PLATFORMS[i % TICKER_PLATFORMS.length];
  return { id: "SYN_TXN_" + (i*7919).toString(36).toUpperCase().padStart(5,"0"), market: r.market, region: r.region, flag: r.flag, cat, amt, platform };
});

const FEATURES = [
  {
    num: "01",
    title: "Real Transaction Data",
    desc: "Sourced from actual e-commerce purchases. Not modeled, not surveyed.",
    icon: "cart",
  },
  {
    num: "02",
    title: "US & EU Coverage",
    desc: "Enriched buyer profiles across North America and key European markets.",
    icon: "globe",
  },
  {
    num: "03",
    title: "Snowflake-Native",
    desc: "Query directly inside your Snowflake environment. Zero data movement.",
    icon: "snowflake",
  },
  {
    num: "04",
    title: "Meta-Ready Formatting",
    desc: "Activation-ready audiences for paid social and performance campaigns.",
    icon: "target",
  },
];

const PERSONAS = [
  {
    key: "marketer",
    role: "Performance Marketer",
    title: "Cut CPAs without burning test budget.",
    body: "Lookalikes are only as good as the seed. Cartlytics seeds Meta with real buyers, segmented by category, AOV, and LTV so you scale what's already proven to convert, not what the algorithm guesses.",
    bullets: [
      "Seed audiences from verified purchase behavior, not pixel scraps",
      "Filter by AOV, category, frequency, and LTV percentile before sync",
      "One-click push to Meta, no CSV juggling, no hashing headaches",
    ],
    icon: "target",
  },
  {
    key: "dtc",
    role: "DTC Brand",
    title: "See the 80% of your buyer you're missing.",
    body: "Your CRM knows what they bought from you. Cartlytics shows what they buy everywhere else: the categories, price points, and frequencies that tell you where to expand, what to bundle, and who's actually worth retargeting.",
    bullets: [
      "Feed Meta LLAs that actually scale, built off verified high-LTV buyers",
      "Uncover the next category to launch based on real cross-brand purchase data",
      "Retarget with intent signals that close, not just impressions that burn budget",
    ],
    icon: "user",
  },
  {
    key: "data",
    role: "Data Team",
    title: "One integration. Zero pipelines.",
    body: "Native Snowflake share. No CSVs, no S3 buckets, no ETL. Join Cartlytics tables directly to your warehouse, refresh daily, and let your analysts and ML team work against fresh, governed data.",
    bullets: [
      "Snowflake Secure Data Share with no data movement",
      "Stable schema, daily incremental refresh",
      "SOC 2 Type II, GDPR, and CCPA compliant",
    ],
    icon: "stack",
  },
];

const SQL_QUERIES = [
  {
    name: "high_ltv_buyers.sql",
    code: [
      ["com", "-- High-LTV beauty buyers in EU, last 90 days"],
      ["kw", "SELECT "], ["", "profile_id, market_region, ltv_usd, top_category"],
      ["kw", "FROM "], ["", "cartlytics.profiles_enriched"],
      ["kw", "WHERE "], ["", "region "], ["kw", "= "], ["str", "'EU'"],
      ["", "  "], ["kw", "AND "], ["", "ltv_usd "], ["kw", "> "], ["num", "1500"],
      ["", "  "], ["kw", "AND "], ["fn", "ARRAY_CONTAINS"], ["", "(categories, "], ["str", "'Beauty'"], ["", ")"],
      ["", "  "], ["kw", "AND "], ["", "last_purchase_at "], ["kw", "> "], ["fn", "DATEADD"], ["", "(day, "], ["num", "-90"], ["", ", "], ["fn", "CURRENT_DATE"], ["", "())"],
      ["kw", "ORDER BY "], ["", "ltv_usd "], ["kw", "DESC"],
      ["kw", "LIMIT "], ["num", "100"], ["", ";"],
    ],
    rows: [
      ["SYN_8K2A91X", "UK Market", "$3,420", "Beauty"],
      ["SYN_4Q1L77B", "Iberia Market", "$2,890", "Beauty"],
      ["SYN_2H8N31A", "DACH Market", "$2,610", "Beauty"],
      ["SYN_6V5R20C", "France Market", "$2,340", "Beauty"],
      ["SYN_9D3T48E", "Benelux Market", "$2,180", "Beauty"],
      ["SYN_1B7M62F", "Nordics Market", "$1,950", "Beauty"],
      ["SYN_3F2K85G", "Ireland Market", "$1,720", "Beauty"],
    ],
    cols: ["profile_id","market_region","ltv_usd","top_category"],
  },
  {
    name: "lapsed_audience.sql",
    code: [
      ["com", "-- Lapsed-30 audience for win-back campaign"],
      ["kw", "SELECT "], ["", "profile_id, audience_key, last_category, last_aov_usd"],
      ["kw", "FROM "], ["", "cartlytics.profiles_enriched"],
      ["kw", "WHERE "], ["", "purchase_frequency_90d "], ["kw", "= "], ["num", "0"],
      ["", "  "], ["kw", "AND "], ["", "purchase_frequency_180d "], ["kw", ">= "], ["num", "2"],
      ["", "  "], ["kw", "AND "], ["", "predicted_ltv_usd "], ["kw", "> "], ["num", "800"],
      ["kw", "ORDER BY "], ["", "predicted_ltv_usd "], ["kw", "DESC"], ["", ";"],
    ],
    rows: [
      ["SYN_5G9P14H", "AUD_7A_F2", "Apparel", "$142"],
      ["SYN_8L4M22J", "AUD_C1_9B", "Wellness", "$98"],
      ["SYN_2N7Q56K", "AUD_4E_8A", "Beauty", "$76"],
      ["SYN_6R1S88L", "AUD_2F_4C", "Home", "$210"],
      ["SYN_9T8U03M", "AUD_9D_1E", "Apparel", "$165"],
    ],
    cols: ["profile_id","audience_key","last_category","last_aov_usd"],
  },
  {
    name: "meta_export.sql",
    code: [
      ["com", "-- Format audience for Meta Custom Audience upload"],
      ["kw", "SELECT "], ["", "privacy_safe_audience_key,"],
      ["", "       country_region, market_region, age_bucket"],
      ["kw", "FROM "], ["", "cartlytics.profiles_meta_ready"],
      ["kw", "WHERE "], ["", "segment "], ["kw", "= "], ["str", "'high_ltv_beauty'"],
      ["", "  "], ["kw", "AND "], ["", "consent_flag "], ["kw", "= "], ["num", "TRUE"], ["", ";"],
    ],
    rows: [
      ["AUD_3A_9C", "US", "US Northeast", "25-34"],
      ["AUD_7C_1A", "US", "US South", "35-44"],
      ["AUD_5B_3F", "EU", "DACH Market", "25-34"],
      ["AUD_1D_8C", "UK", "UK Market", "45-54"],
      ["AUD_9E_5D", "EU", "France Market", "35-44"],
    ],
    cols: ["audience_key","country_region","market_region","age_bucket"],
  },
];

Object.assign(window, {
  genProfile, CONSENT_ONLY_PROFILE, TICKER_ITEMS, FEATURES, PERSONAS, SQL_QUERIES, CATEGORIES, SEGMENTS
});
