<?php
/**
 * Template Parts
 *
 * @package cyberpress
 */

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

/**
 * Template Parts
 *
 * @class       CyberPress_Template_Parts
 * @package     cyberpress
 */
class CyberPress_Template_Parts {

    /**
     * Registering hooks for pieces of plugin templates.
     */
    public static function init() {
        add_action( 'init', array( __CLASS__, 'remove_unsupported_wrappers' ) );

        add_action( 'cyberpress_wrapper_start', array( __CLASS__, 'wrapper_start' ) );
        add_action( 'cyberpress_wrapper_end', array( __CLASS__, 'wrapper_end' ) );

        add_action( 'cyberpress_games_archive_title', array( __CLASS__, 'games_archive_title' ) );
        add_action( 'cyberpress_players_archive_title', array( __CLASS__, 'players_archive_title' ) );
        add_action( 'cyberpress_teams_archive_title', array( __CLASS__, 'teams_archive_title' ) );
        add_action( 'cyberpress_matches_archive_title', array( __CLASS__, 'matches_archive_title' ) );
        add_action( 'cyberpress_tournaments_archive_title', array( __CLASS__, 'tournaments_archive_title' ) );

        add_action( 'cyberpress_archive_pagination', array( __CLASS__, 'archive_pagination' ), 10, 1 );

        add_action( 'cyberpress_archive_game_loop_start', array( __CLASS__, 'archive_game_loop_start' ) );
        add_action( 'cyberpress_archive_game_loop_end', array( __CLASS__, 'archive_game_loop_end' ) );
        add_action( 'cyberpress_games_wrapper_start', array( __CLASS__, 'archive_game_wrapper_start' ) );
        add_action( 'cyberpress_games_wrapper_end', array( __CLASS__, 'archive_game_wrapper_end' ) );
        add_action( 'cyberpress_archive_game_loop', array( __CLASS__, 'archive_game_loop' ) );

        add_action( 'cyberpress_players_wrapper_start', array( __CLASS__, 'archive_player_wrapper_start' ) );
        add_action( 'cyberpress_players_wrapper_end', array( __CLASS__, 'archive_player_wrapper_end' ) );
        add_action( 'cyberpress_archive_player_loop', array( __CLASS__, 'archive_player_loop' ) );
        add_action( 'cyberpress_archive_player_loop_start', array( __CLASS__, 'archive_player_loop_start' ) );
        add_action( 'cyberpress_archive_player_loop_end', array( __CLASS__, 'archive_player_loop_end' ) );

        add_action( 'cyberpress_teams_wrapper_start', array( __CLASS__, 'archive_team_wrapper_start' ) );
        add_action( 'cyberpress_teams_wrapper_end', array( __CLASS__, 'archive_team_wrapper_end' ) );
        add_action( 'cyberpress_archive_team_loop', array( __CLASS__, 'archive_team_loop' ) );
        add_action( 'cyberpress_archive_team_loop_start', array( __CLASS__, 'archive_team_loop_start' ) );
        add_action( 'cyberpress_archive_team_loop_end', array( __CLASS__, 'archive_team_loop_end' ) );

        add_action( 'cyberpress_archive_match_loop', array( __CLASS__, 'archive_match_loop' ) );
        add_action( 'cyberpress_archive_match_loop_start', array( __CLASS__, 'archive_match_loop_start' ) );
        add_action( 'cyberpress_archive_match_loop_end', array( __CLASS__, 'archive_match_loop_end' ) );
        add_action( 'cyberpress_matches_wrapper_start', array( __CLASS__, 'archive_match_wrapper_start' ) );
        add_action( 'cyberpress_matches_wrapper_end', array( __CLASS__, 'archive_match_wrapper_end' ) );

        add_action( 'cyberpress_archive_tournament_loop', array( __CLASS__, 'archive_tournament_loop' ) );
        add_action( 'cyberpress_archive_tournament_loop_start', array( __CLASS__, 'archive_tournament_loop_start' ) );
        add_action( 'cyberpress_archive_tournament_loop_end', array( __CLASS__, 'archive_tournament_loop_end' ) );
        add_action( 'cyberpress_tournaments_wrapper_start', array( __CLASS__, 'archive_tournament_wrapper_start' ) );
        add_action( 'cyberpress_tournaments_wrapper_end', array( __CLASS__, 'archive_tournament_wrapper_end' ) );

        add_action( 'cyberpress_single_post_navigation', array( __CLASS__, 'single_post_navigation' ) );

        add_action( 'cyberpress_single_game', array( __CLASS__, 'single_game' ) );
        add_action( 'cyberpress_single_game_thumbnail', array( __CLASS__, 'single_game_thumbnail' ) );
        add_action( 'cyberpress_single_game_title', array( __CLASS__, 'single_game_title' ) );
        add_action( 'cyberpress_single_game_content', array( __CLASS__, 'single_game_content' ) );

        add_action( 'cyberpress_single_match', array( __CLASS__, 'single_match' ) );
        add_action( 'cyberpress_single_match_title', array( __CLASS__, 'single_match_title' ) );
        add_action( 'cyberpress_single_match_participants', array( __CLASS__, 'single_match_participants' ) );
        add_action( 'cyberpress_single_match_content', array( __CLASS__, 'single_match_content' ) );
        add_action( 'cyberpress_single_match_videos', array( __CLASS__, 'single_match_videos' ) );
        add_action( 'cyberpress_single_match_screenshots', array( __CLASS__, 'single_match_screenshots' ) );

        add_action( 'cyberpress_single_player', array( __CLASS__, 'single_player' ) );
        add_action( 'cyberpress_single_player_title', array( __CLASS__, 'single_player_title' ) );
        add_action( 'cyberpress_single_player_thumbnail', array( __CLASS__, 'single_player_thumbnail' ) );
        add_action( 'cyberpress_single_player_info', array( __CLASS__, 'single_player_info' ) );
        add_action( 'cyberpress_single_player_content', array( __CLASS__, 'single_player_content' ) );
        add_action( 'cyberpress_single_player_games_stats', array( __CLASS__, 'single_player_games_stats' ) );
        add_action( 'cyberpress_single_player_teams', array( __CLASS__, 'single_player_teams' ) );
        add_action( 'cyberpress_single_player_twitch', array( __CLASS__, 'single_player_twitch' ) );
        add_action( 'cyberpress_single_player_social', array( __CLASS__, 'single_player_social' ) );

        add_action( 'cyberpress_single_team', array( __CLASS__, 'single_team' ) );
        add_action( 'cyberpress_single_team_title', array( __CLASS__, 'single_team_title' ) );
        add_action( 'cyberpress_single_team_thumbnail', array( __CLASS__, 'single_team_thumbnail' ) );
        add_action( 'cyberpress_single_team_info', array( __CLASS__, 'single_team_info' ) );
        add_action( 'cyberpress_single_team_content', array( __CLASS__, 'single_team_content' ) );
        add_action( 'cyberpress_single_team_players', array( __CLASS__, 'single_team_players' ) );
        add_action( 'cyberpress_single_team_twitch', array( __CLASS__, 'single_team_twitch' ) );
        add_action( 'cyberpress_single_team_social', array( __CLASS__, 'single_team_social' ) );

        add_action( 'cyberpress_single_tournament', array( __CLASS__, 'single_tournament' ) );
        add_action( 'cyberpress_single_tournament_title', array( __CLASS__, 'single_tournament_title' ) );
        add_action( 'cyberpress_single_tournament_info', array( __CLASS__, 'single_tournament_info' ) );
        add_action( 'cyberpress_single_tournament_content', array( __CLASS__, 'single_tournament_content' ) );
        add_action( 'cyberpress_single_tournament_matches', array( __CLASS__, 'single_tournament_matches' ) );
        add_action( 'cyberpress_single_tournament_videos', array( __CLASS__, 'single_tournament_videos' ) );
        add_action( 'cyberpress_single_tournament_screenshots', array( __CLASS__, 'single_tournament_screenshots' ) );

        add_action( 'cyberpress_sidebar', array( __CLASS__, 'sidebar' ) );
        add_action( 'cyberpress_progress', array( __CLASS__, 'progress' ) );
        add_action( 'cyberpress_content_none', array( __CLASS__, 'content_none' ) );

        add_action( 'cyberpress_matches_wrapper_block_start', array( __CLASS__, 'matches_wrapper_block_start' ), 10, 1 );
        add_action( 'cyberpress_matches_wrapper_block_end', array( __CLASS__, 'matches_wrapper_block_end' ) );
        add_action( 'cyberpress_matches_loop_block_start', array( __CLASS__, 'matches_loop_block_start' ), 10, 1 );
        add_action( 'cyberpress_matches_loop_block_end', array( __CLASS__, 'matches_loop_block_end' ) );
        add_action( 'cyberpress_matches_loop_block', array( __CLASS__, 'matches_loop_block' ), 10, 1 );

        add_action( 'cyberpress_games_wrapper_block_start', array( __CLASS__, 'games_wrapper_block_start' ), 10, 1 );
        add_action( 'cyberpress_games_wrapper_block_end', array( __CLASS__, 'games_wrapper_block_end' ) );
        add_action( 'cyberpress_games_loop_block_start', array( __CLASS__, 'games_loop_block_start' ), 10, 1 );
        add_action( 'cyberpress_games_loop_block_end', array( __CLASS__, 'games_loop_block_end' ) );
        add_action( 'cyberpress_games_loop_block', array( __CLASS__, 'games_loop_block' ), 10, 1 );

        add_action( 'cyberpress_players_wrapper_block_start', array( __CLASS__, 'players_wrapper_block_start' ), 10, 1 );
        add_action( 'cyberpress_players_wrapper_block_end', array( __CLASS__, 'players_wrapper_block_end' ) );
        add_action( 'cyberpress_players_loop_block_start', array( __CLASS__, 'players_loop_block_start' ), 10, 1 );
        add_action( 'cyberpress_players_loop_block_end', array( __CLASS__, 'players_loop_block_end' ) );
        add_action( 'cyberpress_players_loop_block', array( __CLASS__, 'players_loop_block' ), 10, 1 );

        add_action( 'cyberpress_teams_wrapper_block_start', array( __CLASS__, 'teams_wrapper_block_start' ), 10, 1 );
        add_action( 'cyberpress_teams_wrapper_block_end', array( __CLASS__, 'teams_wrapper_block_end' ) );
        add_action( 'cyberpress_teams_loop_block_start', array( __CLASS__, 'teams_loop_block_start' ), 10, 1 );
        add_action( 'cyberpress_teams_loop_block_end', array( __CLASS__, 'teams_loop_block_end' ) );
        add_action( 'cyberpress_teams_loop_block', array( __CLASS__, 'teams_loop_block' ), 10, 1 );

        add_action( 'cyberpress_tournaments_wrapper_block_start', array( __CLASS__, 'tournaments_wrapper_block_start' ), 10, 1 );
        add_action( 'cyberpress_tournaments_wrapper_block_end', array( __CLASS__, 'tournaments_wrapper_block_end' ) );
        add_action( 'cyberpress_tournaments_loop_block_start', array( __CLASS__, 'tournaments_loop_block_start' ), 10, 1 );
        add_action( 'cyberpress_tournaments_loop_block_end', array( __CLASS__, 'tournaments_loop_block_end' ) );
        add_action( 'cyberpress_tournaments_loop_block', array( __CLASS__, 'tournaments_loop_block' ), 10, 1 );

        add_action( 'cyberpress_blocks_pagination', array( __CLASS__, 'blocks_pagination' ), 10, 2 );

        add_action( 'pre_get_posts', array( __CLASS__, 'archive_query' ) );

        add_action( 'pre_get_posts', array( __CLASS__, 'modify_query_get_parent_team_posts' ) );
    }

