{% extends '/views/parts/logic/block-settings.twig' %}
{% block blocksettings  %}
    <div class="site-footer__inner">
        <div class="site-footer__main {{ inner_classes }} {{ theme_settings.container }}">
            {% set columns = footer_settings.columns ?? [] %}

            {% for col in columns %}
                {% set type = col.column_type ?? '' %}
                {% set includeSocial = (col.include_social_links is defined and col.include_social_links is not empty) %}

            <div class="site-footer__col site-footer__col--{{ type }}">
                {% if type == 'logo_tagline' %}
                    <div class="footer-logo">
                        {% set overrideId = col.logo_override ?? null %}
                        {% if overrideId %}
                            {% set overrideUrl = function('wp_get_attachment_image_url', overrideId, 'full') %}
                            {% set overrideAlt = function('get_post_meta', overrideId, '_wp_attachment_image_alt', true) %}
                            {% if overrideUrl %}
                                <a class="navbar-brand" href="/">
                                    <img src="{{ overrideUrl }}" alt="{{ overrideAlt ?: site.title }}" loading="lazy">
                                </a>
                            {% endif %}
                        {% else %}
                            {% if logo %}
                                {% set image = logo %}
                                <a class="navbar-brand" href="/">
                                    {{ include('/parts/image.twig') }}
                                </a>
                            {% endif %}
                        {% endif %}
                    </div>

                    {% set tagline = site_settings['Company Details']['Tagline'] ?? '' %}
                    {% if tagline %}
                        <div class="footer-tagline">{{ tagline }}</div>
                    {% endif %}

                    {% if includeSocial %}
                        {{ include('views/parts/footer-social.twig') }}
                    {% endif %}

                    {% elseif type == 'menu' %}
                        {% if col.title %}<h4 class="footer-col__title">{{ col.title }}</h4>{% endif %}

                        {% set selected_menu_id = col.menu ?? '' %}
                        {% if selected_menu_id and menus_by_id[selected_menu_id] is defined and menus_by_id[selected_menu_id] %}
                            <div class="footer-menu">
                                {% set given_menu = menus_by_id[selected_menu_id] %}
                                {% set navstyle = "column" %}
                                {{ include('/parts/menu.twig') }}
                            </div>
                        {% endif %}

                        {% if includeSocial %}
                            {{ include('views/parts/footer-social.twig') }}
                        {% endif %}

                    {% elseif type == 'contact' %}
                        {% if col.title %}<h4 class="footer-col__title">{{ col.title }}</h4>{% endif %}

                        {% set phone = site_settings['Company Details']['Phone number'] ?? '' %}
                        {% set email = site_settings['Company Details']['Primary Email'] ?? '' %}
                        {% set address = site_settings['Company Details']['Address'] ?? '' %}
                        {% set showAddress = (col.show_address is defined and col.show_address is not empty) %}

                        {% if phone %}
                            <div class="footer-contact-phone contact-phone">
                                <a title="Contact Telephone Number" href="tel:{{ phone }}">{{ phone }}</a>
                            </div>
                        {% endif %}

                        {% if email %}
                            <div class="footer-contact-email contact-email">
                                <a title="Contact Email Address" href="mailto:{{ email }}">{{ email }}</a>
                            </div>
                        {% endif %}

                        {% if showAddress and address %}
                            <div class="footer-contact-address contact-address">
                                {{ address }}
                            </div>
                        {% endif %}

                        {% if includeSocial %}
                            {{ include('views/parts/footer-social.twig') }}
                        {% endif %}

                    {% elseif type == 'social' %}
                        {% if col.title %}<h4 class="footer-col__title">{{ col.title }}</h4>{% endif %}
                        {{ include('views/parts/footer-social.twig') }}

                    {% elseif type == 'text' %}
                        {% if col.title %}<h4 class="footer-col__title">{{ col.title }}</h4>{% endif %}
                        {% if col.text %}<div class="footer-col__text">{{ col.text }}</div>{% endif %}

                        {% if includeSocial %}
                            {{ include('views/parts/footer-social.twig') }}
                        {% endif %}
                    {% endif %}
                </div>
            {% endfor %}
        </div>

        <div class="site-footer__lower {{ inner_classes }} {{ theme_settings.container }}">
            <div class="site-footer__col">
                <div class="footer-policies">
                    {% if policy_menu.items is not empty %}
                        <div class="menu-policy justify-content-start">
                            {% set given_menu = policy_menu %}
                            {% set navstyle = "inline" %}
                            {{ include('/parts/menu.twig') }}
                        </div>
                    {% endif %}
                </div>
                <div class="footer-copyright">
                    <p>Copyright {{ "now"|date("Y") }}. All Rights Reserved.</p>
                </div>
            </div>
            <div class="site-footer__col">
                <div class="footer-company-info">
                    <p>{{ site_settings["Company Details"]["Company Name"] }} is a private limited company registered in England & Wales. Reg no: {{ site_settings["Company Details"]["Company Number"] }}</p>
                </div>
            </div>
            <div class="site-footer__col">
                <div class="apexl-logo">
                    <a title="Apexl Studios Logo and Link" href="https://apexlstudios.com" target="_blank" rel="nofollow"><img height="45px" src="{{ theme.parent.uri }}/assets/images/apexlstudios/apexl-studios-logo-white.svg"></a>
                </div>
                <div class="apexl-attribution">
                    <a title="Apexl Studios, Digital Production, Web Design, Web Development" href="https://apexlstudios.com/development" target="_blank" rel="nofollow">Website by Apexl Studios Ltd</a>
                </div>
            </div>
        </div>
    </div>
{% endblock %}