/**
 * M-TEER Workbook content, transcribed from inputdata.docx.
 *
 * SOURCE FIDELITY RULES APPLIED HERE
 *  - Every title, instruction, prompt, quote and table value below is copied
 *    verbatim from the source document. Nothing medical is paraphrased,
 *    summarised or invented.
 *  - Where the source repeats an identical paper template (20 case planning
 *    sheets, 10 jet maps, 10 case logs, 50 teaching entries), the template is
 *    modelled ONCE as a repeatable activity and the source's copy count is
 *    recorded in `config.suggestedCopies`. The app lets a learner create as
 *    many entries as they need, so duplicating the row 20 times would add no
 *    information.
 *  - Blank cells in the source are answer spaces for the learner and are
 *    preserved as empty fields, not filled in.
 */

export interface SeedBlock {
  type: string;
  title?: string;
  payload: Record<string, unknown>;
}

export interface SeedActivity {
  /** Stable key used to make re-seeding idempotent. */
  key: string;
  type: string;
  title: string;
  description?: string;
  instructions?: string;
  config?: Record<string, unknown>;
  blocks: SeedBlock[];
}

export interface SeedLesson {
  title: string;
  description?: string;
  activities: SeedActivity[];
}

export interface SeedModule {
  slug: string;
  title: string;
  description?: string;
  lessons: SeedLesson[];
}

export interface SeedSection {
  slug: string;
  title: string;
  description?: string;
  modules: SeedModule[];
}

export interface SeedQuickReference {
  slug: string;
  category: string;
  title: string;
  summary?: string;
  blocks: SeedBlock[];
}

const CANVAS_DEFAULTS = {
  canvasWidth: 1024,
  canvasHeight: 768,
  allowEraser: true,
  allowUndo: true,
  allowRedo: true,
  allowClear: true,
  allowSave: true,
};

/** Drawing canvas block with the workbook's own prompt as the instruction. */
function canvas(instructions: string, extra: Record<string, unknown> = {}): SeedBlock {
  return {
    type: 'DRAWING_CANVAS',
    payload: { ...CANVAS_DEFAULTS, instructions, ...extra },
  };
}

function colouringCanvas(
  instructions: string,
  extra: Record<string, unknown> = {},
): SeedBlock {
  return {
    type: 'COLOURING_CANVAS',
    payload: { ...CANVAS_DEFAULTS, instructions, ...extra },
  };
}

function text(body: string): SeedBlock {
  return { type: 'TEXT', payload: { text: body } };
}

function heading(body: string, level = 2): SeedBlock {
  return { type: 'HEADING', payload: { text: body, level: String(level) } };
}

function instruction(body: string): SeedBlock {
  return { type: 'INSTRUCTION', payload: { text: body } };
}

function checklist(items: string[], title?: string): SeedBlock {
  return { type: 'CHECKLIST', title, payload: { items } };
}

function insight(title: string, body: string, attribution?: string): SeedBlock {
  return {
    type: 'CLINICAL_INSIGHT',
    payload: { title, text: body, ...(attribution ? { attribution } : {}) },
  };
}

function quote(body: string, attribution?: string): SeedBlock {
  return {
    type: 'QUOTE',
    payload: { text: body, ...(attribution ? { attribution } : {}) },
  };
}

function infoBox(title: string, body: string, tone = 'info'): SeedBlock {
  return { type: 'INFO_BOX', payload: { title, text: body, tone } };
}

function reflection(prompt: string): SeedBlock {
  return { type: 'REFLECTION', payload: { prompt, placeholder: 'Write your reflection here...' } };
}

function measurementTable(
  instructions: string,
  columns: string[],
  rows: string[],
  units?: string,
): SeedBlock {
  return {
    type: 'MEASUREMENT_TABLE',
    payload: { instructions, columns, rows, ...(units ? { units } : {}) },
  };
}

function form(instructions: string, fields: { name: string; label: string; type?: string }[]): SeedBlock {
  return { type: 'FORM', payload: { instructions, fields } };
}

// ---------------------------------------------------------------------------
// SECTION A — KNOW IT
// ---------------------------------------------------------------------------

