/* global React */

// =====================================================================
//  MARKET LAYER — one codebase, two price lists.
//
//    id    → Indonesia      · rates in IDR  (mediakit.dhanyindraswara.com)
//    intl  → International  · rates in USD  (mediakit-eng.dhanyindraswara.com)
//
//  Everything that differs between the two markets lives in this file
//  and NOWHERE else. To change a price, edit the MARKETS object below —
//  no component code needs to be touched.
//
//  The DOMAIN decides — there is no currency switcher, and a visitor
//  never sees both price lists:
//    the hostname matches INTL_HOSTS below (the -eng domain) → USD
//    anything else                                          → IDR
//  `?market=intl` is a preview escape hatch for checking the USD site
//  before its DNS is live. It is not linked from anywhere.
// =====================================================================

// Hostnames (or hostname fragments) that should open in USD by default.
const INTL_HOSTS = ["mediakit-eng.", "-eng.", "media-kit-eng."];

const MARKETS = {
  // ─────────────────────────────────────────────────────────────────
  //  INDONESIA · IDR
  // ─────────────────────────────────────────────────────────────────
  id: {
    key: "id",
    label: "Indonesia",
    short: "IDR",
    flag: "🇮🇩",
    titleSuffix: "",

    // WhatsApp prefilled messages
    wa: {
      collab: "Halo Dhany, saya tertarik untuk berkolaborasi.",
      speaking: "Halo Dhany, saya ingin mengundang kamu sebagai pembicara.",
    },

    // ── Collaboration packages (index.html → Collab) ────────────────
    collab: {
      subtitle:
        "Rates below are per campaign, in IDR. Story and carousel bonus always included free. Long-term partnership is the easiest path.",
      foot: "All rates in IDR · custom scope quoted per brief · invoice on request.",
      prices: {
        single:   { price: "Rp 1,2 jt",      unit: "/ piece" },
        bundle:   { price: "Rp 2 jt",        unit: " · bundle" },
        longterm: { price: "Call for price", unit: null },
      },
    },

    // ── Speaking fees (speaker.html → SpeakerFees) ──────────────────
    fees: {
      subtitle:
        "Fees below are for a solo engagement — just me. Jabodetabek rates are all-in; for out-of-town events, transport and accommodation are arranged by the host.",
      onsiteNote:
        "Out-of-town fee is for the session only — transport & accommodation arranged by the host.",
      onlineNote: "Fully online — same rate wherever your audience is.",
      rows: {
        keynote:  [{ label: "Jabodetabek", price: "Rp 6 jt" }, { label: "Luar Jabodetabek", price: "Rp 9 jt" }],
        workshop: [{ label: "Half day / full day", price: "By call" }],
        webinar:  [{ label: "Online, anywhere", price: "Rp 3 jt" }],
        panel:    [{ label: "Jabodetabek", price: "Rp 6 jt" }, { label: "Luar Jabodetabek", price: "Rp 9 jt" }],
      },
    },

    // ── Session formats (speaker.html → SpeakerFormats) ─────────────
    formats: {
      subtitle:
        "On-site in Indonesia or online anywhere. Every format is tailored to your audience — tell me the goal and I'll scope it.",
    },

    // ── Small copy bits reused across sections ──────────────────────
    location: "Jakarta, Indonesia",
    paymentMeta: "Invoiced in IDR",
    audienceNote:
      "Demographics are based on platform insights — request the latest report for full breakdown.",
  },

  // ─────────────────────────────────────────────────────────────────
  //  INTERNATIONAL · USD
  //  ⚠️  THIS IS THE ONLY PLACE USD PRICES LIVE — edit here.
  // ─────────────────────────────────────────────────────────────────
  intl: {
    key: "intl",
    label: "International",
    short: "USD",
    flag: "🌐",
    titleSuffix: " · International (USD)",

    wa: {
      collab: "Hi Dhany, I'd like to discuss a brand collaboration. (International — USD rates)",
      speaking: "Hi Dhany, I'd like to invite you as a speaker. (International — USD rates)",
    },

    collab: {
      subtitle:
        "Rates below are per campaign, in USD, for brands outside Indonesia. Story and carousel bonus always included free. Long-term partnership is the easiest path.",
      foot: "All rates in USD · paid by Wise / SWIFT transfer or PayPal · invoice on request · transfer fees and any local withholding tax on the client side.",
      prices: {
        single:   { price: "$650",           unit: "/ piece" },
        bundle:   { price: "$750",           unit: " · bundle" },
        longterm: { price: "Call for price", unit: null },
      },
    },

    fees: {
      subtitle:
        "Fees below are for a solo engagement — just me. Online sessions run worldwide at a flat rate; for on-site events outside Indonesia, flights, visa, and accommodation are arranged by the host.",
      onsiteNote:
        "On-site fee covers the session only — international flights, visa & accommodation arranged by the host.",
      onlineNote: "Fully online — same rate in any time zone, EU and US hours included.",
      rows: {
        keynote:  [{ label: "Online · worldwide", price: "$750" }, { label: "On-site · international", price: "$1,800" }],
        workshop: [{ label: "Half day / full day", price: "By call" }],
        webinar:  [{ label: "Online, anywhere", price: "$500" }],
        panel:    [{ label: "Online · worldwide", price: "$500" }, { label: "On-site · international", price: "$1,200" }],
      },
    },

    formats: {
      subtitle:
        "Online anywhere in the world, or on-site at your event. Every format is tailored to your audience — tell me the goal and I'll scope it.",
    },

    location: "Jakarta, Indonesia · GMT+7",
    paymentMeta: "Invoiced in USD",
    audienceNote:
      "43% of the audience is outside Indonesia — Malaysia, Singapore, the Philippines, the US, India and Europe. Request the latest report for the full breakdown.",
  },
};

// ── resolve the market for this page view ────────────────────────────
//  The visitor never chooses: the domain decides. A `?market=` override
//  exists only so the USD site can be previewed before its DNS is live.

function resolveMarket() {
  try {
    const param = new URLSearchParams(window.location.search).get("market");
    if (param && MARKETS[param]) return param;

    const host = window.location.hostname.toLowerCase();
    if (INTL_HOSTS.some((h) => host.startsWith(h) || host.includes(h))) return "intl";
  } catch (e) {
    /* exotic URL → fall through to the default */
  }
  return "id";
}

const MARKET = resolveMarket();

// Stamp the market on <html> (a CSS hook) and mark the title.
document.documentElement.dataset.market = MARKET;
document.title += MARKETS[MARKET].titleSuffix;

// ── the active market, for components and for the inline app scripts ──
function currentMarket() {
  return MARKETS[MARKET];
}

function useMarket() {
  return { key: MARKET, t: MARKETS[MARKET] };
}

// WhatsApp deep link for the active market.
const WA_NUMBER = "6281805759025";
function waLink(kind = "collab") {
  return "https://wa.me/" + WA_NUMBER + "?text=" + encodeURIComponent(currentMarket().wa[kind]);
}

window.MARKETS = MARKETS;
window.useMarket = useMarket;
window.currentMarket = currentMarket;
window.waLink = waLink;
