<?php
/**
 * Athlorix functions and definitions.
 *
 * @package Athlorix
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! function_exists( 'athlorix_setup' ) ) {
	/**
	 * Configure theme supports and editor styles.
	 */
	function athlorix_setup() {
		load_theme_textdomain( 'athlorix', get_template_directory() . '/languages' );
		add_theme_support( 'wp-block-styles' );
		add_theme_support( 'editor-styles' );
		add_theme_support( 'responsive-embeds' );
		add_theme_support( 'align-wide' );
		add_theme_support( 'post-thumbnails' );
		add_theme_support(
			'custom-logo',
			array(
				'height'      => 80,
				'width'       => 240,
				'flex-height' => true,
				'flex-width'  => true,
			)
		);

		$editor_styles = array( 'assets/editor-style.css' );
		if ( is_rtl() ) {
			$editor_styles[] = 'rtl.css';
		}
		add_editor_style( $editor_styles );
	}
}
add_action( 'after_setup_theme', 'athlorix_setup' );

/**
 * Enqueue the theme stylesheet.
 */
function athlorix_enqueue_assets() {
	$version = wp_get_theme()->get( 'Version' );
	wp_enqueue_style( 'athlorix-style', get_stylesheet_uri(), array(), $version );
	wp_style_add_data( 'athlorix-style', 'rtl', 'replace' );

	// Load the lightweight hero slider only where a slider is likely present.
	if ( is_front_page() || is_home() || is_page() ) {
		wp_enqueue_script(
			'athlorix-slider',
			get_template_directory_uri() . '/assets/slider.js',
			array(),
			$version,
			true
		);
	}
}
add_action( 'wp_enqueue_scripts', 'athlorix_enqueue_assets' );

/**
 * Register the Athlorix pattern category.
 */
function athlorix_register_pattern_categories() {
	register_block_pattern_category(
		'athlorix',
		array(
			'label' => esc_html__( 'Athlorix', 'athlorix' ),
		)
	);
}
add_action( 'init', 'athlorix_register_pattern_categories' );
/**
 * Register custom block styles.
 */
function athlorix_register_block_styles() {
	register_block_style(
		'core/button',
		array(
			'name'  => 'athlorix-pill',
			'label' => __( 'Athlorix Pill', 'athlorix' ),
		)
	);
	register_block_style(
		'core/image',
		array(
			'name'  => 'athlorix-rounded',
			'label' => __( 'Athlorix Rounded', 'athlorix' ),
		)
	);
	register_block_style(
		'core/group',
		array(
			'name'  => 'athlorix-card',
			'label' => __( 'Athlorix Card', 'athlorix' ),
		)
	);
}
add_action( 'init', 'athlorix_register_block_styles' );