const SECTION_A: SeedSection = {
  slug: 'section-a-know-it',
  title: 'SECTION A — KNOW IT',
  description:
    'Anatomy Drawing Modules. Understand the mitral valve as a connected system, one structure at a time.',
  modules: [
    {
      slug: 'a1-mitral-valve-apparatus',
      title: 'MODULE A1 — The Mitral Valve Apparatus: Build It from Scratch',
      description:
        'Learning Goal: Understand all six components of the mitral apparatus as a connected system.',
      lessons: [
        {
          title: 'The 6-Layer Build',
          activities: [
            {
              key: 'a1-drawing-exercise',
              type: 'DRAWING',
              title: 'Drawing Exercise — "The 6-Layer Build"',
              instructions:
                'Build the mitral apparatus one layer at a time, in the order listed.',
              blocks: [
                text(
                  'Learning Goal: Understand all six components of the mitral apparatus as a connected system.',
                ),
                checklist(
                  [
                    'Draw the annulus (saddle shape — hint: not flat!)',
                    'Add the anterior leaflet (large, sail-like, A1–A2–A3)',
                    'Add the posterior leaflet (smaller, 3 scallops: P1–P2–P3)',
                    'Draw the commissures (AC and PC — the forgotten landmarks)',
                    'Add primary, secondary, tertiary chordae tendineae',
                    'Place the papillary muscles (anterolateral + posteromedial)',
                  ],
                  'The 6-Layer Build',
                ),
                canvas(
                  'Sketch the heart cross-section and build your 6-layer mitral apparatus here.',
                ),
                checklist(
                  [
                    'Anterior leaflet',
                    'Posterior leaflet',
                    'Annulus',
                    'Chordae tendineae',
                    'Papillary muscles',
                    'Commissures',
                  ],
                  'Colouring Key — apply these colours to your drawing above',
                ),
                insight(
                  'MAISANO MOMENT',
                  'The annulus is saddle-shaped for a reason. When you flatten it, you create disease. Nature’s geometry is the best teacher.',
                ),
              ],
            },
          ],
        },
      ],
    },
    {
      slug: 'a2-scallop-segmentation-map',
      title: 'MODULE A2 — Scallop Segmentation Map',
      description: 'The Carpentier Segmentation System: Colour & Label.',
      lessons: [
        {
          title: 'The Carpentier Segmentation System',
          activities: [
            {
              key: 'a2-scallop-map',
              type: 'COLOURING',
              title: 'Scallop Segmentation Map',
              instructions: 'Surgeon’s view (from left atrium looking down)',
              blocks: [
                measurementTable(
                  'Surgeon’s view (from left atrium looking down)',
                  ['Anterior Leaflet', '', '', 'Commissures'],
                  ['A1 | A2 | A3 — AC (anterolateral)', 'P1 | P2 | P3 — PC (posteromedial)'],
                ),
                checklist(
                  [
                    'Colour each scallop a different shade in the drawing canvas below',
                    'Mark the primary TEER target zone (A2–P2)',
                    'Draw a MitraClip device at A2–P2',
                    'Label the typical DMR prolapse location',
                    'Label the typical SMR tethering pattern',
                  ],
                  'Candidate Tasks',
                ),
                colouringCanvas('Draw the en-face mitral valve and complete the tasks above.'),
              ],
            },
          ],
        },
      ],
    },
    {
      slug: 'a3-the-subvalvular-world',
      title: 'MODULE A3 — The Subvalvular World',
      description: 'Full-page blank cross-section for candidate to draw and label.',
      lessons: [
        {
          title: 'The Subvalvular Apparatus',
          activities: [
            {
              key: 'a3-subvalvular',
              type: 'DRAWING',
              title: 'The Subvalvular World',
              instructions: 'Full-page blank cross-section for candidate to draw and label.',
              blocks: [
                checklist([
                  'Primary chordae (to leaflet edges)',
                  'Secondary chordae (to leaflet bodies)',
                  'Tertiary chordae (to posterior leaflet base)',
                  'Anterolateral papillary muscle (dual blood supply)',
                  'Posteromedial papillary muscle (single supply — why it ruptures in MI)',
                ]),
                canvas('Sketch the LV cross-section with the full subvalvular apparatus.'),
                reflection(
                  'CLINICAL INSIGHT — Answer After Drawing: Why does the posteromedial papillary muscle rupture more often in inferior myocardial infarction?',
                ),
              ],
            },
          ],
        },
      ],
    },
    {
      slug: 'a4-mitral-valve-in-3d-space',
      title: 'MODULE A4 — The Mitral Valve in 3D Space',
      description:
        'Perspective drawing exercise. For each view below, trace the valve as it would appear and note the corresponding probe angle.',
      lessons: [
        {
          title: 'Perspective Drawing Exercise',
          activities: [
            {
              key: 'a4-en-face',
              type: 'TRACING',
              title: '1. En face (“surgical”) view from above',
              blocks: [canvas('Trace the en-face view here.')],
            },
            {
              key: 'a4-long-axis',
              type: 'TRACING',
              title: '2. Long-axis (parasternal echo) view',
              blocks: [canvas('Trace the long-axis view here.')],
            },
            {
              key: 'a4-bicommissural',
              type: 'TRACING',
              title: '3. Bicommissural (TEE) view',
              blocks: [canvas('Trace the bicommissural view here.')],
            },
            {
              key: 'a4-match-views',
              type: 'MEASUREMENT',
              title: 'Match each view to its probe angle',
              blocks: [
                measurementTable(
                  'Match each view to its probe angle.',
                  ['View', 'Probe Angle (°)', 'Key Structures Seen'],
                  [
                    'En face / surgical view — 3D reconstruction',
                    'Long-axis — 120–135°',
                    'Bicommissural — 60°',
                  ],
                ),
              ],
            },
          ],
        },
      ],
    },
  ],
};

// ---------------------------------------------------------------------------
// SECTION B — SEE IT
// ---------------------------------------------------------------------------

const TEE_VIEWS = [
  'View 1: Midesophageal 4-chamber (0°)',
  'View 2: Midesophageal commissural (60°)',
  'View 3: Midesophageal long-axis (120°–135°)',
  'View 4: Transgastric basal short-axis (“fish-mouth view”)',
  'View 5: Biplane imaging of A2–P2',
  'View 6: 3D en-face “surgeon’s view”',
  'View 7: Colour Doppler jet mapping',
  'View 8: Post-clip assessment view',
];

