<?php
/**
 Plugin Name: Halloween Panda
 Plugin URI: https://wordpress.org/plugins/halloween-panda/
 Description: Add halloween design to your WordPress website
 Author: Pixolette
 Author URI: https://pixolette.com
 Domain Path: halloween-panda
 Version: 1.0.6
*/

defined( 'ABSPATH' ) or die( 'No script kiddies please!' );

// Define Rule: Pixolette _ HalloweenPanda _ Path .
if ( ! defined( 'PIX_HAL_PAN_PATH' ) ) {
	define( 'PIX_HAL_PAN_PATH', plugin_dir_path( __FILE__ ) );
}

if ( ! defined( 'PIX_HAL_PAN_URL' ) ) {
	define( 'PIX_HAL_PAN_URL', plugins_url() . '/halloween-panda/' );
}

require_once PIX_HAL_PAN_PATH . '_controllers/hp-controller.php';
require_once PIX_HAL_PAN_PATH . '_models/hp-main.php';
use PixHalloweenPanda\Controllers\Main as PixHalPanMainController;
use PixHalloweenPanda\Models\Main as PixHalPanMainModel;

// Init plugin in wp-admin section.
add_action( 'admin_menu', 'pix_halpan_init_plugin_page' );

/**
 *
 * Init admin page.
 */
function pix_halpan_init_plugin_page() {
	add_menu_page( 'Halloween Panda', 'Halloween panda', 'manage_options', 'pix-halloween-panda', array( new PixHalPanMainController, 'init_backend' ), 'dashicons-admin-customizer' );
}

add_action( 'admin_enqueue_scripts', 'pix_halpan_admin_enqueue_scripts_and_styles' );

/**
 *
 * Add styles and js scripts
 */
function pix_halpan_admin_enqueue_scripts_and_styles() {
	wp_enqueue_style( 'pix-hp-wpadmin-style', PIX_HAL_PAN_URL . 'assets/css/hp-backend.css', array(), '1.0.0' );
}

add_action( 'wp_enqueue_scripts', 'pix_halpan_enqueue_scripts_and_styles' );

/**
 *
 * Add styles and js scripts in frontend
 */
function pix_halpan_enqueue_scripts_and_styles() {
	wp_enqueue_style( 'pix-hp-wp-style', PIX_HAL_PAN_URL . 'assets/css/hp-frontend.min.css', array(), '1.0.0' );
	wp_enqueue_script( 'pix-hp-wp-script', PIX_HAL_PAN_URL . 'assets/js/hp-frontend.min.js', array( 'jquery', 'pix-hp-wp-script-fall', 'pix-hp-wp-script-cookies' ), '', true );
	wp_enqueue_script( 'pix-hp-wp-script-fall', PIX_HAL_PAN_URL . 'assets/js/snowfall.jquery.min.js', array( 'jquery' ), '', true );
	wp_enqueue_script( 'pix-hp-wp-script-cookies', PIX_HAL_PAN_URL . 'assets/js/js.cookie.min.js', array( 'jquery' ), '', true );
}

add_action( 'wp_footer', 'pix_halpan_template' );

/**
 * Include overlay review form into header section
 *
 * @var function
 */
function pix_halpan_template() {

	$hp_model = new PixHalPanMainModel();
	$hp_options = json_decode( $hp_model->options_data );
	include_once PIX_HAL_PAN_PATH . '_views/hp-frontend.php';

}

register_activation_hook( __FILE__, 'pix_halpan_install' );
/**
 * Creates custom table pxreviews. Used to store the user's revies.
 * Runs only when plugin is activated
 *
 * @var function
 */
function pix_halpan_install() {
	$options = array(
		'px_hp_is_active' => 'yes',
		'px_hp_display_type' => 'pumpkins',
		'px_hp_display_position' => 'bottom',
		'px_hp_is_fixed' => 'yes',
		'px_hp_pumpkin_fall' => 'no',
		'px_hp_display_popup' => 'no',
		'px_hp_popup_type' => '1',
		'px_hp_popup_position' => 'right'
	);
	$main_model = new PixHalPanMainModel();
	$main_model->save_options( $options );
}