    /**
     * Removing a wrapper if the theme does not support the plugin.
     */
    public static function remove_unsupported_wrappers() {
        $theme_support = current_theme_supports( 'cyberpress' );

        if ( ! $theme_support ) {
            remove_action( 'cyberpress_wrapper_start', array( __CLASS__, 'wrapper_start' ) );
            remove_action( 'cyberpress_wrapper_end', array( __CLASS__, 'wrapper_end' ) );
        }
    }

    /**
     * Conclusion main wrapper template. Start.
     */
    public static function wrapper_start() {
        self::get_template( 'global/wrapper-start.php' );
    }

    /**
     * Conclusion main wrapper template. End.
     */
    public static function wrapper_end() {
        self::get_template( 'global/wrapper-end.php' );
    }

    /**
     * Title Display Templates. Games archive.
     */
    public static function games_archive_title() {
        self::get_template( 'games/archive-parts/title.php' );
    }

    /**
     * Title Display Templates. Players archive.
     */
    public static function players_archive_title() {
        self::get_template( 'players/archive-parts/title.php' );
    }

    /**
     * Title Display Templates. Teams archive.
     */
    public static function teams_archive_title() {
        self::get_template( 'teams/archive-parts/title.php' );
    }

    /**
     * Title Display Templates. Matches archive.
     */
    public static function matches_archive_title() {
        self::get_template( 'matches/archive-parts/title.php' );
    }

