---
import yaml from "js-yaml";
import fs from "fs";
import { marked } from "marked";

import SectionDefault from "./SectionDefault.astro";
import SectionIframeChannels from "./SectionIframeChannels.astro";

const { src } = Astro.props;

// Load YAML
const data = yaml.load(fs.readFileSync(src, "utf8")) ?? { sections: [] };

// Markdown → HTML
const sections = (data.sections as any[]).map((s: any) => ({
  ...s,
  html: marked(s.content || "")
}));
---

{sections.map((section: any, index: number) => {
  const type = section.type || "default";

  if (type === "iframe-channels") {
    return <SectionIframeChannels section={section} index={index} />;
  }

  return <SectionDefault section={section} index={index} />;
})}
