from random import choice

from flask import Flask, render_template, request


# "__name__" is a special Python variable for the name of the current module
# Flask wants to know this to know what any imported things are relative to.
app = Flask(__name__)

AWESOMENESS = [
    'awesome', 'terrific', 'fantastic', 'neato', 'fantabulous', 'wowza', 'oh-so-not-meh',
    'brilliant', 'ducky', 'coolio', 'incredible', 'wonderful', 'smashing', 'lovely']


@app.route('/')
def start_here():
    """Homepage."""

    return "Hi! This is the home page."


@app.route('/hello')
def say_hello():
    """Save hello to user."""

    return render_template("hello.html")


@app.route('/greet')
def greet_person():
    """Greet user."""

    player = request.args.get("person")

    compliment = choice(AWESOMENESS)

    return render_template("compliment.html",
                           person=player,
                           compliment=compliment)


@app.route('/game')
def show_madlib_form():
    """Does the player want to play?"""

    player_choice = request.args.get("yesno")

    if player_choice == "no":
        return render_template("goodbye.html")

    elif player_choice == "yes":
        return render_template("game.html")

    else:
        return "Please choose an option."


@app.route('/madlib')
def show_madlib():
    """Creates the madlib story based on user input """

    madlib_templates = ["Cow jumped over the {{ noun }}", "The duck is {{ adjective }} {{ preposition }} waddles",
                       "{{ person }} {{ verb }} {{ article }} {{ noun }}"]

    sentence = choice(madlib_templates)
    person = request.args.get("person")
    color = request.args.get("color")
    noun = request.args.get("noun")
    adjective = request.args.get("adjective")
    verb = request.args.get("verb")
    preposition = request.args.get("preposition")
    article = request.args.get("article")
    punctuation = request.args.get("punctuation")

    return render_template("madlib.html",
                           sentence=sentence,
                           person=person,
                           color=color,
                           noun=noun,
                           adjective=adjective,
                           verb=verb,
                           preposition=preposition,
                           article=article,
                           punctuation=punctuation)

if __name__ == '__main__':
    # debug=True gives us error messages in the browser and also "reloads" our web app
    # if we change the code.
    app.run(debug=True)
