{% import "_includes/forms" as forms %}

{% macro configWarning(setting) -%}
    {% set setting = '<code>'~setting~'</code>' %}
    {{ "This is being overridden by the {setting} config setting in your {file} config file."|t('contact-form-extensions', {
        setting: setting,
        file: 'contact-form-extensions.php'
    })|raw }}
{%- endmacro %}

{% from _self import configWarning %}

<div id="tab-settings">
    {{ forms.lightswitchField({
        label: 'Save submissions to the database',
        instructions: 'Save the submissions to the database so they can be viewed in the control panel',
        id: 'enableDatabase',
        name: 'enableDatabase',
        disabled:     'enableDatabase' in overrides,
        warning:      'enableDatabase' in overrides ? configWarning('enableDatabase'),
        on: settings.enableDatabase == true
    }) }}

    {{ forms.lightswitchField({
        label: 'Send confirmation email',
        instructions: 'Sends a confirmation email to the person who filled in the contact form, a `fromEmail` field is required.',
        id: 'enableConfirmationEmail',
        name: 'enableConfirmationEmail',
        disabled:     'enableConfirmationEmail' in overrides,
        warning:      'enableConfirmationEmail' in overrides ? configWarning('enableConfirmationEmail'),
        on: settings.enableConfirmationEmail,
        toggle: "confirmationTemplate"
    }) }}

    <div id="confirmationTemplate" class="hidden" style="margin-bottom: 20px;">
        {{ forms.textField({
            label: 'Set the template for the confirmation email',
            instructions: 'The template will receive a `submission` variable',
            id: 'confirmationTemplate',
            name: 'confirmationTemplate',
            required: true,
            errors: settings.getErrors('confirmationTemplate'),
            disabled:     'confirmationTemplate' in overrides,
            warning:      'confirmationTemplate' in overrides ? configWarning('confirmationTemplate'),
            value: settings.confirmationTemplate,
        }) }}

        {{ forms.textField({
            label: 'Confirmation Subject',
            instructions: 'The subject for the confirmation email',
            id: 'confirmationSubject',
            name: 'confirmationSubject',
            required: true,
            errors: settings.getErrors('confirmationSubject'),
            disabled:     'confirmationSubject' in overrides,
            warning:      'confirmationSubject' in overrides ? configWarning('confirmationSubject'),
            value: settings.getConfirmationSubject,
        }) }}
    </div>

    {{ forms.lightswitchField({
        label: 'Overwrite the e-mail template',
        instructions: 'Overwrite the templates for the emails that are sent.',
        id: 'enableTemplateOverwrite',
        name: 'enableTemplateOverwrite',
        disabled:     'enableTemplateOverwrite' in overrides,
        warning:      'enableTemplateOverwrite' in overrides ? configWarning('enableTemplateOverwrite'),
        on: settings.enableTemplateOverwrite,
        toggle: "templateSettings"
    }) }}

    <div id="templateSettings" class="hidden">
        {{ forms.textField({
            label: 'Set a template for the notification email',
            instructions: 'The template will receive a `submission` variable',
            id: 'notificationTemplate',
            name: 'notificationTemplate',
            required: true,
            errors: settings.getErrors('notificationTemplate'),
            disabled:     'notificationTemplate' in overrides,
            warning:      'notificationTemplate' in overrides ? configWarning('notificationTemplate'),
            value: settings.notificationTemplate,
        }) }}
    </div>
