from importlib import resources

from dash import Dash, html, page_container
from flask import Response

BULMA_CSS = "https://cdn.jsdelivr.net/npm/bulma@1.0.0/css/bulma.min.css"


def create_app(pages_folder="pages") -> Dash:
    """
    Create a "naked" app with minimum bulma styling

    Returns:
        Dash app
    """
    infra_css_url = "/_mpships_infra/mpships.css"

    app = Dash(
        __name__,
        suppress_callback_exceptions=True,
        pages_folder=pages_folder,
        use_pages=True,
        external_stylesheets=[BULMA_CSS, infra_css_url],
    )

    app.layout = html.Div([page_container])

    @app.server.get(infra_css_url)
    def _mpships_css():
        css = (resources.files("mpships_infra") / "assets" / "mpships.css").read_bytes()
        return Response(css, mimetype="text/css")

    return app
