<?php
/**
 * Status tab – Latest syncs.
 *
 * @package northmill-online-shared
 */

declare(strict_types=1);

use Northmill_Online_Shared\Abstracts\Hub_API\Sync\Ajax\Models\Sync_Request_Model;

defined( 'ABSPATH' ) || exit;

/**
 * View parameters.
 *
 * @var array $params
 */

/**
 * All Sync_Request_Models
 *
 * @var Sync_Request_Model[] $ajax_syncers
 */
$ajax_syncers = $params['ajax_syncers'];

?>
<h2><?php esc_html_e( 'Latest syncs with Hub', 'northmill-online-shared' ); ?></h2>
<p>
<?php
echo wp_kses_post(
	sprintf(
				// translators: %s: column name.
		__( 'The %s column can be clicked to edit the value. Press enter to save. Press escape to cancel.', 'northmill-online-shared' ),
		'<i>' . __( 'Latest sync', 'northmill-online-shared' ) . '</i>',
	)
);
?>
</p>
<table class="nmf-sync-table">
	<thead>
	<tr>
		<th><?php esc_html_e( 'Type', 'northmill-online-shared' ); ?></th>
		<th><?php esc_html_e( 'Latest sync', 'northmill-online-shared' ); ?></th>
		<th><?php esc_html_e( 'Latest Ajax sync', 'northmill-online-shared' ); ?></th>
		<th><?php esc_html_e( 'Latest Ajax sync all', 'northmill-online-shared' ); ?></th>
		<th><?php esc_html_e( 'Latest Cron sync', 'northmill-online-shared' ); ?></th>
	</tr>
	</thead>
	<tbody>
	<?php
	foreach ( $ajax_syncers as $sync_type => $data ) {
		echo '<tr>';
		echo '<td>' . esc_html( $data->syncer->get_display_name() ) . '</td>';
		echo '<td class="nmf-latest-sync" data-syncer="' . esc_attr( $sync_type ) . '">' . esc_html( $data->syncer->get_last_synced_wp_option() ) . '</td>';
		echo '<td>' . esc_html( $data->syncer->get_last_synced_wp_option( 'ajax' ) ) . '</td>';
		echo '<td>' . esc_html( $data->syncer->get_last_synced_wp_option( 'ajax_all' ) ) . '</td>';
		echo '<td>' . esc_html( $data->syncer->get_last_synced_wp_option( 'cron' ) ) . '</td>';
		echo '</tr>';
	}
	?>
	</tbody>
</table>
