<?php

function aurora_lite_scroll_to_top() {
    echo '<button id="scrollToTop" aria-label="' . esc_attr__( 'Scroll to top', 'aurora-lite' ) . '" title="' . esc_attr__( 'Back to top', 'aurora-lite' ) . '"><i class="fa-solid fa-angle-up"></i></button>';
}
add_action('wp_footer', 'aurora_lite_scroll_to_top');


function aurora_lite_copyright_text() {
    $custom_text   = get_theme_mod('aurora_lite_footer_copyright_text', '');
    $fallback_text = "© " . wp_date('Y') . " " . get_bloginfo('name') . ". All rights reserved.";

    $text = $custom_text ?: $fallback_text;
    $text .= ' Styled with Aurora WP Theme';

    return wp_kses_post($text);
}


function aurora_lite_show_footer_socials() {
    if ( get_theme_mod( 'aurora_lite_show_socials_in_footer', true ) ) {
        echo '<div class="aurora-lite-footer-socials">';
        aurora_lite_show_socials();
        aurora_lite_footer_email();
        echo '</div>';
    }
}

function aurora_lite_footer_menu( $location = 'footer1' ) {
    $locations = get_nav_menu_locations();

    if ( empty( $locations[ $location ] ) ) {
        return;
    }

    $menu_id = $locations[ $location ];
    $menu_items = wp_get_nav_menu_items( $menu_id );

    if ( empty( $menu_items ) ) {
        return;
    }
    ?>
    <nav class="footer-navigation">
        <ul class="footer-menu">
            <?php foreach ( $menu_items as $item ) : ?>
                <li class="footer-menu-item">
                    <a href="<?php echo esc_url( $item->url ); ?>">
                        <?php echo esc_html( $item->title ); ?>
                    </a>
                </li>
            <?php endforeach; ?>
        </ul>
    </nav>
    <?php
}


function aurora_lite_footer_col_title( $col ) {

    $col = absint( $col );

    if ( $col < 2 || $col > 4 ) {
        echo '&nbsp;';
        return;
    }

    $title = get_theme_mod( "aurora_lite_footer_col_{$col}_title", '' );

    if ( '' === $title ) {
        echo '&nbsp;';
        return;
    }

    echo esc_html( $title );
}

function aurora_lite_footer_bio() {

    $bio = get_theme_mod('aurora_lite_footer_bio', '');
    echo '<p class="footer-bio">';

    if ( ! empty( $bio ) ) {
        echo wp_kses_post( $bio );
    }

    echo '</p>';
}