const SECTION_B: SeedSection = {
  slug: 'section-b-see-it',
  title: 'SECTION B — SEE IT',
  description:
    'Echo Tracing & Interpretation Pages. You treat what you see — train your eye through your hand.',
  modules: [
    {
      slug: 'b1-tee-view-tracing-library',
      title: 'MODULE B1 — TEE View Tracing Library',
      description:
        'For each of the 8 essential TEER TEE views, trace the key structures, label them, note the probe angle and depth, and write what you are specifically looking for in TEER planning.',
      lessons: [
        {
          title: 'The 8 Essential TEER TEE Views',
          activities: TEE_VIEWS.map((view, index) => ({
            key: `b1-view-${index + 1}`,
            type: 'TRACING',
            title: view,
            instructions:
              'Trace the key structures, label them, note the probe angle and depth, and write what you are specifically looking for in TEER planning.',
            blocks: [
              canvas('Trace the echo image and label structures here.'),
              form('Record your observations for this view.', [
                { name: 'probeAngleDepth', label: 'Probe Angle / Depth' },
                { name: 'keyStructures', label: 'Key Structures to Label', type: 'textarea' },
                { name: 'teerPlanningPurpose', label: 'TEER Planning Purpose', type: 'textarea' },
              ]),
            ],
          })),
        },
      ],
    },
    {
      slug: 'b2-measure-it-yourself',
      title: 'MODULE B2 — Measure It Yourself',
      description:
        'Practice measurement worksheet — complete using a live case or recorded loop.',
      lessons: [
        {
          title: 'Practice Measurement Worksheet',
          activities: [
            {
              key: 'b2-measurements',
              type: 'MEASUREMENT',
              title: 'TEER Planning Measurements',
              instructions:
                'Practice measurement worksheet — complete using a live case or recorded loop.',
              config: { repeatable: true, suggestedCopies: 5 },
              blocks: [
                measurementTable(
                  'Complete using a live case or recorded loop.',
                  ['TEER Planning Measurement', 'Value', 'Unit'],
                  [
                    'Coaptation gap — mm',
                    'Anterior leaflet length — mm',
                    'Posterior leaflet length — mm',
                    'Mitral valve area — cm²',
                    'EROA — cm²',
                    'Vena contracta — mm',
                    'Annular diameter (AP) — mm',
                    'Annular diameter (IC) — mm',
                    'Mean gradient (baseline) — mmHg',
                    'Post-clip gradient — mmHg',
                  ],
                ),
                infoBox(
                  'REPEAT THIS PAGE',
                  'Photocopy or redraw this table for at least 5 different cases during your fellowship — trend your own measurement accuracy over time.',
                  'warning',
                ),
              ],
            },
          ],
        },
      ],
    },
    {
      slug: 'b3-jet-location-map',
      title: 'MODULE B3 — Jet Location Map',
      description:
        'For each case encountered in fellowship, draw the MR jet location and direction on the blank en-face template, classify the jet, note the likely mechanism, and record the date and a brief case description.',
      lessons: [
        {
          title: 'Jet Location Mapping',
          activities: [
            {
              key: 'b3-jet-map',
              type: 'DRAWING',
              title: 'Jet Map — Case Entry',
              instructions:
                'Draw the MR jet location and direction on the blank en-face template, classify the jet, note the likely mechanism, and record the date and a brief case description.',
              config: { repeatable: true, suggestedCopies: 10 },
              blocks: [
                quote('Ten cases drawn by hand = ten cases never forgotten.', 'REMEMBER'),
                canvas('Draw the en-face mitral valve and mark the jet location and direction.'),
                form('Record this case.', [
                  { name: 'date', label: 'Date' },
                  { name: 'caseDescription', label: 'Brief Case Description', type: 'textarea' },
                  {
                    name: 'classification',
                    label: 'Classification (Central / Commissural / Eccentric)',
                  },
                  { name: 'mechanism', label: 'Likely Mechanism (Carpentier)' },
                ]),
              ],
            },
          ],
        },
      ],
    },
  ],
};

// ---------------------------------------------------------------------------
// SECTION C — MAP IT
// ---------------------------------------------------------------------------

const CARPENTIER_TYPES = [
  {
    key: 'c1-type-i',
    title: 'TYPE I — Normal leaflet motion',
    instructions: 'Sketch the MR mechanism (e.g., annular dilation, leaflet perforation).',
    canvasPrompt: 'Draw Type I mechanism here.',
  },
  {
    key: 'c1-type-ii',
    title: 'TYPE II — Excessive leaflet motion',
    instructions:
      'Draw prolapse, flail, or chordal rupture. Mark which scallop is involved — A1? P2? A commissure?',
    canvasPrompt: 'Draw Type II mechanism here.',
  },
  {
    key: 'c1-type-iiia',
    title: 'TYPE IIIa — Restricted motion (diastole AND systole)',
    instructions: 'Draw rheumatic thickening or calcification causing restriction.',
    canvasPrompt: 'Draw Type IIIa mechanism here.',
  },
  {
    key: 'c1-type-iiib',
    title: 'TYPE IIIb — Restricted motion (systole only)',
    instructions:
      'Draw tethered leaflets with papillary muscle displacement. Note: this is the SMR hallmark.',
    canvasPrompt: 'Draw Type IIIb mechanism here.',
  },
];

