<?php
/**
 * Sports Leagues :: Shortcode > Games.
 *
 * @since   0.5.5
 * @package Sports_Leagues
 */

/**
 * Sports Leagues :: Shortcode > Games.
 *
 * @since 0.5.5
 * @since 0.14.1 Refactored to extend Sports_Leagues_Shortcode_Base.
 */
class Sports_Leagues_Shortcode_Games extends Sports_Leagues_Shortcode_Base {

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

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

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

	/**
	 * Get default attribute values.
	 *
	 * @return array
	 * @since 0.14.1
	 */
	protected function get_defaults(): array {
		return [
			'tournament_id'         => '',
			'stage_id'              => '',
			'season_id'             => '',
			'league_id'             => '',
			'group_id'              => '',
			'round_id'              => '',
			'venue_id'              => '',
			'date_from'             => '',
			'date_to'               => '',
			'finished'              => '',
			'filter_by_team'        => '',
			'filter_by_game_day'    => '',
			'limit'                 => '',
			'days_offset'           => '',
			'days_offset_to'        => '',
			'priority'              => '',
			'sort_by_date'          => '',
			'sort_by_game_day'      => '',
			'group_by'              => '',
			'group_by_header_style' => '',
			'show_team_logo'        => 1,
			'show_game_datetime'    => 1,
			'tournament_logo'       => 1,
			'class'                 => 'mt-4',
			'exclude_ids'           => '',
			'include_ids'           => '',
			'outcome_id'            => '',
			'header_style'          => 'header',
			'header_class'          => '',
			'game_layout'           => '',
			'show_load_more'        => false,
		];
	}

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

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

	/**
	 * Get form field definitions.
	 *
	 * @return array
	 * @since 0.14.1
	 */
	protected function get_form_fields(): array {
		return [
			// Query Filters Section
			[
				'type'  => 'section_header',
				'label' => __( 'Query Filters', 'sports-leagues' ),
			],
			[
				'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'    => 'select',
				'name'    => 'finished',
				'label'   => __( 'Game Status', 'sports-leagues' ),
				'default' => '',
				'options' => [
					''  => __( 'All', 'sports-leagues' ),
					'1' => __( 'Finished', 'sports-leagues' ),
					'0' => __( 'Upcoming', 'sports-leagues' ),
				],
			],
			[
				'type'     => 'selector',
				'name'     => 'filter_by_team',
				'label'    => __( 'Filter By Teams', 'sports-leagues' ),
				'entity'   => 'team',
				'multiple' => true,
			],

			// Date Filters Section
			[
				'type'  => 'section_header',
				'label' => __( 'Date Filters', 'sports-leagues' ),
			],
			[
				'type'        => 'text',
				'name'        => 'date_from',
				'label'       => __( 'Date From', 'sports-leagues' ),
				'default'     => '',
				'description' => __( 'Format: YYYY-MM-DD', 'sports-leagues' ),
			],
			[
				'type'        => 'text',
				'name'        => 'date_to',
				'label'       => __( 'Date To', 'sports-leagues' ),
				'default'     => '',
				'description' => __( 'Format: YYYY-MM-DD', 'sports-leagues' ),
			],
			[
				'type'        => 'text',
				'name'        => 'filter_by_game_day',
				'label'       => __( 'Filter By GameDay', 'sports-leagues' ),
				'default'     => '',
				'description' => __( 'Comma separated list of options', 'sports-leagues' ),
			],
			[
				'type'        => 'text',
				'name'        => 'days_offset',
				'label'       => __( 'Dynamic days filter', 'sports-leagues' ),
				'default'     => '',
				'description' => __( 'For example: "-2" from 2 days ago and newer; "2" from day after tomorrow and newer', 'sports-leagues' ),
			],
			[
				'type'        => 'text',
				'name'        => 'days_offset_to',
				'label'       => __( 'Dynamic days filter to', 'sports-leagues' ),
				'default'     => '',
				'description' => __( 'For example: "1" till tomorrow (tomorrow not included)', 'sports-leagues' ),
			],

			// Sorting & Grouping Section
			[
				'type'  => 'section_header',
				'label' => __( 'Sorting & Grouping', 'sports-leagues' ),
			],
			[
				'type'    => 'select',
				'name'    => 'sort_by_date',
				'label'   => __( 'Sort By Date', 'sports-leagues' ),
				'default' => '',
				'options' => [
					''     => __( 'none', 'sports-leagues' ),
					'asc'  => __( 'Ascending', 'sports-leagues' ),
					'desc' => __( 'Descending', 'sports-leagues' ),
				],
			],
			[
				'type'    => 'select',
				'name'    => 'sort_by_game_day',
				'label'   => __( 'Sort By GameDay', 'sports-leagues' ),
				'default' => '',
				'options' => [
					''     => __( 'none', 'sports-leagues' ),
					'asc'  => __( 'Ascending', 'sports-leagues' ),
					'desc' => __( 'Descending', 'sports-leagues' ),
				],
			],
			[
				'type'    => 'select',
				'name'    => 'group_by',
				'label'   => __( 'Group By', 'sports-leagues' ),
				'default' => '',
				'options' => [
					''        => __( 'none', 'sports-leagues' ),
					'day'     => __( 'Day', 'sports-leagues' ),
					'month'   => __( 'Month', 'sports-leagues' ),
					'gameday' => __( 'GameDay', 'sports-leagues' ),
					'stage'   => __( 'Stage', 'sports-leagues' ),
				],
			],
			[
				'type'    => 'number',
				'name'    => 'limit',
				'label'   => __( 'Games Limit', 'sports-leagues' ),
				'default' => 10,
			],

			// Display Options Section
			[
				'type'  => 'section_header',
				'label' => __( 'Display Options', 'sports-leagues' ),
			],
			[
				'type'    => 'yes_no',
				'name'    => 'show_team_logo',
				'label'   => __( 'Show team logo', 'sports-leagues' ),
				'default' => '1',
			],
			[
				'type'    => 'yes_no',
				'name'    => 'show_game_datetime',
				'label'   => __( 'Show game datetime', 'sports-leagues' ),
				'default' => '1',
			],
			[
				'type'    => 'yes_no',
				'name'    => 'tournament_logo',
				'label'   => __( 'Show tournament logo', 'sports-leagues' ),
				'default' => '1',
			],
			[
				'type'    => 'yes_no',
				'name'    => 'show_load_more',
				'label'   => __( 'Show Load More', 'sports-leagues' ),
				'default' => '0',
			],

			// Advanced Options Section
			[
				'type'  => 'section_header',
				'label' => __( 'Advanced Options', 'sports-leagues' ),
			],
			[
				'type'        => 'selector',
				'name'        => 'outcome_id',
				'label'       => __( 'Show Outcome for team ID', 'sports-leagues' ),
				'entity'      => 'team',
				'multiple'    => false,
				'description' => __( 'works only in "slim" layout', 'sports-leagues' ),
			],
			[
				'type'        => 'selector',
				'name'        => 'include_ids',
				'label'       => __( 'Include IDs', 'sports-leagues' ),
				'entity'      => 'game',
				'multiple'    => true,
				'description' => __( 'comma-separated list of IDs', 'sports-leagues' ),
			],
			[
				'type'        => 'selector',
				'name'        => 'exclude_ids',
				'label'       => __( 'Exclude IDs', 'sports-leagues' ),
				'entity'      => 'game',
				'multiple'    => true,
				'description' => __( 'comma-separated list of IDs', 'sports-leagues' ),
			],
		];
	}
}
