<?php
/**
 * Sport Configurator
 *
 * @link       https://anwp.pro
 * @since      0.10.0
 *
 * @package    Sports_Leagues
 * @subpackage Sports_Leagues/admin/views
 */

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

// Must check that the user has the required capability
if ( ! current_user_can( 'manage_options' ) ) {
	wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'sports-leagues' ) );
}

$app_id = apply_filters( 'sports-leagues/configurator-page/vue_app_id', 'sl-app-sport-configurator' );

// Get menu collapsed status
$is_menu_collapsed = 'yes' === get_user_setting( 'anwp-sl-collapsed-menu' );

/*
|--------------------------------------------------------------------
| App Options
|--------------------------------------------------------------------
*/
$app_options = [
	'sports_available' => [
		[
			'title' => esc_html__( 'Basketball', 'sports-leagues' ),
			'slug'  => 'basketball',
		],
		[
			'title' => esc_html__( 'Handball', 'sports-leagues' ),
			'slug'  => 'handball',
		],
		[
			'title' => esc_html__( 'Rugby', 'sports-leagues' ),
			'slug'  => 'rugby',
		],
		[
			'title' => esc_html__( 'American football', 'sports-leagues' ),
			'slug'  => 'football',
		],
		[
			'title' => esc_html__( 'Ice Hockey', 'sports-leagues' ),
			'slug'  => 'ice_hockey',
		],
		[
			'title' => esc_html__( 'Other', 'sports-leagues' ),
			'slug'  => 'other',
		],
	],
];

/*
|--------------------------------------------------------------------
| Data Options
|--------------------------------------------------------------------
*/
$data_options = [
	'position'            => [
		'name_min' => 1,
		'abbr'     => true,
		'id'       => true,
		'title'    => 'Position',
	],
	'roster_status'       => [
		'name_min' => 3,
		'abbr'     => false,
		'id'       => false,
		'title'    => 'Roster Status',
	],
	'roster_groups'       => [
		'name_min' => 3,
		'abbr'     => false,
		'id'       => true,
		'title'    => 'Roster Group',
	],
	'game_player_groups'  => [
		'name_min' => 3,
		'abbr'     => false,
		'id'       => true,
		'title'    => 'Player Game Group',
	],
	'staff_roster_groups' => [
		'name_min' => 3,
		'abbr'     => false,
		'id'       => true,
		'title'    => 'Staff Roster Group',
	],
	'game_staff_groups'   => [
		'name_min' => 3,
		'abbr'     => false,
		'id'       => true,
		'title'    => 'Staff Game Group',
	],
	'official_groups'     => [
		'name_min' => 3,
		'abbr'     => false,
		'id'       => true,
		'title'    => 'Official Group',
	],
	'game_team_stats'     => [
		'name_min' => 3,
		'abbr'     => false,
		'id'       => true,
		'title'    => 'Game Team Stat',
	],
	'tournament_types'    => [
		'name_min' => 3,
		'abbr'     => false,
		'id'       => true,
		'title'    => 'Tournament Type',
	],
];

/*
|--------------------------------------------------------------------
| Recommended Data (shared from Sports_Leagues_Config class)
|--------------------------------------------------------------------
*/
$recommended_config = Sports_Leagues_Config::get_recommended_configs();

?>
<script type="text/javascript">
	var _slConfiguratorDataOptions = <?php echo wp_json_encode( $data_options ); ?>;
	var _slConfiguratorOptions     = <?php echo wp_json_encode( $app_options ); ?>;
	var _slConfiguratorRecommended = <?php echo wp_json_encode( $recommended_config ); ?>;
	var _slConfigurator            = <?php echo wp_json_encode( get_option( 'sports_leagues_config', [] ) ); ?>;