const SECTION_C: SeedSection = {
  slug: 'section-c-map-it',
  title: 'SECTION C — MAP IT',
  description:
    'Pathology Classification Sketches. Draw the mechanism, and the diagnosis follows.',
  modules: [
    {
      slug: 'c1-carpentier-classification',
      title: 'MODULE C1 — Carpentier Classification Drawing Pages',
      description: 'For each type, draw the mitral leaflet motion and annotate the mechanism.',
      lessons: [
        {
          title: 'Carpentier Types',
          activities: CARPENTIER_TYPES.map((type) => ({
            key: type.key,
            type: 'DRAWING',
            title: type.title,
            instructions: type.instructions,
            blocks: [text(type.instructions), canvas(type.canvasPrompt)],
          })),
        },
      ],
    },
    {
      slug: 'c2-dmr-vs-smr',
      title: 'MODULE C2 — DMR vs. SMR Side-by-Side Sketch',
      description: 'Full double-page spread — draw both etiologies and compare directly.',
      lessons: [
        {
          title: 'Side-by-Side Comparison',
          activities: [
            {
              key: 'c2-comparison',
              type: 'DRAWING',
              title: 'DMR vs. SMR Side-by-Side Sketch',
              instructions: 'Draw both etiologies and compare directly.',
              blocks: [
                measurementTable(
                  'Compare the two etiologies directly.',
                  ['DMR — Degenerative', 'SMR — Secondary/Functional'],
                  [
                    'Draw the prolapsing or flail segment | Draw the tethered leaflets',
                    'Mark the chordal rupture if present | Mark the papillary muscle displacement',
                    'Sketch the LV: normal size/function | Sketch the dilated cardiomyopathy LV',
                    'Colour the jet direction (usually eccentric) | Colour the central or posterior jet',
                  ],
                ),
                heading('DMR — Drawing Canvas', 3),
                canvas('Draw the DMR valve and LV here.'),
                heading('SMR — Drawing Canvas', 3),
                canvas('Draw the SMR valve and LV here.'),
              ],
            },
          ],
        },
      ],
    },
    {
      slug: 'c3-barlows-disease-anatomy-map',
      title: "MODULE C3 — Barlow's Disease Anatomy Map",
      description: 'The complex anatomy challenge.',
      lessons: [
        {
          title: 'The Complex Anatomy Challenge',
          activities: [
            {
              key: 'c3-barlows',
              type: 'DRAWING',
              title: "Barlow's Disease Anatomy Map",
              instructions: 'The complex anatomy challenge — map the following features.',
              blocks: [
                checklist([
                  'Bileaflet prolapse pattern',
                  'Excess leaflet tissue (“billowing”)',
                  'Annular dilation',
                  'Multiple jet locations',
                ]),
                canvas("Draw the Barlow's valve with all features above."),
                reflection(
                  'REFLECTION: Why does this anatomy make TEER technically demanding? What would Prof. Maisano weigh when comparing TEER vs. surgical repair here?',
                ),
              ],
            },
          ],
        },
      ],
    },
  ],
};

// ---------------------------------------------------------------------------
// SECTION D — PLAN IT
// ---------------------------------------------------------------------------

const CHALLENGING_VIGNETTES = [
  "Vignette 1: Barlow's disease with bileaflet prolapse",
  'Vignette 2: Posterior leaflet length < 7 mm',
  'Vignette 3: Heavily calcified posterior annulus',
  'Vignette 4: Prior surgical annuloplasty ring',
  'Vignette 5: Coaptation gap > 10 mm',
  'Vignette 6: Rheumatic valve with restricted motion',
  'Vignette 7: Very small MVA (borderline 4 cm²)',
  'Vignette 8: Post-MI acute SMR',
];

const SECTION_D: SeedSection = {
  slug: 'section-d-plan-it',
  title: 'SECTION D — PLAN IT',
  description:
    'Pre-Procedural Case Planning Templates. Every successful procedure begins on paper.',
  modules: [
    {
      slug: 'd1-teer-case-planning-sheet',
      title: 'MODULE D1 — The TEER Case Planning Sheet',
      description: 'Use one copy per case during your fellowship. 20 copies are provided below.',
      lessons: [
        {
          title: 'Case Planning',
          activities: [
            {
              key: 'd1-case-planning-sheet',
              type: 'CASE_SCENARIO',
              title: 'M-TEER Case Planning Sheet',
              instructions: 'Use one copy per case during your fellowship.',
              config: { repeatable: true, suggestedCopies: 20 },
              blocks: [
                form('Patient and case details.', [
                  { name: 'patientCode', label: 'Patient code' },
                  { name: 'ageSex', label: 'Age / Sex' },
                  { name: 'mrEtiology', label: 'MR etiology (DMR / SMR / Mixed)' },
                  { name: 'nyhaClass', label: 'NYHA class (I–IV)' },
                  { name: 'ef', label: 'EF (%)' },
                  { name: 'stsScore', label: 'STS score' },
                ]),
                heading('Anatomy Sketch', 3),
                canvas('Draw the valve anatomy here.'),
                form('Procedural plan.', [
                  { name: 'targetZone', label: 'Target zone' },
                  { name: 'clipStrategy', label: 'Clip strategy (Single / Double / Triple)' },
                  { name: 'clipSize', label: 'Clip size (NT / NTW / XT / XTW)' },
                  { name: 'transseptalHeight', label: 'Transseptal height (target 3.5–4 cm)' },
                  { name: 'keyChallenges', label: 'Key challenges', type: 'textarea' },
                  { name: 'heartTeamDecision', label: 'Heart team decision', type: 'textarea' },
                ]),
              ],
            },
          ],
        },
      ],
    },
    {
      slug: 'd2-teer-able-or-not-decision-tree',
      title: 'MODULE D2 — The “TEER-able or Not?” Decision Tree Sketchpad',
      description:
        'Build your own decision flowchart using the prompts below, then compare with the “Maisano Model” in M-TEER Simplified.',
      lessons: [
        {
          title: 'Build Your Own Decision Tree',
          activities: [
            {
              key: 'd2-decision-tree-sketchpad',
              type: 'DRAWING',
              title: 'The “TEER-able or Not?” Decision Tree Sketchpad',
              instructions:
                'Build your own decision flowchart using the prompts below, then compare with the “Maisano Model” in M-TEER Simplified.',
              blocks: [
                checklist(
                  [
                    'Start: “Patient referred for M-TEER”',
                    'Is anatomy suitable? — What makes it unsuitable?',
                    'Is the MR severe? — How do you confirm severity?',
                    'Is the patient symptomatic? — NYHA / 6MWD / BNP',
                    'Surgery possible? — STS score / comorbidities',
                    'Heart team consensus — document the discussion',
                  ],
                  'Prompts',
                ),
                canvas('Draw your own decision tree / flowchart here.'),
                reflection(
                  'COMPARE: After completing your flowchart, compare it with the model decision tree in Chapter 11 of M-TEER Simplified. What did you miss? What did you add that wasn’t there?',
                ),
              ],
            },
          ],
        },
      ],
    },
    {
      slug: 'd3-challenging-anatomy-sketchbook',
      title: 'MODULE D3 — Challenging Anatomy Sketchbook',
      description:
        'Eight dedicated pages for difficult cases. For each vignette: sketch what you expect on echo, sketch your clip strategy, and reflect on what Prof. Maisano would advise.',
      lessons: [
        {
          title: 'Difficult Case Vignettes',
          activities: CHALLENGING_VIGNETTES.map((vignette, index) => ({
            key: `d3-vignette-${index + 1}`,
            type: 'DRAWING',
            title: vignette,
            instructions:
              'Sketch what you expect on echo, sketch your clip strategy, and reflect on what Prof. Maisano would advise.',
            blocks: [
              canvas('Sketch what you expect to see on echo:'),
              canvas('Sketch your clip strategy:'),
              reflection('REFLECTION: What would Prof. Maisano advise here?'),
            ],
          })),
        },
      ],
    },
  ],
};

