import os
from flask import Flask, render_template, request, send_from_directory, redirect, url_for
import uuid
import csv

app = Flask(__name__)


@app.route("/")
def home():
    return render_template("index.html")

@app.route("/dwnld")
def dwnld_page():
    return render_template("download.html")

@app.route("/download")
def download():
    return send_from_directory('game', 'Game-master.zip')


@app.route("/about")
def about():
    return render_template("about.html")

@app.route("/contact", methods=["GET", "POST"])
def contact():
    if request.method == "POST":
        # Get form data
        name = request.form.get("name")
        email = request.form.get("email")
        message = request.form.get("message")
        
        # Here you can process the message, send emails, save to database, etc.
        # let's just print the data to the console
        print(f"Name: {name}, Email: {email}, Message: {message}")

        return render_template("thank_you.html", name=name)

    return render_template("contact.html")


@app.route("/login", methods=["GET", "POST"])
def login():
    if request.method == "POST":
        # Get form data
        username = request.form.get("username")
        password = request.form.get("password")
        
        # Here you would typically validate the user's credentials
        # For this example, let's assume the user is valid
        
        # Redirect the user to their account page
        return redirect(url_for('account', name=username))
        
    return render_template("login.html")

@app.route("/account/<name>")
def account(name):
    # Render the account page with the user's name
    return render_template("account.html", name=name)



if __name__ == "__main__":
    app.run(debug=True)



@app.route('/')
def button_page():
    return render_template('account.html')

@app.route('/index', methods=['GET', 'POST'])
def display_text():
    if request.method == 'POST':
        return render_template('index.html', show_text=True)
    else:
        return render_template('index.html', show_text=False)

if __name__ == '__main__':
    app.run(debug=True)


    
    
    
    
    
#CSV_FILE_PATH = 'data.csv'

#@app.route('/')                               
#def login1():
   # return render_template('login.html')

#@app.route('/login', methods=['POST'])
#def submit():
    #username = request.form['username']
    #password = request.form['password']
    
    # Проверка существования файла, если нет - создаем с заголовками
    #if not os.path.exists(CSV_FILE_PATH):
        #with open(CSV_FILE_PATH, mode='w', newline='') as file:
           # writer = csv.writer(file)
           # writer.writerow(['username', 'password'])

    # Запись данных в CSV файл
    #with open(CSV_FILE_PATH, mode='a', newline='') as file:
       # writer = csv.writer(file)
       # writer.writerow([username, password])
    
   # return redirect(url_for('login1'))

#if __name__ == '__main__':
  # app.run(debug=True)