from flask import Flask, request

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "<p>Hello, World!</p>"

@app.route("/hello")
def hello():
    return "<p>Hello to us :)</p>"

@app.route("/hello/<name>")
def hello_you(name):
    return f"<p>Hello to { name } :)</p>"
    # return "<p>Hello to" + name + " :)</p>"

html_template = """
<form action="/guestbook" method="POST">

Name: <br>
<input name="guest" type="text"><br>

Message:<br>
<textarea name="message" cols="80" rows="10"></textarea><br>

<input type="submit">
</form>
"""

@app.route("/guestbook", methods=["GET", "POST"])
def guestbook():
    # print(html_template)

    if request.method == "GET":

        return html_template
    
    if request.method == "POST":

        guest = request.form["guest"]
        message = request.form["message"]

        print(guest)
        print(message)

        return f"""
            { html_template } 
            <hr> 
            <h1>{ guest }</h1> 
            <p>{ message }</p>
            """        