{% extends "freeform/_layouts/settings" %}

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

{% set crumbs = [
    { label: craft.freeform.name, url: url("freeform") },
    { label: "Settings"|t("freeform"), url: url("freeform/settings") },
] %}

{% set title = "General Settings"|t("freeform") %}

{% block content %}

    <input type="hidden" name="action" value="freeform/settings/save-settings">
    {{ redirectInput('freeform/settings/general') }}
    {{ csrfInput() }}

    <h2 class="first">{{ "Control Panel"|t('freeform') }}</h2>

    {% if craft.freeform.pro %}

        {{ forms.textField({
            class: "code",
            label: "Custom Plugin Name"|t('freeform'),
            instructions: "Override the plugin name by specifying your own here."|t('freeform'),
            placeholder: craft.freeform.name,
            id: "pluginName",
            name: "settings[pluginName]",
            value: settings.pluginName,
            errors: settings.getErrors("pluginName"),
        }) }}

    {% endif %}

    {{ forms.selectField({
        label: "Default View"|t('freeform'),
        instructions: "The default page to go to when clicking the Freeform nav item."|t('freeform'),
        name: "settings[defaultView]",
        value: settings.defaultView,
        errors: settings.errors("defaultView"),
        options: {
            forms: "Forms"|t('freeform'),
            submissions: "Submissions"|t('freeform'),
        },
    }) }}

    {{ forms.selectField({
        label: "Plugin Badge"|t('freeform'),
        instructions: "Select the options you'd like to be included in the plugin badge count (when applicable)."|t('freeform'),
        name: "settings[badgeType]",
        value: settings.badgeType,
        errors: settings.errors("badgeType"),
        options: {
            '': "Don't Show"|t('freeform'),
            all: "Update Notices & Logged Errors"|t('freeform'),
            notices: "Update Notices only"|t('freeform'),
            errors: "Logged Errors only"|t('freeform'),
            submissions: "Submission Count"|t('freeform'),
            spam: "Spam Folder Count"|t('freeform'),
        },
    }) }}

    {% if craft.freeform.pro %}

        {{ forms.lightswitchField({
            label: "Site-Aware Forms"|t('freeform'),
            instructions: "When enabled, forms become aware of the currently active Site when loaded on the front end. In the control panel, you can filter form lists by Site and prevent other admins from accessing forms that belong to Sites they don't have access to. By default, any new forms created will be visible for the Site they were created on (with the ability to enable additional sites)."|t('freeform'),
            name: "settings[sitesEnabled]",
            on: settings.sitesEnabled,
            errors: settings.errors("sitesEnabled"),
            tip: "To enable translations on forms per Site, go to the form builder and enable the 'Translatable' setting under the 'Settings' tab."|t('freeform'),
        }) }}

    {% endif %}

    {{ forms.textField({
        label: "Queue Job Priority"|t('freeform'),
        instructions: "Set the queue job priority for background Freeform tasks to determine if they should run with a different priority compared to other jobs. Jobs with a lower priority are executed first."|t('freeform'),
        name: "settings[queuePriority]",
        value: settings.queuePriority,
        errors: settings.errors("queuePriority"),
        placeholder: "Leave empty to use the Craft default of 1024."|t('freeform'),
    }) }}

    {{ forms.selectField({
        label: "Logging Level"|t('freeform'),
        instructions: "Set the logging level for Freeform. 'Errors' logs only errors, 'Info' logs information about what's been processed, and 'Debug' logs all processes occurring, which is useful for setup and debugging."|t('freeform'),
        name: "settings[loggingLevel]",
        value: settings.loggingLevel,
        errors: settings.errors("loggingLevel"),
        options: {
            error: "Errors (recommended)"|t('freeform'),
            info: "Info"|t('freeform'),
            debug: "Debug"|t('freeform'),
        },
    }) }}

    <hr>

    <h2>{{ "Element Field Type"|t('freeform') }}</h2>

    {{ forms.lightswitchField({
        label: "Restrict Form options in Form Field Type to User permissions"|t('freeform'),
        instructions: "Enable this to only show forms the user or group has permissions to manage in the list of options for the Form Element Field Type (relating forms in Entries, etc)."|t('freeform'),
        name: "settings[formFieldShowOnlyAllowedForms]",
        on: settings.formFieldShowOnlyAllowedForms,
        errors: settings.errors("formFieldShowOnlyAllowedForms"),
    }) }}

    <hr>

    <h2>{{ "Exporting"|t('freeform') }}</h2>

    {{ forms.lightswitchField({
        label: "Remove Newlines from Textareas for Exporting"|t('freeform'),
        instructions: "Enable this to have newlines removed from Textarea fields in submissions when exporting."|t('freeform'),
        name: "settings[removeNewlines]",
        on: settings.removeNewlines,
        errors: settings.errors("removeNewlines"),
    }) }}

    {{ forms.lightswitchField({
        label: "Use Option Labels when Exporting"|t('freeform'),
        instructions: "Enable this to have fields with options use the submission's option labels instead of values when exporting."|t('freeform'),
        name: "settings[exportLabels]",
        on: settings.exportLabels,
        errors: settings.errors("exportLabels"),
    }) }}

    {{ forms.lightswitchField({
        label: "Use Field Handles for Headings when Exporting"|t('freeform'),
        instructions: "Enable this to use field handles as headings instead of field labels when exporting submissions."|t('freeform'),
        name: "settings[exportHandlesAsNames]",
        on: settings.exportHandlesAsNames,
        errors: settings.errors("exportHandlesAsNames"),
    }) }}

    <hr>

    <h2>{{ "Fields"|t('freeform') }}</h2>

    {{ forms.lightswitchField({
        label: "Fill Form Values from the GET Query String"|t('freeform'),
        instructions: "Enable this to be able to fill form field values from a GET query string in URI."|t('freeform'),
        name: "settings[fillWithGet]",
        on: settings.fillWithGet,
        errors: settings.errors("fillWithGet"),
    }) }}

    {{ forms.lightswitchField({
        label: "Allow Dashes in Field Handles"|t('freeform'),
        instructions: "Enable this to be able to allow users to include dashes in field handle names in the form builder."|t('freeform'),
        warning: "Dashes in field handle names are not allowed by default. Enabling this could negatively affect other parts of Craft, especially GraphQL functionality. Use with caution and only if necessary."|t('freeform'),
        name: "settings[allowDashesInFieldHandles]",
        on: settings.allowDashesInFieldHandles,
        errors: settings.errors("allowDashesInFieldHandles"),
    }) }}

    <hr>

    <h2>{{ "Submission Data"|t('freeform') }}</h2>

    {{ forms.lightswitchField({
        label: "Enable Search Index Updating on New Submissions"|t('freeform'),
        instructions: "Enable this to have Craft update search indexes whenever a new submission is created."|t('freeform'),
        name: "settings[updateSearchIndexes]",
        on: settings.updateSearchIndexes,
        errors: settings.errors("updateSearchIndexes"),
    }) }}

    {% if craft.freeform.pro %}

        {{ forms.lightswitchField({
            label: "Automatically Purge Submission Data"|t('freeform'),
            instructions: "If you wish to have Freeform automatically purge submission data after a specified number of days, enable this setting and specify the number of days after submission date it should purge submissions."|t('freeform'),
            warning: "Enabling this and saving this settings page will result in purging feature beginning, and cannot be undone (it may not happen immediately, and may take a couple hours before the next process runs)."|t('freeform'),
            name: "purge-toggle",
            on: settings.purgableSubmissionAgeInDays,
            toggle: "purge",
            errors: settings.errors("purgableSubmissionAgeInDays"),
        }) }}

        <div id="purge" class="field {{ not settings.purgableSubmissionAgeInDays ? 'hidden' }}">
            {{ forms.selectField({
                label: "Days After Submission Date to Purge"|t('freeform'),
                instructions: "Select the number of days after submissions have been submitted for Freeform to begin automatically purging. This process will only run every hour, and only when Freeform is accessed on the front end in templates or in the control panel."|t('freeform'),
                name: "settings[purgableSubmissionAgeInDays]",
                value: settings.purgableSubmissionAgeInDays,
                errors: settings.errors("purgableSubmissionAgeInDays"),
                id: "purge-value",
                options: {
                    0: "Please select"|t("freeform"),
                    1: "1 day"|t("freeform"),
                    2: "2 days"|t("freeform"),
                    3: "3 days"|t("freeform"),
                    4: "4 days"|t("freeform"),
                    5: "5 days"|t("freeform"),
                    6: "6 days"|t("freeform"),
                    7: "7 days"|t("freeform"),
                    14: "14 days"|t("freeform"),
                    30: "30 days"|t("freeform"),
                    60: "60 days"|t("freeform"),
                    90: "90 days"|t("freeform"),
                    120: "120 days"|t("freeform"),
                    180: "180 days"|t("freeform"),
                    365: "365 days"|t("freeform"),
                }
            }) }}
        </div>

    {% endif %}

    {{ forms.lightswitchField({
        label: "Automatically Purge Unfinalized Assets"|t('freeform'),
        instructions: "Enable this to have Freeform automatically purge unfinalized asset files after a specified period of time."|t('freeform'),
        name: "settings[purgeAssets]",
        on: settings.purgeAssets,
        toggle: "purge-assets",
        errors: settings.errors("purgeAssets"),
    }) }}

    <div id="purge-assets" class="field {{ not settings.purgeAssets ? 'hidden' }}">
        {{ forms.selectField({
            label: "Time to Wait Before Purging Assets"|t('freeform'),
            instructions: "Select how long Freeform should keep unfinalized asset files before purging."|t('freeform'),
            name: "settings[purgableUnfinalizedAssetAgeInMinutes]",
            value: settings.purgableUnfinalizedAssetAgeInMinutes,
            errors: settings.getErrors("purgableUnfinalizedAssetAgeInMinutes"),
            id: "purgableUnfinalizedAssetAgeInMinutes",
            options: {
                60: "1 hour"|t("freeform"),
                120: "2 hours"|t("freeform"),
                180: "3 hours (recommended)"|t("freeform"),
                240: "4 hours"|t("freeform"),
                480: "8 hours"|t("freeform"),
                720: "12 hours"|t("freeform"),
                1440: "24 hours"|t("freeform"),
                2880: "48 hours"|t("freeform"),
                4320: "72 hours"|t("freeform"),
                10080: "1 week"|t("freeform"),
                20160: "2 weeks"|t("freeform"),
            }
        }) }}
    </div>

    <div id="logging-level-warning" class="hidden">
        {{- "A logging level of 'Info' or 'Debug' should not be used in production regularly as logs may contain sensitive data."|t('freeform') -}}
    </div>

{% endblock %}
