# Standard Library
from pathlib import Path

# Pip
from flask import Flask

# Local
from .homescreen import homescreen
from .mainapp import mainapp


def create_app(*args):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config["APPLICATION_ROOT"] = "/hsk"

    # ensure the instance folder exists
    instance_path = Path(app.instance_path)
    instance_path.mkdir(parents=True, exist_ok=True)

    # configs
    app.config.from_mapping(
        SECRET_KEY="dev",
        DATABASE=instance_path / "flaskr.sqlite",
    )

    app.config.from_pyfile("config.py", silent=True)

    for blueprint in (homescreen, mainapp):
        app.register_blueprint(blueprint)

    return app
