from django.shortcuts import render
from datetime import date

from avis_locataire.models import AvisLocataire

# Constantes des couleurs pour le calendrier
SAISON_CREUSE_COLOR = "#b2eab2"
SAISON_NORMALE_COLOR = "#b2d8ff"
SAISON_HAUTE_COLOR = "#ffd9b2"


# Create your views here.
def index(request):
    head_title = "L'île Maurice autrement..."
    html_background = "html_background"
    return render(request, 'index.html', {'head_title': head_title, 'html_background': html_background})


def route_des_epices(request):
    head_title = "Location Ile Maurice"
    html_background = ""

    month = date.today().month
    year = date.today().year

    last_avis = AvisLocataire.objects.filter(afficher='Oui').latest('date_avis')
    note_globale = get_note_globale()

    return render(request, 'route_des_epices.html', {
        'head_title': head_title, 
        'html_background': html_background,
        'month': month,
        'year': year,
        'last_avis': last_avis,
        'note_globale': note_globale,
    })


def get_note_globale():
    list_avis = AvisLocataire.objects.filter(afficher='Oui')
    number_avis = AvisLocataire.objects.filter(afficher='Oui').count()

    note_globale = 0
    for avis in list_avis:
        note_globale = note_globale + int(avis.note)

    note_globale = int((note_globale / (number_avis * 5)) * 100)

    return note_globale


def villa_route_des_epices(request):
    head_title = "La Villa Route des Epîces"
    html_background = ""

    month = date.today().month
    year = date.today().year

    return render(request, 'villa_route_des_epices.html', {
        'head_title': head_title, 
        'html_background': html_background,
        'month': month,
        'year': year
    })


def videos_villa_route_des_epices(request):
    head_title = "La Villa Route des Epîces en vidéos"
    html_background = ""

    month = date.today().month
    year = date.today().year

    return render(request, 'videos_villa_route_des_epices.html', {
        'head_title': head_title, 
        'html_background': html_background,
        'month': month,
        'year': year
    })


def cookies(request):
    head_title = "Cookies"
    return render(request, 'cookies.html', {'head_title': head_title})


def mentions_legales(request):
    head_title = "Mentions légales"
    site_name = "ile-maurice-location.com"
    proprietaire = "Ramchurn Rikesh"

    month = date.today().month
    year = date.today().year

    return render(request, 'mentions_legales.html', {
        'head_title': head_title, 
        'month': month,
        'year': year,
        'site_name': site_name, 
        'proprietaire': proprietaire
    })


def contrat_location_view(request):
    head_title = "Conditions Générales de Vente"
        
    month = date.today().month
    year = date.today().year

    return render(request, 'contrat_location.html', {
        'head_title': head_title,
        'month': month,
        'year': year,
    })


def tarifs_view(request):
    head_title = "Tarifs des locations"
        
    month = date.today().month
    year = date.today().year

    return render(request, 'tarifs.html', {
        'head_title': head_title,
        'month': month,
        'year': year,
        'saison_creuse_color': SAISON_CREUSE_COLOR,
        'saison_normale_color': SAISON_NORMALE_COLOR,
        'saison_haute_color': SAISON_HAUTE_COLOR,
    })


def ile_maurice_view(request):
    head_title = "L'île Maurice"
        
    month = date.today().month
    year = date.today().year

    return render(request, 'ile_maurice.html', {
        'head_title': head_title,
        'month': month,
        'year': year,
    })