// ce-data-c.jsx — The Connection Experiment (version C)
// 7 question screens: matrix (city people) · far ones · barriers · role · city · age · gender
// Photos are placeholders — easily swapped (just change the `photo` paths).

const CE_PHOTOS = {
  intro:    "assets/imagery/dinner-friends.jpg",
  matrix:   "assets/imagery/dinner-warm.jpg",
  q4:       "assets/imagery/far-ones.jpg",
  q5:       "assets/imagery/gap-hang-soon.jpg",
  q6:       "assets/imagery/coctel.jpg",
  q7:       "assets/imagery/about-location.jpg",
  q8:       "assets/imagery/about-age.jpg",
  q9:       "assets/imagery/about-identity.jpg",
  reveal:   "assets/imagery/coctel.jpg",
  waitlist: "assets/imagery/golden-hour.jpg",
};

// Per-photo focal point for the header crop.
const CE_FOCUS = {
  matrix:   "center 58%",
  q4:       "center 32%",
  q5:       "center 82%",
  q6:       "center 50%",
  q7:       "center 72%",
  q8:       "center 76%",
  q9:       "center 38%",
  reveal:   "center 50%",
  waitlist: "center 50%",
};

// Three stages: Quality time (matrix + far ones) · The gap (barriers + role) · About you (city, age, gender)
const CE_QUESTIONS = [
  {
    id: "matrix", type: "matrix", stage: 0, stagePos: 1, stageLen: 2,
    eyebrow: "Quality time", photo: CE_PHOTOS.matrix,
    title: "How do you feel about the quality time you get with the people who live in your city?",
    bold: ["quality time", "live in your city"],
    hint: "Only the people who live in your same city \u2014 close enough to actually see.",
    rows: [
      { key: "family",  label: "Your family" },
      { key: "friends", label: "Your closest friends" },
      { key: "partner", label: "Your partner" },
    ],
    na: "Doesn't apply",
    scale: {
      // low → high, left to right. Only points 0 / 2 / 4 are labeled.
      points: ["Way less than I want", "Less than I want", "About right", "A good amount", "More than enough"],
      labeled: [0, 2, 4],
    },
  },
  {
    id: "q4", type: "single", stage: 0, stagePos: 2, stageLen: 2,
    eyebrow: "The far ones", photo: CE_PHOTOS.q4,
    title: "And the ones who live far. The ones a text is supposed to keep close. How's that going?",
    options: ["We're as close as ever", "It's about right", "I wish it were more", "We've gone quiet", "Doesn't apply"],
  },
  {
    id: "q5", type: "multi", stage: 1, stagePos: 1, stageLen: 2,
    eyebrow: "The gap", photo: CE_PHOTOS.q5,
    title: "You all say \u201cwe should hang soon.\u201d Soon never comes. Be honest, what's really in the way?",
    hint: "Pick all that feel true.",
    options: [
      "Our calendars never line up",
      "We live too far apart now",
      "We're just in different life stages now",
      "Money's tight",
      "I'm just tired",
      "Staying home is easier",
      "We never know what to do",
      "Nothing, we're good",
    ],
  },
  {
    id: "q6", type: "multi", stage: 1, stagePos: 2, stageLen: 2,
    eyebrow: "The gap", photo: CE_PHOTOS.q6,
    title: "When plans actually come together, who are you in the group?",
    hint: "Pick all that feel true.",
    options: [
      "The one who makes it happen and I love it",
      "The one who shows up, no planning",
      "The tired organizer, I do it but it drains me",
      "The one quietly wishing someone else would",
      "Honestly? No one organizes, so we don't",
    ],
  },
  {
    id: "q7", type: "text", stage: 2, stagePos: 1, stageLen: 3,
    eyebrow: "About you", photo: CE_PHOTOS.q7,
    title: "Last thing. A little about you, so we can make sense of what the world is telling us. Where in the world are you?",
    placeholder: "Your city, country",
  },
  {
    id: "q8", type: "single", stage: 2, stagePos: 2, stageLen: 3,
    eyebrow: "About you", photo: CE_PHOTOS.q8,
    title: "How long have you been at this whole adulting thing?",
    options: ["18 to 24", "25 to 34", "35 to 44", "45 to 54", "55+"],
  },
  {
    id: "q9", type: "single", stage: 2, stagePos: 3, stageLen: 3,
    eyebrow: "About you", photo: CE_PHOTOS.q9,
    title: "How do you identify?",
    options: ["Woman", "Man", "Non-binary", "Prefer to self-describe", "Prefer not to say"],
  },
];

