<?php
/**
 * Reusable segment legend — explains the six trust segments and their score
 * bands. Score bands are derived from the live thresholds so the legend stays
 * accurate even when they are customised.
 *
 * @package TrustLens\Admin\Views
 * @since   1.2.6
 */

defined( 'ABSPATH' ) || exit;

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template variables scoped to included view file.

$wstl_thresholds = wp_parse_args(
	get_option( 'trustlens_segment_thresholds', array() ),
	array(
		'vip'      => 90,
		'trusted'  => 70,
		'normal'   => 50,
		'caution'  => 30,
		'risk'     => 10,
		'critical' => 0,
	)
);
$wstl_thresholds = apply_filters( 'trustlens/segment_thresholds', $wstl_thresholds );

$wstl_segment_desc = array(
	'vip'      => __( 'Top customers. Loyal, clean history — safe to prioritise.', 'trustlens' ),
	'trusted'  => __( 'Good standing. Reliable buyers with no real red flags.', 'trustlens' ),
	'normal'   => __( 'Typical customer. Nothing notable yet — keep watching.', 'trustlens' ),
	'caution'  => __( 'Minor red flags, such as elevated returns or coupon use.', 'trustlens' ),
	'risk'     => __( 'Several concerns. Worth a look before high-value orders.', 'trustlens' ),
	'critical' => __( 'High likelihood of abuse. Review and block if warranted.', 'trustlens' ),
);

$wstl_segment_order = array( 'vip', 'trusted', 'normal', 'caution', 'risk', 'critical' );
?>
<details class="wstl-legend">
	<summary class="wstl-legend-summary"><?php esc_html_e( 'What do the segments mean?', 'trustlens' ); ?></summary>
	<ul class="wstl-legend-list">
		<?php
		$wstl_prev_low = 101;
		foreach ( $wstl_segment_order as $wstl_seg ) :
			$wstl_low      = (int) ( $wstl_thresholds[ $wstl_seg ] ?? 0 );
			$wstl_high     = $wstl_prev_low - 1;
			$wstl_prev_low = $wstl_low;
			?>
			<li class="wstl-legend-item">
				<span class="wstl-segment-badge wstl-segment-<?php echo esc_attr( $wstl_seg ); ?>">
					<?php echo esc_html( wstl_get_segment_label( $wstl_seg ) ); ?>
				</span>
				<span class="wstl-legend-range"><?php echo esc_html( $wstl_low . '–' . $wstl_high ); ?></span>
				<span class="wstl-legend-desc"><?php echo esc_html( $wstl_segment_desc[ $wstl_seg ] ); ?></span>
			</li>
		<?php endforeach; ?>
	</ul>
</details>
<?php // phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound ?>
