#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import datetime
import os.path as path
from pathlib import Path, PosixPath

import dash
from webviz_config.webviz_store import WEBVIZ_STORAGE
from webviz_config.webviz_assets import WEBVIZ_ASSETS
from webviz_config.common_cache import CACHE



{% for module in _imports %}
{%- if module is string -%}
import {{ module }}
{%- else -%}
import {{ module[0] }} as {{ module[1] }}
{%- endif %}
{% endfor %}

app = dash.Dash()
app.config.suppress_callback_exceptions = True

app.webviz_settings = {
    "plotly_layout": {{ plotly_layout }},
}

CACHE.init_app(app.server)

WEBVIZ_STORAGE.storage_folder = path.join(
    path.dirname(path.realpath(__file__)), "webviz_storage"
)

# The lines below can be simplified when assignment
# expressions become available in Python 3.8
# (https://www.python.org/dev/peps/pep-0572)

containers = []

{% for page in pages %}
{% for content in page.content %}
{% if content is not string %}
containers.append({{ content._call_signature[0] }})
{% endif %}
{% endfor %}
{% endfor %}

for container in containers:
    if hasattr(container, "add_webvizstore"):
        WEBVIZ_STORAGE.register_function_arguments(container.add_webvizstore())

WEBVIZ_STORAGE.build_store()

WEBVIZ_ASSETS.make_portable(path.join(path.dirname(path.realpath(__file__)), "assets"))
