from flask import render_template

from app import app
from app.forms import DatasetForm
from app.processing import process_data


@app.route("/")
@app.route("/index")
def index():
    return render_template("index.html", title="Home Page")


@app.route("/data")
def data():
    form = DatasetForm()
    if form.validate_on_submit():
        return render_template("visualization.html", form=form, title="Visualization")
    return render_template("data.html", title="Data", form=form)


@app.route("/visualization")
def visualization(form):
    plot, map = process_data(form.dataset)
    return render_template(
        "visualization.html", title="Visualization", plot=plot, map=map
    )
