<?php
/**
 * Order metabox partial.
 *
 * @package TrustLens\Admin\Views
 * @since   1.1.5
 */

defined( 'ABSPATH' ) || exit;
?>
<?php
$wstl_seg   = (string) $customer->segment;
$wstl_score = max( 0, min( 100, (int) $customer->trust_score ) );
?>
<div class="wstl-ct wstl-ct--<?php echo esc_attr( $wstl_seg ); ?><?php echo $is_risky ? ' is-risky' : ''; ?>">
	<style>
	.wstl-ct{--seg:#607080;margin:-6px -12px -12px;padding:14px 12px 12px;font-size:13px;color:#1e293b;-webkit-font-smoothing:antialiased}
	.wstl-ct--vip{--seg:#1E7A46}.wstl-ct--trusted{--seg:#2B6FE8}.wstl-ct--normal{--seg:#607080}
	.wstl-ct--caution{--seg:#B88318}.wstl-ct--risk{--seg:#C4652B}.wstl-ct--critical{--seg:#B23A48}
	.wstl-ct.is-risky{background:color-mix(in srgb,var(--seg) 6%,#fff);border-top:3px solid var(--seg)}
	.wstl-ct__top{display:flex;align-items:center;justify-content:space-between;gap:8px}
	.wstl-ct__pill{display:inline-block;background:var(--seg);color:#fff;font-size:10px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;padding:3px 9px;border-radius:999px;line-height:1.4}
	.wstl-ct__score{line-height:1;font-variant-numeric:tabular-nums}
	.wstl-ct__score b{font-size:30px;font-weight:800;color:var(--seg)}
	.wstl-ct__score i{font-size:13px;font-style:normal;font-weight:600;color:#94a3b8}
	.wstl-ct__track{height:6px;border-radius:999px;background:#eef1f4;margin:11px 0 0;overflow:hidden}
	.wstl-ct__track span{display:block;height:100%;border-radius:999px;background:var(--seg)}
	.wstl-ct__stats{display:flex;margin:13px 0 0;text-align:center}
	.wstl-ct__stats div{flex:1;border-left:1px solid #eef1f4}
	.wstl-ct__stats div:first-child{border-left:0}
	.wstl-ct__stats b{display:block;font-size:15px;font-weight:700;color:#1e293b;font-variant-numeric:tabular-nums}
	.wstl-ct__stats i{display:block;margin-top:2px;font-size:10px;font-style:normal;text-transform:uppercase;letter-spacing:.04em;color:#64748b}
	.wstl-ct__flag{margin:13px 0 0;padding:7px 10px;border-radius:5px;background:color-mix(in srgb,var(--seg) 12%,#fff);color:var(--seg);font-size:12px;font-weight:600}
	.wstl-ct__foot{margin:13px 0 0}
	.wstl-ct__link{color:#1E7A46;font-weight:600;text-decoration:none}
	.wstl-ct__link:hover{text-decoration:underline}
	</style>

	<div class="wstl-ct__top">
		<span class="wstl-ct__pill"><?php echo esc_html( wstl_get_segment_label( $wstl_seg ) ); ?></span>
		<span class="wstl-ct__score"><b><?php echo esc_html( (string) $wstl_score ); ?></b><i>/100</i></span>
	</div>

	<div class="wstl-ct__track"><span style="width:<?php echo esc_attr( (string) $wstl_score ); ?>%"></span></div>

	<div class="wstl-ct__stats">
		<div><b><?php echo esc_html( number_format_i18n( $customer->total_orders ) ); ?></b><i><?php esc_html_e( 'orders', 'trustlens' ); ?></i></div>
		<div><b><?php echo esc_html( number_format_i18n( $customer->total_refunds ) ); ?></b><i><?php esc_html_e( 'returns', 'trustlens' ); ?></i></div>
		<div><b><?php echo esc_html( number_format( $customer->return_rate, 0 ) ); ?>%</b><i><?php esc_html_e( 'return rate', 'trustlens' ); ?></i></div>
	</div>

	<?php if ( $is_risky ) : ?>
		<p class="wstl-ct__flag"><?php esc_html_e( 'Review this order carefully.', 'trustlens' ); ?></p>
	<?php endif; ?>

	<p class="wstl-ct__foot">
		<a class="wstl-ct__link" href="<?php echo esc_url( admin_url( 'admin.php?page=trustlens-customers&customer=' . $email_hash ) ); ?>"><?php esc_html_e( 'View full profile', 'trustlens' ); ?> &rarr;</a>
		<?php
		/**
		 * Fires after the order metabox action links.
		 *
		 * @since 1.2.0
		 * @param object $customer   Customer object.
		 * @param string $email_hash Customer email hash.
		 */
		do_action( 'trustlens/order_metabox_actions', $customer, $email_hash );
		?>
	</p>
</div>
