<?php
/**
 * Admin pages, assets, dashboard widget, and order metabox.
 *
 * @package TrustLens\Admin
 * @since   1.0.0
 */

defined( 'ABSPATH' ) || exit;

/**
 * Handles admin page registration and rendering.
 *
 * @since 1.1.5
 */
class TrustLens_Admin_Pages {

	/**
	 * Register hooks.
	 *
	 * @since 1.1.5
	 * @return void
	 */
	public function register_hooks(): void {
		add_action( 'admin_menu', array( $this, 'register_menu' ) );
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
		add_action( 'wp_dashboard_setup', array( $this, 'register_dashboard_widget' ) );
		add_action( 'add_meta_boxes', array( $this, 'register_order_metabox' ) );
	}

	/**
	 * Register admin menu.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public function register_menu(): void {
		add_menu_page(
			__( 'TrustLens', 'trustlens' ),
			__( 'TrustLens', 'trustlens' ),
			'manage_woocommerce',
			'trustlens',
			array( $this, 'render_dashboard_page' ),
			'dashicons-visibility',
			56
		);

		add_submenu_page( 'trustlens', __( 'Dashboard', 'trustlens' ), __( 'Dashboard', 'trustlens' ), 'manage_woocommerce', 'trustlens', array( $this, 'render_dashboard_page' ) );
		add_submenu_page( 'trustlens', __( 'Customers', 'trustlens' ), __( 'Customers', 'trustlens' ), 'manage_woocommerce', 'trustlens-customers', array( $this, 'render_customers_page' ) );
		add_submenu_page( 'trustlens', __( 'Notifications', 'trustlens' ), __( 'Notifications', 'trustlens' ), 'manage_woocommerce', 'trustlens-notifications', array( $this, 'render_notifications_page' ) );
		add_submenu_page( 'trustlens', __( 'Automation', 'trustlens' ), __( 'Automation', 'trustlens' ), 'manage_woocommerce', 'trustlens-automation', array( $this, 'render_automation_page' ) );
		// Registered for everyone so free users get an in-context upsell instead of
		// a "not allowed" dead-end; the view renders the Pro monitor or the upsell.
		// Gate on wstl_has_chargebacks() to match the header nav + command palette.
		if ( wstl_has_chargebacks() ) {
			add_submenu_page( 'trustlens', __( 'Chargeback Monitor', 'trustlens' ), __( 'Chargeback Monitor', 'trustlens' ), 'manage_woocommerce', 'trustlens-chargeback-monitor', array( $this, 'render_chargeback_monitor_page' ) );
		}
		add_submenu_page( 'trustlens', __( 'Settings', 'trustlens' ), __( 'Settings', 'trustlens' ), 'manage_woocommerce', 'trustlens-settings', array( $this, 'render_settings_page' ) );
	}

	/**
	 * Render the Chargeback Monitor page.
	 *
	 * @since 1.2.1
	 * @return void
	 */
	public function render_chargeback_monitor_page(): void {
		include TRUSTLENS_PLUGIN_DIR . 'admin/views/chargeback-monitor.php';
	}