</div>
<div id="tab-recaptcha" class="hidden">
    {{ forms.lightswitchField({
        label: 'Enable Invisible reCAPTCHA',
        instructions: 'Make sure to render the captcha with `{{ craft.contactFormExtensions.recaptcha | raw }}` in your forms.',
        id: 'recaptcha',
        name: 'recaptcha',
        disabled:     'recaptcha' in overrides,
        warning:      'recaptcha' in overrides ? configWarning('recaptcha'),
        on: settings.recaptcha == true,
        toggle: "recaptchaSettings"
    }) }}

    <div id="recaptchaSettings" {% if not settings.recaptcha %}class="hidden"{% endif %}>
        {{ forms.selectField({
            label: 'reCAPTCHA version',
            instructions: 'reCAPTCHA v2 (challenge) or v3 (score)',
            id: 'recaptchaVersion',
            name: 'recaptchaVersion',
            options: [
                {label: 'V2', value: null},
                {label: 'V3', value: '3'},
            ],
            value: settings.recaptchaVersion,
            toggle: true,
            targetPrefix: 'version-',
            disabled:     'recaptchaVersion' in overrides,
            warning:      'recaptchaVersion' in overrides ? configWarning('recaptchaVersion'),
        }) }}

        {{ forms.lightswitchField({
            label: 'Override reCAPTCHA URLs',
            instructions: 'Override the urls used for the reCAPTCHA API and Verification API',
            id: 'enableRecaptchaOverride',
            name: 'enableRecaptchaOverride',
            disabled:     'enableRecaptchaOverride' in overrides,
            warning:      'enableRecaptchaOverride' in overrides ? configWarning('enableRecaptchaOverride'),
            on: settings.enableRecaptchaOverride,
            toggle: "recaptchaUrlSettings"
        }) }}

        <div id="recaptchaUrlSettings" class="hidden" style="margin-bottom: 20px;">
            {{ forms.autosuggestField({
                label: 'reCAPTCHA URL',
                instructions: 'This will override the reCAPTCHA API URL',
                id: 'recaptchaUrl',
                name: 'recaptchaUrl',
                required: true,
                errors: settings.getErrors('recaptchaUrl'),
                disabled:     'recaptchaUrl' in overrides,
                warning:      'recaptchaUrl' in overrides ? configWarning('recaptchaUrl'),
                value: settings.recaptchaUrl,
                suggestEnvVars: true,
            }) }}

            {{ forms.autosuggestField({
                label: 'reCAPTCHA Verification URL',
                instructions: 'This will override the reCAPTCHA API Verification URL',
                id: 'recaptchaVerificationUrl',
                name: 'recaptchaVerificationUrl',
                required: true,
                errors: settings.getErrors('recaptchaVerificationUrl'),
                disabled:     'recaptchaVerificationUrl' in overrides,
                warning:      'recaptchaVerificationUrl' in overrides ? configWarning('recaptchaVerificationUrl'),
                value: settings.recaptchaVerificationUrl,
                suggestEnvVars: true,
            }) }}
        </div>

        {{ forms.autosuggestField({
            label: 'Site Key',
            instructions: 'reCAPTCHA Site Key',
            id: 'recaptchaSiteKey',
            name: 'recaptchaSiteKey',
            required: true,
            errors: settings.getErrors('recaptchaSiteKey'),
            disabled:     'recaptchaSiteKey' in overrides,
            warning:      'recaptchaSiteKey' in overrides ? configWarning('recaptchaSiteKey'),
            value: settings.recaptchaSiteKey,
            suggestEnvVars: true,
        }) }}

        {{ forms.autosuggestField({
            label: 'Secret Key',
            instructions: 'reCAPTCHA Secret Key',
            id: 'recaptchaSecretKey',
            name: 'recaptchaSecretKey',
            required: true,
            errors: settings.getErrors('recaptchaSecretKey'),
            disabled:     'recaptchaSecretKey' in overrides,
            warning:      'recaptchaSecretKey' in overrides ? configWarning('recaptchaSecretKey'),
            value: settings.recaptchaSecretKey,
            suggestEnvVars: true,
        }) }}

        {{ forms.textField({
            label: 'Timeout',
            instructions: 'How long before the reCAPTCHA session times out.',
            id: 'recaptchaTimeout',
            name: 'recaptchaTimeout',
            type: 'number',
            disabled:     'recaptchaTimeout' in overrides,
            warning:      'recaptchaTimeout' in overrides ? configWarning('recaptchaTimeout'),
            value: settings.recaptchaTimeout,
        }) }}

        {{ forms.lightswitchField({
            label: 'Hide Badge',
            instructions: 'Hide the reCAPTCHA badge. Make sure to inform your users in a different way that you\'re [using the reCAPTCHA service](https://stackoverflow.com/questions/44543157/how-to-hide-the-google-invisible-recaptcha-badge/44543771#44543771)',
            id: 'recaptchaHideBadge',
            name: 'recaptchaHideBadge',
            disabled:     'recaptchaHideBadge' in overrides,
            warning:      'recaptchaHideBadge' in overrides ? configWarning('recaptchaHideBadge'),
            on: settings.recaptchaHideBadge == true,
        }) }}

        <div id="version-3" class="{{ settings.recaptchaVersion == '3' ? '' : 'hidden' }}">
            {{ forms.textField({
                label: 'Threshold',
                instructions: 'reCAPTCHA v3 returns a score (1.0 is very likely a good interaction, 0.0 is very likely a bot). Based on the score, you can take variable action in the context of your site.',
                id: 'recaptchaThreshold',
                name: 'recaptchaThreshold',
                disabled: 'recaptchaThreshold' in overrides,
                warning: 'recaptchaThreshold' in overrides ? configWarning('recaptchaThreshold'),
                type: 'number',
                value: settings.recaptchaThreshold,
                placeholder: 'A number between 0 and 1',
            }) }}
        </div>

        <div id="version-" class="{{ settings.recaptchaVersion == '' ? '' : 'hidden' }}">
            {{ forms.selectField({
                label: 'Badge position',
                instructions: 'Reposition the reCAPTCHA badge. "inline" allows you to control the CSS.',
                id: 'recaptchaDataBadge',
                name: 'recaptchaDataBadge',
                options: [
                    {label: 'Bottom Right', value: 'bottomright'},
                    {label: 'Bottom Left', value: 'bottomleft'},
                    {label: 'Inline', value: 'inline'},
                ],
                value: settings.recaptchaDataBadge,
                disabled:     'recaptchaDataBadge' in overrides,
                warning:      'recaptchaDataBadge' in overrides ? configWarning('recaptchaDataBadge'),
            }) }}

            {{ forms.lightswitchField({
                label: 'Debug',
                instructions: 'Enable the reCAPTCHA debug mode.',
                id: 'recaptchaDebug',
                name: 'recaptchaDebug',
                disabled:     'recaptchaDebug' in overrides,
                warning:      'recaptchaDebug' in overrides ? configWarning('recaptchaDebug'),
                on: settings.recaptchaDebug == true,
            }) }}
        </div>





    </div>
</div>
