{%- set separator = config.extra.separator | default(value="•") -%}

{%- set rel_attributes = macros_rel_attributes::rel_attributes() | trim -%}

{%- if config.markdown.external_links_target_blank -%}
    {%- set blank_target = "target=_blank" -%}
{%- else -%}
    {%- set blank_target = "" -%}
{%- endif -%}

<footer>
    <section>
        <nav class="socials nav-navs">
            {%- if config.extra.socials %}
                <ul>
                    {%- if config.generate_feed and config.extra.feed_icon -%}
                    <li>
                        <a class="nav-links no-hover-padding social" rel="{{ rel_attributes }}" {{ blank_target }} href={{ get_url(path=config.feed_filename, lang=lang, trailing_slash=false) | safe }}>
                        <img alt="feed" title="feed" src="{{ get_url(path='/social_icons/rss.svg') }}">
                        </a>
                    </li>
                    {%- endif -%}

                    {# Mail icon #}
                    {%- if config.extra.email -%}
                        {%- set email_already_encoded = (config.extra.email is not containing("@")) -%}
                        {%- set email_needs_decoding = email_already_encoded or config.extra.encode_plaintext_email -%}

                        {%- if email_already_encoded -%}
                            {%- set encoded_email = config.extra.email -%}
                            {# Verify the pre-encoded e-mail is valid (i.e. contains an '@') #}
                            {%- set decoded_email = encoded_email | base64_decode -%}
                            {%- if '@' not in decoded_email -%}
                                {{ throw(message="ERROR: The provided e-mail appears to be base64-encoded, but does not decode to a valid e-mail address.")}}
                            {%- endif -%}
                        {%- elif config.extra.encode_plaintext_email -%}
                            {%- set encoded_email = config.extra.email | base64_encode -%}
                        {%- endif -%}

                        <li class="{% if email_needs_decoding %}js{% endif %}">
                            {%- if email_needs_decoding -%}
                                <a class="nav-links no-hover-padding social" href="#" data-encoded-email="{{ encoded_email | safe }}">
                            {%- else -%}
                                <a class="nav-links no-hover-padding social" href="mailto:{{ config.extra.email | safe }}">
                            {%- endif -%}
                                <img alt="email" title="email" src="{{ get_url(path='social_icons/email.svg') }}">
                            </a>
                        </li>
                    {%- endif -%}

                    {% for social in config.extra.socials %}
                        <li>
                            <a class="nav-links no-hover-padding social" rel="{{ rel_attributes }} me" {{ blank_target }} href={{ social.url | safe }}>
                                <img alt={{ social.name }} title={{ social.name }} src="{{ get_url(path='social_icons/' ~ social.icon ~ '.svg') }}">
                            </a>
                        </li>
                    {% endfor %}
                </ul>
            {% endif %}
        </nav>
        <div class="credits">
            <small>
                {# Shows optional Copyright notice #}
                {%- if config.extra.copyright -%}
                    {% set current_year = now() | date(format="%Y") %}
                    {# Translate the copyright if set in the config #}
                    {%- if config.extra.translate_copyright -%}
                        <p>{{ macros_translate::translate(key="copyright", default=config.extra.copyright, language_strings=language_strings) | replace(from="$CURRENT_YEAR", to=current_year) | replace(from="$SEPARATOR", to=separator) | markdown | safe }}</p>
                    {%- else -%}
                        <p>{{ config.extra.copyright | replace(from="$CURRENT_YEAR", to=current_year) | replace(from="$SEPARATOR", to=separator) | markdown | safe }}</p>
                    {%- endif -%}
                {%- endif -%}

                {# Shows "Powered by Zola & tabi" notice #}
                {{ macros_translate::translate(key="powered_by", default="Powered by", language_strings=language_strings) }}
                <a rel="{{ rel_attributes }}" {{ blank_target }} href="https://www.getzola.org">Zola</a>
                {{ macros_translate::translate(key="and", default="&", language_strings=language_strings) }}
                <a rel="{{ rel_attributes }}" {{ blank_target }} href="https://github.com/welpo/tabi">tabi</a>

                {# Shows link to remote repository #}
                {%- if config.extra.remote_repository_url and config.extra.show_remote_source | default(value=true) -%}
                {{ separator }}
                    <a rel="{{ rel_attributes }}" {{ blank_target }} href="{{ config.extra.remote_repository_url }}">
                        {{ macros_translate::translate(key="site_source", default="Site source", language_strings=language_strings) }}
                    </a>
                {%- endif -%}
            </small>
        </div>
    </section>

    {# Load the decoding script if email is encoded #}
    {%- if email_needs_decoding -%}
        <script src="{{ get_url(path='js/decodeMail.min.js') }}" async></script>
    {%- endif -%}
</footer>
