<?php
/*=================================================;
/* REGISTER ASSETS
/*================================================= */
function rt_scripts() {

    // Main style
    wp_enqueue_style('retheme-style', get_template_directory_uri() . '/assets/css/style.min.css', false, '1.0.0');
    wp_enqueue_script('retheme-script', get_template_directory_uri() . '/assets/js/main.min.js', false, '1.0.0', true);

    // Layout
    wp_enqueue_style('retheme-frontpage', get_template_directory_uri() . '/assets/css/front-page.min.css', false, '1.0.0');
    wp_enqueue_style('retheme-layout', get_template_directory_uri() . '/assets/css/layouts.min.css', false, '1.0.0');
    wp_enqueue_script('retheme-layout', get_template_directory_uri() . '/assets/js/layout.min.js', false, '1.0.0', true);

    // Utilities
    wp_enqueue_style('retheme-utilities', get_template_directory_uri() . '/assets/css/utilities.min.css', false, '1.2.0');

    // Widget
    wp_enqueue_style('retheme-widget', get_template_directory_uri() . '/assets/css/elements/widget.min.css', false, '1.0.0');

    // Navigation
    wp_enqueue_style('retheme-navigation', get_template_directory_uri() . '/assets/css/elements/navigation.min.css', false, '1.0.0');
    wp_enqueue_script('retheme-navigation', get_template_directory_uri() . '/assets/js/navigation.min.js', ['animate'], '1.0.0', true);

    // Animate
    wp_enqueue_style('animate', get_template_directory_uri() . '/assets/animate/animate.min.css', false, '4.1.1');
    wp_enqueue_script('animate', get_template_directory_uri() . '/assets/animate/animate.min.js', false, '1.0.0', true);

    // Swiper
    wp_enqueue_style('swiper', get_template_directory_uri() . '/assets/swiper/swiper-bundle.min.css', false, '8.4.7');
    wp_enqueue_script('swiper', get_template_directory_uri() . '/assets/swiper/swiper-bundle.min.js', false, '8.4.5', true);
    wp_enqueue_style('retheme-swiper', get_template_directory_uri() . '/assets/swiper/retheme-swiper.min.css', false, '6.1.0');
    wp_enqueue_script('retheme-swiper', get_template_directory_uri() . '/assets/swiper/retheme-swiper.min.js', ['swiper'], '6.0.0', true);

    // Modal
    wp_enqueue_style('retheme-modal', get_template_directory_uri() . '/assets/css/elements/modal.min.css', false, '1.0.0');
    wp_enqueue_script('retheme-modal', get_template_directory_uri() . '/assets/js/modal.min.js', ['animate'], '1.0.0', true);

    // Slide panel
    wp_enqueue_style('retheme-slidepanel', get_template_directory_uri() . '/assets/css/elements/slidepanel.min.css', false, '1.0.0');
    wp_enqueue_script('retheme-slidepanel', get_template_directory_uri() . '/assets/js/slidepanel.min.js', ['animate'], '1.0.0', true);

    // Plugins
    wp_enqueue_style('retheme-elementor', get_template_directory_uri() . '/assets/css/plugins/elementor.min.css', ['elementor-common'], '1.0.0');
    wp_enqueue_style('retheme-tutor-lms', get_template_directory_uri() . '/assets/css/plugins/tutor-lms.min.css', ['tutor'], '1.0.0');
    wp_enqueue_style('retheme-contact-form-7', get_template_directory_uri() . '/assets/css/plugins/contact-form-7.min.css', ['contact-form-7'], '1.0.0');

    // Single Trip
    if (is_singular('trip')) {
        wp_enqueue_script('retheme-single-trip', get_template_directory_uri() . '/assets/js/single-trip.min.js', ['swiper', 'retheme-swiper'], '1.0.0', true);
        wp_enqueue_style('retheme-accordion', get_template_directory_uri() . '/assets/css/elements/accordion.min.css', false, '1.0.0');
        wp_enqueue_script('retheme-accordion', get_template_directory_uri() . '/assets/js/accordion.min.js', ['animate'], '1.0.0', true);
    }

    // Comment
    if (is_singular() && comments_open() && get_option('thread_comments')) {
        wp_enqueue_style('retheme-comment', get_template_directory_uri() . '/assets/css/comment-style.min.css', false, '1.0.0');
        wp_enqueue_script('comment-reply');
    }
}
add_action('wp_enqueue_scripts', 'rt_scripts');

/*====================================================
/* CUSTOM INLINE STYLE
/*====================================================*/
function rt_custom_inline_css() {
    $image = wp_get_attachment_url(rt_get_option('global_background_image'));
    if ($image) {
        $custom_css = '.retheme-default-scheme:before {content: ""; position: absolute; top: 0; right: 0; left: 0; z-index: -1; height: 700px; background-size: cover; background-position: center center;} .retheme-default-scheme .site-header:not(.is-sticky) .site-header__main, .retheme-default-scheme .site-header-mobile:not(.is-sticky) .site-header-mobile__main{background-color:transparent !important;}';
        $custom_css .= '.retheme-default-scheme:before{background-image: url("' . $image . '")}';

        // Enqueue stylesheet
        wp_enqueue_style('retheme-inline-style', get_stylesheet_uri());
        wp_add_inline_style('retheme-inline-style', $custom_css);
    }
}
add_action('wp_enqueue_scripts', 'rt_custom_inline_css');

/*=================================================;
/* MOVE JQUERY IN FOOTER
/*================================================= */
function rt_script_move_jquery_into_footer($wp_scripts) {

    if (is_admin()) {
        return;
    }

    if (rt_get_option('move_jquery_to_footer', true)) {
        $wp_scripts->add_data('jquery', 'group', 1);
        $wp_scripts->add_data('jquery-core', 'group', 1);
        $wp_scripts->add_data('jquery-migrate', 'group', 1);
    }
}
add_action('wp_default_scripts', 'rt_script_move_jquery_into_footer');

/*=================================================;
/* REMOVE EMOJI
/*================================================= */
function rt_script_remove_wp_emoji() {
    if (is_admin()) {
        return;
    }
    if (rt_get_option('remove_wp_emoji', true)) {
        remove_action('wp_head', 'print_emoji_detection_script', 7);
        remove_action('admin_print_scripts', 'print_emoji_detection_script');
        remove_action('wp_print_styles', 'wp_enqueue_emoji_styles');
        remove_action('admin_print_styles', 'wp_enqueue_emoji_styles');
    }
}
add_action('after_setup_theme', 'rt_script_remove_wp_emoji');
