{% extends "sprout-base-sitemaps/_layouts/sitemaps" %}
{% import "_includes/forms" as forms %}
{% import 'sprout-base/_includes/sproutcp' as sprout %}

{% set title = "Sitemaps"|t %}

{% block contextMenu %}
    {% if craft.app.getIsMultiSite() %}
        {% if enableMultilingualSitemaps %}
            {% include "sprout-base-sitemaps/sitemaps/_sitegroupmenu" with {
                selectedSiteId: currentSite.id,
                siteIds: editableSiteIds,
                urlFormat: pluginHandle ~ "/sitemaps/{handle}"
            } %}
        {% else %}
            {% include "_elements/sitemenu" with {
                selectedSiteId: currentSite.id,
                siteIds: editableSiteIds,
                urlFormat: pluginHandle ~ "/sitemaps/{handle}"
            } %}
        {% endif %}
    {% endif %}
{% endblock %}

{% set priorityList = {
    '1.0': '1.0 ↑ Highest'|t,
    '0.9': '0.9',
    '0.8': '0.8',
    '0.7': '0.7',
    '0.6': '0.6',
    '0.5': '0.5',
    '0.4': '0.4',
    '0.3': '0.3',
    '0.2': '0.2',
    '0.1': '0.1',
    '0.0': '0.0 ↓ Lowest'|t
} %}

{% set frequencyList = {
    'always': 'Always'|t,
    'hourly': 'Hourly'|t,
    'daily': 'Daily'|t,
    'weekly': 'Weekly'|t,
    'monthly': 'Monthly'|t,
    'yearly': 'Yearly'|t,
    'never': 'Never'|t
} %}

{% block sitemapSectionTableRowHead %}

    <th style="padding-left:9px;width:30%">{{ name }} <span
            class="info">{{ "All of your " ~name~" that have unique URLs are listed here.  Enable each "~name~" you want to include in your sitemap."|t }}</span>
    </th>
    <th style="width:32%;">{{ "URL Pattern"|t }}</th>
    <th style="width:15%;">{{ "Priority"|t }} {% if loop.index == 1 %} <span
            class="info">{{ "The priority of this URL relative to other URLs on your site. Valid values range from 0.0 to 1.0. This value does not affect how your pages are compared to pages on other sites—it only lets the search engines know which pages you deem most important for the crawlers." }}</span>{% endif %}
    </th>
    <th style="width:15%;">{{ "Change Frequency"|t }} <span
            class="info">{{ "The value 'always' should be used to describe documents that change each time they are accessed. The value 'never' should be used to describe archived URLs." }}</span>
    </th>
    <th style="width:8%;text-align: center;">{{ "Enabled"|t }} {% if loop.index == 1 %}
            <span class="info">{{ "Make the content in this section appear in your sitemap."|t }}</span>{% endif %}
    </th>
    <th class="thin"></th>

{% endblock %}

{% block sitemapSectionTableRow %}

    <td>
        {% include "sprout-base-sitemaps/sitemaps/_titlecolumn" with {
            sitemapSection: sitemapSection
        } %}
    </td>
    <td>
        {% if sitemapSection.uri == '__home__' %}
            <span data-icon="home" title="Homepage"></span>
        {% else %}
            {% if craft.sproutSitemap.uriHasTags(sitemapSection.uri) %}
                <code>
                    {{ "Dynamic URL"|t('sprout-base-sitemaps') }}
                    <span class="info">
                        <h6>{{ "Dynamic URL details"|t('sprout-base-sitemaps') }}</h6>
                        <p>{{ sitemapSection.uri }}</p>
                    </span>
                </code>
            {% else %}
                <code>{{ sitemapSection.uri }}</code>
            {% endif %}

        {% endif %}

        <input type="hidden"
               name="sproutseo[sections][{{ urlEnabledSectionKey }}][uri]"
               value="{{ sitemapSection.uri }}">
    </td>
    <td>
        {{ forms.selectField({
            name: 'sproutseo[sections][' ~ urlEnabledSectionKey ~ '][priority]',
            options: priorityList,
            value: sitemapSection.priority ?? 0.5,
            errors: "",
            required: false
        }) }}
    </td>
    <td>
        {{ forms.selectField({
            name: 'sproutseo[sections][' ~ urlEnabledSectionKey ~ '][changeFrequency]',
            options: frequencyList,
            value: sitemapSection.changeFrequency ?? 'weekly',
            errors: "",
            required: false
        }) }}
    </td>
    <td style="text-align: center;">
        {{ forms.lightswitch({
            name: 'sproutseo[sections][' ~ urlEnabledSectionKey ~ '][enabled]',
            on: sitemapSection.enabled == 1 ?? false
        }) }}
    </td>
    <td>
        {# @todo - Refactor
        Find a better way to get the columns to be even. This tag is unnecessary
        aside from helping to style the table column widths evenly. #}
        <span style="display: inline-block;width:13px;"></span>
    </td>

{% endblock %}

{% block customSectionTableRowHead %}

    <th colspan="2" style="padding-left:9px;width:62%">{{ "Custom URL"|t }}
        <span
            class="info">{{ "A Custom Page allows you to add a Custom URL that will display in your sitemap when enabled."|t }}</span>
    </th>
    <th style="width:15%;">{{ "Priority"|t }}</th>
    <th style="width:15%;">{{ "Change Frequency"|t }}</th>
    <th style="width:8%;text-align: center;">{{ "Enabled"|t }}</th>
    <th class="thin"></th>

{% endblock %}

{% block customSectionTableRow %}

    <td colspan="2">
        {% include "sprout-base-sitemaps/sitemaps/_titlecolumn" with {
            sitemapSection: customSection,
            isCustom: true
        } %}

        <input type="hidden"
               name="sproutseo[sections][{{ customSectionId }}][id]"
               value="{{ customSectionId }}">
        <input type="hidden"
               name="sproutseo[sections][{{ customSectionId }}][uri]"
               value="{{ customSection.uri }}">
    </td>
    <td>
        {{ forms.selectField({
            name: 'sproutseo[sections][' ~ customSectionId ~ '][priority]',
            options: priorityList,
            value: customSection.priority ?? 0.5,
            errors: "",
            required: false
        }) }}
    </td>
    <td>
        {{ forms.selectField({
            name: 'sproutseo[sections][' ~ customSectionId ~ '][changeFrequency]',
            options: frequencyList,
            value: customSection.changeFrequency ?? 'weekly',
            errors: "",
            required: false
        }) }}
    </td>
    <td style="text-align: center;">
        {{ forms.lightswitch({
            name: 'sproutseo[sections][' ~ customSectionId ~ '][enabled]',
            on: customSection.enabled == 1 ?? false
        }) }}
    </td>
    <td>
        <a class="delete icon" title="Delete"></a>
    </td>

{% endblock %}

{% js %}
    new Craft.SproutSeo.Sitemap();
{% endjs %}