<?php

function nav_404() {
    
    if ( ! has_nav_menu( '404_menu' ) ) {
        return;
    }

    wp_nav_menu( [
        'theme_location' => '404_menu',
        'container'      => 'nav',
        'container_class'=> 'error-404-navigation',
        'menu_class'     => 'error-404-menu',
        'depth'          => 1,
        'fallback_cb'    => false,
    ] );
}

function aurora_404_button() {

    $text = get_theme_mod( 'aurora_lite_404_button_text', '' );
    $url  = get_theme_mod( 'aurora_404_button_url', '' );

    if ( empty( $text ) || empty( $url ) ) {
        return;
    }

    echo '<a href="' . esc_url( $url ) . '" class="aurora-lite-404-button">';
    echo esc_html( $text );
    echo '</a>';
}

function aurora_lite_404_bgi() {

    if ( ! is_404() ) return;

    $bg_value = get_theme_mod('aurora_lite_404_bg_image');

    $layout = get_theme_mod('aurora_lite_404_page_layout', 'Default');

    $fallback_path = get_template_directory() . '/assets/images/' . $layout . '.jpg';
    $fallback_url  = file_exists( $fallback_path ) ? get_template_directory_uri() . '/assets/images/' . $layout . '.jpg' : '';

    $bg_image = ! empty( $bg_value ) ? esc_url( $bg_value ) : esc_url( $fallback_url );

    if ( ! empty( $bg_image ) ) {
        wp_add_inline_style( 'aurora-lite-style', ':root { --error-bg-image: url("' . esc_url( $bg_image ) . '"); }' );
    }
}
add_action('wp_enqueue_scripts', 'aurora_lite_404_bgi');