    /**
     * Title Display Templates. Tournaments archive.
     */
    public static function tournaments_archive_title() {
        self::get_template( 'tournaments/archive-parts/title.php' );
    }

    /**
     * Sidebar output.
     */
    public static function sidebar() {
        do_action( 'cyberpress_before_sidebar' );

        get_sidebar( 'cyberpress' );

        do_action( 'cyberpress_after_sidebar' );
    }

    /**
     * Progress bar.
     *
     * @param array $data - array with data items. Example:
            array(
                array(
                    'label' => 'Label 1',
                    'value' => 10,
                ),
                array(
                    'label' => 'Label 2',
                    'value' => 20,
                ),
            ).
     */
    public static function progress( $data ) {
        self::get_template( 'global/progress.php', $data );
    }

    /**
     * Archive Pagination template.
     *
     * @param WP_Query|object $custom_query - Custom query to the database to generate pagination.
     */
    public static function archive_pagination( $custom_query ) {
        global $wp_query;
        if ( ! isset( $custom_query ) || empty( $custom_query ) ) {
            $custom_query = $wp_query;
        }
        self::get_template( 'global/pagination.php', array( 'query' => $custom_query ) );
    }

    /**
     * Archive Wrapper Game start.
     */
    public static function archive_game_wrapper_start() {
        self::get_template( 'games/archive-parts/wrapper-start.php' );
    }

