/* =========================================================================
   PR NEW-BUSINESS HEALTH CHECK  —  diagnostic data
   -------------------------------------------------------------------------
   EDIT HERE. Each question is one object. Shape:
     { id, area, question, help, options:[{label, score}] }
   score runs 0 (weakest) .. 3 (strongest). Options are ordered weakest first.
   10-question blend. q5 (triggers) and q9 (ownership) are 73 Media additions.
   All question and option copy is client-confirmed.
   ========================================================================= */

const QUESTIONS = [
  {
    id: 'q1',
    area: 'Where new business comes from',
    question: 'When a new client signs, where do they usually come from?',
    help: 'Starting with how growth actually happens for you today. There is no wrong answer.',
    options: [
      { label: 'It varies, and we don\u2019t track it closely', score: 0 },
      { label: 'A referral or word of mouth', score: 1 },
      { label: 'They found us through our work, content, or search', score: 2 },
      { label: 'We reached out to them first', score: 3 },
    ],
  },
  {
    id: 'q2',
    area: 'Outbound motion',
    question: 'What does your outbound look like right now, if you do any?',
    help: 'Every firm runs this differently, so paint the real picture, not the ideal one.',
    options: [
      { label: 'We don\u2019t really do outbound', score: 0 },
      { label: 'A bit of email or LinkedIn when things slow down', score: 1 },
      { label: 'A mix of channels, run in pushes when we have capacity', score: 2 },
      { label: 'A steady program across a few channels', score: 3 },
    ],
  },
  {
    id: 'q3',
    area: 'Conversation volume',
    question: 'How many cold conversations do you start in a typical month?',
    help: 'Cold meaning brands that did not already know you. It is the clearest signal of an engine that is actually running.',
    options: [
      { label: 'Close to none', score: 0 },
      { label: 'A handful', score: 1 },
      { label: 'Several, but it varies a lot', score: 2 },
      { label: 'A predictable number every month', score: 3 },
    ],
  },
  {
    id: 'q4',
    area: 'Positioning and message',
    question: 'If a prospect asked why you and not the agency down the street, how ready is the answer?',
    help: 'We are checking whether your angle survives a cold approach.',
    options: [
      { label: 'We would talk about our work and our people', score: 0 },
      { label: 'We have a few points, nothing fixed', score: 1 },
      { label: 'We have a clear position we repeat', score: 2 },
      { label: 'We have a sharp angle that lands in a cold message', score: 3 },
    ],
  },
  {
    id: 'q5',
    area: 'Trigger and intent signals',
    question: 'Do you watch for the moments that make a brand more likely to need PR?',
    help: 'Things like a new marketing lead stepping in, a fresh funding round, or a brand publicly parting with its current agency.',
    options: [
      { label: 'No, we don\u2019t track that', score: 0 },
      { label: 'We notice sometimes, by chance', score: 1 },
      { label: 'We keep an eye on a few accounts', score: 2 },
      { label: 'We track these triggers and reach out when they come up', score: 3 },
    ],
  },
  {
    id: 'q6',
    area: 'Target clarity',
    question: 'Could you list twenty specific brands you would genuinely want to work with?',
    help: 'A concrete test of how sharp your targeting really is.',
    options: [
      { label: 'Not without sitting down to think about it', score: 0 },
      { label: 'A handful come to mind', score: 1 },
      { label: 'Yes, we keep a list', score: 2 },
      { label: 'Yes, and we follow what is happening at each one', score: 3 },
    ],
  },
  {
    id: 'q7',
    area: 'Predictability',
    question: 'How far ahead can you currently see your revenue?',
    help: 'This is the visibility that lets you hire, invest, and plan with confidence.',
    options: [
      { label: 'We don\u2019t really look at it that way', score: 0 },
      { label: 'Mostly the current quarter', score: 1 },
      { label: 'Around six months', score: 2 },
      { label: 'A year or more', score: 3 },
    ],
  },
  {
    id: 'q8',
    area: 'Follow-up and nurture',
    question: 'When a brand is a great fit but is not ready to move yet, what happens?',
    help: 'This is where a lot of good business quietly goes.',
    options: [
      { label: 'We move on', score: 0 },
      { label: 'We try to remember to follow up', score: 1 },
      { label: 'We stay in loose contact', score: 2 },
      { label: 'We have a set way to stay in touch until they are ready', score: 3 },
    ],
  },
  {
    id: 'q9',
    area: 'Ownership',
    question: 'Who handles new business outreach day to day?',
    help: 'Most firms stall right here, when new business is nobody\u2019s actual job.',
    options: [
      { label: 'It is shared, with no clear owner', score: 0 },
      { label: 'The founder or principal, around client work', score: 1 },
      { label: 'Senior staff, when they have time', score: 2 },
      { label: 'Someone whose main job is new business', score: 3 },
    ],
  },
  {
    id: 'q10',
    area: 'Measurement and visibility',
    question: 'How do you currently measure your new business?',
    help: 'If you cannot see it, you cannot improve it.',
    options: [
      { label: 'We don\u2019t track it formally', score: 0 },
      { label: 'We know roughly how many clients we won this year', score: 1 },
      { label: 'We track meetings, win rate, and average value', score: 2 },
      { label: 'We track all of that, plus pipeline value and what is likely to close', score: 3 },
    ],
  },
];

