from flask import render_template
from app.forms.login import LoginForm
from app.forms.search import SearchForm
from app.models.forum import Forum

def render(*args, styles=[], scripts=[], **kwargs):
    # TODO: debugguer cette merde : au logout, ça foire
    # if current_user.is_authenticated:
    #     login_form = LoginForm()
    #     return render_template(*args, **kwargs, login_form=login_form)
    # return render_template(*args, **kwargs)

    # Pour jouer sur les feuilles de style ou les scripts :
    # render('page.html', styles=['-css/form.css', '+css/admin/forms.css'])

    styles_ = [
        'css/global.css',
        'css/navbar.css',
        'css/header.css',
        'css/container.css',
        'css/editor.css',
        'css/form.css',
        'css/footer.css',
        'css/flash.css',
        'css/table.css',
        'css/pagination.css',
        'css/responsive.css',
    ]
    scripts_ = [
        'scripts/trigger_menu.js',
        'scripts/pc-utils.js',
        'scripts/smartphone_patch.js',
        'scripts/editor.js',
    ]

    for s in styles:
        print(s[1:])
        if s[0] == '-':
            styles_.remove(s[1:])
        if s[0] == '+':
            styles_.append(s[1:])

    for s in scripts:
        print(s[1:])
        if s[0] == '-':
            scripts_.remove(s[1:])
        if s[0] == '+':
            scripts_.append(s[1:])

    return render_template(*args, **kwargs, styles=styles_, scripts=scripts_)
