<?php
/**
 * Plugin Name: RoarDev Mega Menu Builder
 * Plugin URI: https://roardev.xyz/mega-menu-builder
 * Description: Modern mega menu builder for WordPress. Create beautiful, mobile-friendly mega menus using Gutenberg or Elementor. The ultimate WordPress menu builder for floating and centered mega menu layouts.
 * Version: 1.0.0
 * Author: RoarDev
 * Author URI: https://roardev.xyz
 * License: GPL v2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: roardev-mega-menu-builder
 * Domain Path: /languages
 * Requires at least: 6.0
 * Tested up to: 6.9
 * Requires PHP: 7.4
 * 
 * @package RoarDevMegaMenuBuilder
 */

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

// Define plugin constants
define('ROARDEV_MMB_VERSION', '1.0.0');
define('ROARDEV_MMB_PATH', plugin_dir_path(__FILE__));
define('ROARDEV_MMB_URL', plugin_dir_url(__FILE__));
define('ROARDEV_MMB_BASENAME', plugin_basename(__FILE__));

// Load plugin files
require_once ROARDEV_MMB_PATH . 'includes/cpt.php';
require_once ROARDEV_MMB_PATH . 'includes/menu-ui.php';
require_once ROARDEV_MMB_PATH . 'includes/menu-save.php';
require_once ROARDEV_MMB_PATH . 'includes/render.php';
require_once ROARDEV_MMB_PATH . 'includes/helpers.php';
require_once ROARDEV_MMB_PATH . 'includes/accessibility.php';
require_once ROARDEV_MMB_PATH . 'includes/migration.php';

/**
 * Enqueue frontend assets
 */
function roardev_mmb_enqueue_frontend_assets()
{
    if (!roardev_mmb_has_mega_menu()) {
        return;
    }

    wp_enqueue_style(
        'roardev-mmb-frontend',
        ROARDEV_MMB_URL . 'assets/css/frontend.css',
        array(),
        ROARDEV_MMB_VERSION
    );

    wp_enqueue_script(
        'roardev-mmb-frontend',
        ROARDEV_MMB_URL . 'assets/js/frontend.js',
        array(),
        ROARDEV_MMB_VERSION,
        true
    );

    if (class_exists('\\Elementor\\Plugin')) {
        \Elementor\Plugin::$instance->frontend->enqueue_styles();
    }
}
add_action('wp_enqueue_scripts', 'roardev_mmb_enqueue_frontend_assets');

/**
 * Enqueue admin assets
 */
function roardev_mmb_enqueue_admin_assets($hook)
{
    // Only load on menu edit page
    if ($hook !== 'nav-menus.php') {
        return;
    }

    wp_enqueue_style('wp-color-picker');
    wp_enqueue_script('wp-color-picker');

    wp_enqueue_style(
        'roardev-mmb-admin',
        ROARDEV_MMB_URL . 'assets/css/admin.css',
        array('wp-color-picker'),
        ROARDEV_MMB_VERSION
    );

    wp_enqueue_script(
        'roardev-mmb-admin',
        ROARDEV_MMB_URL . 'assets/js/admin.js',
        array('jquery', 'wp-color-picker'),
        ROARDEV_MMB_VERSION,
        true
    );
}
add_action('admin_enqueue_scripts', 'roardev_mmb_enqueue_admin_assets');
