<?php
/**
 * Admin status page.
 *
 * @package flo-sync
 */

namespace NMFS\Admin\Pages;

use NMFS\Plugin_Upgrade;
use NMFS\Sync\Items\Article_Availabilities\Article_Availabilities;
use Northmill_Online_Shared_Sync\Northmill_Online_Shared\Abstracts\Hub_API\Hub_Accounts\Shipping\Shipping_Zones;

defined( 'ABSPATH' ) || exit;

/**
 * Admin status page.
 */
class Admin_Status {

	/**
	 * Setup shared hooks.
	 *
	 * @param string $service_name_underscored The service name in underscored format.
	 *
	 * @return void
	 */
	public static function setup_shared_hooks( string $service_name_underscored ): void {
		add_filter(
			'northmill_online_shared_admin_status_tabs_' . $service_name_underscored,
			array( self::class, 'filter_status_page_tabs' )
		);
	}
	/**
	 * Filter the tabs on the status page.
	 *
	 * @param array $tabs The current tabs.
	 *
	 * @return array The updated tabs
	 */
	public static function filter_status_page_tabs( array $tabs ): array {
		$tabs['article-availabilities'] = array(
			'title'         => __( 'Article availability', 'flo-sync' ),
			'template_part' => 'article-availabilities',
			'view_params'   => function () {
				return array(
					'availabilities' => Article_Availabilities::get_all_availabilities(),
				);
			},
		);

		$tabs['woocommerce-settings'] = array(
			'title'         => __( 'WooCommerce settings', 'flo-sync' ),
			'template_part' => 'woocommerce-settings',
			'view_params'   => function () {
				return array(
					'shipping_zones' => Shipping_Zones::get_all_zones(),
				);
			},
			'toc'           => array(
				array(
					'id'    => 'shipping-methods',
					'title' => __( 'Shipping methods', 'flo-sync' ),
				),
				array(
					'id'    => 'price-decimals',
					'title' => __( 'Price decimals', 'flo-sync' ),
				),
			),
		);

		self::maybe_add_test_tab( $tabs );

		return $tabs;
	}

	/**
	 * Maybe add a test tab.
	 *
	 * @param array $tab The current sections.
	 *
	 * @phpcs:disable Squiz.PHP.NonExecutableCode.Unreachable
	 * @phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_print_r
	 * @phpcs:disable Squiz.Commenting.InlineComment.InvalidEndChar
	 * @phpcs:disable Squiz.PHP.CommentedOutCode.Found
	 * @noinspection PhpUnreachableStatementInspection
	 * @noinspection PhpUnusedParameterInspection
	 * @noinspection RedundantSuppression
	 */
	private static function maybe_add_test_tab( array &$tab ): void {
		return;

		ob_start();

		$updates = Plugin_Upgrade::get_upgrades( array() );
		$updater = $updates['4.1.0'];
		// $updater( false );

		$content     = ob_get_clean();
		$tab['test'] = array(
			'title'   => 'Test',
			'content' => $content,
		);
	}
	// @phpcs:enable Squiz.PHP.NonExecutableCode.Unreachable
	// @phpcs:enable WordPress.PHP.DevelopmentFunctions.error_log_print_r
	// @phpcs:enable Squiz.Commenting.InlineComment.InvalidEndChar
	// @phpcs:enable Squiz.PHP.CommentedOutCode.Found
}