/* The prescription, per area. Each gap maps to a capability area, then gives the
   prospect genuine, actionable steps they could take themselves. The steps quietly
   showcase the 73 Media method so the done-for-you CTA lands. The proof stays on the
   CTA, not in the steps. Doctor voice, no em dashes, no exclamations. */
const PRESCRIPTIONS = {
  q1: {
    system: 'Data + Intent Engineering',
    pain: 'Referrals are someone else\u2019s decision to make. When they slow down, and they always do at some point, you have no lever to pull and no way to see it coming.',
    fix: 'Start by studying the clients you have already won and pulling out the traits they share: industry, size, and the trigger that made them ready to buy. Turn that into a written ideal client profile, then build a named list of companies that match it and prioritize the ones showing in-market signals. Now you have a channel you can turn up on purpose instead of waiting on whoever happens to refer you.',
  },
  q2: {
    system: 'Multi-Channel Outreach',
    channels: true,
    pain: 'Outbound that only fires when things go quiet arrives exactly when you can least afford to wait for it to work. By the time the pipeline looks thin, the gap is already months out.',
    fix: 'Stop leaning on any single channel. Build one coordinated motion across email, LinkedIn, phone, and direct mail, and sequence the touches so each one builds on the last. Run it every week on a fixed cadence rather than in bursts, so pipeline becomes something you produce on schedule instead of something you chase once it already looks thin.',
  },
  q3: {
    system: 'White-Glove Conversion',
    pain: 'With almost no cold conversations, your entire business depends on the few people who already know you. That is a ceiling, and it sits lower than your ambition.',
    fix: 'Feed the top of your funnel with enough qualified, intent-matched targets to produce a predictable number of new conversations every month. Then respond fast, within minutes if you can, and have one person own every positive reply through to a booked meeting. Speed of response is one of the biggest levers there is on how many conversations turn into real calls.',
  },
  q4: {
    system: 'Lead Magnets & Premium Copy',
    pain: 'If the answer to why you is your work and your people, it sounds like every other agency, because every agency says that. A cold prospect has no reason to choose sameness.',
    fix: 'Get specific about the one thing that makes buyers in your category move, and build your message around that instead of your work and your people. Lead with a point of view and a concrete outcome, and give a cold prospect something of real value up front, like a tailored asset built for them, so they have a reason to take you seriously before the first call.',
  },
  q5: {
    system: 'Intent & Trigger Monitoring',
    pain: 'PR is a timing business. A brand that just lost its agency, raised a round, or hired a new marketing lead is in the market for a few weeks, and if you are not watching, you only hear about it after the pitch list is already set.',
    fix: 'Pick the handful of signals that reliably mean a brand is about to need PR: a new marketing or comms leader, a funding announcement, a product launch, a public agency split. Set up alerts for them across your target list, and reach out in the window while the need is fresh. A timed message tied to a real trigger beats a cold one to the same brand many times over.',
  },
  q6: {
    system: 'ICP & List Engineering',
    pain: 'If you cannot name the brands you want, neither can your outreach. Without a sharp list, every message has to be generic, and generic messages get deleted. Vague targeting is the quiet reason most outbound never lands.',
    fix: 'Sit down and translate your best clients into a specific, written profile, then build a real list of the exact brands and decision-makers that fit it, well past twenty. Enrich and intent-score each one before you reach out, so your outreach only ever lands on accounts that genuinely fit and are more likely to be in-market right now.',
  },
  q7: {
    system: 'Compounding GTM System',
    pain: 'When you can only see as far as the current quarter, you cannot hire, invest, or commit with any confidence. The whole business ends up running on nerves instead of numbers.',
    fix: 'Connect your targeting, outreach, and follow-up into one system where every signal, reply, and booked meeting sharpens the next. Keep enough known and weighted opportunities moving that you can see two and three quarters out, not just the one in front of you. That visibility is the difference between guessing at revenue and forecasting it.',
  },
  q8: {
    system: 'Lead Nurturing Systems',
    channels: true,
    pain: 'Most deals are not lost, they are forgotten. The interested-but-not-ready prospect is where the majority of revenue actually lives, and follow up when we remember is exactly where it leaks out.',
    fix: 'Build a follow-up sequence for the interested-but-not-ready and keep showing up across email, LinkedIn, phone, and direct mail over weeks and months. Reuse the messaging that is already working in your live outreach. When their timing finally changes, you want to be the name already in the conversation, not one they have to recall.',
  },
  q9: {
    system: 'A Dedicated New-Business Engine',
    pain: 'When new business is squeezed in around client work, it is the first thing to drop the moment a project heats up. Shared ownership usually means no ownership, and the pipeline goes quiet exactly when everyone is heads-down and busy.',
    fix: 'Make new business someone\u2019s actual job, with the time and targets to match, rather than a task the founder fits between fires. Give that owner a clear weekly number and a simple system to run, so outreach keeps happening whether or not the team is slammed. The firms that grow predictably are the ones where pipeline does not depend on a quiet week.',
  },
  q10: {
    system: 'Pipeline & KPI Infrastructure',
    pain: 'What you do not measure, you cannot improve. When new business is not tracked, you cannot tell a good month from a lucky one, and you have no idea which part of the engine to fix.',
    fix: 'Get every prospect into one place with clear stages, from first touch to booked meeting, and track the key numbers: conversations started, meetings booked, win rate, average value, and total pipeline value. Once you can see those, you can forecast from evidence instead of memory and spot exactly where deals are leaking out.',
  },
};

