<?php
/**
 * StoreSheet daily sync digest email (plain text).
 *
 * @package StoreSheet
 *
 * @var array<string,mixed> $summary
 * @var string              $email_heading
 */

defined( 'ABSPATH' ) || exit;

$labels    = array(
	'product' => __( 'Products', 'storesheet' ),
	'order'   => __( 'Orders', 'storesheet' ),
	'coupon'  => __( 'Coupons', 'storesheet' ),
);
$resources = isset( $summary['resources'] ) && is_array( $summary['resources'] ) ? $summary['resources'] : array();

echo '= ' . esc_html( wp_strip_all_tags( $email_heading ) ) . " =\n\n";
esc_html_e( 'StoreSheet sync activity for the last 24 hours:', 'storesheet' );
echo "\n\n";

foreach ( $labels as $key => $label ) {
	$r = isset( $resources[ $key ] ) && is_array( $resources[ $key ] ) ? $resources[ $key ] : array();
	printf(
		"%s: %d synced, %d failed, %d skipped\n",
		esc_html( $label ),
		(int) ( $r['success'] ?? 0 ),
		(int) ( $r['failed'] ?? 0 ),
		(int) ( $r['skipped'] ?? 0 )
	);
}

echo "\n";
printf( "%s: %d\n", esc_html__( 'Total failed', 'storesheet' ), (int) ( $summary['total_failed'] ?? 0 ) );
