"""This code defines which web page is displayed to the user.

AUTHOR        :  Brian Ha (summer intern)
MENTOR        :  Gene Massion
MBARI TEAM    :  Chemical Sensor Group
PROJECT       :  Coastal Profiling Floats (CPF)
DATE CREATED  :  2018-06-29
LAST REVISION :  2018-07-31
"""

# 3rd Party Library Imports
# =============================================================================
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Output, Input


# CPF MCS-Specific Imports
# =============================================================================
from gui.app import app
from gui.pages import home, fleet_overview, float_viewer, command


# Flask Application Object Hosted by "mod_wsgi" on Top of an Apache Web Server
# =============================================================================
server = app.server


# Functions
# =============================================================================
def main():
    app.run_server(debug=True)


# Page Layout
# =============================================================================
app.layout = html.Div([
    dcc.Location(id='url', refresh=False),
    html.Div(id='page-content')
], style={'margin': 0})


# Callbacks
# =============================================================================
@app.callback(Output('page-content', 'children'),
              [Input('url', 'pathname')])
def display_page(pathname):
    if pathname == '/fleet_overview':
        return fleet_overview.layout
    elif pathname == '/float_viewer':
        return float_viewer.layout
    elif pathname == '/command':
        return command.layout
    else:
        return home.layout
    # You could also return a 404 "URL not found" page here
