from abc import ABC, abstractmethod

import dash_mp_components as mpc
from crystal_toolkit.core.mpcomponent import MPComponent
from dash import html


class MPShipsApp(MPComponent, ABC):
    @abstractmethod
    def get_layout(self, payload=None):
        """Return a Dash layout for the app. If the app requires any
        global set-up before a layout can be generated, put this in
        the app's initializer.

        :param payload: anything in the URL after
        https://materialsproject.org/your_app_name/
        """
        raise NotImplementedError

    def app_container(self, children, **kwargs):
        return html.Div(children, **kwargs)

    def get_mp_layout(self, payload=None):
        mp_apps_sidebar = html.Div()
        mp_app_header = html.Header()
        mp_app_content = html.Section()

        return html.Div(
            [
                self.app_container(
                    mpc.DrawerContextProvider(
                        [
                            mp_apps_sidebar,
                            html.Div(
                                [mp_app_header, mp_app_content],
                                className="mp-app-content-container",
                            ),
                        ]
                    ),
                    id=self.id("app-container"),
                    className="mp-app-container is-gapless",
                ),
            ]
        )
