<?php

/**
 * Plugin Name: Flyerimage
 * Description: Manage your campaign, leaflet, add modal centrally.
 * Plugin URL: https://flyerimage.com
 * Author: thousand31
 * Version: 3.0.1
 * License: GPLv2 or later
 * License URL: https://www.gnu.org/licenses/gpl-2.0.html
 */


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

require_once __DIR__ . '/vendor/autoload.php';

/**
 * The main plugin class
 */
final class Flyer_Image
{

    /**
     * Plugin version
     *
     * @var version | string
     */
    const version = '3.0.1';

    /**
     * class constructor
     */
    private function __construct()
    {
        $this->define_constants();
        register_activation_hook(__FILE__, [$this, 'activate']);
        add_action('plugins_loaded', [$this, 'init_plugin']);
    }

    /**
     * Initializes a singleton instances
     *
     * @return \Flyer_Image
     */
    public static function init()
    {
        static $instance = false;
        if (!$instance) {
            $instance = new self();
        }
        return $instance;
    }

    /**
     * Define the required plugin constants
     *
     * @return void
     */
    public function define_constants()
    {
        // define('WP_DEBUG', true);
        // define('WP_DEBUG_LOG', true);
        // define('WP_DEBUG_DISPLAY', true);
        define('FLYER_IMAGE_VERSION', self::version);
        define('FLYER_IMAGE_FILE', __FILE__);
        define('FLYER_IMAGE_PATH', __DIR__);
        define('FLYER_IMAGE_URL', plugins_url('', FLYER_IMAGE_FILE));
        define('FLYER_IMAGE_PUBLIC_PATH', FLYER_IMAGE_PATH.'/webapp');
        define('FLYER_IMAGE_PUBLIC_URL', FLYER_IMAGE_URL . '/webapp');
        define('FLYER_IMAGE_ADMIN_BASE_URL', get_site_url() . '/wp-admin/admin.php?page='.'flyer-image');
    }

    /**
     * Initialze the plugin
     *
     * @return void
     */
    public function init_plugin()
    {
        // loading assets
        new Flyerimage\Core\Init\Assets();
        new Flyerimage\Core\Init\RestAPI();
        if (is_admin()) {
            new Flyerimage\Core\Init\Admin();
            new Flyerimage\Core\Init\OnboardingNotice();
        }
    }

    /**
     * Do stuff upon plugin activation
     *
     * @return void
     */
    public function activate()
    {
        (new Flyerimage\Core\Init\Installer())->run();
        // Reset onboarding notice on activation
        Flyerimage\Core\Init\OnboardingNotice::reset_notice();
        register_uninstall_hook(__FILE__, [$this, 'uninstall']);
        register_deactivation_hook(__FILE__, [$this, 'deactivation']);
    }

    /**
     * Do stuff upon plugin uninstall
     *
     * @return void
     */
    public function uninstall()
    {
        (new Flyerimage\Core\Init\Installer())->uninstall();
    }

    /**
     * Do stuff upon plugin deactivation
     *
     * @return void
     */
    public function deactivation()
    {
        (new Flyerimage\Core\Init\Installer())->deactivation();
    }
}

/**
 * Initializes the main plugin
 *
 * @return \Flyer_Image
 */
function flyer_image()
{
    return Flyer_Image::init();
}

// Kick-off the plugin
define("FLYER_IMAGE_WP_PLUGIN_SLUG_NAME_V252202251", "flyerimage");
define("FLYER_IMAGE_WP_PLUGIN_DIRECTORY_NAME_V252202251", "flyerimage");
define("FLYER_IMAGE_WP_PLUGIN_API_BASE_V252202251", "flyer_image_v9622105412/v1"); // also change in HomeController
flyer_image();