<?php
/**
 * Main Plugin Class
 *
 * @package PureDash
 */

namespace PureDash;

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

/**
 * Main Plugin Class
 *
 * @since 1.0.0
 */
final class PureDash_Cleaner {

	/**
	 * Instance of this class.
	 *
	 * @var object
	 */
	private static $instance;

	/**
	 * Get the instance of the class.
	 *
	 * @return object
	 */
	public static function get_instance() {
		if ( ! isset( self::$instance ) ) {
			self::$instance = new self();
			self::$instance->setup_constants();
			self::$instance->includes();
			self::$instance->hooks();
		}
		return self::$instance;
	}

	/**
	 * Setup plugin constants.
	 */
	private function setup_constants() {
		// Already defined globally for simplicity in templates
	}

	/**
	 * Include required files.
	 */
	private function includes() {
		// Autoload handled by SPL
	}

	/**
	 * Setup hooks.
	 */
	private function hooks() {
		add_action( 'init', array( $this, 'init' ) );
		register_activation_hook( PUREDASH_FILE, array( $this, 'activate' ) );
		register_deactivation_hook( PUREDASH_FILE, array( $this, 'deactivate' ) );
		add_filter( 'plugin_action_links_' . plugin_basename( PUREDASH_FILE ), array( $this, 'plugin_action_links' ) );
	}

	/**
	 * Initialize the plugin.
	 */
	public function init() {
		// Initialize Core Logic - Only for authenticated users
		if ( is_user_logged_in() && class_exists( 'PureDash\\Core' ) ) {
			new \PureDash\Core();
		}

		// Initialize Settings - Only for admin non-AJAX requests
		if ( is_admin() && ! wp_doing_ajax() && class_exists( 'PureDash\\Settings' ) ) {
			new \PureDash\Settings();
		}
	}

	/**
	 * Activation hook.
	 */
	public function activate() {
		// Set default options if not exists
		if ( false === get_option( 'puredash-cleaner_blacklist' ) ) {
			add_option( 'puredash-cleaner_blacklist', array() );
		}

		// Schema version
		if ( false === get_option( 'puredash-cleaner_schema_version' ) ) {
			add_option( 'puredash-cleaner_schema_version', '1.0.0' );
		}
	}

	/**
	 * Deactivation hook.
	 */
	public function deactivate() {
		// Flush rewrite rules if needed, or cleanup temporary data
	}

	/**
	 * Add specific links to the plugin action links.
	 *
	 * @param array $links Plugin action links.
	 * @return array Modified links.
	 */
	public function plugin_action_links( $links ) {
		$settings_link = '<a href="' . admin_url( 'options-general.php?page=puredash-cleaner' ) . '">' . esc_html__( 'Settings', 'puredash-cleaner' ) . '</a>';
		array_unshift( $links, $settings_link );
		return $links;
	}
}
