/* ============================================================
   Guided Workshop — content data
   Each chapter contains items of 3 possible types:
     - "content"  : rich text + media (image / video / embed)
     - "poll"     : anonymous poll, opens a live session for participants
     - "evidence" : file upload + notes
   Exports: window.GW_CHAPTERS, window.GW_TOTAL, window.GW_ACTIONS
   ============================================================ */

const MINING_IMG  = "https://images.unsplash.com/photo-1581094288338-2314dddb7ece?w=1200&q=80&fm=jpg";
const TEAM_IMG    = "https://images.unsplash.com/photo-1664575599618-8f6bd76fc670?w=1200&q=80&fm=jpg";
const VIDEO_THUMB = "https://images.unsplash.com/photo-1518709268805-4e9042af9f23?w=1200&q=80&fm=jpg";
const SLIDES_IMG  = "https://images.unsplash.com/photo-1454165804606-c3d57bc86b40?w=1200&q=80&fm=jpg";

/* helper */
const p = (txt) => ({ kind: "para", text: txt });
const h = (txt) => ({ kind: "heading", text: txt });
const img = (src, caption) => ({ kind: "image", src, caption });
const video = (src, poster) => ({ kind: "video", src, poster });
const bullets = (items) => ({ kind: "bullets", items });
const callout = (label, text) => ({ kind: "callout", label, text });
const gallery = (images, opts) => ({ kind: "gallery", images, ...opts });

/* Builder for media-only items (image or video — no surrounding text).
   Maps to the "Image Picker" question type in the creator's form builder.
   For multi-image upload, pass `images: [{src, caption?}, ...]` instead of `src`. */
const mediaItem = ({ id, num, title, mediaKind, src, images, poster, description, showTitle = true, commentBox = false, fit = "cover" }) =>
  ({ id, num, title, type: "media", mediaKind, src, images, poster, description, showTitle, commentBox, fit });

/* Builder for interactive question items.
   questionType is one of:
     - "radio"    : single-select from options[]
     - "rating"   : 1..max scale, rendered as stars or numbers
     - "boolean"  : Yes / No
     - "text"     : single-line input
     - "textarea" : multi-line input
   mode is orthogonal:
     - "individual" (default) : only the completer answers
     - "poll"                 : anonymous responses collected via a live
                                session (open the poll, share session code,
                                participants respond on their own devices)
   Common: description?, showTitle (default true), commentBox (default false),
           required (default false), session (required when mode === "poll"). */
const questionItem = (opts) => ({
  type: "question",
  showTitle: true,
  commentBox: false,
  required: false,
  mode: "individual",
  ...opts,
});

