<?php
/**
 * Recommended plugins for Real Estate Pack
 */

function real_estate_pack_magical_plugins($plugins) {
    $theme_plugins = array(
        'magical-posts-display' => array(
            'name'        => __('Posts Display', 'real-estate-pack'),
            'slug'        => 'magical-posts-display',
            'file'        => 'magical-posts-display/magical-posts-display.php',
            'description' => __('Display posts in beautiful layouts.', 'real-estate-pack'),
            'category'    => 'Content Display',
            'essential'   => false,
            'featured'    => true,
            'is_local'    => false,
        ),
        'magical-addons-for-elementor' => array(
            'name'        => __('Magical Addons', 'real-estate-pack'),
            'slug'        => 'magical-addons-for-elementor',
            'file'        => 'magical-addons-for-elementor/magical-addons-for-elementor.php',
            'description' => __('Premium quality addons for Elementor page builder.', 'real-estate-pack'),
            'category'    => 'Page Builder',
            'essential'   => false,
            'featured'    => true,
            'is_local'    => false,
        ),
        'gallery-box' => array(
            'name'        => __('Gallery Box', 'real-estate-pack'),
            'slug'        => 'gallery-box',
            'file'        => 'gallery-box/gallery-box.php',
            'description' => __('Beautiful gallery and lightbox plugin.', 'real-estate-pack'),
            'category'    => 'Media',
            'essential'   => false,
            'featured'    => true,
            'is_local'    => false,
        ),
        'click-to-top' => array(
            'name'        => __('Click To Top', 'real-estate-pack'),
            'slug'        => 'click-to-top',
            'file'        => 'click-to-top/click-to-top.php',
            'description' => __('One-click scroll to top button.', 'real-estate-pack'),
            'category'    => 'Utility',
            'essential'   => false,
            'featured'    => true,
            'is_local'    => false,
        ),
        'easy-share-solution' => array(
            'name'        => __('Easy Share', 'real-estate-pack'),
            'slug'        => 'easy-share-solution',
            'file'        => 'easy-share-solution/easy-share-solution.php',
            'description' => __('Easily add social sharing buttons.', 'real-estate-pack'),
            'category'    => 'Utility',
            'essential'   => false,
            'featured'    => true,
            'is_local'    => false,
        ),
        'wp-edit-password-protected' => array(
            'name'        => __('Password Protected', 'real-estate-pack'),
            'slug'        => 'wp-edit-password-protected',
            'file'        => 'wp-edit-password-protected/wp-edit-password-protected.php',
            'description' => __('Manage password protection.', 'real-estate-pack'),
            'category'    => 'Security',
            'essential'   => false,
            'featured'    => true,
            'is_local'    => false,
        ),
        'magical-blocks' => array(
            'name'        => __('Magical Blocks', 'real-estate-pack'),
            'slug'        => 'magical-blocks',
            'file'        => 'magical-blocks/magical-blocks.php',
            'description' => __('Gutenberg blocks to enhance the block editor experience.', 'real-estate-pack'),
            'category'    => 'Content Display',
            'essential'   => false,
            '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', 'real-estate-pack'),
            'slug'        => 'magical-products-display',
            'file'        => 'magical-products-display/magical-products-display.php',
            'description' => __('Display WooCommerce products in beautiful layouts.', 'real-estate-pack'),
            'category'    => 'eCommerce',
            'essential'   => false,
            'featured'    => true,
            'is_local'    => false,
        );
    }

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

/**
 * AI Marketing Expert success notice
 */
function real_estate_pack_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, 'real_estate_pack_ai_notice_dismissed', true);
    if ($dismissed) {
        return;
    }

    if (isset($_GET['real_estate_pack_ai_dismiss']) && '1' === $_GET['real_estate_pack_ai_dismiss']) {
        update_user_meta($user_id, 'real_estate_pack_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!', 'real-estate-pack')
        : __('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!', 'real-estate-pack');
    ?>
    <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', 'real-estate-pack'); ?></strong> &mdash;
            <?php esc_html_e('Now active on your site! — A must-have plugin in the current AI world.', 'real-estate-pack'); ?>
        </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('real_estate_pack_ai_dismiss', '1')); ?>" class="button button-primary" style="font-weight:600;">
                <?php esc_html_e('Got it!', 'real-estate-pack'); ?>
            </a>
        </p>
    </div>
    <?php
}
add_action('admin_notices', 'real_estate_pack_ai_marketing_notice');