    /**
     * Archive Wrapper Game end.
     */
    public static function archive_game_wrapper_end() {
        self::get_template( 'games/archive-parts/wrapper-end.php' );
    }

    /**
     * Archive Game loop start.
     */
    public static function archive_game_loop_start() {
        $attributes = CyberPress_Settings::get_group_options( 'games' );

        $attributes = array_merge(
            $attributes,
            array(
                'is_archive' => true,
            )
        );

        self::get_template( 'games/loop/loop-start.php', array( 'attributes' => $attributes ) );
    }

    /**
     * Archive Game loop end.
     */
    public static function archive_game_loop_end() {
        self::get_template( 'games/loop/loop-end.php' );
    }

    /**
     * Archive Wrapper Player start.
     */
    public static function archive_player_wrapper_start() {
        self::get_template( 'players/archive-parts/wrapper-start.php' );
    }

    /**
     * Archive Wrapper Player end.
     */
    public static function archive_player_wrapper_end() {
        self::get_template( 'players/archive-parts/wrapper-end.php' );
    }

    /**
     * Archive Player loop.
     */
    public static function archive_player_loop() {
        $attributes = CyberPress_Settings::get_group_options( 'players' );

        self::get_template(
            'players/loop/loop.php',
            array(
                'attributes' => $attributes,
            )
        );
    }

    /**
     * Archive Player loop start.
     */
    public static function archive_player_loop_start() {
        $attributes = CyberPress_Settings::get_group_options( 'players' );

        $attributes = array_merge(
            $attributes,
            array(
                'is_archive' => true,
            )
        );

        self::get_template( 'players/loop/loop-start.php', array( 'attributes' => $attributes ) );
    }

    /**
     * Archive Player loop end.
     */
    public static function archive_player_loop_end() {
        self::get_template( 'players/loop/loop-end.php' );
    }

    /**
     * Archive Wrapper Team start.
     */
    public static function archive_team_wrapper_start() {
        self::get_template( 'teams/archive-parts/wrapper-start.php' );
    }

    /**
     * Archive Wrapper Team end.
     */
    public static function archive_team_wrapper_end() {
        self::get_template( 'teams/archive-parts/wrapper-end.php' );
    }

    /**
     * Archive Team loop.
     */
    public static function archive_team_loop() {
        $attributes = CyberPress_Settings::get_group_options( 'teams' );

        self::get_template(
            'teams/loop/loop.php',
            array(
                'attributes' => $attributes,
            )
        );
    }

    /**
     * Archive Team loop start.
     */
    public static function archive_team_loop_start() {
        $attributes = CyberPress_Settings::get_group_options( 'teams' );

        $attributes = array_merge(
            $attributes,
            array(
                'is_archive' => true,
            )
        );

        self::get_template( 'teams/loop/loop-start.php', array( 'attributes' => $attributes ) );
    }

    /**
     * Archive Team loop end.
     */
    public static function archive_team_loop_end() {
        self::get_template( 'teams/loop/loop-end.php' );
    }

    /**
     * Archive Match loop.
     */
    public static function archive_match_loop() {
        $attributes = CyberPress_Settings::get_group_options( 'matches' );

        self::get_template(
            'matches/loop/loop.php',
            array(
                'attributes' => $attributes,
            )
        );
    }

