from django.shortcuts import render
from django.contrib.auth.decorators import login_required, permission_required
from django.urls import reverse
from .forms import EventForm

def keywords(additional_keywords=None):
    default_keywords = 'Dance calander, '
    if additional_keywords:
        additional_keywords = ', '.join(map(str, additional_keywords))
    return (default_keywords + additional_keywords)


def index(request):
    context = {
        'title': 'Dance calendar',
        'icon': 'calendar alternate outline',
        'description': 'Calendar of dance events.',
        'keywords': keywords(('index')),
    }
    return render(request, 'dancecalendar/index.html', context)

def events(request):
    context = {
        'parent_title': 'Dance calendar',
        'parent_url': reverse('dancecalendar:index'),
        'parent_icon': 'calander alternate outline',
        'title': 'Events',
        'icon': 'sitemap',
        'description': 'List of events from the dance calander',
        'keywords': keywords(('events', 'list', 'eventlist', 'event list', 'list of events')),
    }
    return render(request, 'dancecalendar/events.html', context)

@login_required
@permission_required('dancecalendar.add_evet', raise_exception=True)
def add_event(request):
    if request.method == 'POST':
        pass
    else:   # Not a post request.
        form = EventForm()
    context = {
        'parent_title': 'Dance calendar',
        'parent_url': reverse('dancecalendar:index'),
        'parent_icon': 'calander alternate outline',
        'title': 'Add event',
        'icon': 'sitemap',
        'description': 'Add an event to the dance calander',
        'keywords': keywords(('add', 'event', 'add event')),
        'form': form,
    }
    return render(request, 'dancecalendar/add_event.html', context)
def event(request):
    pass
