"""Cross-runtime conformance checks for the typed content preset hosts."""

import json
from pathlib import Path


ROOT = Path(__file__).parents[1]

HOSTS = {
    "html": {
        "content.testimonials": ("grid", "js/starter-blocks.js#mountTestimonialsGrid"),
        "content.faq": ("list", "js/starter-blocks.js#mountFaqList"),
        "content.services": ("grid", "js/starter-blocks.js#mountServicesGrid"),
        "content.team": ("grid", "js/starter-blocks.js#mountTeamGrid"),
        "content.locations": ("list", "js/starter-blocks.js#mountLocationsList"),
        "content.pricing": ("grid", "js/starter-blocks.js#mountPricingGrid"),
        "content.gallery": ("grid", "js/starter-blocks.js#mountGalleryGrid"),
        "content.events": ("list", "js/starter-blocks.js#mountEventsList"),
    },
    "react_app": {
        "content.testimonials": ("grid", "src/components/starter/content-blocks.jsx#TestimonialsGrid"),
        "content.faq": ("list", "src/components/starter/content-blocks.jsx#FaqList"),
        "content.services": ("grid", "src/components/starter/content-blocks.jsx#ServicesGrid"),
        "content.team": ("grid", "src/components/starter/content-blocks.jsx#TeamGrid"),
        "content.locations": ("list", "src/components/starter/content-blocks.jsx#LocationsList"),
        "content.pricing": ("grid", "src/components/starter/content-blocks.jsx#PricingGrid"),
        "content.gallery": ("grid", "src/components/starter/content-blocks.jsx#GalleryGrid"),
        "content.events": ("list", "src/components/starter/content-blocks.jsx#EventsList"),
    },
    "nuxt_app": {
        "content.testimonials": ("grid", "components/starter/blocks/TestimonialsGrid.vue"),
        "content.faq": ("list", "components/starter/blocks/FaqList.vue"),
        "content.services": ("grid", "components/starter/blocks/ServicesGrid.vue"),
        "content.team": ("grid", "components/starter/blocks/TeamGrid.vue"),
        "content.locations": ("list", "components/starter/blocks/LocationsList.vue"),
        "content.pricing": ("grid", "components/starter/blocks/PricingGrid.vue"),
        "content.gallery": ("grid", "components/starter/blocks/GalleryGrid.vue"),
        "content.events": ("list", "components/starter/blocks/EventsList.vue"),
    },
}


def test_all_content_preset_hosts_are_mapped_and_resolvable():
    for starter, expected in HOSTS.items():
        root = ROOT / "boilerplates" / starter
        payload = json.loads((root / "p2hs" / "app-block-hosts.json").read_text(encoding="utf-8"))
        mapped = {(item["block"], item["slot"]): item for item in payload["hosts"]}
        for block, (slot, implementation) in expected.items():
            host = mapped[(block, slot)]
            assert host["implementation"] == implementation
            source_path, _, export = implementation.partition("#")
            source = (root / source_path).read_text(encoding="utf-8")
            if export:
                assert export in source

