# Pip
from flask import Blueprint, render_template, request

mainapp = Blueprint(
    "mainapp",
    __name__,
    template_folder="templates",
    url_prefix="/hsk/app",
    static_folder="static",
)


@mainapp.route("/", methods=["GET", "POST"])
def show():
    if request.method == "GET":
        args = request.args.to_dict()
        deck_type = args.get("deck_type", "")
        language = args.get("language", "")
        output_type = args.get("output_type", "")
        if not deck_type or not language or not output_type:
            state = "new"
        else:
            print()
            print(deck_type, language, output_type)
            print()
            state = "complete"
    elif request.method == "POST":
        state = "ready"
        form = request.form.to_dict()

    return render_template(f"app.html", data=locals())