	/**
	 * Enqueue admin assets.
	 *
	 * @since 1.0.0
	 * @param string $hook Current admin page.
	 * @return void
	 */
	public function enqueue_assets( string $hook ): void {
		if ( strpos( $hook, 'trustlens' ) === false && 'index.php' !== $hook ) {
			return;
		}

		// The WP main dashboard (index.php) only hosts the TrustLens "Customer Trust"
		// dashboard widget, which is a static PHP partial styled entirely by admin.css.
		// It needs no page JS (admin.js has no widget code), no Pro-upsell styles, and
		// no wp-pointer. Enqueue just the base stylesheet and bail so the full ~67 KB
		// admin bundle never loads on every store's home screen.
		if ( 'index.php' === $hook ) {
			$dash_css_path = TRUSTLENS_PLUGIN_DIR . 'admin/css/admin.css';
			$dash_css_ver  = file_exists( $dash_css_path ) ? (string) filemtime( $dash_css_path ) : TRUSTLENS_VERSION;
			wp_enqueue_style( 'trustlens-admin', TRUSTLENS_PLUGIN_URL . 'admin/css/admin.css', array(), $dash_css_ver );
			return;
		}

		$admin_css_path           = TRUSTLENS_PLUGIN_DIR . 'admin/css/admin.css';
		$dashboard_css_path       = TRUSTLENS_PLUGIN_DIR . 'admin/css/dashboard.css';
		$customers_css_path       = TRUSTLENS_PLUGIN_DIR . 'admin/css/customers.css';
		$customer_detail_css_path = TRUSTLENS_PLUGIN_DIR . 'admin/css/customer-detail.css';
		$settings_css_path        = TRUSTLENS_PLUGIN_DIR . 'admin/css/settings.css';
		$notifications_css_path   = TRUSTLENS_PLUGIN_DIR . 'admin/css/notifications.css';
		$pro_upsell_css_path      = TRUSTLENS_PLUGIN_DIR . 'admin/css/pro-upsell.css';
		$admin_js_path            = TRUSTLENS_PLUGIN_DIR . 'admin/js/admin.js';
		$admin_css_ver            = file_exists( $admin_css_path ) ? (string) filemtime( $admin_css_path ) : TRUSTLENS_VERSION;
		$dashboard_css_ver        = file_exists( $dashboard_css_path ) ? (string) filemtime( $dashboard_css_path ) : TRUSTLENS_VERSION;
		$customers_css_ver        = file_exists( $customers_css_path ) ? (string) filemtime( $customers_css_path ) : TRUSTLENS_VERSION;
		$customer_detail_css_ver  = file_exists( $customer_detail_css_path ) ? (string) filemtime( $customer_detail_css_path ) : TRUSTLENS_VERSION;
		$settings_css_ver         = file_exists( $settings_css_path ) ? (string) filemtime( $settings_css_path ) : TRUSTLENS_VERSION;
		$notifications_css_ver    = file_exists( $notifications_css_path ) ? (string) filemtime( $notifications_css_path ) : TRUSTLENS_VERSION;
		$pro_upsell_css_ver       = file_exists( $pro_upsell_css_path ) ? (string) filemtime( $pro_upsell_css_path ) : TRUSTLENS_VERSION;
		$admin_js_ver             = file_exists( $admin_js_path ) ? (string) filemtime( $admin_js_path ) : TRUSTLENS_VERSION;

		wp_enqueue_style( 'trustlens-admin', TRUSTLENS_PLUGIN_URL . 'admin/css/admin.css', array(), $admin_css_ver );
		wp_enqueue_style( 'wp-pointer' );
		wp_enqueue_script( 'wp-pointer' );

		wp_enqueue_style( 'trustlens-pro-upsell', TRUSTLENS_PLUGIN_URL . 'admin/css/pro-upsell.css', array( 'trustlens-admin' ), $pro_upsell_css_ver );

		if ( strpos( $hook, 'page_trustlens' ) !== false && strpos( $hook, 'customers' ) === false && strpos( $hook, 'settings' ) === false && strpos( $hook, 'notifications' ) === false && strpos( $hook, 'automation' ) === false ) {
			wp_enqueue_style( 'trustlens-dashboard', TRUSTLENS_PLUGIN_URL . 'admin/css/dashboard.css', array( 'trustlens-admin' ), $dashboard_css_ver );
			$cc_css_path = TRUSTLENS_PLUGIN_DIR . 'admin/css/command-center.css';
			$cc_css_ver  = file_exists( $cc_css_path ) ? (string) filemtime( $cc_css_path ) : TRUSTLENS_VERSION;
			wp_enqueue_style( 'trustlens-command-center', TRUSTLENS_PLUGIN_URL . 'admin/css/command-center.css', array( 'trustlens-admin', 'trustlens-dashboard' ), $cc_css_ver );
		}

		if ( strpos( $hook, 'trustlens-customers' ) !== false ) {
			wp_enqueue_style( 'trustlens-customers', TRUSTLENS_PLUGIN_URL . 'admin/css/customers.css', array( 'trustlens-admin' ), $customers_css_ver );

			if ( isset( $_GET['customer'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display-only query parameter.
				wp_enqueue_style( 'trustlens-customer-detail', TRUSTLENS_PLUGIN_URL . 'admin/css/customer-detail.css', array( 'trustlens-admin', 'trustlens-customers' ), $customer_detail_css_ver );
			}
		}

		if ( strpos( $hook, 'trustlens-settings' ) !== false ) {
			wp_enqueue_style( 'trustlens-settings', TRUSTLENS_PLUGIN_URL . 'admin/css/settings.css', array( 'trustlens-admin' ), $settings_css_ver );
		}

		if ( strpos( $hook, 'trustlens-notifications' ) !== false ) {
			wp_enqueue_style( 'trustlens-notifications', TRUSTLENS_PLUGIN_URL . 'admin/css/notifications.css', array( 'trustlens-admin' ), $notifications_css_ver );
		}

		if ( strpos( $hook, 'trustlens-automation' ) !== false
			&& wstl_has_automation()
			&& wstl_can_use_pro()
			&& file_exists( TRUSTLENS_PLUGIN_DIR . 'admin/views/automation-pro.php' ) ) {
			$automation_css_path = TRUSTLENS_PLUGIN_DIR . 'admin/css/automation.css';
			$automation_css_ver  = file_exists( $automation_css_path ) ? (string) filemtime( $automation_css_path ) : TRUSTLENS_VERSION;
			// `trustlens-settings` carries the modal styles shared with Settings;
			// `trustlens-automation` adds the Split Inspector layout on top.
			wp_enqueue_style( 'trustlens-settings', TRUSTLENS_PLUGIN_URL . 'admin/css/settings.css', array( 'trustlens-admin' ), $settings_css_ver );
			wp_enqueue_style( 'trustlens-automation', TRUSTLENS_PLUGIN_URL . 'admin/css/automation.css', array( 'trustlens-admin', 'trustlens-settings' ), $automation_css_ver );
		}

		if ( strpos( $hook, 'trustlens-settings' ) !== false && isset( $_GET['tab'] ) && 'data' === $_GET['tab'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display-only query parameter.
			$sync        = TrustLens_Historical_Sync::instance();
			$sync_status = $sync->get_status();
			if ( 'running' === $sync_status['status'] ) {
				$progress = $sync->get_progress();
				wp_add_inline_style( 'trustlens-admin', '#wstl-sync-status .wstl-progress-fill { width: ' . (float) $progress . '% !important; }' );
			}
		}

		// Command Center dashboard (top-level TrustLens page) — Chart.js trend
		// visuals via the shared theme + command-center-charts.js.
		if ( 'toplevel_page_trustlens' === $hook ) {
			$cc_theme_path  = TRUSTLENS_PLUGIN_DIR . 'admin/js/chart-theme.js';
			$cc_theme_ver   = file_exists( $cc_theme_path ) ? (string) filemtime( $cc_theme_path ) : TRUSTLENS_VERSION;
			$cc_charts_path = TRUSTLENS_PLUGIN_DIR . 'admin/js/command-center-charts.js';
			$cc_charts_ver  = file_exists( $cc_charts_path ) ? (string) filemtime( $cc_charts_path ) : TRUSTLENS_VERSION;

			wp_enqueue_script( 'chartjs', TRUSTLENS_PLUGIN_URL . 'admin/vendor/chart-js/chart.umd.min.js', array(), '4.5.1', true );
			wp_enqueue_script( 'trustlens-chart-theme', TRUSTLENS_PLUGIN_URL . 'admin/js/chart-theme.js', array( 'chartjs' ), $cc_theme_ver, true );
			wp_enqueue_script( 'trustlens-command-center-charts', TRUSTLENS_PLUGIN_URL . 'admin/js/command-center-charts.js', array( 'chartjs', 'trustlens-chart-theme' ), $cc_charts_ver, true );
		}

		// Chargeback Monitor page (Pro) — chart + backfill JS + shared stylesheet.
		$chargeback_css_path = TRUSTLENS_PLUGIN_DIR . 'admin/css/chargeback-monitor.css';
		$chargeback_css_ver  = file_exists( $chargeback_css_path ) ? (string) filemtime( $chargeback_css_path ) : TRUSTLENS_VERSION;
		$chargeback_js_path  = TRUSTLENS_PLUGIN_DIR . 'admin/js/chargeback-monitor.js';
		$chargeback_js_ver   = file_exists( $chargeback_js_path ) ? (string) filemtime( $chargeback_js_path ) : TRUSTLENS_VERSION;

		// Chargeback Monitor stylesheet — only on its own page now (the dashboard
		// summary card it served was replaced by the Command Center panel).
		$is_monitor_page = strpos( $hook, 'chargeback-monitor' ) !== false;

		if ( $is_monitor_page ) {
			wp_enqueue_style( 'trustlens-chargeback-monitor', TRUSTLENS_PLUGIN_URL . 'admin/css/chargeback-monitor.css', array( 'trustlens-admin' ), $chargeback_css_ver );
		}

		if ( $is_monitor_page ) {
			$chart_theme_path = TRUSTLENS_PLUGIN_DIR . 'admin/js/chart-theme.js';
			$chart_theme_ver  = file_exists( $chart_theme_path ) ? (string) filemtime( $chart_theme_path ) : TRUSTLENS_VERSION;
			wp_enqueue_script( 'chartjs', TRUSTLENS_PLUGIN_URL . 'admin/vendor/chart-js/chart.umd.min.js', array(), '4.5.1', true );
			wp_enqueue_script( 'trustlens-chart-theme', TRUSTLENS_PLUGIN_URL . 'admin/js/chart-theme.js', array( 'chartjs' ), $chart_theme_ver, true );
			wp_enqueue_script( 'trustlens-chargeback-monitor', TRUSTLENS_PLUGIN_URL . 'admin/js/chargeback-monitor.js', array( 'jquery', 'chartjs', 'trustlens-chart-theme' ), $chargeback_js_ver, true );
		}

		wp_enqueue_script( 'trustlens-admin', TRUSTLENS_PLUGIN_URL . 'admin/js/admin.js', array( 'jquery' ), $admin_js_ver, true );

		wp_localize_script(
			'trustlens-admin',
			'TrustLens',
			array(
				'ajaxUrl' => admin_url( 'admin-ajax.php' ),
				'nonce'   => wp_create_nonce( 'trustlens_admin' ),
				'i18n'    => array(
					'confirm_allowlist'          => __( 'Add this customer to the allowlist?', 'trustlens' ),
					'confirm_reset'              => __( 'Are you sure you want to delete all TrustLens data? This cannot be undone.', 'trustlens' ),
					'confirm_delete'             => __( 'Are you sure you want to delete the selected customers? This cannot be undone.', 'trustlens' ),
					'confirm_bulk'               => __( 'Apply this action to the selected customers?', 'trustlens' ),
					'select_customers'           => __( 'Please select at least one customer.', 'trustlens' ),
					'select_action'              => __( 'Please select an action.', 'trustlens' ),
					'success'                    => __( 'Action completed successfully.', 'trustlens' ),
					'error'                      => __( 'An error occurred. Please try again.', 'trustlens' ),
					'test_notification_timeout'  => __( 'Request timed out. Your server may not be sending mail (e.g. SMTP not configured). Try an SMTP plugin or check your server mail settings.', 'trustlens' ),
					'starting'                   => __( 'Starting...', 'trustlens' ),
					'stopping'                   => __( 'Stopping...', 'trustlens' ),
					'resetting'                  => __( 'Resetting...', 'trustlens' ),
					'start_sync'                 => __( 'Start Sync', 'trustlens' ),
					'stop_sync'                  => __( 'Stop Sync', 'trustlens' ),
					'sync_complete'              => __( 'Sync complete!', 'trustlens' ),
					'processing'                 => __( 'Processing...', 'trustlens' ),
					'customers_processed'        => __( 'customers processed', 'trustlens' ),
					'confirm_seed'               => __( 'Generate 65 test customers? This will add sample data to your database.', 'trustlens' ),
					'confirm_remove'             => __( 'Remove all test customers? This action cannot be undone.', 'trustlens' ),
					'confirm_check_clean'        => __( 'Scan all tables for test data and permanently delete anything found?', 'trustlens' ),
					'request_failed'             => __( 'Request failed.', 'trustlens' ),
					'add_rule'                   => __( 'Add Automation Rule', 'trustlens' ),
					'edit_rule'                  => __( 'Edit Automation Rule', 'trustlens' ),
					'save_rule'                  => __( 'Save Rule', 'trustlens' ),
					'saving'                     => __( 'Saving...', 'trustlens' ),
					'confirm_delete_rule'        => __( 'Are you sure you want to delete this automation rule?', 'trustlens' ),
					/* translators: %d: number of selected customers. */
					'n_selected'                 => __( '%d selected', 'trustlens' ),
				),
			)
		);
	}

	/**
	 * Render dashboard page.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public function render_dashboard_page(): void {
		include TRUSTLENS_PLUGIN_DIR . 'admin/views/dashboard.php';
	}

	/**
	 * Render customers page.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public function render_customers_page(): void {
		if ( isset( $_GET['customer'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display-only query parameter.
			$this->render_customer_detail_page();
			return;
		}

		$repo     = new TrustLens_Customer_Repository();
		$per_page = 20;
		$page     = isset( $_GET['paged'] ) ? absint( wp_unslash( $_GET['paged'] ) ) : 1; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$segment  = isset( $_GET['segment'] ) ? sanitize_text_field( wp_unslash( $_GET['segment'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$search   = isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$orderby  = isset( $_GET['orderby'] ) ? sanitize_text_field( wp_unslash( $_GET['orderby'] ) ) : 'trust_score'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$order    = isset( $_GET['order'] ) ? sanitize_text_field( wp_unslash( $_GET['order'] ) ) : 'ASC'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended

		// Advanced filters (empty string means "not applied").
		// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Display-only GET filters.
		$score_min = ( isset( $_GET['score_min'] ) && '' !== $_GET['score_min'] ) ? absint( wp_unslash( $_GET['score_min'] ) ) : '';
		$score_max = ( isset( $_GET['score_max'] ) && '' !== $_GET['score_max'] ) ? absint( wp_unslash( $_GET['score_max'] ) ) : '';
		$rate_min  = ( isset( $_GET['rate_min'] ) && '' !== $_GET['rate_min'] ) ? max( 0, (float) sanitize_text_field( wp_unslash( $_GET['rate_min'] ) ) ) : '';
		$status    = isset( $_GET['status'] ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : '';
		// phpcs:enable WordPress.Security.NonceVerification.Recommended
		$status    = in_array( $status, array( 'blocked', 'allowlisted', 'flagged' ), true ) ? $status : '';

		$filter_args = array(
			'segment'   => $segment,
			'search'    => $search,
			'score_min' => $score_min,
			'score_max' => $score_max,
			'rate_min'  => $rate_min,
			'status'    => $status,
		);

		$customers = $repo->get_customers(
			array_merge(
				$filter_args,
				array(
					'per_page' => $per_page,
					'page'     => $page,
					'orderby'  => $orderby,
					'order'    => $order,
				)
			)
		);
		$total = $repo->count( $filter_args );

		$total_pages    = ceil( $total / $per_page );
		$segment_counts = $repo->get_segment_counts();

		include TRUSTLENS_PLUGIN_DIR . 'admin/views/customers.php';
	}

	/**
	 * Render customer detail page.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	private function render_customer_detail_page(): void {
		$email_hash = isset( $_GET['customer'] ) ? sanitize_text_field( wp_unslash( $_GET['customer'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$customer   = wstl_get_customer( $email_hash );

		if ( ! $customer ) {
			wp_die( esc_html__( 'Customer not found.', 'trustlens' ) );
		}

		$signals = TrustLens_Score_Calculator::get_signals( $email_hash );

		global $wpdb;
		// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
		$events = $wpdb->get_results(
			$wpdb->prepare(
				"SELECT * FROM {$wpdb->prefix}trustlens_events
				 WHERE email_hash = %s
				 ORDER BY created_at DESC
				 LIMIT 20",
				$email_hash
			)
		);
		// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared

		$repo            = new TrustLens_Customer_Repository();
		$trend_data      = $repo->get_return_rate_trend( $email_hash );
		$avg_return_rate = $repo->get_avg_return_rate();

		include TRUSTLENS_PLUGIN_DIR . 'admin/views/customer-detail.php';
	}

	/**
	 * Render notifications page.
	 *
	 * @since 1.1.0
	 * @return void
	 */
	public function render_notifications_page(): void {
		include TRUSTLENS_PLUGIN_DIR . 'admin/views/notifications.php';
	}

	/**
	 * Render settings page.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public function render_settings_page(): void {
		include TRUSTLENS_PLUGIN_DIR . 'admin/views/settings.php';
	}

	/**
	 * Render automation page.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public function render_automation_page(): void {
		include TRUSTLENS_PLUGIN_DIR . 'admin/views/automation.php';
	}

	/**
	 * Register dashboard widget.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public function register_dashboard_widget(): void {
		if ( ! get_option( 'trustlens_enable_dashboard', true ) || ! current_user_can( 'manage_woocommerce' ) ) {
			return;
		}

		wp_add_dashboard_widget( 'trustlens_dashboard_widget', __( 'TrustLens - Customer Trust', 'trustlens' ), array( $this, 'render_dashboard_widget' ) );
	}

	/**
	 * Render dashboard widget.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public function render_dashboard_widget(): void {
		$repo       = new TrustLens_Customer_Repository();
		$high_risk  = $repo->get_high_risk( 5 );
		$counts     = $repo->get_segment_counts();
		$risk_count = $counts['risk'] + $counts['critical'];
		include TRUSTLENS_PLUGIN_DIR . 'admin/views/partials/dashboard-widget.php';
	}

	/**
	 * Register order metabox.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public function register_order_metabox(): void {
		if ( ! get_option( 'trustlens_enable_order_warning', true ) ) {
			return;
		}

		$screen = class_exists( '\Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController' ) ? wc_get_page_screen_id( 'shop-order' ) : 'shop_order';

		add_meta_box( 'trustlens_customer_trust', __( 'Customer Trust', 'trustlens' ), array( $this, 'render_order_metabox' ), $screen, 'side', 'high' );
	}

	/**
	 * Render order metabox.
	 *
	 * @since 1.0.0
	 * @param WP_Post|WC_Order $post_or_order Post or order object.
	 * @return void
	 */
	public function render_order_metabox( $post_or_order ): void {
		$order = $post_or_order instanceof WC_Order ? $post_or_order : wc_get_order( $post_or_order->ID );

		if ( ! $order ) {
			return;
		}

		$email_hash = wstl_get_email_hash( $order->get_billing_email() );
		$customer   = wstl_get_customer( $email_hash );

		if ( ! $customer ) {
			echo '<p>' . esc_html__( 'No trust data available for this customer.', 'trustlens' ) . '</p>';
			return;
		}

		$color    = wstl_get_segment_color( $customer->segment );
		$is_risky = in_array( $customer->segment, array( 'risk', 'critical' ), true );
		include TRUSTLENS_PLUGIN_DIR . 'admin/views/partials/order-metabox.php';
	}
}
