<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

if ( ! function_exists( 'reeid_is_astra_theme' ) ) {
    function reeid_is_astra_theme(): bool {
        return function_exists( 'get_template' ) && get_template() === 'astra';
    }
}

if ( ! function_exists( 'reeid_astra_detach_menu_dropdown_filter' ) ) {
    function reeid_astra_detach_menu_dropdown_filter(): void {
        if ( is_admin() ) {
            return;
        }

        if ( ! function_exists( 'reeid_is_astra_theme' ) || ! reeid_is_astra_theme() ) {
            return;
        }

        remove_filter( 'nav_menu_item_title', 'astra_dropdown_icon_to_menu_link', 10 );
    }
}

add_action( 'wp', 'reeid_astra_detach_menu_dropdown_filter', 20 );

if ( ! function_exists( 'reeid_astra_style_handle_fallback' ) ) {
    function reeid_astra_style_handle_fallback(): string {
        if ( ! function_exists( 'reeid_is_astra_theme' ) || ! reeid_is_astra_theme() ) {
            return '';
        }

        return wp_style_is( 'astra-theme-css', 'enqueued' ) || wp_style_is( 'astra-theme-css', 'registered' )
            ? 'astra-theme-css'
            : '';
    }
}