#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import dash
import os.path as path
from webviz_config.webviz_store import webviz_storage
from webviz_config.webviz_assets import webviz_assets
from webviz_config.common_cache import cache
from pathlib import Path, PosixPath
{% 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

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'))