// ---------------------------------------------------------------------------
// SECTION E — DO IT
// ---------------------------------------------------------------------------

const CLIP_PANELS = [
  'Panel 1: Guiding catheter in LA — draw the curve',
  'Panel 2: Clip delivery system deployed — draw orientation',
  'Panel 3: Clip opened, perpendicular to coaptation line — draw',
  'Panel 4: Clip advanced to LV — draw depth',
  'Panel 5: Leaflets grasped — draw closed clip with tissue',
  'Panel 6: Echo assessment — draw colour Doppler result',
];

const SECTION_E: SeedSection = {
  slug: 'section-e-do-it',
  title: 'SECTION E — DO IT',
  description:
    'Procedural Step Visualisation. Rehearse the procedure with your pencil before you rehearse it with your hands.',
  modules: [
    {
      slug: 'e1-transseptal-puncture-map',
      title: 'MODULE E1 — The Transseptal Puncture Map',
      description: 'On the blank atrial septal diagram below, draw and label the key landmarks.',
      lessons: [
        {
          title: 'The Transseptal Puncture',
          activities: [
            {
              key: 'e1-transseptal-map',
              type: 'ANNOTATION',
              title: 'The Transseptal Puncture Map',
              instructions: 'On the blank atrial septal diagram below, draw and label:',
              blocks: [
                checklist([
                  'Ideal puncture site (posterior, superior — 3.5–4 cm above the MV plane)',
                  'Consequences of anterior puncture (too close to the aorta)',
                  'Consequences of inferior puncture (inadequate working height)',
                  'The “tenting” sign on the TEE bicaval view',
                  'Needle, dilator, and guide sheath trajectory',
                ]),
                checklist(
                  ['SVC', 'IVC', 'Fossa ovalis', 'Right atrium', 'Left atrium'],
                  'Reference Layout — label each structure in your drawing',
                ),
                canvas(
                  'Draw the atrial septum with right atrium and left atrium, and complete all labelling tasks.',
                ),
              ],
            },
          ],
        },
      ],
    },
    {
      slug: 'e2-clip-positioning-approach-vector',
      title: 'MODULE E2 — Clip Positioning: The Approach Vector',
      description: 'Step-by-step procedural storyboard — draw each of the six panels below.',
      lessons: [
        {
          title: 'Procedural Storyboard',
          activities: [
            {
              key: 'e2-approach-vector',
              type: 'PROCEDURE_STEPS',
              title: 'Clip Positioning: The Approach Vector',
              instructions: 'Step-by-step procedural storyboard — draw each of the six panels below.',
              blocks: CLIP_PANELS.flatMap((panel) => [
                heading(panel, 3),
                canvas(panel),
              ]),
            },
          ],
        },
      ],
    },
    {
      slug: 'e3-double-clip-strategy-map',
      title: 'MODULE E3 — The Double-Clip Strategy Map',
      description:
        'For five different MR patterns, draw the position of clip 1, the residual jet after clip 1, the position of clip 2, and the final result with estimated gradient. Reflect on whether a second clip was the right call.',
      lessons: [
        {
          title: 'Double-Clip Patterns',
          activities: [
            {
              key: 'e3-double-clip-map',
              type: 'DRAWING',
              title: 'Double-Clip Map — Pattern',
              instructions:
                'Draw the position of clip 1, the residual jet after clip 1, the position of clip 2, and the final result with estimated gradient.',
              config: { repeatable: true, suggestedCopies: 5 },
              blocks: [
                canvas('Draw clip 1 position, residual jet, clip 2 position, and final result.'),
                form('Record the result.', [
                  { name: 'residualMrGrade', label: 'Final residual MR grade' },
                  { name: 'transmitralGradient', label: 'Estimated transmitral gradient' },
                  {
                    name: 'secondClipJustified',
                    label: 'Was a second clip the right call? Why?',
                    type: 'textarea',
                  },
                ]),
              ],
            },
          ],
        },
      ],
    },
    {
      slug: 'e4-perfect-vs-acceptable-clip',
      title: 'MODULE E4 — The “Perfect Clip” vs. “Acceptable Clip” Illustration',
      description: 'Side-by-side drawing exercise.',
      lessons: [
        {
          title: 'Perfect vs. Acceptable',
          activities: [
            {
              key: 'e4-perfect-vs-acceptable',
              type: 'DRAWING',
              title: 'The “Perfect Clip” vs. “Acceptable Clip” Illustration',
              instructions: 'Side-by-side drawing exercise.',
              blocks: [
                measurementTable(
                  'Compare the two results.',
                  ['Perfect Result', 'Acceptable Result'],
                  [
                    'Draw: MR ≤ 1+, ΔP < 5 mmHg, both leaflets well grasped | Draw: MR 2+ but gradient safe, patient stable, anatomy limited',
                  ],
                ),
                heading('Perfect Result — Drawing Canvas', 3),
                canvas('Draw: MR ≤ 1+, ΔP < 5 mmHg, both leaflets well grasped'),
                heading('Acceptable Result — Drawing Canvas', 3),
                canvas('Draw: MR 2+ but gradient safe, patient stable, anatomy limited'),
                reflection(
                  "REFLECTION: At what point do you stop? Write Prof. Maisano's teaching on this.",
                ),
              ],
            },
          ],
        },
      ],
    },
  ],
};

