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

/**
 * Register Mega Menu custom post type
 */
function roardev_mmb_register_cpt()
{
    register_post_type('roardev_mega_menu', array(
        'label' => 'Mega Menus',
        'public' => false,
        'show_ui' => true,
        'show_in_rest' => true,
        'supports' => array('title', 'editor'),
        'menu_icon' => 'dashicons-menu-alt3',
    ));
}
add_action('init', 'roardev_mmb_register_cpt');

/**
 * Add donation notice to Mega Menu list page
 */
function roardev_mmb_admin_notice()
{
    $screen = get_current_screen();
    if ($screen && $screen->post_type === 'roardev_mega_menu' && $screen->base === 'edit') {
        ?>
        <div class="notice notice-info"
            style="background: #fff; border-left: 4px solid #FFDD00; padding: 20px; margin: 15px 0; text-align: center;">
            <p style="margin: 0 0 15px 0; font-size: 15px; color: #23282d;">
                <strong>💖 Enjoying Mega Menu Builder?</strong> Support the development and help us create more awesome
                features!
            </p>
            <a href="https://buymeacoffee.com/iksopnil" target="_blank" rel="noopener">
                <img src="<?php echo esc_url(plugins_url('assets/img/08f1cf468ace518fc8cc9e352a2e613f.png', dirname(__FILE__))); ?>"
                    alt="Buy Me A Coffee" style="height: 50px !important; width: auto !important;">
            </a>
            <div style="margin-top: 30px; padding-top: 20px; border-top: 1px solid #ddd;">
                <h3 style="margin: 0 0 15px 0; font-size: 16px; color: #23282d;">📺 Video Tutorial</h3>
                <iframe width="560" height="315" src="https://www.youtube.com/embed/MrYCYbsqi5E?si=tyLZEvNIaLmRF6V4"
                    title="YouTube video player" frameborder="0"
                    allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
                    referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
            </div>
        </div>
        <?php
    }
}
add_action('admin_notices', 'roardev_mmb_admin_notice');

/**
 * Add YouTube tutorial to post add/edit page
 */
function roardev_mmb_add_youtube_tutorial()
{
    $screen = get_current_screen();
    if ($screen && $screen->post_type === 'roardev_mega_menu' && in_array($screen->base, array('post', 'post-new'))) {
        ?>
        <div
            style="margin: 20px 0; padding: 20px; background: #fff; border: 1px solid #ccd0d4; box-shadow: 0 1px 1px rgba(0,0,0,.04);">
            <h3 style="margin-top: 0;">📺 Video Tutorial</h3>
            <iframe width="560" height="315" src="https://www.youtube.com/embed/MrYCYbsqi5E?si=tyLZEvNIaLmRF6V4"
                title="YouTube video player" frameborder="0"
                allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
                referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
        </div>
        <?php
    }
}
add_action('edit_form_after_editor', 'roardev_mmb_add_youtube_tutorial');
