<?php
/**
 * Recommended plugins for PortfolioX
 *
 * Core plugins (Posts Display, Magical Addons, Easy Share, Click To Top,
 * Password Protected, Elementor, Magical Blocks) come from the Magical Plugin
 * Activation library defaults. This file adds theme-specific extras.
 */

function portfoliox_magical_plugins($plugins) {
    $theme_plugins = array(
        'gallery-box' => array(
            'name'        => __('Gallery Box', 'portfoliox'),
            'slug'        => 'gallery-box',
            'file'        => 'gallery-box/gallery-box.php',
            'description' => __('Beautiful gallery and lightbox plugin.', 'portfoliox'),
            'category'    => 'Media',
            'required'    => false,
            'featured'    => true,
            'is_local'    => false,
        ),
        'ai-marketing-expert' => array(
            'name'        => __('AI Marketing Expert', 'portfoliox'),
            'slug'        => 'ai-marketing-expert',
            'file'        => 'ai-marketing-expert/ai-marketing-expert.php',
            'description' => __('AI-powered marketing suite with email marketing, content generator, SEO analyzer, social media, and chatbot.', 'portfoliox'),
            'category'    => 'Marketing',
            'required'    => false,
            'timed_auto'  => true,
            'featured'    => true,
            'is_local'    => false,
        ),
    );

    if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
        $theme_plugins['magical-products-display'] = array(
            'name'        => __('Magical Products Display', 'portfoliox'),
            'slug'        => 'magical-products-display',
            'file'        => 'magical-products-display/magical-products-display.php',
            'description' => __('Display WooCommerce products in beautiful layouts.', 'portfoliox'),
            'category'    => 'eCommerce',
            'required'    => false,
            'featured'    => true,
            'is_local'    => false,
        );
    }

    return array_merge($plugins, $theme_plugins);
}
add_filter('magical_plugin_activation_recommended_plugins', 'portfoliox_magical_plugins');

/**
 * AI Marketing Expert success notice
 */
function portfoliox_ai_marketing_notice() {
    if (!is_plugin_active('ai-marketing-expert/ai-marketing-expert.php')) {
        return;
    }

    $user_id = get_current_user_id();
    $dismissed = get_user_meta($user_id, 'portfoliox_ai_notice_dismissed', true);
    if ($dismissed) {
        return;
    }

    if (isset($_GET['portfoliox_ai_dismiss']) && '1' === $_GET['portfoliox_ai_dismiss']) {
        update_user_meta($user_id, 'portfoliox_ai_notice_dismissed', 1);
        return;
    }

    $has_woo = is_plugin_active('woocommerce/woocommerce.php');
    $message = $has_woo
        ? __('Supercharge your sales and turn visitors into loyal customers — automatically. Built by WordPress experts, it\'s the smartest AI tool in your dashboard. We promise you\'ll be a fan!', 'portfoliox')
        : __('Attract more visitors, grow your audience, and keep them engaged — automatically. Built by WordPress experts, it\'s the smartest AI tool in your dashboard. We promise you\'ll be a fan!', 'portfoliox');
    ?>
    <div class="notice notice-success is-dismissible" style="border-left-color:#2271b1; padding:16px 20px;">
        <p style="font-size:14px; margin:0 0 8px;">
            <strong style="color:#2271b1;"><?php esc_html_e('AI Marketing Expert', 'portfoliox'); ?></strong> &mdash;
            <?php esc_html_e('Now active on your site! — A must-have plugin in the current AI world.', 'portfoliox'); ?>
        </p>
        <p style="margin:0 0 12px; font-size:13px; line-height:1.6;">
            <?php echo esc_html($message); ?>
        </p>
        <p style="margin:0;">
            <a href="<?php echo esc_url(add_query_arg('portfoliox_ai_dismiss', '1')); ?>" class="button button-primary" style="font-weight:600;">
                <?php esc_html_e('Got it!', 'portfoliox'); ?>
            </a>
        </p>
    </div>
    <?php
}
add_action('admin_notices', 'portfoliox_ai_marketing_notice');
