# AUTOGENERATED! DO NOT EDIT! File to edit: 02_app_templates.ipynb (unless otherwise specified).

__all__ = ['App']

# Cell
import traitlets
import time
import json
import base64
import ipyvuetify
import ipywidgets
import pandas as pd
from markdown import markdown
import ipyvuetify as v
from nbdev.imports import *
from .outputs import *
from .inputs import *

# Cell

class App():
    def __init__(self, app_title='', inputs=[], outputs={}, *args, **kwargs):
        self.app_title = app_title
        self.inputs = inputs
        self.outputs = outputs

    def show(self):
        output_containers = [ipywidgets.Output() for i in self.outputs]

        nav_button = v.AppBarNavIcon(class_='mt-1 mb-1 mx-2', )

        progress_spinner = v.ProgressCircular(indeterminate=False,
                                              class_='mt-2 mb-2 mx-2')

        mybutton = v.Btn(class_='icon',
                         style_='min-width:100px',
                         color='primary',
                         children=[v.Icon(children=['mdi-check'])])

        cancel_button = v.Btn(class_='icon',
                              style_='min-width:100px',
                              color='error',
                              children=[v.Icon(children=['mdi-cancel'])])

        myinputs = v.Container(children=[
            *self.inputs,
            v.Row(children=[
                v.Col(width=6, children=[mybutton]),
                v.Col(width=6, children=[cancel_button])
            ])
        ])

        vnd = v.NavigationDrawer(v_model=True,
                                 absolute=True,
                                 right=False,
                                 style_='min-height=800px;',
                                 children=[
                                     v.Html(tag='div',
                                            class_="headline",
                                            children=["Configuration"]), myinputs
                                 ])


        def toggle_drawer(widget, event, data):
            vnd.v_model = not vnd.v_model

        def get_data(myinputs = self.inputs):
            return pd.DataFrame({'a':[1,2,3],'b':[2,3,4]})

        def inputs_complete(widget, event, data):
            vnd.v_model = not vnd.v_model
            progress_spinner.indeterminate = True
            try:
                df = get_data(myinputs)
                for j, i in enumerate(self.outputs):
                    output_containers[j].clear_output()
                    with output_containers[j]:
                        display(self.outputs[i](self.inputs))
                progress_spinner.indeterminate = False
            except:
                return

        nav_button.on_event('click', toggle_drawer)
        cancel_button.on_event('click', toggle_drawer)
        mybutton.on_event('click', inputs_complete)

        return v.Container(
            class_='mx-auto my-0 py-0',
            style_='',
            children=[
                v.Tabs(
                    background_color="primary",
                    style_='min-height:600px',
                    dark=True,
                    children=[
                        nav_button,
                        v.ToolbarTitle(class_='py-2 px-4', children=[self.app_title]),
                        *[v.Tab(children=[i]) for i in self.outputs.keys()],
                        *[v.TabItem(children=[i]) for i in output_containers],
                        v.Spacer(),
                        progress_spinner,
                    ]), vnd
            ])