# Pip
from flask import Blueprint, abort, current_app, render_template, send_from_directory
from jinja2 import TemplateNotFound

homescreen = Blueprint(
    "homescreen",
    __name__,
    template_folder="templates",
    url_prefix="/hskankicreator",
    static_folder="static",
)


@homescreen.route("/")
def index():
    """main page"""
    return render_template("index.html")


@homescreen.route("/favicon.ico")
def favicon():
    """favicon"""
    return send_from_directory(
        current_app.static_folder, "favicon.ico", mimetype="image/vnd.microsoft.icon"
    )


@homescreen.route("/", defaults={"page": "index"})
@homescreen.route("/<page>")
def show(page):
    """general entry for other pages"""
    try:
        return render_template(f"{page}.html")
    except TemplateNotFound:
        abort(404)