// ---------------------------------------------------------------------------
// SECTION F — FIX IT
// ---------------------------------------------------------------------------

const COMPLICATIONS = [
  'F1.1 — Single Leaflet Attachment (SLA)',
  'F1.2 — Significant residual MR post-clip',
  'F1.3 — Mitral stenosis (elevated gradient)',
  'F1.4 — Cardiac tamponade',
  'F1.5 — Clip embolisation',
  'F1.6 — Transseptal complications',
  'F1.7 — Acute haemodynamic deterioration',
];

const SECTION_F: SeedSection = {
  slug: 'section-f-fix-it',
  title: 'SECTION F — FIX IT',
  description:
    'Complication Scenario Mapping. The operator who has rehearsed the complication is the operator who survives it calmly.',
  modules: [
    {
      slug: 'f1-complication-recognition-cards',
      title: 'MODULE F1 — Complication Recognition Cards',
      description:
        'For each complication: draw what it looks like on echo, complete the decision flowchart for what to do next, and record the relevant Maisano teaching.',
      lessons: [
        {
          title: 'Complication Recognition',
          activities: COMPLICATIONS.map((complication, index) => ({
            key: `f1-complication-${index + 1}`,
            type: 'DRAWING',
            title: complication,
            instructions:
              'Draw what it looks like on echo, complete the decision flowchart for what to do next, and record the relevant Maisano teaching.',
            blocks: [
              canvas('What does it look like on echo?'),
              canvas('What do you do next? (complete the flowchart)'),
              reflection(
                "MAISANO'S LESSON: Record the principle or teaching that applies to this scenario.",
              ),
            ],
          })),
        },
      ],
    },
    {
      slug: 'f2-my-toughest-cases-log',
      title: 'MODULE F2 — My Toughest Cases Log',
      description:
        'Reflective log — 10 illustrated pages. For each challenging case encountered, complete the entry below.',
      lessons: [
        {
          title: 'Toughest Cases',
          activities: [
            {
              key: 'f2-toughest-case-log',
              type: 'CASE_SCENARIO',
              title: 'Toughest Case Log — Entry',
              instructions: 'For each challenging case encountered, complete the entry below.',
              config: { repeatable: true, suggestedCopies: 10 },
              blocks: [
                form('Case details.', [
                  { name: 'date', label: 'Date' },
                  { name: 'caseSummary', label: 'Case summary', type: 'textarea' },
                  {
                    name: 'complicationOrChallenge',
                    label: 'The complication or challenge',
                    type: 'textarea',
                  },
                  { name: 'howManaged', label: 'How it was managed', type: 'textarea' },
                  {
                    name: 'whatIWouldDoDifferently',
                    label: 'What I would do differently',
                    type: 'textarea',
                  },
                  {
                    name: 'maisanoComment',
                    label: "Prof. Maisano's comment",
                    type: 'textarea',
                  },
                ]),
                canvas('Sketch what happened:'),
              ],
            },
          ],
        },
      ],
    },
  ],
};

// ---------------------------------------------------------------------------
// SECTION G — COLOUR IT
// ---------------------------------------------------------------------------

const COLOURING_PLATES = [
  {
    title: 'Plate 1: The mitral apparatus en face (from the atrium)',
    palette:
      'Suggested palette: red (anterior leaflet), blue (posterior leaflet), gold (annulus), green (chordae)',
  },
  {
    title: 'Plate 2: Cross-section of LV with valve and subvalvular apparatus',
    palette:
      'Suggested palette: pink (myocardium), orange (papillary muscles), green (chordae), red/blue (leaflets)',
  },
  {
    title: 'Plate 3: The Carpentier scallop map — detailed',
    palette: 'Suggested palette: six distinct shades, one per scallop (A1–A3, P1–P3)',
  },
  {
    title: 'Plate 4: Normal coaptation in systole vs. diastole',
    palette: 'Suggested palette: closed valve in deep red, open valve in light blue',
  },
  {
    title: 'Plate 5: DMR — prolapsing P2 scallop',
    palette:
      'Suggested palette: highlight the flail segment in bright red against blue posterior leaflet',
  },
  {
    title: 'Plate 6: SMR — tethered leaflets in dilated LV',
    palette:
      'Suggested palette: enlarged LV in pale pink, tethered leaflets in deep blue, displaced papillary muscles in orange',
  },
  {
    title: 'Plate 7: MitraClip in situ (grasping A2–P2)',
    palette: 'Suggested palette: metallic grey/silver clip, red and blue leaflets grasped together',
  },
  {
    title: 'Plate 8: PASCAL device — illustrating paddle + spacer design',
    palette:
      'Suggested palette: differentiate paddles, spacer, and clasps with three distinct colours',
  },
];