    /**
     * Archive Wrapper Match loop start.
     */
    public static function archive_match_wrapper_start() {
        self::get_template( 'matches/archive-parts/wrapper-start.php' );
    }

    /**
     * Archive Wrapper Match loop end.
     */
    public static function archive_match_wrapper_end() {
        self::get_template( 'matches/archive-parts/wrapper-end.php' );
    }

    /**
     * Archive Match loop start.
     */
    public static function archive_match_loop_start() {
        $attributes = CyberPress_Settings::get_group_options( 'matches' );

        $attributes = array_merge(
            $attributes,
            array(
                'is_archive' => true,
            )
        );

        self::get_template( 'matches/loop/loop-start.php', array( 'attributes' => $attributes ) );
    }

    /**
     * Archive Match loop end.
     */
    public static function archive_match_loop_end() {
        self::get_template( 'matches/loop/loop-end.php' );
    }

    /**
     * Archive Tournament loop.
     */
    public static function archive_tournament_loop() {
        $attributes = CyberPress_Settings::get_group_options( 'tournaments' );

        self::get_template(
            'tournaments/loop/loop.php',
            array(
                'attributes' => $attributes,
            )
        );
    }

    /**
     * Archive Wrapper Tournament loop start.
     */
    public static function archive_tournament_wrapper_start() {
        self::get_template( 'tournaments/archive-parts/wrapper-start.php' );
    }

    /**
     * Archive Wrapper Tournament loop end.
     */
    public static function archive_tournament_wrapper_end() {
        self::get_template( 'tournaments/archive-parts/wrapper-end.php' );
    }

    /**
     * Archive Tournament loop start.
     */
    public static function archive_tournament_loop_start() {
        $attributes = CyberPress_Settings::get_group_options( 'tournaments' );

        $attributes = array_merge(
            $attributes,
            array(
                'is_archive' => true,
            )
        );

        self::get_template( 'tournaments/loop/loop-start.php', array( 'attributes' => $attributes ) );
    }

    /**
     * Archive Tournament loop end.
     */
    public static function archive_tournament_loop_end() {
        self::get_template( 'tournaments/loop/loop-end.php' );
    }

    /**
     * Single previous/next post navigation.
     */
    public static function single_post_navigation() {
        self::get_template( 'global/post-navigation.php' );
    }

    /**
     * Single Game Page Template.
     */
    public static function single_game() {
        self::get_template( 'games/single-parts/content.php' );
    }

    /**
     * Single Game Thumbnail Template.
     */
    public static function single_game_thumbnail() {
        self::get_template( 'games/single-parts/thumbnail.php' );
    }

    /**
     * Single Game Title Template.
     */
    public static function single_game_title() {
        self::get_template( 'games/single-parts/title.php' );
    }

    /**
     * Single Game Content Template.
     */
    public static function single_game_content() {
        self::get_template( 'games/single-parts/entry-content.php' );
    }

    /**
     * Single Match Page Template.
     */
    public static function single_match() {
        self::get_template( 'matches/single-parts/content.php' );
    }

    /**
     * Single Match Title Template.
     */
    public static function single_match_title() {
        self::get_template( 'matches/single-parts/title.php' );
    }

    /**
     * Single Match Participants Template.
     */
    public static function single_match_participants() {
        self::get_template( 'matches/single-parts/participants.php' );
    }

    /**
     * Single Match Content Template.
     */
    public static function single_match_content() {
        self::get_template( 'matches/single-parts/entry-content.php' );
    }

    /**
     * Single Match Videos Template.
     */
    public static function single_match_videos() {
        self::get_template( 'matches/single-parts/videos.php' );
    }

    /**
     * Single Match Screenshots Template.
     */
    public static function single_match_screenshots() {
        self::get_template( 'matches/single-parts/screenshots.php' );
    }

    /**
     * Single Player Page Template.
     */
    public static function single_player() {
        self::get_template( 'players/single-parts/content.php' );
    }

    /**
     * Single Player Title Template.
     */
    public static function single_player_title() {
        self::get_template( 'players/single-parts/title.php' );
    }

    /**
     * Single Player Thumbnail Template.
     */
    public static function single_player_thumbnail() {
        self::get_template( 'players/single-parts/thumbnail.php' );
    }

    /**
     * Single Player Info Template.
     */
    public static function single_player_info() {
        self::get_template( 'players/single-parts/info.php' );
    }

    /**
     * Single Player Content Template.
     */
    public static function single_player_content() {
        self::get_template( 'players/single-parts/entry-content.php' );
    }

