<?php
/**
 * @package EasyAnimatedPopup
 *
 * Plugin Name: Easy Animated Popup
 * Plugin URI: https://sgt-lab.com/animated-popup/
 * Description: Setup and create animated popup in seconds, increase lead and conversions for your website.
 * Author: Saigon-tech
 * Version: 1.0.0
 * Author URI: https://www.saigon-tech.vn/
 * Text Domain: easy-animated-popup
 *
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit;
};

defined( 'EAPSGT_VERSION' ) or define( 'EAPSGT_VERSION', '1.0.0' );
defined( 'EAPSGT_WP_VERSION' ) or define( 'EAPSGT_WP_VERSION', '5.x' );
defined( 'EAPSGT_PLUGIN_URL' ) or define( 'EAPSGT_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
defined( 'EAPSGT_PLUGIN_DIR' ) or define( 'EAPSGT_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );

// include setting files here
require_once EAPSGT_PLUGIN_DIR . 'includes/popup/popup_setup.php';
require_once EAPSGT_PLUGIN_DIR . 'includes/post_type.php';
require_once EAPSGT_PLUGIN_DIR . 'easy-animated-popup-admin.php';
require_once EAPSGT_PLUGIN_DIR . 'includes/settings/add_settings_menu.php';
require_once EAPSGT_PLUGIN_DIR . 'includes/settings/animation_settings.php';
require_once EAPSGT_PLUGIN_DIR . 'includes/settings/display_settings.php';
require_once EAPSGT_PLUGIN_DIR . 'includes/settings/tab_template.php';
require_once EAPSGT_PLUGIN_DIR . 'includes/settings/tab_basic_settings.php';
require_once EAPSGT_PLUGIN_DIR . 'includes/popup/config.php';
$eapsgtTemplates = EAPSGT_AnimatedPopupConfig::templates();
foreach ( $eapsgtTemplates as $eapsgtTemplate ) {
	require_once EAPSGT_PLUGIN_DIR . 'includes/templates/admin/' . $eapsgtTemplate . '.php';
	require_once EAPSGT_PLUGIN_DIR . 'includes/templates/general/' . $eapsgtTemplate . '.php';

}

class EAPSGT_Plugin {
	private $pluginFile;

	function __construct() {
		$this->pluginFile = __FILE__;
	}

	function register() {
		add_action( 'admin_enqueue_scripts', array( $this, 'eapsgt_enqueue_styles' ), 11 );
		add_action( 'admin_enqueue_scripts', array( $this, 'eapsgt_enqueue_scripts' ), 11 );
	}

	function activate() {
		flush_rewrite_rules();
	}

	function deactivate() {
		flush_rewrite_rules();
	}

	// enqueue all styles
	function eapsgt_enqueue_styles() {
		wp_enqueue_style( 'jquery-ui' );
		wp_enqueue_style( 'jquery-styles', plugins_url( '/assets/css/vendor/jquery-ui/jquery-ui.css', $this->pluginFile ), false, null, 'all' );
		wp_enqueue_style( 'eapsgt-custom-style', plugins_url( '/assets/css/admin/eapsgt_custom_styles.min.css', $this->pluginFile ), false, null, 'all' );
		wp_enqueue_style( 'eapsgt-animation-style', plugins_url( '/assets/css/admin/eapsgt_animation_settings.min.css', $this->pluginFile ), false, null, 'all' );
		wp_enqueue_style( 'eapsgt-animate-css', plugins_url( '/assets/css/vendor/animate.min.css', $this->pluginFile ), false, null, 'all' );
		wp_enqueue_style( 'eapsgt-template', plugins_url( '/assets/css/admin/eapsgt_custom_template.min.css', $this->pluginFile ) );
		wp_enqueue_style( 'eapsgt-style', plugins_url( '/assets/css/admin/eapsgt-style.min.css', $this->pluginFile ) );
	}

	// enqueue all scripts
	function eapsgt_enqueue_scripts() {
		wp_enqueue_script( 'jquery' );
		wp_enqueue_script( 'jquery-ui-slider' );
		wp_enqueue_script( 'eapsgt-script-template', plugins_url( '/assets/js/eapsgt_custom_template.min.js', $this->pluginFile ) );
		wp_enqueue_script( 'eapsgt-animation-preview-script', plugins_url( '/assets/js/eapsgt_animation_preview.min.js', $this->pluginFile ), array( 'jquery' ), null, false );
		wp_enqueue_script( 'eapsgt-basic-script', plugins_url( '/assets/js/eapsgt_basic_template.min.js', $this->pluginFile ), array( 'jquery' ), null, false );
		wp_enqueue_script( 'eapsgt-lazysizes-script', plugins_url( '/assets/js/vendor/lazysizes.min.js', $this->pluginFile ), array( 'jquery' ), null, false );
		wp_enqueue_script( 'eapsgt-script-basic-settings', plugins_url( '/assets/js/eapsgt_custom_basic_settings.min.js', $this->pluginFile ) );
	}
}

if ( class_exists( 'EAPSGT_Plugin' ) ) {
	$EAPSGT_Plugin = new EAPSGT_Plugin();
	$EAPSGT_Plugin->register();
}

// activation
register_activation_hook( __FILE__, array( $EAPSGT_Plugin, 'active' ) );

// deactivation
register_deactivation_hook( __FILE__, array( $EAPSGT_Plugin, 'deactivate' ) );

function eapsgt_activation_hook( $plugin ) {
	if ( $plugin == plugin_basename( __FILE__ ) ) {
		exit( wp_redirect( admin_url( 'edit.php?post_type=eapsgt' ) ) );
	}
}

add_action( 'activated_plugin', 'eapsgt_activation_hook' );
