<?php
/**
 * Plugin compatibility status AJAX handler.
 *
 * @package CoffeeWP_Media_Cleanup
 */

namespace CWPM\Ajax;

defined( 'ABSPATH' ) || exit;

// phpcs:disable WordPress.Security.NonceVerification.Missing -- nonce verified centrally in BaseHandler::verify_request().

class CompatHandler extends BaseHandler {

	/**
	 * Constructor — register AJAX actions.
	 */
	public function __construct() {
		add_action( 'wp_ajax_cwpm_compat_status', array( $this, 'compat_status' ) );
	}

	/**
	 * Return compat-notice payload for ACF + Elementor detection state.
	 */
	public function compat_status() {
		check_ajax_referer( 'cwpm_nonce', 'nonce' );
		$this->verify_request( 'manage_options', array( 'message' => __( 'Insufficient permissions.', 'coffeewp-media-cleanup' ) ) );

		$plugins = \CWPM\Compat\PluginCompat::get_for_notice();

		wp_send_json_success( array( 'plugins' => $plugins ) );
	}
}
