<?php
/**
 * Cloudi7 ID Card Generator
 *
 * A simple, lightweight, and universal ID card generator for schools,
 * companies, events, clubs, and organizations.
 *
 * @package           Cloudi7_ID_Card_Generator
 * @author            CLOUDi7
 * @license           GPL-2.0-or-later
 *
 * @wordpress-plugin
 * Plugin Name:       Cloudi7 ID Card Generator
 * Plugin URI:        https://www.cloudi7.com/cloudi7-id-card-generator/
 * Description:       Create and manage ID cards for schools, companies, events, clubs, and organizations directly from your WordPress dashboard.
 * Version:           1.0.1
 * Requires at least: 5.8
 * Tested up to:      7.0
 * Requires PHP:      7.4
 * Author:            CLOUDi7
 * Author URI:        https://www.cloudi7.com
 * License:           GPL v2 or later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       cloudi7-id-card-generator
 * Domain Path:       /languages
 */

// Prevent direct access.
if (!defined('ABSPATH')) {
	exit;
}

// ---------------------------------------------------------------------------
// Plugin Constants
// ---------------------------------------------------------------------------

/**
 * Plugin version.
 *
 * Bump this on every release so WordPress detects the update.
 */
define('Cloudi7_ICG_VERSION', '1.0.1');

/**
 * Absolute path to the plugin root directory (with trailing slash).
 *
 * Example: /var/www/html/wp-content/plugins/cloudi7-id-card-generator/
 */
define('Cloudi7_ICG_PLUGIN_DIR', plugin_dir_path(__FILE__));

/**
 * Public URL to the plugin root directory (with trailing slash).
 *
 * Example: https://example.com/wp-content/plugins/cloudi7-id-card-generator/
 */
define('Cloudi7_ICG_PLUGIN_URL', plugin_dir_url(__FILE__));

/**
 * Absolute path to the main plugin file.
 *
 * Used by classes that need plugin_basename() context.
 */
define('Cloudi7_ICG_PLUGIN_FILE', __FILE__);

/**
 * Plugin text domain for i18n.
 */
define('Cloudi7_ICG_TEXT_DOMAIN', 'cloudi7-id-card-generator');

// ---------------------------------------------------------------------------
// Autoloader – load required classes
// ---------------------------------------------------------------------------

/**
 * Load the core includes classes.
 */
require_once Cloudi7_ICG_PLUGIN_DIR . 'includes/class-cloudi7-icg-loader.php';
require_once Cloudi7_ICG_PLUGIN_DIR . 'includes/class-cloudi7-icg-activator.php';
require_once Cloudi7_ICG_PLUGIN_DIR . 'includes/class-cloudi7-icg-deactivator.php';
require_once Cloudi7_ICG_PLUGIN_DIR . 'includes/class-cloudi7-icg-i18n.php';
require_once Cloudi7_ICG_PLUGIN_DIR . 'includes/class-cloudi7-icg-id-generator.php';

/**
 * Load the admin class.
 */
require_once Cloudi7_ICG_PLUGIN_DIR . 'admin/class-cloudi7-icg-admin.php';

/**
 * Load the public class.
 */
require_once Cloudi7_ICG_PLUGIN_DIR . 'public/class-cloudi7-icg-public.php';

// ---------------------------------------------------------------------------
// Activation & Deactivation Hooks
// ---------------------------------------------------------------------------

/**
 * Plugin activation hook.
 *
 * Runs Cloudi7_ICG_Activator::activate() once when the plugin is activated.
 */
register_activation_hook(__FILE__, array('Cloudi7_ICG_Activator', 'activate'));

/**
 * Plugin deactivation hook.
 *
 * Runs Cloudi7_ICG_Deactivator::deactivate() once when the plugin is deactivated.
 */
register_deactivation_hook(__FILE__, array('Cloudi7_ICG_Deactivator', 'deactivate'));

// ---------------------------------------------------------------------------
// Core Plugin Class
// ---------------------------------------------------------------------------