const ECHO_ART_VIEWS = [
  'The fish-mouth view (transgastric short-axis)',
  '3D en-face view',
  'Biplane A2–P2 view',
];

const SECTION_G: SeedSection = {
  slug: 'section-g-colour-it',
  title: 'SECTION G — COLOUR IT',
  description:
    'The M-TEER Creative Studio. This section is explicitly artistic. The science is embedded in the beauty.',
  modules: [
    {
      slug: 'g1-the-living-valve',
      title: 'MODULE G1 — “The Living Valve” — Full Anatomical Colouring Plates',
      description:
        'Eight full-page colouring plates. A suggested colour palette is provided for each, but free expression is also invited. Use the notes space beside each plate for clinical observations.',
      lessons: [
        {
          title: 'Anatomical Colouring Plates',
          activities: COLOURING_PLATES.map((plate, index) => ({
            key: `g1-plate-${index + 1}`,
            type: 'COLOURING',
            title: plate.title,
            instructions: plate.palette,
            blocks: [
              text(plate.palette),
              colouringCanvas('Draw and colour this plate.'),
              reflection('Personal notes / clinical observations:'),
            ],
          })),
        },
      ],
    },
    {
      slug: 'g2-the-echo-art-studio',
      title: 'MODULE G2 — The Echo Art Studio',
      description:
        '“Trace and Interpret” — beautified echo silhouettes. Trace, colour, and label each view.',
      lessons: [
        {
          title: 'Trace and Interpret',
          activities: [
            {
              key: 'g2-principle',
              type: 'READING',
              title: 'Principle',
              blocks: [
                quote(
                  'When you can draw what you see on echo, you understand it — not just recognise it.',
                  'PRINCIPLE',
                ),
              ],
            },
            ...ECHO_ART_VIEWS.map((view, index) => ({
              key: `g2-view-${index + 1}`,
              type: 'TRACING',
              title: view,
              instructions: 'Trace, colour, and label this view.',
              blocks: [colouringCanvas('Trace, colour, and label this view.')],
            })),
          ],
        },
      ],
    },
    {
      slug: 'g3-build-your-own-mitraclip',
      title: 'MODULE G3 — Build Your Own MitraClip',
      description:
        'Exploded engineering-style diagram for colouring and assembly understanding.',
      lessons: [
        {
          title: 'Device Anatomy',
          activities: [
            {
              key: 'g3-build-mitraclip',
              type: 'COLOURING',
              title: 'Build Your Own MitraClip',
              instructions: 'Colour and label each component.',
              blocks: [
                checklist([
                  'Clip arms (opened / closed)',
                  'Grippers',
                  'Delivery catheter tip',
                  'Lock mechanism',
                  'PASCAL: paddle, spacer, clasps',
                ]),
                colouringCanvas(
                  'Draw the exploded MitraClip / PASCAL diagram and colour each component.',
                ),
                reflection('REFLECTION: What does each component do mechanically? Write below.'),
              ],
            },
          ],
        },
      ],
    },
    {
      slug: 'g4-heart-team-ecosystem',
      title: 'MODULE G4 — The Heart Team Ecosystem — Visual Map',
      description: 'On the blank canvas below, draw your own mind map.',
      lessons: [
        {
          title: 'The Heart Team',
          activities: [
            {
              key: 'g4-heart-team-map',
              type: 'DRAWING',
              title: 'The Heart Team Ecosystem — Visual Map',
              instructions: 'On the blank canvas below, draw your own mind map of:',
              blocks: [
                checklist([
                  'All the roles in the structural heart team',
                  'Decision flow between members',
                  'How imaging informs the operator',
                  'Post-procedure pathways',
                ]),
                infoBox(
                  'ARTISTIC FREEDOM ENCOURAGED',
                  'Use diagrams, icons, colour coding, and arrows freely — this is your map, in your own visual language.',
                  'success',
                ),
                canvas('Draw your Heart Team Ecosystem mind map here.'),
              ],
            },
          ],
        },
      ],
    },
  ],
};

// ---------------------------------------------------------------------------
// SECTION H — OWN IT
//
// The source document contains MODULE H2 only. Modules H1, H3 and H4 that
// appear in the requirements brief are NOT present in inputdata.docx and are
// deliberately not invented here.
// ---------------------------------------------------------------------------

const SECTION_H: SeedSection = {
  slug: 'section-h-own-it',
  title: 'SECTION H — OWN IT',
  description:
    'Personal Reflection & Fellowship Journal. The procedure is technical. The growth is personal. Capture both.',
  modules: [
    {
      slug: 'h2-maisanos-teachings',
      title: "MODULE H2 — “Maisano's Teachings” — My Personal Collection",
      description:
        '50 entries for capturing teaching moments throughout your fellowship. Each entry includes the date, context, the teaching itself, what it means to you, and a small sketch space.',
      lessons: [
        {
          title: 'Teaching Moments',
          activities: [
            {
              key: 'h2-teaching-entry',
              type: 'REFLECTION',
              title: 'Teaching Entry',
              instructions:
                'Capture a teaching moment: the date, context, the teaching itself, what it means to you, and a sketch.',
              config: { repeatable: true, suggestedCopies: 50 },
              blocks: [
                form('Entry details.', [
                  { name: 'date', label: 'Date' },
                  { name: 'caseContext', label: 'Case / Context', type: 'textarea' },
                ]),
                reflection('Prof. Maisano said:'),
                reflection('What it means to me:'),
                canvas('Sketch:'),
              ],
            },
          ],
        },
      ],
    },
  ],
};

