<?php
/**
 * Sports Leagues :: Shortcode > Players Stats.
 *
 * @since   0.7.0
 * @package Sports_Leagues
 */

/**
 * Sports Leagues :: Shortcode > Players Stats.
 *
 * @since 0.7.0
 * @since 0.14.1 Refactored to extend Sports_Leagues_Shortcode_Base.
 */
class Sports_Leagues_Shortcode_Players_Stats extends Sports_Leagues_Shortcode_Base {

	/**
	 * Get the shortcode tag.
	 *
	 * @return string
	 * @since 0.14.1
	 */
	protected function get_shortcode_tag(): string {
		return 'sl-players-stats';
	}

	/**
	 * Get the shortcode key for options/hooks.
	 *
	 * @return string
	 * @since 0.14.1
	 */
	protected function get_shortcode_key(): string {
		return 'players-stats';
	}

	/**
	 * Get the shortcode label for UI.
	 *
	 * @return string
	 * @since 0.14.1
	 */
	protected function get_shortcode_label(): string {
		return __( 'Players Stats', 'sports-leagues' );
	}

	/**
	 * Get default attribute values.
	 *
	 * @return array
	 * @since 0.14.1
	 */
	protected function get_defaults(): array {
		return [
			'stats_id'          => '',
			'game_id'           => '',
			'team_id'           => '',
			'tournament_id'     => '',
			'stage_id'          => '',
			'league_id'         => '',
			'season_id'         => '',
			'group_id'          => '',
			'round_id'          => '',
			'venue_id'          => '',
			'game_day'          => '',
			'order'             => '',
			'limit'             => 10,
			'soft_limit'        => 0,
			'show_position'     => 1,
			'show_team'         => 1,
			'show_nationality'  => 1,
			'show_photo'        => 1,
			'show_games_played' => 0,
			'link_to_profile'   => 0,
			'class'             => '',
			'position'          => '',
			'show_full'         => '',
		];
	}

	/**
	 * Get documentation URL.
	 *
	 * @return string
	 * @since 0.14.1
	 */
	protected function get_docs_url(): string {
		return 'https://anwppro.userecho.com/knowledge-bases/6/articles/611-players-stats-shortcode';
	}

	/**
	 * Get default preview width.
	 *
	 * @return int
	 * @since 0.14.1
	 */
	protected function get_default_preview_width(): int {
		return 700;
	}

	/**
	 * Get player stats options for the form.
	 *
	 * @return array
	 * @since 0.14.1
	 */
	protected function get_stats_options(): array {
		// Use + operator to preserve numeric stat IDs (array_merge re-indexes them).
		return [ '' => '- ' . __( 'select', 'sports-leagues' ) . ' -' ] + sports_leagues()->player_stats->get_stats_game_countable_options();
	}

	/**
	 * Get player positions for the form.
	 *
	 * @return array
	 * @since 0.14.1
	 */
	protected function get_position_options(): array {
		return sports_leagues()->config->get_player_positions();
	}

	/**
	 * Get form field definitions.
	 *
	 * @return array
	 * @since 0.14.1
	 */
	protected function get_form_fields(): array {
		return [
			// Data Selection Section
			[
				'type'  => 'section_header',
				'label' => __( 'Data Selection', 'sports-leagues' ),
			],
			[
				'type'         => 'select',
				'name'         => 'stats_id',
				'label'        => __( 'Stats', 'sports-leagues' ),
				'options_hook' => 'get_stats_options',
				'default'      => '',
			],
			[
				'type'         => 'tom_select',
				'name'         => 'position',
				'label'        => __( 'Player Position', 'sports-leagues' ),
				'options_hook' => 'get_position_options',
				'multiple'     => true,
				'default'      => '',
			],
			[
				'type'     => 'selector',
				'name'     => 'tournament_id',
				'label'    => __( 'Tournament', 'sports-leagues' ),
				'entity'   => 'tournament',
				'multiple' => false,
			],
			[
				'type'     => 'selector',
				'name'     => 'stage_id',
				'label'    => __( 'Tournament Stage', 'sports-leagues' ),
				'entity'   => 'stage',
				'multiple' => false,
			],
			[
				'type'     => 'selector',
				'name'     => 'season_id',
				'label'    => __( 'Season', 'sports-leagues' ),
				'entity'   => 'season',
				'multiple' => false,
			],
			[
				'type'     => 'selector',
				'name'     => 'league_id',
				'label'    => __( 'League', 'sports-leagues' ),
				'entity'   => 'league',
				'multiple' => false,
			],
			[
				'type'    => 'text',
				'name'    => 'group_id',
				'label'   => __( 'Group ID', 'sports-leagues' ),
				'default' => '',
			],
			[
				'type'    => 'text',
				'name'    => 'round_id',
				'label'   => __( 'Round ID', 'sports-leagues' ),
				'default' => '',
			],
			[
				'type'     => 'selector',
				'name'     => 'venue_id',
				'label'    => __( 'Venue', 'sports-leagues' ),
				'entity'   => 'venue',
				'multiple' => false,
			],
			[
				'type'     => 'selector',
				'name'     => 'team_id',
				'label'    => __( 'Team', 'sports-leagues' ),
				'entity'   => 'team',
				'multiple' => false,
			],
			[
				'type'     => 'selector',
				'name'     => 'game_id',
				'label'    => __( 'Game ID', 'sports-leagues' ),
				'entity'   => 'game',
				'multiple' => false,
			],
			[
				'type'    => 'text',
				'name'    => 'game_day',
				'label'   => __( 'Game Day', 'sports-leagues' ),
				'default' => '',
			],

			// Display Options Section
			[
				'type'  => 'section_header',
				'label' => __( 'Display Options', 'sports-leagues' ),
			],
			[
				'type'    => 'select',
				'name'    => 'order',
				'label'   => __( 'Order', 'sports-leagues' ),
				'default' => '',
				'options' => [
					''    => __( 'Descending', 'sports-leagues' ),
					'ASC' => __( 'Ascending', 'sports-leagues' ),
				],
			],
			[
				'type'    => 'number',
				'name'    => 'limit',
				'label'   => __( 'Limit', 'sports-leagues' ),
				'default' => '10',
			],
			[
				'type'    => 'yes_no',
				'name'    => 'soft_limit',
				'label'   => __( 'Soft Limit', 'sports-leagues' ),
				'default' => '0',
			],
			[
				'type'    => 'yes_no',
				'name'    => 'show_position',
				'label'   => __( 'Show Position', 'sports-leagues' ),
				'default' => '1',
			],
			[
				'type'    => 'yes_no',
				'name'    => 'show_team',
				'label'   => __( 'Show Team', 'sports-leagues' ),
				'default' => '1',
			],
			[
				'type'    => 'yes_no',
				'name'    => 'show_nationality',
				'label'   => __( 'Show Nationality', 'sports-leagues' ),
				'default' => '1',
			],
			[
				'type'    => 'yes_no',
				'name'    => 'show_photo',
				'label'   => __( 'Show Photo', 'sports-leagues' ),
				'default' => '1',
			],
			[
				'type'    => 'yes_no',
				'name'    => 'show_games_played',
				'label'   => __( 'Show Games Played', 'sports-leagues' ),
				'default' => '1',
			],
			[
				'type'    => 'yes_no',
				'name'    => 'link_to_profile',
				'label'   => __( 'Link to Profile', 'sports-leagues' ),
				'default' => '0',
			],
			[
				'type'    => 'yes_no',
				'name'    => 'show_full',
				'label'   => __( 'Show Full List in Modal', 'sports-leagues' ),
				'default' => '0',
			],
		];
	}
}
