<?php

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

add_filter(
	'deploy_sync_content__routes',
	static function ( array $routes = array() ): array {
		$handle_route_callback = static function () {
			// reactive-json assets.
			require_once DEPLOY_SYNC_CONTENT__PLUGIN_DIR . '/admin/partials/bundle-ui-v2-assets.php';

			$reactive_json_data_endpoint = get_rest_url( null, 'deploy-sync-content/v1/dashboard/ui' );
			?>
			<div class="container-deploy-sync-content-options">
				<reactive-json data-url="<?php echo esc_attr( $reactive_json_data_endpoint ); ?>">
					<data-source-request-header data-header-field="X-WP-Nonce"
						data-header-value="<?php echo esc_attr( wp_create_nonce( 'wp_rest' ) ) ?>"></data-source-request-header>
				</reactive-json>
			</div>
			<?php
		};

		$routes['dashboard'] = [
			'id'                    => 'dashboard',
			'label'                 => __( 'Dashboard', 'deploy-sync-content' ),
			'handle_route_callback' => $handle_route_callback,
			'has_tab'               => true,
			'weight'                => -500,
		];

		return $routes;
	},
	- 10
);
