<?php
/**
 * Attendance summary digest email body.
 *
 * @package MerchantKits\AttendanceManager
 *
 * @var string $date_from Range start (Y-m-d).
 * @var string $date_to   Range end (Y-m-d).
 * @var array  $records   Attendance rows in range.
 * @var string $summary   Optional AI-generated summary text.
 */

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

$records = isset( $records ) ? $records : array();
$summary = isset( $summary ) ? $summary : '';

$present = 0;
$late    = 0;
$absent  = 0;
$leave   = 0;

foreach ( $records as $record ) {
	switch ( $record['status'] ) {
		case 'present':
			$present++;
			break;
		case 'late':
			$late++;
			break;
		case 'absent':
			$absent++;
			break;
		case 'on_leave':
			$leave++;
			break;
	}
}
?>
<p>
	<?php
	/* translators: 1: start date, 2: end date. */
	printf( esc_html__( 'Attendance summary for %1$s to %2$s.', 'merchantkits-attendance-manager' ), esc_html( $date_from ), esc_html( $date_to ) );
	?>
</p>
<ul>
	<li><strong><?php esc_html_e( 'Present:', 'merchantkits-attendance-manager' ); ?></strong> <?php echo esc_html( $present ); ?></li>
	<li><strong><?php esc_html_e( 'Late:', 'merchantkits-attendance-manager' ); ?></strong> <?php echo esc_html( $late ); ?></li>
	<li><strong><?php esc_html_e( 'Absent:', 'merchantkits-attendance-manager' ); ?></strong> <?php echo esc_html( $absent ); ?></li>
	<li><strong><?php esc_html_e( 'On Leave:', 'merchantkits-attendance-manager' ); ?></strong> <?php echo esc_html( $leave ); ?></li>
</ul>
<?php if ( '' !== $summary ) : ?>
	<h3><?php esc_html_e( 'AI Summary', 'merchantkits-attendance-manager' ); ?></h3>
	<div style="background:#f9fafb;border:1px solid #e5e7eb;padding:16px;border-radius:4px;white-space:pre-wrap;"><?php echo esc_html( $summary ); ?></div>
<?php endif; ?>
