<?php
	/**
	 * The core plugin class.
	 *
	 * @since      1.0.0
	 * @package    Expandable_Paywall
	 * @subpackage Expandable_Paywall/includes
	 * @author     Pramadillo <support@pramadillo.com>
	 */

	namespace Emoxie\Expandable_Paywall;

	class Expandable_Paywall {

		protected $loader;

		public function __construct() {
			$this->load_dependencies();
			$this->set_locale();
			$this->define_admin_hooks();
			$this->define_public_hooks();

		}

		public function run() {
			$this->loader->run();
		}

		public function get_loader() {
			return $this->loader;
		}


		private function load_dependencies() {

			require_once EXPANDABLE_PAYWALL_PATH . 'includes/class-expandable-paywall-loader.php';
			require_once EXPANDABLE_PAYWALL_PATH . 'includes/class-expandable-paywall-i18n.php';
			require_once EXPANDABLE_PAYWALL_PATH . 'includes/class-expandable-paywall-helper.php';
			require_once EXPANDABLE_PAYWALL_PATH . 'includes/class-expandable-paywall-logger.php';
			require_once EXPANDABLE_PAYWALL_PATH . 'includes/ssp.class.php';
			require_once EXPANDABLE_PAYWALL_PATH . 'admin/class-expandable-paywall-admin.php';
			require_once EXPANDABLE_PAYWALL_PATH . 'public/class-expandable-paywall-public.php';

			$this->loader = new Expandable_Paywall_Loader();

		}

		private function set_locale() {

			$plugin_i18n = new Expandable_Paywall_i18n();

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

		}

		private function define_admin_hooks() {

			$plugin_admin = new Expandable_Paywall_Admin();

			$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' );
			$this->loader->add_action( 'admin_init', $plugin_admin, 'init' );
			$this->loader->add_action( 'admin_head', $plugin_admin, 'admin_menu_separator_styles' );
			$this->loader->add_action( EXPANDABLE_PAYWALL_SLUG . '_authentication_roles', $plugin_admin, 'output_authentication_roles' );
			$this->loader->add_action( EXPANDABLE_PAYWALL_SLUG . '_paywall_settings', $plugin_admin, 'output_paywall_settings' );
			$this->loader->add_action( 'in_plugin_update_message-' . EXPANDABLE_PAYWALL_BASENAME, $plugin_admin, 'prefix_plugin_update_message', 10, 2 );
			$this->loader->add_action( 'load-post.php', $plugin_admin, 'setup_bypass_link_meta_box' );
			$this->loader->add_action( 'load-post-new.php', $plugin_admin, 'setup_bypass_link_meta_box' );
			$this->loader->add_action( 'wp_ajax_exp_get_logs', $plugin_admin, 'ajax_getlogs' );
			$this->loader->add_action( 'wp_ajax_nopriv_exp_get_logs', $plugin_admin, 'ajax_getlogs' );

			$this->loader->add_action( 'wp_ajax_exp_clear_logs', $plugin_admin, 'ajax_clear_logs' );
			$this->loader->add_action( 'wp_ajax_nopriv_exp_clear_logs', $plugin_admin, 'ajax_clear_logs' );

			$this->loader->add_filter( 'plugin_action_links_' . EXPANDABLE_PAYWALL_BASENAME, $plugin_admin, 'plugin_settings_link', 10, 2 );

		}

		private function define_public_hooks() {
			if ( get_option( EXPANDABLE_PAYWALL_SLUG . '_enabled' ) ) {
				$plugin_public = new Expandable_Paywall_Public();

				$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( 'init', $plugin_public, 'init' );

				$this->loader->add_filter( EXPANDABLE_PAYWALL_SLUG . '_roles_that_bypass_paywall', $plugin_public, 'roles_that_bypass_paywall' );

				$this->loader->add_action( 'wp_ajax_' . EXPANDABLE_PAYWALL_SLUG . '_login', $plugin_public, 'ajax_login' );
				$this->loader->add_action( 'wp_ajax_nopriv_' . EXPANDABLE_PAYWALL_SLUG . '_login', $plugin_public, 'ajax_login' );

				$this->loader->add_action( 'wp_ajax_' . EXPANDABLE_PAYWALL_SLUG . '_register', $plugin_public, 'ajax_register' );
				$this->loader->add_action( 'wp_ajax_nopriv_' . EXPANDABLE_PAYWALL_SLUG . '_register', $plugin_public, 'ajax_register' );

				$this->loader->add_action( EXPANDABLE_PAYWALL_SLUG . '_shortcode_login', $plugin_public, 'render_shortcode_login' );
				$this->loader->add_action( EXPANDABLE_PAYWALL_SLUG . '_shortcode_register', $plugin_public, 'render_shortcode_register' );

				$this->loader->add_action( 'login_form_middle', $plugin_public, 'forgot_password_link' );

				if( get_option( EXPANDABLE_PAYWALL_SLUG . '_paywall_enable_structured_data' ) ) {
					$this->loader->add_action( 'wp_footer', $plugin_public, 'output_structured_data' );
				}

				$this->loader->add_filter( 'query_vars', $plugin_public, 'add_bypass_query_vars' );





			}

		}

	}