{% extends 'formie/_layouts/settings' %}

{% import '_includes/forms' as forms %}
{% import 'verbb-base/_macros' as macros %}

{% block content %}

{% set formTemplateOptions = [{  }] %}
{% for template in formTemplates %}
    {% set formTemplateOptions = formTemplateOptions | merge([
        { label: template.name, value: template.id },
    ]) %}
{% endfor %}

<h2>{{ 'Forms' | t('formie') }}</h2>

<form action="" method="post" accept-charset="UTF-8" data-saveshortcut>
    <input type="hidden" name="action" value="formie/settings/save-settings">
    {{ redirectInput('formie/settings/forms') }}
    {{ csrfInput() }}

    {% namespace 'settings' %}
        {{ forms.selectField({
            first: true,
            label: 'Default Form Template' | t('formie'),
            instructions: 'Select a Form Template to be used as the default for all new forms.' | t('formie'),
            name: 'defaultFormTemplate',
            value: settings.defaultFormTemplate,
            errors: settings.getErrors('defaultFormTemplate'),
            warning: macros.configWarning('defaultFormTemplate', 'formie'),
            options: [{
                label: 'Default Formie Template' | t('formie'),
                value: '',
            }] | merge(craft.formie.templates | map(template => {
                label: template.name,
                value: template.handle,
            })),
        }) }}

        {{ forms.selectField({
            label: 'Default Email Template' | t('formie'),
            instructions: 'Select an Email Template to be used as the default for all new forms.' | t('formie'),
            name: 'defaultEmailTemplate',
            value: settings.defaultEmailTemplate,
            errors: settings.getErrors('defaultEmailTemplate'),
            warning: macros.configWarning('defaultEmailTemplate', 'formie'),
            options: [{
                label: 'Default Formie Template' | t('formie'),
                value: '',
            }] | merge(craft.formie.emailTemplates | map(template => {
                label: template.name,
                value: template.handle,
            })),
        }) }}

        {{ forms.lightswitchField({
            label: 'Enable Unload Warning' | t('formie'),
            instructions: 'Whether front-end forms should trigger an "unload" warning when a form‘s content has changed and the user tries to navigate away without submitting.' | t('formie'),
            name: 'enableUnloadWarning',
            on: settings.enableUnloadWarning,
            errors: settings.getErrors('enableUnloadWarning'),
            warning: macros.configWarning('enableUnloadWarning', 'formie'),
        }) }}

        {{ forms.lightswitchField({
            label: 'Enable Back Submission' | t('formie'),
            instructions: 'Whether clicking the "Back" button on front-end forms should submit the current page content. Disabling this will show an "unload" warning and discard any un-saved content.' | t('formie'),
            name: 'enableBackSubmission',
            on: settings.enableBackSubmission,
            errors: settings.getErrors('enableBackSubmission'),
            warning: macros.configWarning('enableBackSubmission', 'formie'),
        }) }}

        {{ forms.textField({
            label: 'Ajax Submission Timeout' | t('formie'),
            instructions: 'Set the number of seconds to set the timeout for Ajax-based forms. This should only be adjusted for forms where a large timeout is expected, such as heavy use of file upload fields. This is also only applicable when using the Theme JS. Default to 10 seconds.' | t('formie'),
            name: 'ajaxTimeout',
            size: 4,
            placeholder: 10,
            value: settings.ajaxTimeout,
            errors: settings.getErrors('ajaxTimeout'),
            warning: macros.configWarning('ajaxTimeout', 'formie'),
        }) }}

        <hr>

        <h3>{{ 'Form Usage' | t('formie') }}</h3>

        {{ forms.lightswitchField({
            label: 'Include Draft Elements' | t('formie'),
            instructions: 'Whether the "Usage" tab in the form builder should include draft elements.' | t('formie'),
            name: 'includeDraftElementUsage',
            on: settings.includeDraftElementUsage,
            errors: settings.getErrors('includeDraftElementUsage'),
            warning: macros.configWarning('includeDraftElementUsage', 'formie'),
        }) }}

        {{ forms.lightswitchField({
            label: 'Include Revision Elements' | t('formie'),
            instructions: 'Whether the "Usage" tab in the form builder should include revision elements.' | t('formie'),
            name: 'includeRevisionElementUsage',
            on: settings.includeRevisionElementUsage,
            errors: settings.getErrors('includeRevisionElementUsage'),
            warning: macros.configWarning('includeRevisionElementUsage', 'formie'),
        }) }}
    {% endnamespace %}

    <hr>

    <input type="submit" class="btn submit" value="{{ 'Save' | t('formie') }}">
</form>

{% endblock %}
