<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

if ( ! class_exists( 'Theme_Enqueue' ) ) :

	class Theme_Enqueue {
		function __construct() {
		}

        function init() {
            add_action( 'wp_enqueue_scripts', [ $this, 'our' ] );
            add_action( 'wp_footer', [ $this, 'my_deregister_scripts' ] );
            remove_action('wp_head', 'print_emoji_detection_script', 7);
            remove_action('wp_print_styles', 'print_emoji_styles');
        }

        function my_deregister_scripts(){
            wp_deregister_script( 'wp-embed' );
        }

		function our() {
			wp_enqueue_script('our-js', get_template_directory_uri() . '/js/bundle.js', date( 'YmdHis' ), true, true );

			wp_localize_script('our-js', 'RT_API', array(
				'root'            => esc_url_raw( rest_url() ),
				'nonce'           => wp_create_nonce( 'wp_rest' ),
				'siteName'        => get_bloginfo( 'name' ),
				'siteDescription' => get_bloginfo( 'description' ),
				'categories'      => $this->get_categories_with_links(),
				'current_user'    => wp_get_current_user()
			) );
		}

		function get_categories_with_links() {
			$categories = get_categories( [ 'hide_empty' => 0 ] );
			foreach ( $categories as $i => $category ) {
				$categories[ $i ]->link = get_category_link( $category->term_id );
			}
			return $categories;
		}
	}

endif;
