from flask import render_template
from app.forms.login import LoginForm
from app.forms.search import SearchForm


def render(*args, styles=[], **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 :
    # 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/form.css',
        'css/footer.css',
        'css/flash.css',
        'css/responsive.css',
        'css/table.css'
    ]
    for s in styles:
        print(s[1:])
        if s[0] == '-':
            styles_.remove(s[1:])
        if s[0] == '+':
            styles_.append(s[1:])

    login_form = LoginForm()
    search_form = SearchForm()
    return render_template(*args, **kwargs,
        login_form=login_form, search_form=search_form, styles=styles_)
