from flask import Blueprint, redirect, request, render_template
from flask import current_app as app

from datetime import datetime, timedelta

views = Blueprint(
    name='views',
    import_name=__name__,
    template_folder='templates',
    static_folder='root',
)

@views.route('/privacy/')
def _privacy():
    return render_template('privacy.html')

@views.route('/cookies/', methods=['POST'])
def _cookie_consent():
    resp = redirect('/')
    resp.set_cookie(
        key='cookie_consent',
        value='true',
        max_age = timedelta(days=14) if request.cookies.get('remember') == 'True' else None,
        path = '/',
        expires = datetime.now() + timedelta(days=14) if request.cookies.get('remember') else None,
        domain = f'{app.config.get("SERVER_NAME")}',
        secure = True
    )
    return resp