/** Maps admin component display names to page-block registry slugs. */
export const COMPONENT_NAME_TO_SLUG: Record<string, string> = {
  Hero: "hero",
  "Dimension Detail": "dimension-detail",
  "Grade Family Guides": "grade-family-guides",
  "Grade Family Guides with API": "grade-family-guides-api",
  "Grade Hero": "grade-hero",
  "Grade Kaleidoscope": "grade-kaleidoscope",
  "Curriculum Hero": "curriculum-hero",
  "Essential Question": "essential-question",
  "Core Courses": "core-courses",
  "DNA Strands": "dna-strands",
  "Year at a Glance": "year-at-glance",
  "Year-Long Story": "year-long-story",
  "Developing the Whole Child": "developing-the-whole-child",
  "Portrait of the Learner": "developing-the-whole-child",
  "Portrait of the Learner — Dimension Grid": "developing-the-whole-child",
  "Fink's Taxonomy of Significant Learning": "finks-taxonomy",
  "Finks Taxonomy": "finks-taxonomy",
  "One Project, Not 13 Tests": "one-project-not-13-tests",
  "Curriculum Architecture": "curriculum-architecture",
  "Problem-Based Experiential Learning": "pbel",
  "Course Hero": "course-hero",
  Science: "course-hero",
  "Why This Course Matters": "why-this-course-matters",
  "How Science Connects to All Learning": "how-connects",
  "How Connects to All Learning": "how-connects",
  "Smarter Assessment = Less Stress": "smarter-assessment",
  "What Your Child Will Gain": "what-your-child-will-gain",
  "Developing the Whole Child (Course)": "course-portrait",
  "Portrait of the Learner (Course)": "course-portrait",
  "Course Portrait — Progress Bars": "course-portrait",
  "Core Skills Your Child Will Master": "course-core-skills",
  "Your Child's Year-Long Journey": "course-journey",
  "What Your Child Will Create": "course-what-they-create",
  "Deep Inquiry Questions to Ask Your Child": "course-inquiry-questions",
  "Simple Ways to Support at Home": "course-support-at-home",
  "Quarter-End Celebration": "course-quarter-celebration",
  "The Nature Investigator": "quarter-hero",
  "Quarter Hero": "quarter-hero",
  "Big Idea": "big-idea",
  "How Each Course Sees This Quarter": "how-each-course-sees",
  "Quarter Learning Tabs": "quarter-learning-tabs",
  "Assessment, Evidence & Inquiry, Growth": "quarter-learning-tabs",
  "Courses (13)": "quarter-courses",
  "Quarter Courses": "quarter-courses",
  "Courses (13) – Assessment, Evidence & Growth": "quarter-courses-and-learning",
  "Quarter Courses & Learning": "quarter-courses-and-learning",
  "Orion STEM Schools": "orion-school-header",
  "What is PBEL?": "what-is-pbel",
  "Why Water? Why Now?": "why-water-why-now",
  "How It Works — The PBEL Cycle": "pbel-cycle",
  "What Your Child Might Do": "what-your-child-might-do",
  "What Families Can Expect — and How You Can Help": "families-expect-help",
  "Benefits for Your Child": "benefits-for-your-child",
  "Our Service Learning Plan (IPARDE)": "service-learning-ipard",
  "Year Timeline at a Glance": "year-timeline-at-glance",
  "How Families Can Help": "how-families-can-help",
  "Deep Inquiry Questions": "deep-inquiry-questions",
  "Stay in the Loop": "stay-in-the-loop",
  "Parent Course Overview": "parent-course-overview",
  "Parent-Facing Course Overview": "parent-course-overview",
  "Design to Impact Hero": "grade-hero",
  "Impact Kaleidoscope": "impact-kaleidoscope",
  "Three Journey Phases": "three-journey-phases",
  "Cross-Cutting Mirrors": "cross-cutting-mirrors",
  "Annual Flow Quarters": "annual-flow-quarters",
  "Diverge Converge Viz": "diverge-converge-viz",
  "Squad Roles": "squad-roles",
  "Grade Band Entrepreneurship": "grade-band-entrepreneurship",
  "Deliverables Evidence": "deliverables-evidence",
  "Design Impact Summit": "design-impact-summit",
  "Closing Vision": "closing-vision",
  "Club Category Grid": "club-category-grid",
  "Steering Committees Grid": "steering-committees-grid",
  "Steering Committees": "steering-committees-grid",
  "Orion Competitions": "orion-competitions",
  "Public Competitions": "public-competitions",
  "Competition Tabs": "competition-tabs",
  "Competitions Timeline": "competition-tabs",
  "SWOT Analysis Grid": "swot-analysis-grid",
  "Root Cause Fishbone": "root-cause-fishbone",
  "Portrait Goals Grid": "portrait-goals-grid",
  "Growth Radar Chart": "growth-radar-chart",
  "Progress How It Works": "progress-how-it-works",
  "Progress Sample Report": "progress-sample-report",
  "PBEL Guide Footer": "pbel-guide-footer",
  Footer: "footer",
};

export type BlockSlugLookup = {
  componentId: number;
  componentName: string;
  componentSlug?: string;
};

export type ComponentSlugRecord = { id: number; slug: string };

export function slugFromComponentName(componentName: string): string {
  return COMPONENT_NAME_TO_SLUG[componentName] ?? "hero";
}

/** Resolve block slug: stored slug → DB component → name map. */
export function resolveBlockSlug(
  block: BlockSlugLookup,
  components?: ComponentSlugRecord[]
): string {
  if (block.componentSlug) return block.componentSlug;
  const fromDb = components?.find((c) => c.id === block.componentId)?.slug;
  if (fromDb) return fromDb;
  return slugFromComponentName(block.componentName);
}