const GW_CHAPTERS = [
  /* ───────────────────────── Chapter 1 ─────────────────────── */
  {
    id: "ch1", num: 1, title: "Instruction",
    items: [
      {
        id: "1.1", num: "1.1", title: "Introduction", type: "content",
        eyebrow: "Welcome",
        blocks: [
          gallery([
            { src: "https://images.unsplash.com/photo-1581094288338-2314dddb7ece?w=1400&q=80&fm=jpg", caption: "Site B — Operations centre" },
            { src: "https://images.unsplash.com/photo-1518709268805-4e9042af9f23?w=1400&q=80&fm=jpg", caption: "Conveyor bay" },
            { src: "https://images.unsplash.com/photo-1454165804606-c3d57bc86b40?w=1400&q=80&fm=jpg", caption: "Daily ops review" },
            { src: "https://images.unsplash.com/photo-1664575599618-8f6bd76fc670?w=1400&q=80&fm=jpg", caption: "Field crew briefing" },
            { src: "https://images.unsplash.com/photo-1565043666747-69f6646db940?w=1400&q=80&fm=jpg", caption: "Maintenance bay" },
            { src: "https://images.unsplash.com/photo-1542744173-8e7e53415bb0?w=1400&q=80&fm=jpg", caption: "Asset register review" },
          ]),
          h("Welcome"),
          p("This workshop walks you through Method 8's Asset Management diagnostic. You'll review your operating model, capture evidence, and surface actions for your team."),
          h("Who this is for"),
          p("Operations leaders, programme owners, and anyone responsible for the operating model that underpins asset performance."),
          callout("Tip", "You can pause at any point — your progress is saved automatically and you can return later."),
        ],
      },
      {
        id: "1.2", num: "1.2", title: "Agenda", type: "content",
        blocks: [
          img(MINING_IMG, "Operational context — Site B"),
          h("Purpose"),
          p("This diagnostic helps organizational leaders assess foundational aspects of their organization and operating model — highlighting strengths and surfacing areas that require attention."),
          h("Outcome"),
          p("By the end of this assessment, you'll have a clearer picture of where your organization stands and what foundational changes may be needed to support long-term growth."),
          h("Estimated time"),
          p("10–15 minutes"),
        ],
      },
      {
        id: "1.3", num: "1.3", title: "Pre-read materials", type: "evidence",
        description: "Upload the most recent operating model document for your business unit. We'll reference it throughout the workshop.",
        accepts: ["PDF", "DOCX", "PPTX"],
        maxSize: "25 MB",
        notesPlaceholder: "Anything specific the team should know about this document?",
      },
    ],
  },

  /* ───────────────────────── Chapter 2 ─────────────────────── */
  {
    id: "ch2", num: 2, title: "Overview of organizational Foundations",
    items: [
      {
        id: "2.1", num: "2.1", title: "Introduction", type: "content",
        blocks: [
          h("The four pillars"),
          p("Method 8's Organizational Foundations framework rests on four pillars: Direction, Structure, Capability, and Performance. Each pillar maps to a small set of practices we'll explore in turn."),
          bullets([
            "Direction — strategy, intent, and priorities",
            "Structure — roles, governance, accountability",
            "Capability — skills, tools, and ways of working",
            "Performance — measurement, feedback, and improvement",
          ]),
        ],
      },
      {
        id: "2.2", num: "2.2", title: "The Overview", type: "content",
        blocks: [
          h("Reading the assessment"),
          p("Each pillar is scored against five maturity bands. A band describes what good looks like at that level — there's no single 'right' answer; the goal is to map your reality honestly."),
          callout("How to use this", "Read each band aloud with your team. Pick the band that reflects the majority of your business unit's behaviour today — not where you aspire to be."),
        ],
      },
      mediaItem({
        id: "2.3", num: "2.3", title: "Foundations Video",
        mediaKind: "video", src: null, poster: VIDEO_THUMB,
        description: "A 4-minute walk-through from our research lead on why the four pillars matter, and how leading organizations use them.",
        showTitle: true, commentBox: true, fit: "cover",
      }),
      mediaItem({
        id: "2.4", num: "2.4", title: "Site context",
        mediaKind: "image",
        images: [
          { src: "https://images.unsplash.com/photo-1581094288338-2314dddb7ece?w=1400&q=80&fm=jpg", caption: "Site B — Operations centre" },
          { src: "https://images.unsplash.com/photo-1518709268805-4e9042af9f23?w=1400&q=80&fm=jpg", caption: "Conveyor bay" },
          { src: "https://images.unsplash.com/photo-1454165804606-c3d57bc86b40?w=1400&q=80&fm=jpg", caption: "Daily ops review" },
          { src: "https://images.unsplash.com/photo-1664575599618-8f6bd76fc670?w=1400&q=80&fm=jpg", caption: "Field crew briefing" },
        ],
        showTitle: false, commentBox: false, fit: "cover",
      }),
      {
        id: "2.5", num: "2.5", title: "Pillar 1: Setting Direction", type: "evidence",
        description: "Attach your current strategy document or one-page strategic plan. If you don't have one, leave a note explaining how strategy is set today.",
        accepts: ["PDF", "DOCX", "Image"],
        maxSize: "25 MB",
        notesPlaceholder: "How is strategic direction set in your business unit today?",
      },
    ],
  },

  /* ───────────────────────── Chapter 3 ─────────────────────── */
  {
    id: "ch3", num: 3, title: "Structure & Accountability",
    items: [
      {
        id: "3.1", num: "3.1", title: "Roles & Responsibilities", type: "content",
        blocks: [
          h("Who owns what"),
          p("Clear ownership is the foundation of a high-performing operating model. We'll start by mapping the key roles in your business unit and surfacing any ambiguity."),
        ],
      },
      {
        id: "3.2", num: "3.2", title: "Governance forums", type: "evidence",
        description: "Provide the terms of reference for your primary operating governance forum (e.g. SteerCo, Operations Review).",
        accepts: ["PDF", "DOCX"],
        maxSize: "25 MB",
        notesPlaceholder: "Note the cadence, attendees, and primary decisions made in this forum.",
      },
      {
        id: "3.3", num: "3.3", title: "Span of control", type: "content",
        blocks: [
          h("Healthy spans"),
          p("Most operating environments target a span of control between 6–10 direct reports per leader. Wider spans often signal under-investment in leadership capacity; narrower spans signal layering."),
        ],
      },
    ],
  },

  /* ───────────────────────── Chapter 4 ─────────────────────── */
  {
    id: "ch4", num: 4, title: "Capability & Ways of Working",
    items: [
      {
        id: "4.1", num: "4.1", title: "Skills inventory", type: "content",
        blocks: [
          h("Mapping current capability"),
          p("Capability assessments work best when grounded in concrete behaviours — not job titles. We'll work through a small set of operating capabilities and rate your team's strength on each."),
        ],
      },
      {
        id: "4.2", num: "4.2", title: "Training & onboarding", type: "evidence",
        description: "Upload your current onboarding plan or the latest training calendar.",
        accepts: ["PDF", "XLSX", "DOCX"],
        maxSize: "25 MB",
        notesPlaceholder: "Roughly how many hours of structured training does a new hire receive in their first 90 days?",
      },
      {
        id: "4.3", num: "4.3", title: "Tooling & systems", type: "content",
        blocks: [
          h("The tools that matter"),
          p("This section focuses on the small handful of tools that genuinely shape day-to-day work — your work-management system, your data platform, and your collaboration stack."),
        ],
      },
      {
        id: "4.4", num: "4.4", title: "Continuous improvement", type: "content",
        blocks: [
          h("Improvement cadence"),
          p("How often does your team run retros, after-action reviews, or improvement sprints? Frequency and quality both matter — fortnightly retros that produce no actions are no better than none."),
        ],
      },
    ],
  },

  /* ───────────────────────── Chapter 5 ─────────────────────── */
  {
    id: "ch5", num: 5, title: "Team polls",
    items: [
      questionItem({
        id: "5.1", num: "5.1", title: "Alignment with the OF Framework",
        questionType: "radio",
        mode: "poll",
        description: "How aligned is your organization with the Organizational Foundations framework?",
        options: ["Fully aligned", "Mostly aligned", "Somewhat aligned", "Unclear"],
        session: { code: "4895 2457", url: "https://method8.com/workshop/4895-2457", participants: 75, responded: 43 },
      }),
      questionItem({
        id: "5.2", num: "5.2", title: "Capability self-rating",
        questionType: "rating",
        mode: "poll",
        description: "How would you rate your business unit's capability to deliver against current strategy?",
        scale: { min: 1, max: 5 },
        scaleStyle: "stars",
        labels: { min: "Insufficient", max: "World-class" },
        session: { code: "8826 1499", url: "https://method8.com/workshop/8826-1499", participants: 75, responded: 47 },
      }),
      questionItem({
        id: "5.3", num: "5.3", title: "Decision rights",
        questionType: "boolean",
        mode: "poll",
        description: "In your business unit, are major operating decisions made at the right level?",
        session: { code: "3120 8847", url: "https://method8.com/workshop/3120-8847", participants: 75, responded: 52 },
      }),
      questionItem({
        id: "5.4", num: "5.4", title: "One word",
        questionType: "text",
        mode: "poll",
        description: "In one word, describe how your operating model feels day-to-day.",
        placeholder: "e.g. heavy, agile, fragmented…",
        session: { code: "2207 5519", url: "https://method8.com/workshop/2207-5519", participants: 75, responded: 38 },
      }),
      questionItem({
        id: "5.5", num: "5.5", title: "Anonymous feedback",
        questionType: "textarea",
        mode: "poll",
        description: "What's the most important thing the programme owner should know that didn't surface earlier?",
        placeholder: "Anything goes — anonymous and unattributed.",
        session: { code: "6612 0078", url: "https://method8.com/workshop/6612-0078", participants: 75, responded: 29 },
      }),
    ],
  },

  /* ───────────────────────── Chapter 6 ─────────────────────── */
  {
    id: "ch6", num: 6, title: "Self-assessment",
    items: [
      questionItem({
        id: "6.1", num: "6.1", title: "How prepared does your team feel for this assessment?",
        questionType: "radio",
        description: "Pick the option that best matches your team's readiness today.",
        options: ["Fully prepared", "Mostly prepared", "Somewhat prepared", "Not at all prepared"],
        commentBox: true,
      }),
      questionItem({
        id: "6.2", num: "6.2", title: "Rate your operating model maturity",
        questionType: "rating",
        description: "Where would you place your business unit on a 5-point maturity scale?",
        scale: { min: 1, max: 5 },
        scaleStyle: "stars",
        labels: { min: "Reactive", max: "Optimised" },
      }),
      questionItem({
        id: "6.3", num: "6.3", title: "Do you have a documented operating-model review cadence?",
        questionType: "boolean",
        commentBox: true,
      }),
      questionItem({
        id: "6.4", num: "6.4", title: "What's the single biggest operating-model risk you face right now?",
        questionType: "text",
        placeholder: "One sentence is enough — name the risk in your own words.",
        required: true,
      }),
      questionItem({
        id: "6.5", num: "6.5", title: "Anything else you'd like the programme owner to know?",
        questionType: "textarea",
        placeholder: "Context, caveats, or links the team should see before they review your results.",
        rows: 5,
      }),
    ],
  },
];

