<?php
/**
 * $content_width is required even though this is a variable-width theme
 */
if ( ! isset( $kindrex_content_width ) ) {
	$kindrex_content_width = 400;
}

function kindrex_load_admin_styles() {
	wp_enqueue_style( 'admin_list_styling', get_template_directory_uri() . '/admin-style-list.css', false, wp_get_theme()->version );
}
add_action( 'admin_enqueue_scripts', 'kindrex_load_admin_styles' );

if ( ! function_exists( 'kindrex_setup' ) ) :
	function kindrex_setup() {
		load_theme_textdomain( 'kindrex', get_template_directory() . '/languages' );
		add_theme_support(
			'custom-logo',
			array(
				'height'      => 227,
				'width'       => 686,
				'flex-width'  => false,
				'flex-height' => false,
			)
		);

		$args = array(
			'default-color'      => 'cccccc',
			'default-repeat'     => 'repeat',
			'default-position-y' => 'top',
			'default-size'       => 'fit',
			'default-attachment' => 'fixed',
			'default-image'      => get_template_directory_uri() . '/images/blue.jpg',
		);
		add_theme_support( 'custom-background', $args );

		add_theme_support( 'title-tag' );
		add_theme_support( 'automatic-feed-links' );
		add_theme_support( 'customize-selective-rekindrex-widgets' );
		add_theme_support( 'post-thumbnails' );
		set_post_thumbnail_size( 150, 150 );
		add_image_size( 'kindrex-single-post-thumbnail', 9999, 9999 );
		add_image_size( 'kindrex-homepage-featured', 350, 350 );
		add_theme_support(
			'starter-content',
			array(
				'widgets' => array(
					'left-sidebar' => array(
						array(
							'text',
							array(
								'title' => esc_html__( 'First Sidebar', 'kindrex' ),
								'text'  => _x( 'This is some text in the first sidebar.', 'Theme Starter Content', 'kindrex' ),
							),
						),
					),
					'center-block' => array(
						array(
							'text',
							array(
								'title' => esc_html__( 'Center Block', 'kindrex' ),
								'text'  => _x( 'This is some text in the center block.', 'Theme Starter Content', 'kindrex' ),
							),
						),
					),
				),
			)
		);
	}
	add_action( 'after_setup_theme', 'kindrex_setup' );
endif;

if ( ! function_exists( 'kindrex_register_menu' ) ) :
	function kindrex_register_menu() {
		register_nav_menus(
			array(
				'top-menu'    => esc_html__( 'Top Menu Location', 'kindrex' ),
				'mobile-menu' => esc_html__( 'Mobile Menu Location', 'kindrex' ),
			)
		);
	}
	add_action( 'init', 'kindrex_register_menu' );
endif;

if ( ! function_exists( 'kindrex_stylesheet' ) ) :
	function kindrex_stylesheet() {
		wp_enqueue_style( 'kindrex-style', get_stylesheet_directory_uri() . '/style.css', array(), wp_get_theme()->version );
	}
	add_action( 'wp_enqueue_scripts', 'kindrex_stylesheet' );
endif;

if ( ! function_exists( 'kindrex_sidebars' ) ) :
	// register the sidebars
	function kindrex_sidebars() {
		register_sidebar(
			array(
				'name' => __( 'Header Block', 'kindrex' ),
				'id'   => 'top-block',
			)
		);
		register_sidebar(
			array(
				'name' => __( 'Left Sidebar', 'kindrex' ),
				'id'   => 'left-sidebar',
			)
		);
		register_sidebar(
			array(
				'name' => __( 'Center Block', 'kindrex' ),
				'id'   => 'center-block',
			)
		);
	}
	add_action( 'widgets_init', 'kindrex_sidebars' );
endif;

// display information about a post under the post title
if ( ! function_exists( 'kindrex_post_meta' ) ) :
	function kindrex_post_meta() {
		echo '<div class="meta">';
		if ( get_post_type() === 'page' ) :
			printf(
				/* translators: %s = author */
				esc_html__( 'Posted by %s', 'kindrex' ),
				get_the_author()
			);
		elseif ( has_category() ) :
			printf(
				/* translators: %1$s = date, %2$s = categories, %3$s = author */
				esc_html__( 'Posted on %1$s in %2$s by %3$s', 'kindrex' ),
				get_the_date(),
				wp_kses_post( get_the_category_list( ',' ) ),
				get_the_author()
			);
		else :
			printf(
				/* translators: %1$s = date, %2$s = author */
				esc_html__( 'Posted on %1$s by %2$s', 'kindrex' ),
				get_the_date(),
				get_the_author()
			);
		endif;
		edit_post_link( _x( 'Edit', 'verb', 'kindrex' ), ' | ' );
		if ( get_post_type() !== 'page' && has_tag() ) :
			echo '<br>';
			the_tags();
		endif;
		echo '</div>';
	}
endif;

// change the archive title to show the search query when showing the archive title on a search result page.
if ( ! function_exists( 'kindrex_search_title' ) ) :
	function kindrex_search_title( $title ) {
		if ( is_search() ) {
			/* translators: %s = search query */
			$title = sprintf( __( 'Search: %s', 'kindrex' ), get_search_query() );
		}
		return $title;
	}
	add_filter( 'get_the_archive_title', 'kindrex_search_title' );
endif;

/**
 * Enqueue scripts
 */
function kindrex_enqueue_scripts() {
	wp_enqueue_script( 'kindrex-header-clock', get_template_directory_uri() . '/js/kindrex-header-clock.js', array(), wp_get_theme()->version, true );
	wp_enqueue_script( 'kindrex-top-button', get_template_directory_uri() . '/js/kindrex-top-button.js', array(), wp_get_theme()->version, true );
	wp_enqueue_script( 'kindrex-navigation-menu', get_template_directory_uri() . '/js/kindrex-navigation-menu.js', array( 'jquery' ), wp_get_theme()->version, true );
	wp_enqueue_script( 'kindrex-mobile-menu', get_template_directory_uri() . '/js/kindrex-mobile-menu.js', array(), wp_get_theme()->version, true );
	wp_enqueue_script( 'kindrex-sticky-social', get_template_directory_uri() . '/js/dw-sticky-social.js', array( 'jquery' ), wp_get_theme()->version, true );
	if ( is_front_page() ) :
		wp_enqueue_script( 'kindrex-slider', get_template_directory_uri() . '/js/kindrex-slider.js', array(), wp_get_theme()->version, true );
	endif;
}
add_action( 'wp_enqueue_scripts', 'kindrex_enqueue_scripts' );

require get_template_directory() . '/inc/social-text-bar.php';
require get_template_directory() . '/inc/footer-content.php';
require get_template_directory() . '/inc/color-select.php';
require get_template_directory() . '/inc/cta-blocks.php';
require get_template_directory() . '/inc/image-slider.php';
require get_template_directory() . '/inc/upsell.php';
require get_template_directory() . '/assets/essential.php';
require get_template_directory() . '/assets/font.php';
require get_template_directory() . '/assets/font-awesome.php';

require get_template_directory() . '/assets/class-aria-walker-nav-menu.php';
