<?php
/**
 * Main plugin class. Singleton that bootstraps all components.
 *
 * @package CoffeeWP_Media_Cleanup
 */

namespace CWPM;

defined( 'ABSPATH' ) || exit;

class Plugin extends Singleton {

	/**
	 * Constructor -- wire up hooks.
	 */
	protected function __construct() {
		parent::__construct();

		Core\Trash::init();
		Core\Logger::init();
		Thumbnail\Sizes::register_hooks();

		add_action( 'add_attachment', array( Media\Scanner::class, 'flush_cache' ) );
		add_action( 'delete_attachment', array( Media\Scanner::class, 'flush_cache' ) );

		if ( is_admin() ) {
			$this->init_admin();
		}
	}

	/**
	 * Initialize admin-only components.
	 */
	private function init_admin() {
		new Admin\Page();
		new Admin\Assets();
		new Ajax\CompatHandler();
		new Ajax\LogHandler();
		new Ajax\SettingsHandler();
		new Ajax\ThumbnailHandler();
		new Ajax\MediaHandler();
		new Ajax\TrashHandler();
		new Ajax\ScanHandler();
	}
}