    /**
     * Single Player Games Stats Template.
     */
    public static function single_player_games_stats() {
        self::get_template( 'players/single-parts/games-stats.php' );
    }

    /**
     * Single Player Teams Template.
     */
    public static function single_player_teams() {
        self::get_template( 'players/single-parts/teams.php' );
    }

    /**
     * Single Player Twitch Template.
     */
    public static function single_player_twitch() {
        self::get_template( 'players/single-parts/twitch.php' );
    }

    /**
     * Single Player Social Template.
     */
    public static function single_player_social() {
        self::get_template( 'players/single-parts/social.php' );
    }

    /**
     * Single Team Page Template.
     */
    public static function single_team() {
        self::get_template( 'teams/single-parts/content.php' );
    }

    /**
     * Single Team Title Template.
     */
    public static function single_team_title() {
        self::get_template( 'teams/single-parts/title.php' );
    }

    /**
     * Single Team Thumbnail Template.
     */
    public static function single_team_thumbnail() {
        self::get_template( 'teams/single-parts/thumbnail.php' );
    }

    /**
     * Single Team Info Template.
     */
    public static function single_team_info() {
        self::get_template( 'teams/single-parts/info.php' );
    }

    /**
     * Single Team Content Template.
     */
    public static function single_team_content() {
        self::get_template( 'teams/single-parts/entry-content.php' );
    }

    /**
     * Single Team Players Template.
     */
    public static function single_team_players() {
        self::get_template( 'teams/single-parts/players.php' );
    }

    /**
     * Single Team Twitch Template.
     */
    public static function single_team_twitch() {
        self::get_template( 'teams/single-parts/twitch.php' );
    }

    /**
     * Single Team Social Template.
     */
    public static function single_team_social() {
        self::get_template( 'teams/single-parts/social.php' );
    }

    /**
     * Single Tournament Page Template.
     */
    public static function single_tournament() {
        self::get_template( 'tournaments/single-parts/content.php' );
    }

    /**
     * Single Tournament Title Template.
     */
    public static function single_tournament_title() {
        self::get_template( 'tournaments/single-parts/title.php' );
    }

    /**
     * Single Tournament Info Template.
     */
    public static function single_tournament_info() {
        self::get_template( 'tournaments/single-parts/info.php' );
    }

    /**
     * Single Tournament Content Template.
     */
    public static function single_tournament_content() {
        self::get_template( 'tournaments/single-parts/entry-content.php' );
    }

    /**
     * Single Tournament Matches Template.
     */
    public static function single_tournament_matches() {
        self::get_template( 'tournaments/single-parts/matches.php' );
    }

    /**
     * Single Tournament Videos Template.
     */
    public static function single_tournament_videos() {
        self::get_template( 'tournaments/single-parts/videos.php' );
    }

    /**
     * Single Tournament Screenshots Template.
     */
    public static function single_tournament_screenshots() {
        self::get_template( 'tournaments/single-parts/screenshots.php' );
    }


    /**
     * None Content Template.
     */
    public static function content_none() {
        self::get_template( 'global/content-none.php' );
    }

    /**
     * Wrapper start loop Matches Block.
     *
     * @param array $attributes - block attributes.
     */
    public static function matches_wrapper_block_start( $attributes ) {
        self::get_template( 'matches/block-parts/wrapper-start.php', array( 'attributes' => $attributes ) );
    }

    /**
     * Wrapper end loop Matches Block.
     */
    public static function matches_wrapper_block_end() {
        self::get_template( 'matches/block-parts/wrapper-end.php' );
    }

    /**
     * Start loop Matches Block.
     *
     * @param array $attributes - block attributes.
     */
    public static function matches_loop_block_start( $attributes ) {
        self::get_template( 'matches/loop/loop-start.php', array( 'attributes' => $attributes ) );
    }

    /**
     * End loop Matches Block.
     */
    public static function matches_loop_block_end() {
        self::get_template( 'matches/loop/loop-end.php' );
    }

    /**
     * Wrapper start loop Games Block.
     *
     * @param array $attributes - block attributes.
     */
    public static function games_wrapper_block_start( $attributes ) {
        self::get_template( 'games/block-parts/wrapper-start.php', array( 'attributes' => $attributes ) );
    }

    /**
     * Wrapper end loop Games Block.
     */
    public static function games_wrapper_block_end() {
        self::get_template( 'games/block-parts/wrapper-end.php' );
    }

    /**
     * Start loop Games Block.
     *
     * @param array $attributes - block attributes.
     */
    public static function games_loop_block_start( $attributes ) {
        self::get_template( 'games/loop/loop-start.php', array( 'attributes' => $attributes ) );
    }