/* Social proof for the results CTA. The automotive case study, real numbers. */
const CASE_STUDY = {
  label: 'Proof it works',
  client: 'Automotive Marketing Firm',
  text: 'They came to us struggling to scale past low-revenue, independent shops. We engineered the full GTM system around them: data and intent targeting, true multi-channel outreach, and white-glove booking onto their calendar.',
  stats: [
    { value: '31+', label: 'Conversations in 30 days' },
    { value: '$2M+', label: 'New pipeline, under 30 days' },
  ],
};

/* Three result bands, keyed to the total score. Names match the backend handoff. */
const BANDS = {
  'Referral led': {
    name: 'Referral led',
    range: [0, 14],
    summary: 'Your new business runs on referrals and reputation. That works until it does not, and it is almost impossible to forecast. The upside is real the moment you add a deliberate motion.',
    headline: 'Your pipeline is referral led.',
  },
  'Building it': {
    name: 'Building it',
    range: [15, 23],
    summary: 'You have started building a real new-business motion. The foundations are there. The activity is still inconsistent, and a few gaps are holding back predictability.',
    headline: 'You are building the engine.',
  },
  'Systematic': {
    name: 'Systematic',
    range: [24, 30],
    summary: 'You run new business like a system. The work now is sharpening and scaling what already works, and closing the last few gaps before they cost you a quarter.',
    headline: 'Your new business runs as a system.',
  },
};

const MAX_SCORE = QUESTIONS.length * 3; // 30

function bandForScore(total) {
  if (total <= BANDS['Referral led'].range[1]) return 'Referral led';
  if (total <= BANDS['Building it'].range[1]) return 'Building it';
  return 'Systematic';
}

/* Given the answers map { q1: optionIndex, ... }, return the full diagnosis. */
function diagnose(answers) {
  let total = 0;
  const scored = QUESTIONS.map((q) => {
    const idx = answers[q.id];
    const opt = (idx != null) ? q.options[idx] : null;
    const score = opt ? opt.score : 0;
    total += score;
    return { id: q.id, area: q.area, score, label: opt ? opt.label : '', question: q.question };
  });
  const band = bandForScore(total);
  // weakest areas: lowest score first, then by question order. Surface up to 3 that score <= 1,
  // but always return at least 2 so the prescription never reads empty.
  const sorted = [...scored].sort((a, b) => a.score - b.score);
  let weak = sorted.filter((s) => s.score <= 1);
  if (weak.length < 2) weak = sorted.slice(0, 2);
  if (weak.length > 3) weak = weak.slice(0, 3);
  const weakestAreas = weak.map((w) => w.id);
  return {
    total,
    pct: Math.round((total / MAX_SCORE) * 100),
    band,
    scored,
    weak,
    weakestAreas,
  };
}

Object.assign(window, { QUESTIONS, PRESCRIPTIONS, CASE_STUDY, BANDS, MAX_SCORE, diagnose, bandForScore });
