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

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

{% set segment3 = craft.app.request.getSegment(3) %}

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

{% set title = "Notices & Alerts"|t("freeform") %}

{% block content %}

    {{ parent() }}

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

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

    {{ forms.booleanMenuField({
        includeEnvVars: true,
        label: "Display Update Warnings & Notices"|t('freeform'),
        instructions: "Freeform will detect if any important updates, notices or warnings are available for this site specifically, and display them on the dashboard. Examples of this might be expiring API integrations and fixes to bugs that likely affect your current site. We respect your privacy, and this information cannot and never will make it to Solspace.com servers. The checks only happen locally here on your site after automatically downloading a generic JSON file from Solspace.com."|t('freeform'),
        name: "settings[displayFeed]",
        value: settings.displayFeed,
        errors: settings.getErrors("displayFeed"),
        disabled: readOnly,
    }) }}

    {% if freeform.edition.isAtLeast('lite') %}

        <hr />

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

        {{ forms.textField({
            class: "code",
            label: "Send Email Alerts for Failed Notifications"|t('freeform'),
            instructions: "Send an email notification alerting the email address(es) below when an email notification cannot be delivered."|t('freeform'),
            placeholder: "e.g john@smith.com, bethany@corporation.com",
            name: "settings[alertNotificationRecipients]",
            value: settings.alertNotificationRecipients,
            errors: settings.getErrors("alertNotificationRecipients"),
            disabled: readOnly,
        }) }}

        {{ forms.textField({
            class: "code",
            label: "Critical System Error Report Recipients"|t('freeform'),
            instructions: "Provide one or more comma-separated email addresses that should receive critical error reports."|t('freeform'),
            placeholder: "e.g john@smith.com, bethany@corporation.com",
            name: "settings[errorNotificationRecipients]",
            value: settings.errorNotificationRecipients,
            errors: settings.getErrors("errorNotificationRecipients"),
            disabled: readOnly,
        }) }}

        <hr>

        <h2>{{ "Digest Email Notifications"|t('freeform') }}</h2>

        {{ forms.textField({
            class: "code",
            label: "Developer Digest Email"|t('freeform'),
            instructions: "Send weekly or daily emails on the day specified (if using 'Weekly') to the email address(es) below. This will include a snapshot of the previous period's performance and any logged errors and upgrade notices."|t('freeform'),
            placeholder: "e.g john@smith.com, bethany@corporation.com",
            name: "settings[digestRecipients]",
            value: settings.digestRecipients,
            errors: settings.getErrors("digestRecipients"),
            disabled: readOnly,
        }) }}

        {{ forms.selectField({
            label: "Developer Digest Email Frequency"|t('freeform'),
            instructions: "Specify how often and which days (if applicable) you'd like to receive the email notifications. The chosen date will attempt to send a notification in the morning from the period before that date."|t('freeform'),
            name: "settings[digestFrequency]",
            value: settings.digestFrequency,
            errors: settings.errors("digestFrequency"),
            disabled: readOnly,
            options: {
                "-1": "Daily" | t('freeform'),
                "0": "Weekly on Sundays" | t('freeform'),
                "1": "Weekly on Mondays" | t('freeform'),
                "2": "Weekly on Tuesdays" | t('freeform'),
                "3": "Weekly on Wednesdays" | t('freeform'),
                "4": "Weekly on Thursdays" | t('freeform'),
                "5": "Weekly on Fridays" | t('freeform'),
                "6": "Weekly on Saturdays" | t('freeform'),
            },
        }) }}

        {{ forms.textField({
            class: "code",
            label: "Stats Digest Email"|t('freeform'),
            instructions: "Send weekly or daily emails on the day specified (if using 'Weekly') to the email address(es) below. This is the same as the Developer one above, but only includes a snapshot of the previous period's performance."|t('freeform'),
            placeholder: "e.g john@smith.com, bethany@corporation.com",
            name: "settings[clientDigestRecipients]",
            value: settings.clientDigestRecipients,
            errors: settings.getErrors("clientDigestRecipients"),
            disabled: readOnly,
        }) }}

        {{ forms.selectField({
            label: "Stats Digest Email Frequency"|t('freeform'),
            instructions: "Specify how often and which days (if applicable) you'd like to receive the email notifications. The chosen date will attempt to send a notification in the morning from the period before that date."|t('freeform'),
            name: "settings[clientDigestFrequency]",
            value: settings.clientDigestFrequency,
            errors: settings.errors("clientDigestFrequency"),
            disabled: readOnly,
            options: {
                "-1": "Daily" | t('freeform'),
                "0": "Weekly on Sundays" | t('freeform'),
                "1": "Weekly on Mondays" | t('freeform'),
                "2": "Weekly on Tuesdays" | t('freeform'),
                "3": "Weekly on Wednesdays" | t('freeform'),
                "4": "Weekly on Thursdays" | t('freeform'),
                "5": "Weekly on Fridays" | t('freeform'),
                "6": "Weekly on Saturdays" | t('freeform'),
            },
        }) }}

        {{ forms.booleanMenuField({
            includeEnvVars: true,
            label: "Send Notifications on Live Environment only"|t('freeform'),
            instructions: "If this setting is enabled, Freeform will only send out Digest emails when the Craft environment is set to production."|t('freeform'),
            name: "settings[digestOnlyOnProduction]",
            value: settings.digestOnlyOnProduction,
            errors: settings.getErrors("digestOnlyOnProduction"),
            disabled: readOnly,
        }) }}

    {% endif %}

{% endblock %}