// Result types + scoring. Driven mainly by role (q6), modulated by barriers
// (q5) and how connected they feel (matrix rows + far ones q4).
const CE_RESULTS = {
  glue: {
    eyebrow: "Your connection type", name: "The Glue",
    desc: "You are the one who makes it happen. You text first, you pick the place, you get everyone in one room. Without you, half these plans would still be a \u201cwe should.\u201d",
    cost: "You keep everyone together, but you are always the one reaching out. If you stopped, you wonder if anyone would.",
    move: "Keep doing your thing, but let someone else carry it once in a while. You are allowed to be organized for, too.",
  },
  anchor: {
    eyebrow: "Your connection type", name: "The Tired Anchor",
    desc: "You organize because if you do not, nothing happens, and lately that costs you more than it used to. The love is there. The energy is thinning.",
    cost: "You are still holding everyone together, but it is draining you, and nobody has noticed you are running low.",
    move: "Do not disappear, delegate. Hand off one piece of the next plan. The group needs you steady, not burnt out.",
  },
  rod: {
    eyebrow: "Your connection type", name: "The Ride or Die",
    desc: "You are not the planner, but you never miss. Call you and you are there, every time, no questions.",
    cost: "You are always there when called, but you rarely call. You might be closer to people who do not show up the way you do.",
    move: "You show up beautifully. Try initiating once. The people who always organize would love to be invited for a change.",
  },
  drifter: {
    eyebrow: "Your connection type", name: "The Drifter",
    desc: "You love your people, but life pulled you in different directions. Distance, new seasons, full calendars, and suddenly it has been months.",
    cost: "Every month you wait, the gap gets a little wider, and \u201cwe will catch up soon\u201d gets a little easier to keep saying.",
    move: "Pick one person today. Not \u201csoon,\u201d today. One message restarts more than you think.",
  },
  ghost: {
    eyebrow: "Your connection type", name: "The Ghost",
    desc: "You drifted without meaning to. The group chat is alive, you are just quieter than you used to be.",
    cost: "The longer you stay quiet, the harder the hello feels, and the more you convince yourself they have moved on.",
    move: "You do not owe an explanation, just a hello. Send the most low pressure \u201cI miss you all\u201d and let it be easy.",
  },
  fullcup: {
    eyebrow: "Your connection type", name: "The Full Cup",
    desc: "You are full. You see your people enough, you feel held, and you are proof that closeness in adulthood is still possible.",
    cost: "Closeness this good is rare, and easy to take for granted until life gets busy and it slips.",
    move: "Be the one who pulls someone else in. You have the rhythm others are still looking for. Share it.",
  },
};

function computeResult(a) {
  a = a || {};
  const s = { glue: 0, anchor: 0, rod: 0, drifter: 0, ghost: 0, fullcup: 0 };
  const role = Array.isArray(a.q6) ? a.q6 : [];
  if (role.includes("The one who makes it happen and I love it")) s.glue += 4;
  if (role.includes("The one who shows up, no planning")) s.rod += 4;
  if (role.includes("The tired organizer, I do it but it drains me")) s.anchor += 4;
  if (role.includes("The one quietly wishing someone else would")) { s.ghost += 3; s.drifter += 1; }
  if (role.includes("Honestly? No one organizes, so we don't")) s.drifter += 3;

  const b = Array.isArray(a.q5) ? a.q5 : [];
  if (b.includes("Our calendars never line up")) { s.anchor += 1; s.drifter += 1; }
  if (b.includes("We live too far apart now")) s.drifter += 2;
  if (b.includes("We're just in different life stages now")) s.drifter += 2;
  if (b.includes("Money's tight")) s.drifter += 1;
  if (b.includes("I'm just tired")) { s.anchor += 2; s.ghost += 1; }
  if (b.includes("Staying home is easier")) s.ghost += 2;
  if (b.includes("We never know what to do")) s.drifter += 1;
  if (b.includes("Nothing, we're good")) s.fullcup += 3;

  const pos = ["More than enough", "A good amount", "About right", "It's about right", "We're as close as ever"];
  const gap = ["Way less than I want", "Less than I want", "I wish it were more", "We've gone quiet"];
  const mx = a.matrix || {};
  [mx.family, mx.friends, mx.partner, a.q4].forEach((v) => {
    if (pos.indexOf(v) >= 0) s.fullcup += 1;
    if (gap.indexOf(v) >= 0) s.drifter += 0.5;
  });
  if (a.q4 === "We've gone quiet") s.ghost += 1;

  const order = ["glue", "anchor", "rod", "fullcup", "ghost", "drifter"];
  let best = "glue", bestv = -1;
  order.forEach((id) => { if (s[id] > bestv) { bestv = s[id]; best = id; } });
  if (bestv <= 0) best = "glue";
  return CE_RESULTS[best];
}

Object.assign(window, { CE_PHOTOS, CE_FOCUS, CE_QUESTIONS, CE_RESULTS, computeResult });
