// Seed data for the ConsentIQ builder prototype.
// IMPORTANT: All content here is DRAFT and for UI demonstration only.
// It is not a legal consent document and must be reviewed by a clinician
// before any clinical use.

export type ProcedureOptionChoice = {
  value: string;
  label: string;
};

export type ProcedureOption = {
  id: string;
  label: string;
  kind: "select" | "radio" | "text";
  help?: string;
  choices?: ProcedureOptionChoice[];
  defaultValue?: string;
};

export type ConsentPoint = {
  title: string;
  detail: string;
  severity?: "common" | "rare" | "serious";
};

export type Procedure = {
  slug: string;
  name: string;
  region: string;
  approxDurationMin: number;
  anaesthesia: string[];
  summary: string;
  involves: string[];
  options: ProcedureOption[];
  risks: ConsentPoint[];
  benefits: string[];
  alternatives: string[];
  recovery: string[];
  warnings: string[];
};

const lateralityOption: ProcedureOption = {
  id: "laterality",
  label: "Side",
  kind: "radio",
  help: "Operative side must be confirmed and marked before induction.",
  choices: [
    { value: "left", label: "Left" },
    { value: "right", label: "Right" },
  ],
};

const anaesthesiaOption = (choices: string[]): ProcedureOption => ({
  id: "anaesthesia",
  label: "Anaesthesia",
  kind: "select",
  help: "Final decision sits with the anaesthetic team on the day.",
  choices: choices.map((c) => ({ value: c.toLowerCase(), label: c })),
  defaultValue: choices[0]?.toLowerCase(),
});

const standardWarnings: string[] = [
  "Fever above 38°C or worsening wound redness, swelling, or discharge.",
  "Calf pain or swelling, chest pain, or shortness of breath.",
  "New numbness, weakness, or loss of movement in the operated limb.",
  "Pain that is severe and not controlled by prescribed analgesia.",
];

