from django import template
from datetime import date,datetime
from domini.models import *
 
register = template.Library()

@register.filter(name='account_mail')
def getAccountEmail(value):
  totale = len(value.user_set.all())
  enabled = len(value.user_set.all().filter(enabled=1))
  return f"{totale}/{enabled}"


@register.filter(name='account_alias')
def getAccountAlias(value):
  totale = len(value.alias_set.all())
  enabled = len(value.alias_set.all().filter(enabled=1))
  return f"{totale}/{enabled}"

@register.filter(name='DayExpiration')
def getDayDifference(value):
 return (value - date.today()).days

@register.filter(name='DateFromUnixTimeStamp')
def DateFromUnixTimeStamp(value):
  tmp = datetime.fromtimestamp(value)
  return tmp.strftime("%d/%m/%Y")

@register.simple_tag(name='Expired')
def Expired(value):
  print('value',value,(value - date.today()).days)
  if (value - date.today()).days < 1:
    print ('expired')
    return "text-decoration-line-through"
  return ""

@register.simple_tag(name='ExpiredSoon')
def ExpiredSoon(value):
  print('value',value,(value - date.today()).days)
  if (value - date.today()).days < 30 and (value - date.today()).days > 0:
    return "bg-inf"
  if (value - date.today()).days < 7 and (value - date.today()).days > 0:
    return "bg-danger"


