<?php

/**
 * Kids Summer Camps functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package Kids Summer Camps
 */

define( 'KIDS_SUMMER_CAMPS_URL', trailingslashit( get_template_directory_uri() ) );

if ( ! function_exists( 'kids_summer_camps_setup' ) ) {

	/**
	 * Sets up theme defaults and registers support for various WordPress features.
	 *
	 * Note that this function is hooked into the after_setup_theme hook, which
	 * runs before the init hook. The init hook is too late for some features, such
	 * as indicating support for post thumbnails.
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	function kids_summer_camps_setup() {

		// Make theme available for translation.
		load_theme_textdomain( 'kids-summer-camps', get_template_directory() . '/languages' );

		// Add theme support
		add_theme_support( 'automatic-feed-links' );
		add_theme_support( 'wp-block-styles' );
		add_theme_support( 'title-tag' );
		add_theme_support( 'post-thumbnails' );
		add_theme_support( 'editor-styles' );
		add_theme_support( 'html5', array( 'comment-form', 'comment-list' ) );
		add_theme_support( 'responsive-embeds' );
		add_theme_support( 'customize-selective-refresh-widgets' );
	}
}
add_action( 'after_setup_theme', 'kids_summer_camps_setup' );

/**
 * Enqueue scripts and styles
 */
function kids_summer_camps_scripts() {
	$version = wp_get_theme( 'kids-summer-camps' )->get( 'Version' );
	// Stylesheet
	wp_enqueue_style( 'kids-summer-camps-styles', get_theme_file_uri( '/style.css' ), array(), $version );
	wp_enqueue_style( 'kids-summer-camps-animate', get_template_directory_uri() . '/assets/css/animate.css', array(), $version, 'all' );

	wp_enqueue_style( 'owl.carousel-css', get_template_directory_uri() . '/assets/css/owl.carousel.css', array(),'2.3.4');

	if ( file_exists( get_template_directory() . '/assets/css/theme-style.css' ) ) {
		wp_enqueue_style( 'kids-summer-camps-theme-style', get_template_directory_uri() . '/assets/css/theme-style.css',  array(), $version );
	}

	if ( is_rtl() ) {
		wp_enqueue_style( 'kids-summer-camps-rtl', get_template_directory_uri() . '/assets/css/rtl.css', array( 'kids-summer-camps-styles' ), $version );
	}

	// Scripts
	$script_deps = array( 'jquery' );
	wp_enqueue_script( 'kids-summer-camps-animate', get_template_directory_uri() . '/assets/js/animate.js', $script_deps, $version, true );

	wp_enqueue_script( 'owl.carousel-js', get_template_directory_uri() . '/assets/js/owl.carousel.js', array( 'jquery' ), '2.3.4', true );

	wp_enqueue_script( 'kids-summer-camps-main-script', get_template_directory_uri() . '/assets/js/custom-script.js', array( 'jquery' ), $version, true );

}
add_action( 'wp_enqueue_scripts', 'kids_summer_camps_scripts' );

/**
 * Add editor styles
 */
function kids_summer_camps_editor_style() {
	$version = wp_get_theme( 'kids-summer-camps' )->get( 'Version' );
	wp_enqueue_style( 'kids-summer-camps-editor-style', get_template_directory_uri() . '/assets/css/editor-style.css', array(), $version );
}
add_action( 'enqueue_block_editor_assets', 'kids_summer_camps_editor_style' );

/**
 * Enqueue assets scripts for both backend and frontend
 */
function kids_summer_camps_block_assets() {
	$version = wp_get_theme( 'kids-summer-camps' )->get( 'Version' );
	wp_enqueue_style( 'kids-summer-camps-blocks-style', get_template_directory_uri() . '/assets/css/blocks.css', array(), $version );
}
add_action( 'enqueue_block_assets', 'kids_summer_camps_block_assets' );

/**
 * Load theme patterns and block styles
 */
function kids_summer_camps_enque_setup() {

	require_once get_template_directory() . '/block-patterns.php';
	require_once get_template_directory() . '/block-styles.php';

}
add_action( 'after_setup_theme', 'kids_summer_camps_enque_setup' );