# -*- coding: utf-8 -*-
from os.path import abspath, dirname, join

from ocyan.core.utils import merge_dicts
from ocyan.plugin.wagtail.block_plugin import BlockPluginConfig


class RoadrunnerBootstrap5Config(BlockPluginConfig):
    def contribute_to_settings(self, settings):
        return merge_dicts(
            settings,
            {
                "ROADRUNNER_REGISTRY_FUNCTION": "ocyan.plugin.roadrunner_bs5.utils.get_roadrunner_block_choices"
            },
            overwrite=True,
        )

    def contribute_to_installed_apps(self, installed_apps):
        installed_apps.wagtail.extend(("ocyan.plugin.roadrunner_bs5", "rr"))
        installed_apps.wagtail.append("wagtail.contrib.table_block")
        installed_apps.ocyan.register_extension(
            "ocyan.plugin.roadrunner_bs5.bs5_wagtail_oscar_integrations_extension",
            "ocyan.plugin.wagtail_oscar_integration",
        )
        return installed_apps

    def contribute_to_blocks(self, blocks):
        from .blocks import (
            EmptyBlock,
            GoogleMapsBlock,
            ParallaxBlock,
            SectionedFAQBlock,
            SlideShowBlock,
        )

        return blocks + [
            ("Maps", GoogleMapsBlock(), "rr"),
            ("Parallax", ParallaxBlock(), "rr"),
            ("Slideshow", SlideShowBlock(), "rr"),
            ("Empty", EmptyBlock(), "rr"),
            ("FAQ", SectionedFAQBlock(), "rr"),
        ]

    def contribute_to_fixtures(self, fixtures):
        directory = dirname(__file__)
        filename = abspath(join(directory, "fixtures/roadrunner_bs5/homepage.json"))
        fixtures.add("wagtailhome", filename, 2)
        return fixtures