export const procedures: Procedure[] = [
  {
    slug: "total-knee-replacement",
    name: "Total Knee Replacement",
    region: "Knee",
    approxDurationMin: 90,
    anaesthesia: ["Spinal", "General"],
    summary:
      "Replacement of the worn articular surfaces of the knee with metal and polyethylene implants to relieve pain and restore function.",
    involves: [
      "Anaesthesia and surgical site preparation.",
      "A vertical incision over the front of the knee.",
      "Removal of damaged cartilage and bone from the femur, tibia, and patella.",
      "Cemented or uncemented fixation of the prosthetic components.",
      "Wound closure and dressing.",
    ],
    options: [
      lateralityOption,
      anaesthesiaOption(["Spinal", "General"]),
      {
        id: "implant",
        label: "Implant type",
        kind: "select",
        choices: [
          { value: "cr", label: "Cruciate-retaining (CR)" },
          { value: "ps", label: "Posterior-stabilised (PS)" },
          { value: "uni", label: "Unicompartmental" },
        ],
        defaultValue: "cr",
      },
      {
        id: "fixation",
        label: "Fixation",
        kind: "radio",
        choices: [
          { value: "cemented", label: "Cemented" },
          { value: "uncemented", label: "Uncemented" },
        ],
        defaultValue: "cemented",
      },
    ],
    risks: [
      { title: "Infection", detail: "Superficial or deep prosthetic joint infection, which may require further surgery.", severity: "serious" },
      { title: "DVT / PE", detail: "Blood clots in the leg or lungs. Chemical and mechanical prophylaxis is used.", severity: "serious" },
      { title: "Stiffness", detail: "Reduced range of movement; may require manipulation under anaesthesia." },
      { title: "Implant loosening", detail: "May occur over years and require revision surgery.", severity: "serious" },
      { title: "Nerve or vessel injury", detail: "Uncommon injury to the popliteal structures or peroneal nerve.", severity: "rare" },
      { title: "Persistent pain", detail: "Around 1 in 5 patients report some residual discomfort." },
      { title: "Fracture", detail: "Peri-prosthetic fracture during or after the procedure.", severity: "rare" },
    ],
    benefits: [
      "Relief of arthritic knee pain.",
      "Improved walking distance and function.",
      "Correction of deformity and restoration of alignment.",
    ],
    alternatives: [
      "Analgesia, activity modification, and weight loss.",
      "Physiotherapy and bracing.",
      "Intra-articular injections (steroid, hyaluronic acid).",
      "Osteotomy in selected younger patients.",
    ],
    recovery: [
      "Mobilise with physiotherapy on day 0–1.",
      "Most patients discharged within 1–3 days.",
      "Walking aids for 2–6 weeks.",
      "Return to driving around 6 weeks.",
      "Ongoing rehabilitation for 3–12 months.",
    ],
    warnings: standardWarnings,
  },
  {
    slug: "total-hip-replacement",
    name: "Total Hip Replacement",
    region: "Hip",
    approxDurationMin: 90,
    anaesthesia: ["Spinal", "General"],
    summary:
      "Replacement of the femoral head and acetabulum with prosthetic components to relieve pain from hip arthritis.",
    involves: [
      "Positioning and surgical preparation.",
      "Incision over the hip through the chosen approach.",
      "Removal of the femoral head and preparation of the acetabulum.",
      "Insertion of the acetabular and femoral components.",
      "Reduction, stability check, and closure.",
    ],
    options: [
      lateralityOption,
      anaesthesiaOption(["Spinal", "General"]),
      {
        id: "approach",
        label: "Surgical approach",
        kind: "select",
        choices: [
          { value: "posterior", label: "Posterior" },
          { value: "anterior", label: "Direct anterior" },
          { value: "lateral", label: "Lateral" },
        ],
        defaultValue: "posterior",
      },
      {
        id: "bearing",
        label: "Bearing surface",
        kind: "select",
        choices: [
          { value: "ceramic-poly", label: "Ceramic on polyethylene" },
          { value: "metal-poly", label: "Metal on polyethylene" },
          { value: "ceramic-ceramic", label: "Ceramic on ceramic" },
        ],
        defaultValue: "ceramic-poly",
      },
    ],
    risks: [
      { title: "Infection", detail: "Prosthetic joint infection may require further surgery and antibiotics.", severity: "serious" },
      { title: "Dislocation", detail: "Most common in the first 6 weeks; reduced by appropriate precautions." },
      { title: "DVT / PE", detail: "Blood clots in leg or lungs.", severity: "serious" },
      { title: "Leg length discrepancy", detail: "Small differences are common and usually well tolerated." },
      { title: "Sciatic or femoral nerve injury", detail: "Uncommon but may cause weakness or numbness.", severity: "rare" },
      { title: "Implant loosening", detail: "Long-term complication requiring revision." },
      { title: "Peri-prosthetic fracture", detail: "Of the femur during or after surgery.", severity: "rare" },
    ],
    benefits: [
      "Marked reduction in hip pain.",
      "Improved mobility and quality of life.",
      "Predictable long-term outcomes in most patients.",
    ],
    alternatives: [
      "Analgesia and activity modification.",
      "Physiotherapy and weight loss.",
      "Intra-articular injection.",
      "Hip resurfacing in selected patients.",
    ],
    recovery: [
      "Mobilise day 0–1 with physiotherapy.",
      "Discharge usually within 1–3 days.",
      "Walking aids 2–6 weeks.",
      "Driving around 6 weeks.",
      "Return to low-impact activity at 3 months.",
    ],
    warnings: standardWarnings,
  },
  {
    slug: "acl-reconstruction",
    name: "ACL Reconstruction",
    region: "Knee",
    approxDurationMin: 75,
    anaesthesia: ["General", "Spinal"],
    summary:
      "Arthroscopic reconstruction of the anterior cruciate ligament using an autograft or allograft to restore knee stability.",
    involves: [
      "Examination under anaesthesia.",
      "Arthroscopic assessment of the joint.",
      "Graft harvest (hamstring, patellar tendon, or quadriceps).",
      "Tunnel drilling in the tibia and femur.",
      "Graft passage and fixation.",
    ],
    options: [
      lateralityOption,
      anaesthesiaOption(["General", "Spinal"]),
      {
        id: "graft",
        label: "Graft choice",
        kind: "select",
        choices: [
          { value: "hamstring", label: "Hamstring autograft" },
          { value: "bptb", label: "Bone-patellar tendon-bone (BPTB)" },
          { value: "quads", label: "Quadriceps tendon" },
          { value: "allograft", label: "Allograft" },
        ],
        defaultValue: "hamstring",
      },
    ],
    risks: [
      { title: "Graft failure", detail: "Re-rupture or failure of fixation, particularly with early return to cutting sports.", severity: "serious" },
      { title: "Infection", detail: "Superficial or deep joint infection.", severity: "serious" },
      { title: "Stiffness", detail: "Loss of full extension or flexion." },
      { title: "Donor site pain", detail: "Around the graft harvest site." },
      { title: "DVT", detail: "Blood clots in the leg.", severity: "serious" },
      { title: "Numbness", detail: "Over the anterior knee from infrapatellar branch injury.", severity: "rare" },
    ],
    benefits: [
      "Restored knee stability.",
      "Reduced risk of recurrent giving-way episodes.",
      "Allows return to pivoting sports for most patients.",
    ],
    alternatives: [
      "Structured physiotherapy and activity modification.",
      "Bracing for functional stability.",
      "Acceptance of instability and lifestyle change.",
    ],
    recovery: [
      "Partial weight bearing with crutches for 1–2 weeks.",
      "Physiotherapy starting day 1.",
      "Straight-line running around 3 months.",
      "Return to pivoting sport at 9–12 months.",
    ],
    warnings: standardWarnings,
  },
  {
    slug: "arthroscopic-meniscectomy",
    name: "Arthroscopic Meniscectomy",
    region: "Knee",
    approxDurationMin: 30,
    anaesthesia: ["General", "Spinal"],
    summary:
      "Keyhole removal of the torn portion of a meniscus to relieve mechanical symptoms.",
    involves: [
      "Two or three small portals around the knee.",
      "Diagnostic arthroscopy.",
      "Trimming of the unstable meniscal fragment.",
      "Wound closure with sutures or strips.",
    ],
    options: [
      lateralityOption,
      anaesthesiaOption(["General", "Spinal"]),
      {
        id: "meniscus",
        label: "Meniscus involved",
        kind: "radio",
        choices: [
          { value: "medial", label: "Medial" },
          { value: "lateral", label: "Lateral" },
          { value: "both", label: "Both" },
        ],
        defaultValue: "medial",
      },
    ],
    risks: [
      { title: "Persistent pain", detail: "Symptoms may not fully resolve if arthritis is present." },
      { title: "Infection", detail: "Uncommon superficial or deep infection.", severity: "rare" },
      { title: "DVT", detail: "Blood clots in the leg.", severity: "rare" },
      { title: "Accelerated arthritis", detail: "Long-term increased risk of osteoarthritis in the affected compartment." },
      { title: "Neurovascular injury", detail: "Injury to saphenous or peroneal nerve branches.", severity: "rare" },
    ],
    benefits: [
      "Relief of catching, locking, or mechanical pain.",
      "Early return to daily activity.",
    ],
    alternatives: [
      "Physiotherapy.",
      "Activity modification and analgesia.",
      "Meniscal repair where the tear pattern allows.",
    ],
    recovery: [
      "Weight bearing as tolerated from day 0.",
      "Desk work within 1 week.",
      "Return to sport at 4–6 weeks.",
    ],
    warnings: standardWarnings,
  },
  {
    slug: "rotator-cuff-repair",
    name: "Rotator Cuff Repair",
    region: "Shoulder",
    approxDurationMin: 90,
    anaesthesia: ["General with interscalene block"],
    summary:
      "Arthroscopic repair of a torn rotator cuff tendon to its footprint on the humerus.",
    involves: [
      "Interscalene regional block and general anaesthesia.",
      "Diagnostic arthroscopy of the shoulder.",
      "Debridement of the tear edges.",
      "Anchor placement and tendon-to-bone repair.",
      "Acromioplasty if indicated.",
    ],
    options: [
      lateralityOption,
      {
        id: "tearSize",
        label: "Tear size",
        kind: "select",
        choices: [
          { value: "small", label: "Small (<1cm)" },
          { value: "medium", label: "Medium (1–3cm)" },
          { value: "large", label: "Large (3–5cm)" },
          { value: "massive", label: "Massive (>5cm)" },
        ],
        defaultValue: "medium",
      },
      {
        id: "technique",
        label: "Repair technique",
        kind: "radio",
        choices: [
          { value: "single-row", label: "Single row" },
          { value: "double-row", label: "Double row" },
        ],
        defaultValue: "double-row",
      },
    ],
    risks: [
      { title: "Re-tear", detail: "Particularly with larger tears and older patients.", severity: "serious" },
      { title: "Stiffness", detail: "Post-operative shoulder stiffness is common." },
      { title: "Infection", detail: "Uncommon but may require washout.", severity: "rare" },
      { title: "Nerve injury", detail: "Axillary or suprascapular nerve injury.", severity: "rare" },
      { title: "Persistent pain", detail: "Some patients continue to have pain despite a healed repair." },
    ],
    benefits: [
      "Reduction in shoulder pain.",
      "Restored strength and active elevation.",
      "Improved sleep and daily function.",
    ],
    alternatives: [
      "Physiotherapy and analgesia.",
      "Subacromial steroid injection.",
      "Debridement only for irreparable tears.",
    ],
    recovery: [
      "Sling for 4–6 weeks.",
      "Passive range of motion from week 1.",
      "Active movement from week 6.",
      "Return to strenuous work at 4–6 months.",
    ],
    warnings: standardWarnings,
  },
  {
    slug: "shoulder-arthroscopy",
    name: "Shoulder Arthroscopy",
    region: "Shoulder",
    approxDurationMin: 45,
    anaesthesia: ["General with interscalene block"],
    summary:
      "Keyhole assessment and treatment of conditions within and around the shoulder joint.",
    involves: [
      "Beach-chair or lateral decubitus positioning.",
      "Posterior, anterior, and lateral portals.",
      "Diagnostic arthroscopy of glenohumeral and subacromial spaces.",
      "Targeted treatment (debridement, decompression, release).",
    ],
    options: [
      lateralityOption,
      {
        id: "pathology",
        label: "Primary pathology",
        kind: "select",
        choices: [
          { value: "impingement", label: "Subacromial impingement" },
          { value: "labral", label: "Labral pathology" },
          { value: "acj", label: "Acromioclavicular joint" },
          { value: "frozen", label: "Frozen shoulder release" },
        ],
        defaultValue: "impingement",
      },
    ],
    risks: [
      { title: "Infection", detail: "Joint or wound infection.", severity: "rare" },
      { title: "Stiffness", detail: "Post-operative stiffness requiring further physiotherapy." },
      { title: "Nerve injury", detail: "Traction or positioning-related neuropraxia.", severity: "rare" },
      { title: "Incomplete relief", detail: "Symptoms may not fully resolve." },
    ],
    benefits: [
      "Diagnostic clarity.",
      "Targeted treatment of identified pathology.",
      "Day-case recovery for most patients.",
    ],
    alternatives: [
      "Physiotherapy.",
      "Subacromial injection.",
      "Open surgery for selected pathology.",
    ],
    recovery: [
      "Sling for comfort for 1–2 weeks.",
      "Early range of motion exercises.",
      "Return to desk work in 1–2 weeks.",
    ],
    warnings: standardWarnings,
  },
  {
    slug: "carpal-tunnel-release",
    name: "Carpal Tunnel Release",
    region: "Wrist & Hand",
    approxDurationMin: 20,
    anaesthesia: ["Local", "Regional"],
    summary:
      "Division of the transverse carpal ligament to decompress the median nerve.",
    involves: [
      "Local anaesthetic infiltration.",
      "Short incision in the palm.",
      "Identification and division of the transverse carpal ligament.",
      "Wound closure.",
    ],
    options: [
      lateralityOption,
      anaesthesiaOption(["Local", "Regional"]),
      {
        id: "technique",
        label: "Technique",
        kind: "radio",
        choices: [
          { value: "open", label: "Open" },
          { value: "endoscopic", label: "Endoscopic" },
        ],
        defaultValue: "open",
      },
    ],
    risks: [
      { title: "Incomplete relief", detail: "Persistent numbness, especially with chronic compression." },
      { title: "Scar tenderness", detail: "Pillar pain around the scar for weeks to months." },
      { title: "Nerve or vessel injury", detail: "Injury to median nerve branches or superficial palmar arch.", severity: "rare" },
      { title: "Infection", detail: "Uncommon superficial infection.", severity: "rare" },
      { title: "Complex regional pain syndrome", detail: "Rare chronic pain condition.", severity: "rare" },
    ],
    benefits: [
      "Relief of night-time numbness.",
      "Improved hand function.",
      "Day-case procedure under local anaesthetic.",
    ],
    alternatives: [
      "Night splinting.",
      "Steroid injection into the carpal tunnel.",
      "Activity modification.",
    ],
    recovery: [
      "Bulky dressing for 48 hours.",
      "Light activity from day 1.",
      "Sutures removed at 10–14 days.",
      "Return to manual work at 2–4 weeks.",
    ],
    warnings: standardWarnings,
  },
  {
    slug: "lumbar-discectomy",
    name: "Lumbar Discectomy",
    region: "Spine",
    approxDurationMin: 75,
    anaesthesia: ["General"],
    summary:
      "Removal of a prolapsed lumbar disc fragment that is compressing a nerve root.",
    involves: [
      "Prone positioning under general anaesthesia.",
      "Small midline incision at the affected level.",
      "Partial laminotomy and flavectomy.",
      "Retraction of the nerve root and removal of the disc fragment.",
      "Wound closure.",
    ],
    options: [
      {
        id: "level",
        label: "Disc level",
        kind: "select",
        choices: [
          { value: "l3-4", label: "L3/4" },
          { value: "l4-5", label: "L4/5" },
          { value: "l5-s1", label: "L5/S1" },
        ],
        defaultValue: "l4-5",
      },
      {
        id: "side",
        label: "Side",
        kind: "radio",
        choices: [
          { value: "left", label: "Left" },
          { value: "right", label: "Right" },
          { value: "central", label: "Central" },
        ],
        defaultValue: "left",
      },
    ],
    risks: [
      { title: "Recurrent disc prolapse", detail: "Up to 1 in 10 patients may re-herniate at the same level.", severity: "serious" },
      { title: "Dural tear", detail: "Leakage of cerebrospinal fluid, usually repaired at the time." },
      { title: "Nerve root injury", detail: "Weakness, numbness, or worsening radicular pain.", severity: "serious" },
      { title: "Infection", detail: "Wound or deeper disc-space infection.", severity: "serious" },
      { title: "Bleeding", detail: "Epidural haematoma is rare but urgent.", severity: "rare" },
      { title: "Ongoing back pain", detail: "Discectomy addresses leg pain more reliably than back pain." },
    ],
    benefits: [
      "Relief of radicular leg pain.",
      "Improved walking and sitting tolerance.",
      "Return to normal activity for most patients.",
    ],
    alternatives: [
      "Physiotherapy and analgesia.",
      "Nerve root block.",
      "Continued conservative management.",
    ],
    recovery: [
      "Mobilise same day.",
      "Overnight stay usual.",
      "Return to desk work 2–4 weeks.",
      "Avoid heavy lifting for 6 weeks.",
    ],
    warnings: standardWarnings,
  },
  {
    slug: "acdf",
    name: "Anterior Cervical Discectomy and Fusion (ACDF)",
    region: "Spine",
    approxDurationMin: 120,
    anaesthesia: ["General"],
    summary:
      "Removal of a cervical disc through an anterior approach with fusion of the adjacent vertebrae.",
    involves: [
      "Supine positioning and general anaesthesia.",
      "Transverse anterior neck incision.",
      "Retraction of the carotid sheath and trachea/oesophagus.",
      "Discectomy and decompression of the canal and foramina.",
      "Placement of a cage and/or plate for fusion.",
    ],
    options: [
      {
        id: "levels",
        label: "Levels treated",
        kind: "select",
        choices: [
          { value: "1", label: "Single level" },
          { value: "2", label: "Two levels" },
          { value: "3", label: "Three levels" },
        ],
        defaultValue: "1",
      },
      {
        id: "instrumentation",
        label: "Instrumentation",
        kind: "radio",
        choices: [
          { value: "cage-only", label: "Cage only" },
          { value: "cage-plate", label: "Cage and plate" },
        ],
        defaultValue: "cage-plate",
      },
    ],
    risks: [
      { title: "Hoarseness", detail: "Recurrent laryngeal nerve irritation, usually temporary." },
      { title: "Dysphagia", detail: "Difficulty swallowing in the first weeks." },
      { title: "Non-union", detail: "Failure of fusion, which may require revision." },
      { title: "Adjacent segment disease", detail: "Accelerated degeneration of adjacent levels over years." },
      { title: "Vascular injury", detail: "Injury to the carotid or vertebral artery.", severity: "rare" },
      { title: "Spinal cord or nerve injury", detail: "Can cause weakness, numbness, or paralysis.", severity: "serious" },
      { title: "Oesophageal injury", detail: "Very rare but potentially serious.", severity: "rare" },
    ],
    benefits: [
      "Decompression of cervical nerve roots or cord.",
      "Relief of arm pain and neurological symptoms.",
      "Stabilisation of the treated level.",
    ],
    alternatives: [
      "Physiotherapy and analgesia.",
      "Cervical epidural or root block.",
      "Posterior decompression in selected cases.",
      "Disc replacement in selected cases.",
    ],
    recovery: [
      "Overnight or 1–2 day stay.",
      "Soft collar for comfort if used.",
      "Return to desk work 2–4 weeks.",
      "Fusion consolidates over 3–6 months.",
    ],
    warnings: standardWarnings,
  },
  {
    slug: "ankle-fracture-orif",
    name: "Ankle Fracture ORIF",
    region: "Foot & Ankle",
    approxDurationMin: 75,
    anaesthesia: ["General", "Spinal"],
    summary:
      "Open reduction and internal fixation of a displaced ankle fracture using plates and screws.",
    involves: [
      "Positioning and tourniquet application.",
      "Incisions over the involved malleoli.",
      "Reduction of the fracture.",
      "Fixation with plates, screws, and/or wires.",
      "Intra-operative imaging and wound closure.",
    ],
    options: [
      lateralityOption,
      anaesthesiaOption(["General", "Spinal"]),
      {
        id: "pattern",
        label: "Fracture pattern",
        kind: "select",
        choices: [
          { value: "lateral", label: "Isolated lateral malleolus" },
          { value: "bimalleolar", label: "Bimalleolar" },
          { value: "trimalleolar", label: "Trimalleolar" },
          { value: "syndesmotic", label: "With syndesmotic injury" },
        ],
        defaultValue: "bimalleolar",
      },
    ],
    risks: [
      { title: "Wound problems", detail: "Delayed healing, dehiscence, or infection — higher in smokers and diabetics.", severity: "serious" },
      { title: "Infection", detail: "Superficial or deep infection that may need further surgery.", severity: "serious" },
      { title: "Metalwork irritation", detail: "Prominent metalwork may later need removal." },
      { title: "Non-union or malunion", detail: "Failure to heal in anatomical position." },
      { title: "Post-traumatic arthritis", detail: "Long-term risk after intra-articular ankle fracture." },
      { title: "DVT / PE", detail: "Blood clots in the leg or lungs.", severity: "serious" },
      { title: "Nerve injury", detail: "Superficial peroneal or sural nerve injury.", severity: "rare" },
    ],
    benefits: [
      "Restoration of anatomical alignment.",
      "Earlier mobilisation than non-operative treatment.",
      "Reduced risk of malunion.",
    ],
    alternatives: [
      "Non-operative treatment in a cast or boot for stable fractures.",
      "Closed reduction and casting in selected cases.",
    ],
    recovery: [
      "Backslab then boot for 6 weeks.",
      "Non-weight bearing for 2–6 weeks depending on fixation.",
      "Physiotherapy after cast removal.",
      "Full return to sport by 4–6 months.",
    ],
    warnings: standardWarnings,
  },
  {
    slug: "hip-hemiarthroplasty",
    name: "Hip Hemiarthroplasty",
    region: "Hip",
    approxDurationMin: 60,
    anaesthesia: ["Spinal", "General"],
    summary:
      "Replacement of the femoral head with a prosthesis, most commonly for displaced intracapsular neck of femur fractures.",
    involves: [
      "Positioning and surgical preparation.",
      "Lateral or posterior approach to the hip.",
      "Removal of the fractured femoral head.",
      "Preparation and insertion of a cemented or uncemented stem with head.",
      "Reduction and wound closure.",
    ],
    options: [
      lateralityOption,
      anaesthesiaOption(["Spinal", "General"]),
      {
        id: "stem",
        label: "Stem fixation",
        kind: "radio",
        choices: [
          { value: "cemented", label: "Cemented" },
          { value: "uncemented", label: "Uncemented" },
        ],
        defaultValue: "cemented",
      },
      {
        id: "headType",
        label: "Head type",
        kind: "radio",
        choices: [
          { value: "unipolar", label: "Unipolar" },
          { value: "bipolar", label: "Bipolar" },
        ],
        defaultValue: "unipolar",
      },
    ],
    risks: [
      { title: "Medical complications", detail: "Chest infection, urinary infection, cardiac events — higher in frail patients.", severity: "serious" },
      { title: "Dislocation", detail: "Of the prosthesis, particularly in the first weeks." },
      { title: "Infection", detail: "Wound or deep prosthetic infection.", severity: "serious" },
      { title: "DVT / PE", detail: "Blood clots in the leg or lungs.", severity: "serious" },
      { title: "Cement reaction", detail: "Transient drop in blood pressure during cementation.", severity: "rare" },
      { title: "Peri-prosthetic fracture", detail: "During or after surgery.", severity: "rare" },
      { title: "Mortality", detail: "30-day mortality is significantly elevated in elderly hip-fracture patients.", severity: "serious" },
    ],
    benefits: [
      "Rapid mobilisation.",
      "Relief of fracture pain.",
      "Restoration of function where possible.",
    ],
    alternatives: [
      "Non-operative management (reserved for patients unfit for surgery).",
      "Total hip replacement in fitter, more active patients.",
      "Internal fixation for undisplaced fractures.",
    ],
    recovery: [
      "Mobilise day 1 with physiotherapy.",
      "Discharge when medically and socially safe.",
      "Ongoing rehabilitation in community.",
    ],
    warnings: standardWarnings,
  },
  {
    slug: "achilles-tendon-repair",
    name: "Achilles Tendon Repair",
    region: "Foot & Ankle",
    approxDurationMin: 45,
    anaesthesia: ["General", "Regional"],
    summary:
      "Operative repair of a ruptured Achilles tendon using open or percutaneous techniques.",
    involves: [
      "Prone positioning.",
      "Incision over the Achilles tendon (open) or small portal incisions (percutaneous).",
      "Identification and apposition of the tendon ends.",
      "Suture repair.",
      "Wound closure and plaster in equinus.",
    ],
    options: [
      lateralityOption,
      anaesthesiaOption(["General", "Regional"]),
      {
        id: "technique",
        label: "Technique",
        kind: "radio",
        choices: [
          { value: "open", label: "Open repair" },
          { value: "percutaneous", label: "Percutaneous repair" },
        ],
        defaultValue: "percutaneous",
      },
    ],
    risks: [
      { title: "Re-rupture", detail: "Risk persists for several months after repair." },
      { title: "Wound complications", detail: "Delayed healing, infection, or skin necrosis.", severity: "serious" },
      { title: "Sural nerve injury", detail: "Numbness over the lateral foot.", severity: "rare" },
      { title: "DVT", detail: "Blood clots during immobilisation.", severity: "serious" },
      { title: "Tendon lengthening", detail: "Loss of push-off power." },
    ],
    benefits: [
      "Reduced re-rupture risk compared with non-operative treatment (in selected patients).",
      "Earlier return to high-level activity.",
    ],
    alternatives: [
      "Functional non-operative treatment in a boot.",
      "Cast immobilisation.",
    ],
    recovery: [
      "Plaster or boot for 6–8 weeks.",
      "Gradual progression from equinus to neutral.",
      "Physiotherapy on boot removal.",
      "Return to running at 4–6 months.",
    ],
    warnings: standardWarnings,
  },
  {
    slug: "bunion-correction",
    name: "Bunion Correction (Hallux Valgus)",
    region: "Foot & Ankle",
    approxDurationMin: 60,
    anaesthesia: ["General", "Regional"],
    summary:
      "Osteotomy of the first metatarsal with soft-tissue balancing to correct hallux valgus deformity.",
    involves: [
      "Regional block and tourniquet.",
      "Incision over the medial forefoot.",
      "Osteotomy of the first metatarsal (e.g. scarf or chevron).",
      "Fixation with screws.",
      "Soft-tissue balancing and closure.",
    ],
    options: [
      lateralityOption,
      anaesthesiaOption(["General", "Regional"]),
      {
        id: "osteotomy",
        label: "Osteotomy",
        kind: "select",
        choices: [
          { value: "scarf", label: "Scarf" },
          { value: "chevron", label: "Chevron" },
          { value: "lapidus", label: "Lapidus fusion" },
          { value: "akin", label: "Scarf + Akin" },
        ],
        defaultValue: "scarf",
      },
    ],
    risks: [
      { title: "Recurrence", detail: "Deformity may recur, particularly with severe pre-operative angles." },
      { title: "Stiffness", detail: "Of the first MTP joint." },
      { title: "Under- or over-correction", detail: "May require revision." },
      { title: "Infection", detail: "Usually superficial.", severity: "rare" },
      { title: "Delayed union or non-union", detail: "Of the osteotomy.", severity: "rare" },
      { title: "Metalwork irritation", detail: "May require screw removal." },
      { title: "Ongoing pain", detail: "Transfer metatarsalgia or nerve irritation." },
    ],
    benefits: [
      "Correction of deformity.",
      "Relief of pain and shoe-wear difficulty.",
      "Improved forefoot function.",
    ],
    alternatives: [
      "Wide footwear and padding.",
      "Orthoses.",
      "Analgesia.",
    ],
    recovery: [
      "Post-operative heel-weight shoe for 6 weeks.",
      "Elevation to reduce swelling.",
      "Normal footwear at 6–8 weeks.",
      "Swelling may persist for several months.",
    ],
    warnings: standardWarnings,
  },
  {
    slug: "distal-radius-orif",
    name: "Distal Radius ORIF",
    region: "Wrist & Hand",
    approxDurationMin: 60,
    anaesthesia: ["General", "Regional"],
    summary:
      "Open reduction and internal fixation of a distal radius fracture using a volar locking plate.",
    involves: [
      "Regional block and tourniquet.",
      "Volar approach to the distal radius.",
      "Reduction of the fracture.",
      "Fixation with a locking plate and screws.",
      "Intra-operative imaging and wound closure.",
    ],
    options: [
      lateralityOption,
      anaesthesiaOption(["General", "Regional"]),
      {
        id: "approach",
        label: "Approach",
        kind: "radio",
        choices: [
          { value: "volar", label: "Volar" },
          { value: "dorsal", label: "Dorsal" },
          { value: "combined", label: "Combined" },
        ],
        defaultValue: "volar",
      },
    ],
    risks: [
      { title: "Tendon irritation or rupture", detail: "Particularly of the flexor pollicis longus or extensor tendons.", severity: "serious" },
      { title: "Median nerve irritation", detail: "May present as new carpal tunnel symptoms." },
      { title: "Stiffness", detail: "Of wrist and fingers — early hand therapy is essential." },
      { title: "Complex regional pain syndrome", detail: "Chronic pain and dysfunction.", severity: "rare" },
      { title: "Infection", detail: "Superficial or deep wound infection.", severity: "rare" },
      { title: "Loss of reduction", detail: "May require revision surgery." },
    ],
    benefits: [
      "Restoration of anatomical alignment.",
      "Early mobilisation of the wrist and hand.",
      "Better function than malunion.",
    ],
    alternatives: [
      "Closed reduction and plaster cast.",
      "K-wire fixation.",
      "External fixation.",
    ],
    recovery: [
      "Light splint for comfort.",
      "Hand therapy from week 1.",
      "Return to desk work 1–2 weeks.",
      "Heavy lifting avoided for 6 weeks.",
    ],
    warnings: standardWarnings,
  },
  {
    slug: "knee-arthroscopy-diagnostic",
    name: "Diagnostic Knee Arthroscopy",
    region: "Knee",
    approxDurationMin: 30,
    anaesthesia: ["General", "Spinal"],
    summary:
      "Keyhole assessment of the knee joint to confirm diagnosis and perform targeted treatment.",
    involves: [
      "Two or three small portal incisions.",
      "Systematic inspection of all compartments.",
      "Targeted treatment as required (debridement, biopsy, trimming).",
      "Wound closure.",
    ],
    options: [
      lateralityOption,
      anaesthesiaOption(["General", "Spinal"]),
      {
        id: "reason",
        label: "Primary indication",
        kind: "select",
        choices: [
          { value: "pain", label: "Unexplained pain" },
          { value: "mechanical", label: "Mechanical symptoms" },
          { value: "instability", label: "Instability" },
          { value: "biopsy", label: "Biopsy" },
        ],
        defaultValue: "mechanical",
      },
    ],
    risks: [
      { title: "Infection", detail: "Superficial or deep infection.", severity: "rare" },
      { title: "DVT", detail: "Blood clots in the leg.", severity: "rare" },
      { title: "Persistent symptoms", detail: "Arthroscopy may not identify a treatable cause." },
      { title: "Neurovascular injury", detail: "Injury to saphenous or popliteal structures.", severity: "rare" },
      { title: "Instrument breakage", detail: "Very rare but may require retrieval.", severity: "rare" },
    ],
    benefits: [
      "Diagnostic clarity where imaging is inconclusive.",
      "Ability to treat findings in the same setting.",
      "Day-case recovery.",
    ],
    alternatives: [
      "Continued observation.",
      "MRI or other imaging.",
      "Physiotherapy and analgesia.",
    ],
    recovery: [
      "Weight bear as tolerated.",
      "Desk work within 3–5 days.",
      "Return to sport at 3–6 weeks depending on findings.",
    ],
    warnings: standardWarnings,
  },
];

export function getProcedure(slug: string): Procedure | undefined {
  return procedures.find((p) => p.slug === slug);
}

export function allRegions(): string[] {
  const set = new Set<string>();
  for (const p of procedures) set.add(p.region);
  return Array.from(set).sort();
}
