<?php
/**
 * Dashboard widget partial.
 *
 * @package TrustLens\Admin\Views
 * @since   1.1.5
 */

defined( 'ABSPATH' ) || exit;

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- View template; variables are scoped to the including method, not the global namespace.
?>
<div class="wstl-dashboard-widget">
	<?php if ( $risk_count > 0 ) : ?>
		<p class="wstl-widget-alert">
			<?php
			echo esc_html(
				sprintf(
					/* translators: %d: number of high-risk customers */
					_n(
						'%d customer requires attention',
						'%d customers require attention',
						$risk_count,
						'trustlens'
					),
					$risk_count
				)
			);
			?>
		</p>
	<?php else : ?>
		<p class="wstl-widget-ok"><?php esc_html_e( 'No high-risk customers detected.', 'trustlens' ); ?></p>
	<?php endif; ?>

	<?php if ( ! empty( $high_risk ) ) : ?>
		<ul class="wstl-widget-list">
			<?php foreach ( $high_risk as $customer ) : ?>
				<li>
					<span class="wstl-segment-badge wstl-segment-<?php echo esc_attr( $customer->segment ); ?>">
						<?php echo esc_html( wstl_get_segment_label( $customer->segment ) ); ?>
					</span>
					<strong><?php echo esc_html( $customer->customer_email ?: __( 'Guest', 'trustlens' ) ); ?></strong>
					<br>
					<small>
						<?php
						printf(
							/* translators: %1$s: return rate, %2$s: refund value */
							esc_html__( '%1$s%% return rate', 'trustlens' ) . ' &middot; ' . esc_html__( '%2$s refunded', 'trustlens' ),
							esc_html( number_format( $customer->return_rate, 0 ) ),
							wp_kses_post( wc_price( $customer->total_refund_value ) )
						);
						?>
					</small>
				</li>
			<?php endforeach; ?>
		</ul>
	<?php endif; ?>

	<p class="wstl-widget-footer">
		<a href="<?php echo esc_url( admin_url( 'admin.php?page=trustlens' ) ); ?>">
			<?php esc_html_e( 'View Dashboard', 'trustlens' ); ?> &rarr;
		</a>
	</p>
</div>