</script>
<div class="wrap anwp-b-wrap">
	<div class="mb-4 pb-1">
		<h1 class="mb-0"><?php echo esc_html__( 'Sports Leagues', 'sports-leagues' ) . ' :: ' . esc_html__( 'Sport Configurator', 'sports-leagues' ); ?></h1>
		<ul class="subsubsub">
			<li><a href="#" class="current"><?php echo esc_html__( 'Sport Configurator', 'sports-leagues' ); ?> </a> |</li>
			<li><a target="_blank" href="<?php echo esc_url( admin_url( 'admin.php?page=sl-player-stats' ) ); ?>"><?php echo esc_html__( 'Player Statistics', 'sports-leagues' ); ?></a> |</li>
			<li><a target="_blank" href="<?php echo esc_url( admin_url( 'admin.php?page=sports_leagues_event' ) ); ?>"><?php echo esc_html__( 'Game Events', 'sports-leagues' ); ?></a></li>
		</ul>
		<div class="clear"></div>
	</div>

	<div class="d-flex mt-2 align-items-start" id="anwp-sl-metabox-page-nav">
		<div class="anwp-sl-menu-wrapper mr-3 d-none d-md-block anwp-flex-none <?php echo esc_attr( $is_menu_collapsed ? 'anwp-sl-collapsed-menu' : '' ); ?>" style="position: sticky; top: 50px;">

			<button id="anwp-sl-publish-click-proxy" class="w-100 button button-primary py-2 mb-4 d-flex align-items-center justify-content-center" type="submit">
				<svg class="anwp-icon anwp-icon--feather anwp-icon--s16"><use xlink:href="#icon-save"></use></svg>
				<span class="ml-2"><?php echo esc_html__( 'Save', 'sports-leagues' ); ?></span>
				<span class="spinner m-0"></span>
			</button>

			<ul class="m-0 p-0 list-unstyled">
				<?php
				$nav_items = [
					// Getting Started Group
					[
						'icon'  => 'gear',
						'label' => esc_html__( 'General Info', 'sports-leagues' ),
						'slug'  => 'anwp-sl-general-metabox',
					],

					// Players Group
					[
						'type'  => 'separator',
						'label' => esc_html__( 'Players', 'sports-leagues' ),
					],
					[
						'icon'  => 'jersey',
						'label' => esc_html__( 'Player Position', 'sports-leagues' ),
						'slug'  => 'anwp-sl-player-position-metabox',
					],
					[
						'icon'  => 'jersey',
						'label' => esc_html__( 'Player Roster Status', 'sports-leagues' ),
						'slug'  => 'anwp-sl-player-roster-status-metabox',
					],
					[
						'icon'  => 'jersey',
						'label' => esc_html__( 'Player Roster Groups', 'sports-leagues' ),
						'slug'  => 'anwp-sl-player-roster-groups-metabox',
					],
					[
						'icon'  => 'jersey',
						'label' => esc_html__( 'Player Game Groups', 'sports-leagues' ),
						'slug'  => 'anwp-sl-player-game-groups-metabox',
					],

					// Staff & Officials Group
					[
						'type'  => 'separator',
						'label' => esc_html__( 'Staff & Officials', 'sports-leagues' ),
					],
					[
						'icon'  => 'organization',
						'label' => esc_html__( 'Staff Roster Groups', 'sports-leagues' ),
						'slug'  => 'anwp-sl-staff-roster-groups-metabox',
					],
					[
						'icon'  => 'organization',
						'label' => esc_html__( 'Staff Game Groups', 'sports-leagues' ),
						'slug'  => 'anwp-sl-staff-game-groups-metabox',
					],
					[
						'icon'  => 'organization',
						'label' => esc_html__( 'Official Groups', 'sports-leagues' ),
						'slug'  => 'anwp-sl-official-groups-metabox',
					],

					// Game Structure Group
					[
						'type'  => 'separator',
						'label' => esc_html__( 'Game Structure', 'sports-leagues' ),
					],
					[
						'icon'  => 'graph',
						'label' => esc_html__( 'Game Team Statistics', 'sports-leagues' ),
						'slug'  => 'anwp-sl-game-team-stats-metabox',
					],
					[
						'icon'  => 'law',
						'label' => esc_html__( 'Standing Points', 'sports-leagues' ),
						'slug'  => 'anwp-sl-points-awarded-metabox',
					],
					[
						'icon'  => 'repo-forked',
						'label' => esc_html__( 'Game Structure', 'sports-leagues' ),
						'slug'  => 'anwp-sl-number-of-periods-metabox',
					],
					[
						'icon'  => 'note',
						'label' => esc_html__( 'Standing Column Names', 'sports-leagues' ),
						'slug'  => 'anwp-sl-standing-columns-text-metabox',
					],
					[
						'icon'  => 'note',
						'label' => esc_html__( 'Team Series (letter)', 'sports-leagues' ),
						'slug'  => 'anwp-sl-team-series-metabox',
					],

					// Tournaments Group
					[
						'type'  => 'separator',
						'label' => esc_html__( 'Tournaments', 'sports-leagues' ),
					],
					[
						'icon'  => 'repo-forked',
						'label' => esc_html__( 'Tournament Types', 'sports-leagues' ),
						'slug'  => 'anwp-sl-tournament-type-metabox',
					],
				];

				/**
				 * Modify metabox nav items
				 *
				 * @since 0.10.0
				 */
				$nav_items = apply_filters( 'sports-leagues/configurator/metabox_nav_items', $nav_items );

				// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
				echo sports_leagues()->helper->create_metabox_navigation( $nav_items );

				/**
				 * Fires at the bottom of Metabox Nav.
				 *
				 * @since 0.10.0
				 */
				do_action( 'sports-leagues/configurator/metabox_nav_bottom' );
				?>
			</ul>

		</div>
		<div class="flex-grow-1 anwp-min-width-0 mb-4">

			<div class="anwp-border anwp-border-blue-300 p-3 anwp-bg-blue-100 mb-4 d-flex align-items-center">
				<svg class="anwp-icon anwp-icon--s36 anwp-icon--octi mr-3 anwp-text-blue-800 anwp-fill-current"><use xlink:href="#icon-info"></use></svg>
				<p class="my-0 anwp-text-sm anwp-text-blue-900">
					It is the most important part of your app, the basis of your sports data.
					<br>Please spend a bit more time on this page to set up everything properly.
					You can use predefined configurations for different sports as a hint.
				</p>
			</div>

			<div id="<?php echo esc_attr( $app_id ); ?>"></div>

			<?php
			/**
			 * Fires at the bottom of Metabox.
			 *
			 * @since 0.10.0
			 */
			do_action( 'sports-leagues/configurator/metabox_bottom' );
			?>
		</div>
	</div>

	<?php do_action( 'sports-leagues/configurator-page/after_config' ); ?>
</div>