    /**
     * End loop Games Block.
     */
    public static function games_loop_block_end() {
        self::get_template( 'games/loop/loop-end.php' );
    }

    /**
     * Wrapper start loop Players Block.
     *
     * @param array $attributes - block attributes.
     */
    public static function players_wrapper_block_start( $attributes ) {
        self::get_template( 'players/block-parts/wrapper-start.php', array( 'attributes' => $attributes ) );
    }

    /**
     * Wrapper end loop Players Block.
     */
    public static function players_wrapper_block_end() {
        self::get_template( 'players/block-parts/wrapper-end.php' );
    }

    /**
     * Wrapper start loop Players Block.
     *
     * @param array $attributes - block attributes.
     */
    public static function players_loop_block_start( $attributes ) {
        self::get_template( 'players/loop/loop-start.php', array( 'attributes' => $attributes ) );

    }

    /**
     * Wrapper end loop Players Block.
     */
    public static function players_loop_block_end() {
        self::get_template( 'players/loop/loop-end.php' );
    }

    /**
     * Wrapper start loop Teams Block.
     *
     * @param array $attributes - block attributes.
     */
    public static function teams_wrapper_block_start( $attributes ) {
        self::get_template( 'teams/block-parts/wrapper-start.php', array( 'attributes' => $attributes ) );
    }

    /**
     * Wrapper end loop Teams Block.
     */
    public static function teams_wrapper_block_end() {
        self::get_template( 'teams/block-parts/wrapper-end.php' );
    }

    /**
     * Wrapper start loop Teams Block.
     *
     * @param array $attributes - block attributes.
     */
    public static function teams_loop_block_start( $attributes ) {
        self::get_template( 'teams/loop/loop-start.php', array( 'attributes' => $attributes ) );
    }

    /**
     * Wrapper end loop Teams Block.
     */
    public static function teams_loop_block_end() {
        self::get_template( 'teams/loop/loop-end.php' );
    }

    /**
     * Wrapper start loop Tournaments Block.
     *
     * @param array $attributes - block attributes.
     */
    public static function tournaments_wrapper_block_start( $attributes ) {
        self::get_template( 'tournaments/block-parts/wrapper-start.php', array( 'attributes' => $attributes ) );
    }

    /**
     * Wrapper end loop Tournaments Block.
     */
    public static function tournaments_wrapper_block_end() {
        self::get_template( 'tournaments/block-parts/wrapper-end.php' );
    }

    /**
     * Wrapper start loop Tournaments Block.
     *
     * @param array $attributes - block attributes.
     */
    public static function tournaments_loop_block_start( $attributes ) {
        self::get_template( 'tournaments/loop/loop-start.php', array( 'attributes' => $attributes ) );
    }

    /**
     * Wrapper end loop Tournaments Block.
     */
    public static function tournaments_loop_block_end() {
        self::get_template( 'tournaments/loop/loop-end.php' );
    }

    /**
     * Matches Block Template.
     *
     * @param boolean $attributes - block attributes.
     */
    public static function matches_loop_block( $attributes ) {
        self::get_template(
            'matches/loop/loop.php',
            array(
                'attributes' => $attributes,
            )
        );
    }

    /**
     * Games Block Template.
     *
     * @param array $attributes - block attributes.
     */
    public static function games_loop_block( $attributes ) {
        self::get_template(
            'games/loop/loop.php',
            array(
                'attributes' => $attributes,
            )
        );
    }

    /**
     * Games Archive Loop Template
     */
    public static function archive_game_loop() {
        $attributes = CyberPress_Settings::get_group_options( 'games' );

        self::get_template(
            'games/loop/loop.php',
            array(
                'attributes' => $attributes,
            )
        );
    }

    /**
     * Players Block Template.
     *
     * @param array $attributes - block attributes.
     */
    public static function players_loop_block( $attributes ) {
        self::get_template(
            'players/loop/loop.php',
            array(
                'attributes' => $attributes,
            )
        );
    }

    /**
     * Teams Block Template.
     *
     * @param array $attributes - block attributes.
     */
    public static function teams_loop_block( $attributes ) {
        self::get_template(
            'teams/loop/loop.php',
            array(
                'attributes' => $attributes,
            )
        );
    }

    /**
     * Tournaments Block Template.
     *
     * @param array $attributes - block attributes.
     */
    public static function tournaments_loop_block( $attributes ) {
        self::get_template(
            'tournaments/loop/loop.php',
            array(
                'attributes' => $attributes,
            )
        );
    }

