<?php

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

use EaLab\WP_Deployer\includes\controller\SynchronizePageController;
use EaLab\WP_Deployer\vendor\Dakwamine\Component\ComponentBasedObject;
use EaLab\WP_Deployer\vendor\Ealab\Deployer\Utility\Environment;

add_filter(
	'deploy_sync_content__routes',
	static function ( array $routes = array() ): array {
		$handle_route_callback = static function ( array $route_info ) {
			try {
				Environment::isProductionEnvironment() && deploy_sync_content__info_notice( __( 'You are on the synchronize page of the <strong>live</strong> site.', 'deploy-sync-content' ) );
			} catch ( \Throwable $throwable ) {
				return;
			}

			$synchronize_route_controller = ComponentBasedObject::getRootComponentByClassName( SynchronizePageController::class, true );
			$synchronize_route_controller->handle( $route_info );
		};

		$routes['synchronize'] = [
			'id'                    => 'synchronize',
			'label'                 => __( 'Synchronize', 'deploy-sync-content' ),
			'handle_route_callback' => $handle_route_callback,
		];

		return $routes;
	},
	-10
);
