<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

final class ClaimPrism_Pro_Value_Path {
	public function __construct() {
		add_action( 'claimprism_dashboard_after_progress', array( $this, 'render' ), 20, 2 );
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
	}

	private function has_pro_access() {
		return function_exists( 'cp_fs' ) && cp_fs()->can_use_premium_code();
	}

	private function has_left_first_run( $job, $summary ) {
		if ( ! empty( get_option( 'claimprism_last_scan', '' ) ) ) {
			return true;
		}

		if ( isset( $job['status'] ) && 'idle' !== $job['status'] ) {
			return true;
		}

		return array_sum( array_map( 'intval', (array) $summary ) ) > 0;
	}

	public function enqueue_assets( $hook ) {
		if ( $this->has_pro_access() || false === strpos( $hook, 'claimprism' ) || false !== strpos( $hook, 'claimprism-governance' ) ) {
			return;
		}

		wp_enqueue_style(
			'claimprism-pro-value-path',
			CLAIMPRISM_URL . 'assets/pro-value-path.css',
			array( 'claimprism-dashboard-dark' ),
			CLAIMPRISM_VERSION
		);
	}

	public function render( $job, $summary ) {
		if ( $this->has_pro_access() || ! $this->has_left_first_run( $job, $summary ) ) {
			return;
		}

		$upgrade_url = function_exists( 'cp_fs' ) ? cp_fs()->get_upgrade_url() : '';
		if ( empty( $upgrade_url ) ) {
			return;
		}
		?>
		<section class="claimprism-pro-value" aria-labelledby="claimprism-pro-value-title">
			<div class="claimprism-pro-value-copy">
				<span class="claimprism-pro-value-kicker"><?php esc_html_e( 'ClaimPrism Pro', 'claimprism' ); ?></span>
				<h2 id="claimprism-pro-value-title"><?php esc_html_e( 'Move from detection to governed claims', 'claimprism' ); ?></h2>
				<p><?php esc_html_e( 'Free helps you detect and prioritize environmental marketing signals. Pro adds the workflow to review, evidence, monitor and govern those claims over time.', 'claimprism' ); ?></p>
				<a class="button button-primary claimprism-pro-value-cta" href="<?php echo esc_url( $upgrade_url ); ?>"><?php esc_html_e( 'Explore ClaimPrism Pro', 'claimprism' ); ?></a>
				<small><?php esc_html_e( 'Pro supports human governance workflows; it does not provide certification or a legal compliance verdict.', 'claimprism' ); ?></small>
			</div>
			<div class="claimprism-pro-value-capabilities" aria-label="<?php echo esc_attr__( 'ClaimPrism Pro capabilities', 'claimprism' ); ?>">
				<div><strong><?php esc_html_e( 'Review workflow', 'claimprism' ); ?></strong><span><?php esc_html_e( 'Assign reviewers, record decisions and preserve review history.', 'claimprism' ); ?></span></div>
				<div><strong><?php esc_html_e( 'Evidence', 'claimprism' ); ?></strong><span><?php esc_html_e( 'Link supporting material and track review or expiry dates.', 'claimprism' ); ?></span></div>
				<div><strong><?php esc_html_e( 'Monitoring & reports', 'claimprism' ); ?></strong><span><?php esc_html_e( 'Track change over time, schedule scans and export operational reports.', 'claimprism' ); ?></span></div>
				<div><strong><?php esc_html_e( 'Claim Governance', 'claimprism' ); ?></strong><span><?php esc_html_e( 'Manage lifecycle, usages, approved wording and drift in one workspace.', 'claimprism' ); ?></span></div>
			</div>
		</section>
		<?php
	}
}

new ClaimPrism_Pro_Value_Path();
