"""
Django settings for {{PROJECT_NAME}} project.

Generated by 'django-admin init_ndr_core' using Django 4.2.7.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""

from pathlib import Path
import os
from django.contrib import messages
from django.urls import reverse_lazy
from ndr_core.ndr_settings import NdrSettings

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "{{SECRET_KEY}}"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['{{ALLOWED_HOST}}']


# Application definition

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
]
# ADDITIONAL NDR CORE APPS
INSTALLED_APPS += NdrSettings.get_installed_apps()

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    'django.middleware.locale.LocaleMiddleware',                # Added
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "{{PROJECT_NAME}}.urls"

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [BASE_DIR / 'templates']
        ,
        "APP_DIRS": True,
        "OPTIONS": {
            "context_processors": [
                "django.template.context_processors.debug",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.contrib.messages.context_processors.messages",
            ],
        },
    },
]

WSGI_APPLICATION = "{{PROJECT_NAME}}.wsgi.application"


# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": BASE_DIR / "db.sqlite3",
    }
}


# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
    },
]


# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/

# THIS IS THE DEFAULT LANGUAGE CODE OF YOUR NDR INSTANCE
LANGUAGE_CODE = "{{INITIAL_LANGUAGE_CODE}}"
LANGUAGE_COOKIE_NAME = 'django_ndr_language'
"""Default language code and cookie name."""

TIME_ZONE = "UTC"

USE_I18N = True
USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

# NDR CORE SETTINGS
###################

# NDR CORE PATH SETTINGS
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
MEDIA_URL = '/media/'
"""Sets the path for static and media files."""

# NDR ADMIN INTERFACE SETTINGS
LOGIN_URL = reverse_lazy('ndr_core:login')
LOGOUT_URL = reverse_lazy('ndr_core:logout')
LOGIN_REDIRECT_URL = reverse_lazy('ndr_core:dashboard')
"""Overwrites the default urls for the django authentication system."""

# NDR FORMS SETTINGS
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = 'bootstrap5'
"""Django crispy forms - used to render forms."""

FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
"""This renderer gives you complete control of how form and widget templates are sourced."""

# NDR TABLES SETTINGS
DJANGO_TABLES2_TEMPLATE = "django_tables2/bootstrap5.html"
"""Django tables2 - used to render tables."""

# MESSAGE TAGS SETTINGS
MESSAGE_TAGS = {
        messages.DEBUG: 'alert-secondary',
        messages.INFO: 'alert-info',
        messages.SUCCESS: 'alert-success',
        messages.WARNING: 'alert-warning',
        messages.ERROR: 'alert-danger',
}
"""Bootstrap css classes to use to display django's built in message tags."""

# CORS SETTINGS
CORS_ALLOW_ALL_ORIGINS = True  # If this is used then `CORS_ALLOWED_ORIGINS` will not have any effect
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOWED_ORIGINS = [

]

CORS_ORIGIN_WHITELIST = (
    'http://localhost:8000',
)

CORS_ALLOW_HEADERS = [
    'accept',
    'accept-encoding',
    'authorization',
    'content-type',
    'dnt',
    'origin',
    'user-agent',
    'x-csrftoken',
    'x-requested-with',
]

# GEOIP SETTINGS
GEOIP_PATH = os.path.join('geoip/')
"""Needed for the geoip functionality."""

# CKEDITOR SETTINGS
CKEDITOR_UPLOAD_PATH = 'uploads/'
"""Needed for the ck-editor"""

# RECAPTCHA SETTINGS
SILENCED_SYSTEM_CHECKS = ['captcha.recaptcha_test_key_error']
RECAPTCHA_PUBLIC_KEY = 'y0uR3c4PtCh4pUbL1cK3y'
RECAPTCHA_PRIVATE_KEY = 'y0uR3c4PtCh4pr1v4t3K3y'
"""Recaptcha key to use for the captcha functionality for the contact form.. """

customColorPalette = [
        {
            'color': 'hsl(4, 90%, 58%)',
            'label': 'Red'
        },
        {
            'color': 'hsl(340, 82%, 52%)',
            'label': 'Pink'
        },
        {
            'color': 'hsl(291, 64%, 42%)',
            'label': 'Purple'
        },
        {
            'color': 'hsl(262, 52%, 47%)',
            'label': 'Deep Purple'
        },
        {
            'color': 'hsl(231, 48%, 48%)',
            'label': 'Indigo'
        },
        {
            'color': 'hsl(207, 90%, 54%)',
            'label': 'Blue'
        },
    ]

