from django import template
from main.templatetags.main_extras import remix

register = template.Library()


@register.filter
def check(s, diff):
    if s is None:
        s = 0
    if s == diff:
        return remix("check", "green")
    else:
        return remix("close", "red")


@register.inclusion_tag("statement/statement_table.html")
def statement_table(statements, **kwargs):
    if (n_max := kwargs.get("n_max")) is not None:
        if statements.count() <= n_max:
            del kwargs["statements_url"]
        statements = statements[:n_max]

    return kwargs | {
        "statements": statements,
    }
