<?php
/**
 * Display the progress of the tracking queue.
 *
 * @package EaLab\WP_Deployer
 */

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

/**
 * Display the progress of the tracking queue.
 */
function deploy_sync_content__tracking_queue_progress(): void {
	$endpoint_url = rest_url( 'deploy-sync-content/v1/tracking-queue/progress' );

	?>
	<tracking-queue-progress data-url="<?php echo esc_attr( $endpoint_url ) ?>">
		<div class="status-text in-progress"><?php echo esc_html__( 'Loading the queue status…', 'deploy-sync-content' ) ?></div>
	</tracking-queue-progress>
	<?php

	/**
	 * Enqueue the assets for the tracking queue progress component.
	 */
	wp_enqueue_style(
		'deploy-sync-content--tracking-queue-progress',
		plugins_url( '/admin/assets/css/tracking-queue-progress.css', DEPLOY_SYNC_CONTENT__PLUGIN_FILE ),
		array(),
		DEPLOY_SYNC_CONTENT__VERSION
	);

	wp_enqueue_script(
		'deploy-sync-content--tracking-queue-progress',
		plugins_url( '/admin/assets/js/tracking-queue-progress.js', DEPLOY_SYNC_CONTENT__PLUGIN_FILE ),
		array(),
		DEPLOY_SYNC_CONTENT__VERSION,
		true
	);

	// Attach the nonce to the script.
	wp_localize_script(
		'deploy-sync-content--tracking-queue-progress',
		'deploy_sync_content__trackingQueueProgress_settings',
		array(
			'rest' => array(
				'nonce' => wp_create_nonce( 'wp_rest' ),
			),
			'text' => array(
				'loadingQueueStatus' => esc_html__( 'Loading the queue status…', 'deploy-sync-content' ),
				'lastHourOutput'     => esc_html__( 'Last hour output:', 'deploy-sync-content' ),
				'networkError'       => esc_html__( 'A network error occurred.', 'deploy-sync-content' ),
				'remainingSteps'     => esc_html__( 'Remaining steps: ', 'deploy-sync-content' ),
				'queueProcessed'     => esc_html__( 'The queue has been processed.', 'deploy-sync-content' ),
			),
		)
	);
}