const GW_TOTAL = GW_CHAPTERS.reduce((n, c) => n + c.items.length, 0);

/* Sample Actions data for the Actions tab */
const GW_ACTIONS = [
  {
    id: "a1",
    title: "Document strategy refresh cadence",
    desc: "Capture how often the strategy is reviewed and refreshed, and who participates.",
    owner: { name: "Andrew Matt",   avatar: "https://i.pravatar.cc/64?img=12" },
    priority: "high", status: "in-progress", due: "Jun 14", tags: ["Direction", "Strategy"],
    linkedItem: "2.5",
  },
  {
    id: "a2",
    title: "Clarify SteerCo decision rights",
    desc: "Draft a one-page decision-rights matrix for the monthly SteerCo and circulate to attendees.",
    owner: { name: "Priya Iyer",    avatar: "https://i.pravatar.cc/64?img=23" },
    priority: "med", status: "in-progress", due: "Jun 21", tags: ["Structure", "Governance"],
    linkedItem: "5.3",
  },
  {
    id: "a3",
    title: "90-day capability uplift plan",
    desc: "Build a concrete plan for closing the capability gaps surfaced in 5.2.",
    owner: { name: "Marcus Chen",   avatar: "https://i.pravatar.cc/64?img=32" },
    priority: "high", status: "open", due: "Jul 02", tags: ["Capability", "L&D"],
    linkedItem: "5.2",
  },
];

window.GW_CHAPTERS = GW_CHAPTERS;
window.GW_TOTAL    = GW_TOTAL;
window.GW_ACTIONS  = GW_ACTIONS;
