<?php
/**
 * Admin.
 *
 * @package Noesia_Commerce_Suite
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- View templates receive local variables from their renderer.
$support_destination  = isset( $support_destination ) ? (bool) $support_destination : ( ! empty( $settings['support_url'] ) || ! empty( $settings['support_email'] ) );
$review_destinations  = isset( $review_destinations ) ? absint( $review_destinations ) : 0;
$care_action_summary = isset( $care_action_summary ) && is_array( $care_action_summary ) ? $care_action_summary : array(
	'last_30_days'  => 0,
	'by_action'     => array(),
	'recent'        => array(),
	'enabled'       => false,
);
?>
<section class="noesia-cs-feature-hero noesia-cs-feature-hero--reviews">
	<div>
		<span><?php esc_html_e( 'Insights', 'noesia-commerce-suite' ); ?></span>
		<h2><?php esc_html_e( 'Reviews & Support Activity', 'noesia-commerce-suite' ); ?></h2>
		<p><?php esc_html_e( 'This screen now focuses on customer care activity and insights. The public hub button settings live inside Order Care Hub → Core Actions.', 'noesia-commerce-suite' ); ?></p>
	</div>
	<a class="noesia-cs-primary-button" href="<?php echo esc_url( add_query_arg( 'noesia_cs_hub_section', 'core', $admin->tab_url( 'order-care-hub' ) ) ); ?>"><?php esc_html_e( 'Edit Core Actions', 'noesia-commerce-suite' ); ?></a>
</section>
<section class="noesia-cs-metrics noesia-cs-metrics--four">
	<?php $admin->metric_card( __( 'Support Block', 'noesia-commerce-suite' ), 'yes' === $settings['enable_support_block'] ? __( 'Enabled', 'noesia-commerce-suite' ) : __( 'Disabled', 'noesia-commerce-suite' ), '●', $support_destination ? __( 'destination configured', 'noesia-commerce-suite' ) : __( 'no destination yet', 'noesia-commerce-suite' ), 'heart' ); ?>
	<?php $admin->metric_card( __( 'Review Block', 'noesia-commerce-suite' ), 'yes' === $settings['enable_review_block'] ? __( 'Enabled', 'noesia-commerce-suite' ) : __( 'Disabled', 'noesia-commerce-suite' ), '●', sprintf( /* translators: %d: numeric value. */ __( '%d destinations', 'noesia-commerce-suite' ), absint( $review_destinations ) ), 'trend' ); ?>
	<?php $admin->metric_card( __( 'Review Gating', 'noesia-commerce-suite' ), __( 'None', 'noesia-commerce-suite' ), '●', __( 'neutral display', 'noesia-commerce-suite' ), 'shield' ); ?>
	<?php $admin->metric_card( __( 'Care Actions', 'noesia-commerce-suite' ), number_format_i18n( $care_action_summary['last_30_days'] ), '●', __( 'last 30 days', 'noesia-commerce-suite' ), 'target' ); ?>
</section>
<section class="noesia-cs-grid noesia-cs-grid--bottom">
	<div class="noesia-cs-panel">
		<div class="noesia-cs-panel__head"><h2><?php esc_html_e( 'Support Destination', 'noesia-commerce-suite' ); ?></h2><span><?php echo $support_destination ? esc_html__( 'configured', 'noesia-commerce-suite' ) : esc_html__( 'missing', 'noesia-commerce-suite' ); ?></span></div>
		<p class="noesia-cs-panel__body-note"><?php esc_html_e( 'The support button appears only when the support block and support button are enabled. It uses the support form URL first, then falls back to support email.', 'noesia-commerce-suite' ); ?></p>
		<ul class="noesia-cs-check-list">
			<li><?php echo ! empty( $settings['support_url'] ) ? esc_html__( 'Support form URL configured', 'noesia-commerce-suite' ) : esc_html__( 'Support form URL not configured', 'noesia-commerce-suite' ); ?></li>
			<li><?php echo ! empty( $settings['support_email'] ) ? esc_html__( 'Support email configured', 'noesia-commerce-suite' ) : esc_html__( 'Support email not configured', 'noesia-commerce-suite' ); ?></li>
		</ul>
	</div>
	<div class="noesia-cs-panel">
		<div class="noesia-cs-panel__head"><h2><?php esc_html_e( 'Review Destinations', 'noesia-commerce-suite' ); ?></h2><span><?php printf( /* translators: %d: numeric value. */ esc_html__( '%d active', 'noesia-commerce-suite' ), absint( $review_destinations ) ); ?></span></div>
		<p class="noesia-cs-panel__body-note"><?php esc_html_e( 'Review links are displayed neutrally. The plugin does not ask customers whether they are happy before showing public review destinations.', 'noesia-commerce-suite' ); ?></p>
		<ul class="noesia-cs-check-list">
			<li><?php echo ! empty( $settings['google_review_url'] ) ? esc_html__( 'Google review URL configured', 'noesia-commerce-suite' ) : esc_html__( 'Google review URL not configured', 'noesia-commerce-suite' ); ?></li>
			<li><?php echo ! empty( $settings['trustpilot_url'] ) ? esc_html__( 'Trustpilot URL configured', 'noesia-commerce-suite' ) : esc_html__( 'Trustpilot URL not configured', 'noesia-commerce-suite' ); ?></li>
			<li><?php echo ! empty( $settings['store_review_url'] ) ? esc_html__( 'Store review URL configured', 'noesia-commerce-suite' ) : esc_html__( 'Store review URL not configured', 'noesia-commerce-suite' ); ?></li>
		</ul>
	</div>
	<div class="noesia-cs-panel">
		<div class="noesia-cs-panel__head"><h2><?php esc_html_e( 'Order Care Hub Behavior', 'noesia-commerce-suite' ); ?></h2><span><?php esc_html_e( 'privacy-safe', 'noesia-commerce-suite' ); ?></span></div>
		<p class="noesia-cs-panel__body-note"><?php esc_html_e( 'The public care page renders support and review buttons without exposing customer email, phone, address or payment data.', 'noesia-commerce-suite' ); ?></p>
	</div>
