# -*- coding: utf-8 -*-
import copy
import os
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

sentry_sdk.init(
    dsn="https://460e310d034c49a794941e087c4fcc6e@o74423.ingest.sentry.io/1196285",
    integrations=[DjangoIntegration()],

    # If you wish to associate users to errors (assuming you are using
    # django.contrib.auth) you may enable sending PII data.
    send_default_pii=True
)

INSTALLED_ADDONS = [
    # <INSTALLED_ADDONS>  # Warning: text inside the INSTALLED_ADDONS tags is auto-generated. Manual changes will be overwritten.
    'aldryn-addons',
    'aldryn-django',
    'aldryn-sso',
    'aldryn-django-cms',
    'aldryn-forms',
    'aldryn-haystack',
    'djangocms-history',
    'djangocms-link',
    'djangocms-page-meta',
    'djangocms-picture',
    'djangocms-text-ckeditor',
    'django-filer',
    # </INSTALLED_ADDONS>
]

import aldryn_addons.settings

aldryn_addons.settings.load(locals())

# all django settings can be altered here

INSTALLED_APPS.insert(0, 'admin_view_permission')
INSTALLED_APPS.extend([
    'snowpenguin.django.recaptcha2',
    'portal',
    'project',
    'fontawesome',
    'aldryn_search',
    'image_cropping',
])

LOGIN_REDIRECT_URL = 'login_redirect'

MIDDLEWARE_CLASSES.extend([
    # add your own middlewares here
])

TEMPLATES[0]['OPTIONS']['context_processors'] += [
    'project.context_processors.search_form',
    'project.context_processors.notification',
    'project.context_processors.new_page_amount',
]

THUMBNAIL_PROCESSORS = ('image_cropping.thumbnail_processors.crop_corners',) + THUMBNAIL_PROCESSORS

MAILCHIMP_USERNAME = 'anja.petersen@tagesschule-elementa.ch'
MAILCHIMP_API_KEY = 'd767408719ce5cdd72ea2c9c2e593533-us12'
MAILCHIMP_LIST_ID = 'da4143acda'

META_USE_TITLE_TAG = True
META_USE_OG_PROPERTIES = True
META_USE_TWITTER_PROPERTIES = True

# ALDRYN_SEARCH_DEFAULT_LANGUAGE = 'de'
ALDRYN_SEARCH_INDEX_BASE_CLASS = 'project.search.SearchIndex'

ALDRYN_SEARCH_EXCLUDED_PLUGINS = [
    'NewsletterSubscriptionPlugin', 'NewsletterArchivePlugin'
]

HAYSTACK_CUSTOM_HIGHLIGHTER = 'project.search.Highlighter'
HAYSTACK_DEFAULT_OPERATOR = 'OR'

if DEFAULT_HAYSTACK_URL and os.getenv('DJANGO_MODE') != 'build':
    from aldryn_haystack import haystack_url

    HAYSTACK_CONNECTIONS = haystack_url.parse_i18n(
        url=DEFAULT_HAYSTACK_URL,
        language_codes=[lang[0] for lang in LANGUAGES],
        default_language_code=LANGUAGE_CODE,
    )

    HAYSTACK_ROUTERS = ['aldryn_search.router.LanguageRouter']

CMS_TEMPLATE_INHERITANCE = False

CMS_TEMPLATES = (
    ('project/content.html', 'Content'),
    ('project/list.html', 'Liste'),
    ('project/contact.html', 'Kontakt'),
    ('project/timetable.html', 'Zeitplan'),
)

CMS_PLACEHOLDER_CONF = {
    None: {
        'plugins': ['SectionPlugin'],
    },
    'contact': {
        'plugins': ['SectionTextPlugin', 'ContactFormButtonPlugin', 'JourneyCalculatorPlugin'],
    },
    'timetable': {
        'plugins': ['TimetablePlugin'],
    },
    'social_media': {
        'name': 'Social Media',
        'plugins': ['SocialMediaListPlugin'],
        'limits': {
            'global': 1,
        },
    },
    'portal_intro': {
        'name': 'Portal Intro',
        'plugins': ['IntroImagePlugin'],
        'limits': {
            'global': 1,
        },
    },
}

CMS_PLUGIN_CACHE = False

CKEDITOR_SETTINGS.update({
    'autoParagraph': False,
    'format_tags': 'p',
    'contentsCss': ['/static/css/main.css'],
    'forcePasteAsPlainText': True,
    'bodyId': 'admin_editor',
    'enterMode': 2,
    'shiftEnterMode': 2,
    'forceEnterMode': True,
    'toolbarLocation': 'bottom',
    'removePlugins': 'contextmenu,liststyle,tabletools',
    'keystrokes': [
        [1114188, None],  # Link
        [2228345, None],
        [3342457, None],
    ],
    'bodyClass': 'section__text',
    'toolbar_CMS': [
        ['Undo', 'Redo', '-', 'Bold', 'Italic', 'Underline', '-', 'RemoveFormat', '-', 'cmsplugins']
    ],
})

CKEDITOR_SETTINGS_BASE = copy.deepcopy(CKEDITOR_SETTINGS)
CKEDITOR_SETTINGS_BASE.update({
    'autoGrow_onStartup': True,
    'autoGrow_minHeight': 100,
    'autoGrow_maxHeight': 650,
    'extraPlugins': 'autogrow',
    'bodyClass': '',
})

