<?php
/**
 * Plugin Name: BW Image Hotspot
 * Plugin URI:  https://bowdenworks.com/
 * Description: Create interactive image hotspots with clickable points and tooltips. Use shortcodes or Gutenberg block to add hotspots to any image.
 * Version:     1.0.0
 * Author:      Bowden Works
 * Author URI:  https://bowdenworks.com/
 * License:     GPL2
 * Text Domain: bw-image-hotspot
 */

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

// Define plugin constants
define( 'BW_IMAGE_HOTSPOT_VERSION', '1.0.0' );
define( 'BW_IMAGE_HOTSPOT_PATH', plugin_dir_path( __FILE__ ) );
define( 'BW_IMAGE_HOTSPOT_URL', plugin_dir_url( __FILE__ ) );

/**
 * Main Plugin Class
 */
class BW_Image_Hotspot {

    /**
     * Instance of this class
     */
    private static $instance = null;

    /**
     * Get instance of this class
     */
    public static function get_instance() {
        if ( null === self::$instance ) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * Constructor
     */
    private function __construct() {
        $this->includes();
        $this->init_hooks();
    }

    /**
     * Include required files
     */
    private function includes() {
        require_once BW_IMAGE_HOTSPOT_PATH . 'includes/shortcodes.php';
        require_once BW_IMAGE_HOTSPOT_PATH . 'includes/block.php';
    }

    /**
     * Initialize hooks
     */
    private function init_hooks() {
        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_assets' ) );
        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );
    }

    /**
     * Enqueue frontend assets
     */
    public function enqueue_frontend_assets() {
        wp_enqueue_style(
            'bw-image-hotspot-style',
            BW_IMAGE_HOTSPOT_URL . 'assets/css/style.css',
            array(),
            BW_IMAGE_HOTSPOT_VERSION
        );

        wp_enqueue_script(
            'bw-image-hotspot-frontend',
            BW_IMAGE_HOTSPOT_URL . 'assets/js/frontend.js',
            array( 'jquery' ),
            BW_IMAGE_HOTSPOT_VERSION,
            true
        );
    }

    /**
     * Enqueue admin assets
     */
    public function enqueue_admin_assets() {
        $screen = get_current_screen();
        if ( $screen && $screen->is_block_editor() ) {
            wp_enqueue_style(
                'bw-image-hotspot-editor',
                BW_IMAGE_HOTSPOT_URL . 'assets/css/editor.css',
                array(),
                BW_IMAGE_HOTSPOT_VERSION
            );
        }
    }
}

// Initialize the plugin
add_action( 'plugins_loaded', array( 'BW_Image_Hotspot', 'get_instance' ) );