</section>

<section class="noesia-cs-grid noesia-cs-grid--bottom">
	<div class="noesia-cs-panel noesia-cs-panel--wide">
		<div class="noesia-cs-panel__head"><h2><?php esc_html_e( 'Care Button Activity', 'noesia-commerce-suite' ); ?></h2><span><?php echo $care_action_summary['enabled'] ? esc_html__( 'enabled', 'noesia-commerce-suite' ) : esc_html__( 'disabled', 'noesia-commerce-suite' ); ?></span></div>
		<p class="noesia-cs-panel__body-note"><?php esc_html_e( 'This basic Free core log counts support, review and reorder button actions from secure care pages. It stores order ID, action type, optional product/item ID and timestamp only; it does not store customer email, phone, address, IP, user agent or payment data.', 'noesia-commerce-suite' ); ?></p>
		<div class="noesia-cs-mini-grid">
			<?php foreach ( $care_action_summary['by_action'] as $action_row ) : ?>
				<div><strong><?php echo esc_html( number_format_i18n( absint( $action_row['count'] ) ) ); ?></strong><span><?php echo esc_html( $action_row['label'] ); ?></span></div>
			<?php endforeach; ?>
		</div>
	</div>
	<div class="noesia-cs-panel">
		<div class="noesia-cs-panel__head"><h2><?php esc_html_e( 'Recent Care Actions', 'noesia-commerce-suite' ); ?></h2><span><?php esc_html_e( 'privacy-safe log', 'noesia-commerce-suite' ); ?></span></div>
		<div class="noesia-cs-mini-log">
			<?php foreach ( $care_action_summary['recent'] as $entry ) : ?>
				<div><strong><?php echo esc_html( $entry['label'] ); ?></strong><span><?php printf( /* translators: 1: first numeric value; 2: second dynamic value. */ esc_html__( 'Order #%1$d · %2$s', 'noesia-commerce-suite' ), absint( $entry['order_id'] ), esc_html( $entry['time'] ? wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), absint( $entry['time'] ) ) : __( 'unknown time', 'noesia-commerce-suite' ) ) ); ?></span></div>
			<?php endforeach; ?>
			<?php if ( empty( $care_action_summary['recent'] ) ) : ?><p><?php esc_html_e( 'No care actions recorded yet.', 'noesia-commerce-suite' ); ?></p><?php endif; ?>
		</div>
	</div>
</section>

<section class="noesia-cs-pro-grid">
	<?php $admin->pro_edition_card( __( 'Care Hub Templates', 'noesia-commerce-suite' ), __( 'Give customers a clearer and more premium care page for support, reviews, warranty and reorders.', 'noesia-commerce-suite' ), 'care_templates' ); ?>
	<?php $admin->pro_edition_card( __( 'Branded Customer Care Flow', 'noesia-commerce-suite' ), __( 'Make support, review, reorder and care messages feel like your own store, not a generic plugin.', 'noesia-commerce-suite' ), 'qr_email_branding' ); ?>
</section>