CKEDITOR_SETTINGS_INPUT = copy.deepcopy(CKEDITOR_SETTINGS_BASE)
CKEDITOR_SETTINGS_INPUT.update({
    'keystrokes': [
        [1114188, None],  # Link
        [1114178, None],  # Bold
        [1114185, None],  # Italic
        [1114197, None],  # Unterline
        [2228345, None],
        [3342457, None],
    ],
    'toolbar_HTMLField': [
        ['Undo', 'Redo'],
    ],
    'bodyClass': 'section__text',
    'height': 100,
})

CKEDITOR_SETTINGS_SECTION_TITLE = copy.deepcopy(CKEDITOR_SETTINGS_INPUT)
CKEDITOR_SETTINGS_SECTION_TITLE['bodyClass'] = 'h2'

CKEDITOR_SETTINGS_SLIDER_TITLE = copy.deepcopy(CKEDITOR_SETTINGS_INPUT)
CKEDITOR_SETTINGS_SLIDER_TITLE['bodyClass'] = 'slider__text__item__title'

CKEDITOR_SETTINGS_SLIDER_TEXT = copy.deepcopy(CKEDITOR_SETTINGS_INPUT)
CKEDITOR_SETTINGS_SLIDER_TEXT['bodyClass'] = 'slider__text__item__text'

CKEDITOR_SETTINGS_TEXT_SLIDER_TEXT = copy.deepcopy(CKEDITOR_SETTINGS_INPUT)
CKEDITOR_SETTINGS_TEXT_SLIDER_TEXT['bodyClass'] = 'text_slider__text'

CKEDITOR_SETTINGS_QUOTE_CONTENT = copy.deepcopy(CKEDITOR_SETTINGS_INPUT)
CKEDITOR_SETTINGS_QUOTE_CONTENT['bodyClass'] = 'quote__content'

CKEDITOR_SETTINGS_QUOTE_SOURCE = copy.deepcopy(CKEDITOR_SETTINGS_INPUT)
CKEDITOR_SETTINGS_QUOTE_SOURCE['bodyClass'] = 'quote__source'

CKEDITOR_SETTINGS_HIGHLIGHT_LIST_ITEM_TITLE = copy.deepcopy(CKEDITOR_SETTINGS_INPUT)
CKEDITOR_SETTINGS_HIGHLIGHT_LIST_ITEM_TITLE['bodyClass'] = 'highlight_list__item__title'

CKEDITOR_SETTINGS_HIGHLIGHT_LIST_ITEM_TEXT = copy.deepcopy(CKEDITOR_SETTINGS_INPUT)
CKEDITOR_SETTINGS_HIGHLIGHT_LIST_ITEM_TEXT['bodyClass'] = 'highlight_list__item__text'

CKEDITOR_SETTINGS_TIMETABLE_ITEM_TITLE = copy.deepcopy(CKEDITOR_SETTINGS_INPUT)
CKEDITOR_SETTINGS_TIMETABLE_ITEM_TITLE['bodyClass'] = 'h2 timetable__item__title'

CKEDITOR_SETTINGS_TIMETABLE_ITEM_TEXT = copy.deepcopy(CKEDITOR_SETTINGS_INPUT)
CKEDITOR_SETTINGS_TIMETABLE_ITEM_TEXT['bodyClass'] = 'section__text timetable__item__text'

DEFAULT_FROM_EMAIL = 'web@tagesschule-elementa.ch'

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.office365.com'
EMAIL_HOST_USER = DEFAULT_FROM_EMAIL
EMAIL_HOST_PASSWORD = 'TagesschuleElementa1234'
EMAIL_PORT = 587

FILER_ENABLE_PERMISSIONS = True

try:
    DEFAULT_STORAGE_DSN
except NameError:
    DEFAULT_PRIVATE_STORAGE = DEFAULT_FILE_STORAGE
else:
    DEFAULT_PRIVATE_STORAGE = 'portal.storage.PrivateS3MediaStorage'

FILER_STORAGES = {
    'private': {
        'main': {
            'ENGINE': DEFAULT_PRIVATE_STORAGE,
            'OPTIONS': {
                'base_url': '/smedia/filer/',
            },
        },
        'thumbnails': {
            'ENGINE': DEFAULT_PRIVATE_STORAGE,
            'OPTIONS': {
                'base_url': '/smedia/filer_thumbnails/',
            },
        },
    },
}

if not DEBUG:
    SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
    SECURE_CONTENT_TYPE_NOSNIFF = True
    SECURE_BROWSER_XSS_FILTER = True
    # SECURE_SSL_REDIRECT = True
    SESSION_COOKIE_SECURE = True
    SESSION_COOKIE_HTTPONLY = True
    CSRF_COOKIE_SECURE = True

    ALLOWED_HOSTS = [
        '127.0.0.1',
        '127.0.0.1:8000',
        'localhost',
        'localhost:8000',
        'tagesschule-elementa.ch',
        'www.tagesschule-elementa.ch',
        'tagesschule.mprofiag.ch',
        'docker.mprofiag.de'
    ]

DATA_UPLOAD_MAX_MEMORY_SIZE = 1024 * 1024 * 1024

RECAPTCHA_PUBLIC_KEY = '6LeILd0ZAAAAAB9xO_y8kS292wv2ikl0M8s7zFn9'
RECAPTCHA_PRIVATE_KEY = '6LeILd0ZAAAAAOGF1AvxdiGcXWLjr2BzHaQ8Zush'

RECAPTCHA_SCORE_THRESHOLD = 0.5