# CKEDITOR 5 SETTINGS
CKEDITOR_5_CONFIGS = {
    'default': {
        'toolbar': ['heading', '|', 'bold', 'italic', 'link',
                    'bulletedList', 'numberedList', 'blockQuote'],
    },
    'page_editor': {
        'toolbar': [
            'heading', '|',
            'bold', 'italic', 'underline', 'strikethrough', '|',
            'link', '|',
            'bulletedList', 'numberedList', '|',
            'outdent', 'indent', '|',
            'blockQuote', 'insertTable', '|',
            'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', '|',
            'code', 'subscript', 'superscript', 'highlight', '|',
            'removeFormat', 'sourceEditing'
        ],
        'table': {
            'contentToolbar': [
                'tableColumn', 'tableRow', 'mergeTableCells',
                'tableProperties', 'tableCellProperties'
            ],
            'tableProperties': {
                'borderColors': customColorPalette,
                'backgroundColors': customColorPalette,
                'defaultProperties': {
                    'borderStyle': 'solid',
                    'borderWidth': '1px',
                    'borderColor': 'hsl(0, 0%, 90%)',
                },
            },
            'tableCellProperties': {
                'borderColors': customColorPalette,
                'backgroundColors': customColorPalette,
            }
        },
        'htmlSupport': {
            'allow': [
                {
                    'name': 'table',
                    'classes': True,
                    'styles': True,
                    'attributes': True
                },
                {
                    'name': 'td',
                    'classes': True,
                    'styles': True,
                    'attributes': True
                },
                {
                    'name': 'th',
                    'classes': True,
                    'styles': True,
                    'attributes': True
                },
                {
                    'name': 'p',
                    'classes': ['lead', 'lead-sm', 'lead-lg'],
                    'styles': True,
                    'attributes': True
                }
            ]
        },
        'heading': {
            'options': [
                {'model': 'paragraph', 'title': 'Paragraph', 'class': 'ck-heading_paragraph'},
                {'model': 'heading1', 'view': 'h1', 'title': 'Heading 1', 'class': 'ck-heading_heading1'},
                {'model': 'heading2', 'view': 'h2', 'title': 'Heading 2', 'class': 'ck-heading_heading2'},
                {'model': 'heading3', 'view': 'h3', 'title': 'Heading 3', 'class': 'ck-heading_heading3'},
                {'model': 'lead', 'view': {'name': 'p', 'classes': 'lead'}, 'title': 'Lead Text', 'class': 'ck-heading_lead'},
                {'model': 'leadSmall', 'view': {'name': 'p', 'classes': ['lead', 'lead-sm']}, 'title': 'Lead Text (Small)', 'class': 'ck-heading_lead-sm'},
                {'model': 'leadLarge', 'view': {'name': 'p', 'classes': ['lead', 'lead-lg']}, 'title': 'Lead Text (Large)', 'class': 'ck-heading_lead-lg'},
            ]
        }
    },
    'result_editor': {
        'toolbar': [
            'heading', '|',
            'bold', 'italic', 'underline', 'strikethrough', '|',
            'link', '|',
            'bulletedList', 'numberedList', '|',
            'outdent', 'indent', '|',
            'blockQuote', 'insertTable', '|',
            'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', '|',
            'code', 'subscript', 'superscript', 'highlight', '|',
            'removeFormat', 'sourceEditing'
        ],
        'table': {
            'contentToolbar': [
                'tableColumn', 'tableRow', 'mergeTableCells',
                'tableProperties', 'tableCellProperties'
            ],
            'tableProperties': {
                'borderColors': customColorPalette,
                'backgroundColors': customColorPalette,
                'defaultProperties': {
                    'borderStyle': 'solid',
                    'borderWidth': '1px',
                    'borderColor': 'hsl(0, 0%, 90%)',
                },
            },
            'tableCellProperties': {
                'borderColors': customColorPalette,
                'backgroundColors': customColorPalette,
            }
        },
        'htmlSupport': {
            'allow': [
                {
                    'name': 'table',
                    'classes': True,
                    'styles': True,
                    'attributes': True
                },
                {
                    'name': 'td',
                    'classes': True,
                    'styles': True,
                    'attributes': True
                },
                {
                    'name': 'th',
                    'classes': True,
                    'styles': True,
                    'attributes': True
                },
                {
                    'name': 'p',
                    'classes': ['lead', 'lead-sm', 'lead-lg'],
                    'styles': True,
                    'attributes': True
                }
            ]
        },
        'heading': {
            'options': [
                {'model': 'paragraph', 'title': 'Paragraph', 'class': 'ck-heading_paragraph'},
                {'model': 'heading1', 'view': 'h1', 'title': 'Heading 1', 'class': 'ck-heading_heading1'},
                {'model': 'heading2', 'view': 'h2', 'title': 'Heading 2', 'class': 'ck-heading_heading2'},
                {'model': 'heading3', 'view': 'h3', 'title': 'Heading 3', 'class': 'ck-heading_heading3'}
            ]
        }
    }
}