/**
 * Class Cloudi7_ID_Card_Generator
 *
 * The main plugin orchestrator.
 *
 * Responsibilities:
 *  - Instantiate and wire up Admin / Public components.
 *  - Register i18n (text-domain loading).
 *  - Delegate all hook registration to Cloudi7_ICG_Loader.
 *  - Expose a static run() entry point so the plugin boots with a single call.
 */
class Cloudi7_ID_Card_Generator
{

	/**
	 * The hook loader responsible for maintaining and triggering all hooks.
	 *
	 * @var Cloudi7_ICG_Loader $loader
	 */
	protected $loader;

	/**
	 * The current version of the plugin.
	 *
	 * @var string $version
	 */
	protected $version;

	/**
	 * Initialize the plugin: instantiate classes and define hooks.
	 */
	public function __construct()
	{
		$this->version = Cloudi7_ICG_VERSION;
		$this->loader = new Cloudi7_ICG_Loader();

		$this->set_locale();
		$this->define_admin_hooks();
		$this->define_public_hooks();
	}

	/**
	 * Define the locale for this plugin for internationalization.
	 *
	 * Uses the Cloudi7_ICG_i18n class to set the domain and register the hook
	 * with WordPress.
	 *
	 * @return void
	 */
	private function set_locale()
	{
		$plugin_i18n = new Cloudi7_ICG_i18n();

		$this->loader->add_action(
			'plugins_loaded',
			$plugin_i18n,
			'load_plugin_textdomain'
		);
	}

	/**
	 * Register all of the hooks related to the admin area functionality.
	 *
	 * @return void
	 */
	private function define_admin_hooks()
	{
		$plugin_admin = new Cloudi7_ICG_Admin($this->version);

		$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
		$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
		$this->loader->add_action('admin_menu', $plugin_admin, 'add_menu_pages');
		$this->loader->add_action('admin_init', $plugin_admin, 'handle_actions');

		// Custom footer credits
		$this->loader->add_filter('admin_footer_text', $plugin_admin, 'admin_footer_text');
		$this->loader->add_filter('update_footer', $plugin_admin, 'update_footer', 11);
	}

	/**
	 * Register all of the hooks related to the public-facing functionality.
	 *
	 * @return void
	 */
	private function define_public_hooks()
	{
		$plugin_public = new Cloudi7_ICG_Public($this->version);

		$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
		$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts');
		$this->loader->add_action('template_redirect', $plugin_public, 'handle_form_submission');

		// Register shortcodes
		$this->loader->add_shortcode('cloudi7_icg_verify', $plugin_public, 'render_cloudi7_icg_verify');
		$this->loader->add_shortcode('cloudi7_icg_apply', $plugin_public, 'render_cloudi7_icg_apply');
	}

	/**
	 * Run the loader to execute all registered hooks with WordPress.
	 *
	 * @return void
	 */
	public function run()
	{
		$this->loader->run();
	}

	/**
	 * Retrieve the version number of the plugin.
	 *
	 * @return string The version number.
	 */
	public function get_version()
	{
		return $this->version;
	}

	/**
	 * Retrieve the loader instance.
	 *
	 * @return Cloudi7_ICG_Loader The main loader object.
	 */
	public function get_loader()
	{
		return $this->loader;
	}
}

// ---------------------------------------------------------------------------
// Bootstrap
// ---------------------------------------------------------------------------

/**
 * Begin plugin execution.
 *
 * Since everything within the plugin is registered via hooks, kicking off the
 * plugin from this point in the file does not affect the page life cycle.
 */
function cloudi7_icg_run()
{
	$plugin = new Cloudi7_ID_Card_Generator();
	$plugin->run();
}

cloudi7_icg_run();

add_action('admin_enqueue_scripts', 'cloudi7_icg_enqueue_inline_styles');
add_action('wp_enqueue_scripts', 'cloudi7_icg_enqueue_inline_styles');
function cloudi7_icg_enqueue_inline_styles() {
	wp_enqueue_style('cloudi7-icg-inline-styles', Cloudi7_ICG_PLUGIN_URL . 'assets/css/cloudi7-icg-inline-styles.css', array(), Cloudi7_ICG_VERSION, 'all');
}
