<?php
/**
 * Plugin Name:       AccessLens - Web Accessibility Audit
 * Plugin URI:        https://wordpress.org/plugins/accesslens/
 * Description:       Web accessibility audit client for the EU Accessibility Act (EAA). Detects WCAG violations via an external engine. The automated scanner identifies approx. 25-40% of issues; manual review is still necessary. Does not guarantee compliance.
 * Version:           0.2.0
 * Requires at least: 6.0
 * Requires PHP:      8.0
 * Author:            manitosdevs
 * Author URI:        https://profiles.wordpress.org/manitosdevs/
 * License:           GPL-2.0-or-later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       accesslens
 * Domain Path:       /languages
 *
 * @package AccessLens
 */

declare(strict_types=1);

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

// Constants.
define( 'ACCESSLENS_VERSION', '0.2.0' );
define( 'ACCESSLENS_PLUGIN_FILE', __FILE__ );
define( 'ACCESSLENS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'ACCESSLENS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'ACCESSLENS_TEXT_DOMAIN', 'accesslens' );

// URL del motor: fija por diseno (modelo serviceware). Ya no es un ajuste editable
// desde el admin; solo se puede sobreescribir via el filtro 'accesslens_engine_url'
// (uso previsto: entornos de desarrollo local).
define( 'ACCESSLENS_ENGINE_URL', 'https://eaa-audit-engine-26367529082.europe-southwest1.run.app' );

// --- Freemius SDK (licencias, free/Pro, actualizaciones) ---
// public_key es publica por diseno. El secret_key NUNCA va aqui (solo wp-config en dev local).
if ( ! function_exists( 'accesslens_fs' ) ) {
	function accesslens_fs() {
		global $accesslens_fs;

		if ( ! isset( $accesslens_fs ) ) {
			require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';

			$accesslens_fs = fs_dynamic_init(
				array(
					'id'                  => '32766',
					'slug'                => 'accesslens',
					'type'                => 'plugin',
					'public_key'          => 'pk_f51396c26e330b3e511adc8561174',
					'is_premium'          => false,
					'has_premium_version' => true,
					'has_addons'          => false,
					'has_paid_plans'      => true,
					'is_org_compliant'    => true,
					'menu'                => array(
						'slug'       => 'accesslens',
						'first-path' => 'admin.php?page=accesslens',
						'account'    => true,
						'support'    => false,
					),
				)
			);
		}

		return $accesslens_fs;
	}

	// Init Freemius.
	accesslens_fs();
	do_action( 'accesslens_fs_loaded' );
}

// Autoload classes.
require_once ACCESSLENS_PLUGIN_DIR . 'includes/class-accesslens-freemius.php';
accesslens_fs()->add_action( 'after_uninstall', 'accesslens_uninstall_cleanup' );
require_once ACCESSLENS_PLUGIN_DIR . 'includes/class-accesslens-options.php';
require_once ACCESSLENS_PLUGIN_DIR . 'includes/class-accesslens-engine-client.php';
require_once ACCESSLENS_PLUGIN_DIR . 'includes/class-accesslens-ajax.php';
require_once ACCESSLENS_PLUGIN_DIR . 'includes/class-accesslens-admin.php';
require_once ACCESSLENS_PLUGIN_DIR . 'includes/class-accesslens-plugin.php';

/**
 * Load translations. WordPress.org auto-loads translations for hosted plugins
 * since WP 4.6, but loading them explicitly here also covers bundled
 * languages/ files when the plugin is installed outside wordpress.org
 * (e.g. local dev, staging, manual zip installs).
 */
function accesslens_load_textdomain(): void {
	load_plugin_textdomain( 'accesslens', false, dirname( plugin_basename( ACCESSLENS_PLUGIN_FILE ) ) . '/languages' );
}
add_action( 'init', 'accesslens_load_textdomain' );

/**
 * Bootstrap the plugin.
 */
function accesslens_audit_init(): void {
	AccessLens_Plugin::get_instance();
}
add_action( 'plugins_loaded', 'accesslens_audit_init' );