export const SECTIONS: SeedSection[] = [
  SECTION_A,
  SECTION_B,
  SECTION_C,
  SECTION_D,
  SECTION_E,
  SECTION_F,
  SECTION_G,
  SECTION_H,
];

// ---------------------------------------------------------------------------
// Quick Reference — the detachable Pocket Reference Card
// ---------------------------------------------------------------------------

export const QUICK_REFERENCE: SeedQuickReference[] = [
  {
    slug: 'anatomy-quick-map-scallop-nomenclature',
    category: 'Anatomy Quick Map',
    title: 'Scallop nomenclature grid',
    summary: 'Pocket Reference Card — Side A',
    blocks: [
      measurementTable(
        'Scallop nomenclature.',
        ['Scallop', 'Location', 'Notes'],
        [
          'A1 / A2 / A3 — Anterior leaflet, lateral to medial',
          'P1 / P2 / P3 — Posterior leaflet, lateral to medial',
          'AC — Anterolateral commissure',
          'PC — Posteromedial commissure',
        ],
      ),
    ],
  },
  {
    slug: 'anatomy-quick-map-carpentier-classification',
    category: 'Anatomy Quick Map',
    title: 'Carpentier classification summary',
    summary: 'Pocket Reference Card — Side A',
    blocks: [
      measurementTable(
        'Carpentier Classification Summary.',
        ['Type', 'Leaflet Motion', 'Typical Cause'],
        [
          'I — Normal — Annular dilation, perforation',
          'II — Excessive — Prolapse, flail, chordal rupture',
          'IIIa — Restricted (diastole + systole) — Rheumatic disease, calcification',
          'IIIb — Restricted (systole only) — Tethering — SMR',
        ],
      ),
    ],
  },
  {
    slug: 'anatomy-quick-map-normal-valve-measurements',
    category: 'Anatomy Quick Map',
    title: 'Normal valve measurements',
    summary: 'Pocket Reference Card — Side A',
    blocks: [
      measurementTable(
        'Normal Valve Measurements.',
        ['Parameter', 'Normal Range'],
        [
          'Mitral valve area — 4–6 cm²',
          'Annular diameter (AP) — ~2.5–3.5 cm',
          'Coaptation length — ≥7–8 mm',
          'Transmitral mean gradient — < 5 mmHg',
        ],
      ),
    ],
  },
  {
    slug: 'procedure-checklist-pre-procedure-echo',
    category: 'Procedure Checklist',
    title: 'Pre-Procedure Echo Checklist',
    summary: 'Pocket Reference Card — Side B',
    blocks: [
      checklist([
        'Confirm MR severity and mechanism (Carpentier type)',
        'Measure coaptation gap, leaflet lengths, MVA, EROA, vena contracta',
        'Assess annular dimensions (AP and IC)',
        'Identify jet location and direction',
        'Screen for anatomical exclusions (severe calcification, very small MVA)',
      ]),
    ],
  },
  {
    slug: 'procedure-checklist-transseptal-height-target',
    category: 'Procedure Checklist',
    title: 'Transseptal Height Target',
    summary: 'Pocket Reference Card — Side B',
    blocks: [
      text(
        'Aim for puncture 3.5–4 cm above the mitral valve plane, posterior and superior on the fossa ovalis.',
      ),
    ],
  },
  {
    slug: 'procedure-checklist-intraprocedural-echo-views',
    category: 'Procedure Checklist',
    title: 'Intraprocedural Echo Views (in sequence)',
    summary: 'Pocket Reference Card — Side B',
    blocks: [
      checklist([
        'Bicaval view — confirm transseptal puncture site',
        '4-chamber and commissural views — guide catheter navigation',
        '3D en-face view — clip orientation and alignment',
        'Biplane A2–P2 — grasping confirmation',
        'Colour Doppler — residual MR assessment',
        'Spectral Doppler — transmitral gradient',
      ]),
    ],
  },
  {
    slug: 'procedure-checklist-stop-criteria',
    category: 'Procedure Checklist',
    title: '“Stop Criteria” — When Not to Add a Clip',
    summary: 'Pocket Reference Card — Side B',
    blocks: [
      checklist([
        'Residual MR is ≤1+ and gradient is acceptable',
        'Transmitral mean gradient is approaching or exceeding 5 mmHg',
        'Further grasping risks single leaflet attachment or leaflet injury',
        'Patient is haemodynamically stable with an “acceptable” result per heart team discussion',
      ]),
    ],
  },
  {
    slug: 'procedure-checklist-post-procedure-assessment',
    category: 'Procedure Checklist',
    title: 'Post-Procedure Assessment Steps',
    summary: 'Pocket Reference Card — Side B',
    blocks: [
      checklist([
        'Final TEE assessment of MR grade and gradient',
        'Confirm clip stability and leaflet attachment',
        'Haemodynamic monitoring in recovery',
        'Plan anticoagulation / antiplatelet strategy',
        'Schedule echo follow-up (discharge, 30 days, 1 year)',
      ]),
    ],
  },
];