    /**
     * Blocks Pagination Template.
     *
     * @param WP_Query|object $query - Custom query to the database for generate pagination.
     * @param boolean         $display - Pagination show option.
     */
    public static function blocks_pagination( $query, $display ) {
        self::get_template(
            'global/blocks-pagination.php',
            array(
                'query'   => $query,
                'display' => $display,
            )
        );
    }

    /**
     * Archive Query.
     *
     * @param WP_Query $query - The WP_Query instance (passed by reference).
     */
    public static function archive_query( $query ) {
        if ( is_post_type_archive( 'game' ) && ! is_admin() ) {
            $query->set( 'posts_per_page', CyberPress_Settings::get_option( 'games_archive_count', 'cyberpress_games' ) );
        }
        if ( is_post_type_archive( 'player' ) && ! is_admin() ) {
            $query->set( 'posts_per_page', CyberPress_Settings::get_option( 'players_archive_count', 'cyberpress_players' ) );
        }
        if ( is_post_type_archive( 'team' ) && ! is_admin() ) {
            $query->set( 'posts_per_page', CyberPress_Settings::get_option( 'teams_archive_count', 'cyberpress_teams' ) );
        }
        if ( is_post_type_archive( 'match' ) && ! is_admin() ) {
            $query->set( 'posts_per_page', CyberPress_Settings::get_option( 'matches_archive_count', 'cyberpress_matches' ) );
        }
        if ( is_post_type_archive( 'tournament' ) && ! is_admin() ) {
            $query->set( 'posts_per_page', CyberPress_Settings::get_option( 'tournaments_archive_count', 'cyberpress_tournaments' ) );
        }
    }

    /**
     * Get parts of templates, passing attributes and including the file.
     *
     * @param string $template_name - Name of Template.
     * @param array  $args (default: array()) - Arguments for dynamic transfer inside a template.
     * @param string $template_path (default: '') - Path for connecting a third-party template.
     * @param string $default_path (default: '') - Path to default template file.
     */
    public static function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
        if ( ! empty( $args ) && is_array( $args ) ) {
            // @codingStandardsIgnoreLine
            extract( $args );
        }

        $located = self::locate_template( $template_name, $template_path, $default_path );

        // Allow 3rd party plugin filter template file from their plugin.
        $located = apply_filters( 'cyberpress_get_template', $located, $template_name, $args, $template_path, $default_path );

        do_action( 'cyberpress_before_template_part', $template_name, $template_path, $located, $args );

        include $located;

        do_action( 'cyberpress_after_template_part', $template_name, $template_path, $located, $args );
    }

    /**
     * Locate a template and return the path for inclusion.
     *
     * This is the load order:
     *
     *      yourtheme       /   $template_path  /   $template_name
     *      yourtheme       /   $template_name
     *      $default_path   /   $template_name
     *
     * @param string $template_name - Name of Template.
     * @param string $template_path (default: '') - Path for connecting a third-party template.
     * @param string $default_path (default: '') - Path to default template file.
     * @return string
     */
    public static function locate_template( $template_name, $template_path = '', $default_path = '' ) {
        if ( ! $template_path ) {
            $template_path = 'cyberpress/';
        }

        if ( ! $default_path ) {
            $default_path = untrailingslashit( cyberpress()->plugin_path ) . '/templates/';
        }

        // Look within passed path within the theme - this is priority.
        $template = locate_template(
            array(
                trailingslashit( $template_path ) . $template_name,
                $template_name,
            )
        );

        // Get default template.
        if ( ! $template ) {
            $template = $default_path . $template_name;
        }

        // Return what we found.
        return apply_filters( 'cyberpress_locate_template', $template, $template_name, $template_path );
    }

    /**
     * This function enables someone to hook into `pre_get_posts` and modify *only* the main query. This is a boolean function, meaning it returns either TRUE or FALSE.
     * In this case, the function is used to substitute the query output for the timestamps on the archive page.
     * We display only parent team posts.
     *
     * @param WP_Query $query - Only the main query.
     * @return mixed
     */
    public static function modify_query_get_parent_team_posts( $query ) {
        // Only modify the main query on the frontend to prevent infinite recursion in admin.
        if ( is_admin() || ! $query->is_main_query() ) {
            return $query;
        }

        if ( isset( $query->query['post_type'] ) && 'team' === $query->query['post_type'] && is_archive() ) {
            $query->set( 'post_parent', 0 );
        }
        return $query;
    }
}
