<?php
/**
 * Postomatic Plugin - Postomatic Plugin Main Class.
 *
 *  PHP Version 5.6
 *
 * @package  Postomatic
 * @category Plugin
 * @license  GPL-2.0-or-later https://www.gnu.org/licenses/gpl-2.0.html
 * @link     https://buildomatics.com/postomatics
 * @since    1.0.0
 */

namespace Postomatic;

// Exit if accessed directly to prevent direct script access.
use Postomatic\Core\Ajax_Handler;

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

/**
 * Postomatic Plugin Main Class.
 *
 * Handles plugin initialization and core functionality.
 *
 * @category Plugin
 * @license  GPL-2.0-or-later https://www.gnu.org/licenses/gpl-2.0.html
 * @link     https://buildomatics.com/postomatics
 */
class Postomatic {

	/**
	 * Runs the plugin and initializes its core functionality.
	 *
	 * Checks if the current context is admin and loads
	 * necessary admin dependencies if true.
	 *
	 * @return void
	 * @since  1.0.0
	 * @access public
	 */
	public function run(): void {
		// Initialize admin functionality only in the WordPress admin area.
		if ( \is_admin() ) {
			$this->load_admin_dependencies();
		}

		// Always load public facing assets.
		$this->load_public_assets();
	}

	/**
	 * Loads and initializes admin-specific dependencies.
	 *
	 * Requires the admin class file and instantiates the
	 * Postomatic_Admin class to set up administrative functionality.
	 *
	 * @throws \Exception If admin class file cannot be loaded.
	 * @return void
	 * @since  1.0.0
	 * @access private
	 */
	private function load_admin_dependencies(): void {
		// Initialize hooks.
		$admin_hooks = new Ajax_Handler();
		$admin_hooks->init();

		// Instantiate and initialize admin functionality.
		$admin = new Admin\Init();
		$admin->init();
	}

	/**
	 * Loads public facing assets.
	 *
	 * @return void
	 */
	private function load_public_assets(): void {
		$public_assets = new Frontend\Public_Assets();
		$public_assets->init();
	}
}
