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

declare(strict_types=1);

use Northmill_Online_Shared\Helpers\Time_Helpers;

defined( 'ABSPATH' ) || exit;

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

?>
<h2 id="cron-events"><?php esc_html_e( 'Cron events', 'northmill-online-shared' ); ?></h2>
<table class="nmf-sync-table">
	<thead>
	<tr>
		<th><?php esc_html_e( 'Event', 'northmill-online-shared' ); ?></th>
		<th><?php esc_html_e( 'Is enabled', 'northmill-online-shared' ); ?></th>
		<th><?php esc_html_e( 'Status', 'northmill-online-shared' ); ?></th>
		<th><?php esc_html_e( 'Recurrence', 'northmill-online-shared' ); ?></th>
		<th><?php esc_html_e( 'Next scheduled', 'northmill-online-shared' ); ?></th>
	</tr>
	</thead>
	<tbody>
	<?php

	foreach ( $params['cron_events'] as $cron_event ) {
		echo '<tr>';
		echo '<td>' . esc_html( $cron_event->get_event() ) . '</td>';
		echo '<td>' . esc_html( $cron_event->get_is_enabled() ) . '</td>';
		echo '<td>' . esc_html( $cron_event->get_status() ) . '</td>';
		echo '<td>' . esc_html( $cron_event->get_recurrence() ) . '</td>';
		echo '<td>' . ( $cron_event->get_next_scheduled() ? esc_html( wp_date( 'Y-m-d H:i:s', $cron_event->get_next_scheduled() ) ) : '' ) . '</td>';
		echo '</tr>';
	}
	?>
	</tbody>
</table>
<h2 id="active-cron-locks"><?php esc_html_e( 'Active cron locks', 'northmill-online-shared' ); ?></h2>
<table class="nmf-sync-table">
	<thead>
	<tr>
		<th><?php esc_html_e( 'Name', 'northmill-online-shared' ); ?></th>
		<th><?php esc_html_e( 'Lock time', 'northmill-online-shared' ); ?></th>
		<th><?php esc_html_e( 'Lock age', 'northmill-online-shared' ); ?></th>
		<th><?php esc_html_e( 'Lock value', 'northmill-online-shared' ); ?></th>
		<th><?php esc_html_e( 'Remove lock', 'northmill-online-shared' ); ?></th>
	</tr>
	</thead>
	<tbody>
	<?php

	foreach ( $params['locks'] as $lock_name => $lock ) {
		echo '<tr>';
		echo '<td>' . esc_html( $lock_name ) . '</td>';
		echo '<td>' . esc_html( wp_date( 'Y-m-d H:i:s', $lock['time'] ) ) . '</td>';
		echo '<td>' . esc_html( Time_Helpers::get_timestamp_age( $lock['time'] ) ) . '</td>';
		echo '<td>' . esc_html( $lock['value'] ) . '</td>';
		echo '<td><a href="#" class="nmf-cron-remove" data-lock-name="' . esc_attr( $lock_name ) . '">' . esc_html__( 'Remove', 'northmill-online-shared' ) . '</a></td>';
		echo '</tr>';
	}
	?>
	</tbody>
</table>
