<!-- Add new popup screen -->
<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals -- Template-scope compatibility variables are retained for extensions.

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

// use Admin\Classes\Request\Instant_Popup_Builder_Admin_Request;
// use Admin\PopupManager\Class_instant_popup_builder_manager;
require_once(plugin_dir_path(dirname(__FILE__)) . 'PopupManager/class-instant-popup-builder-manager.php');

$instant_popup_builder_popups = Class_instant_popup_builder_manager::get_popups();
$instant_popup_builder_is_active = Class_instant_popup_builder_manager::get_active_popup();
$instant_popup_builder_licenses = Class_instant_popup_builder_license::getLicense();
$instant_popup_builder_extensions = [];
foreach ($instant_popup_builder_licenses as $instant_popup_builder_exten) {
    if (
        !is_object($instant_popup_builder_exten)
        || !isset($instant_popup_builder_exten->popup_type)
        || !is_scalar($instant_popup_builder_exten->popup_type)
    ) {
        continue;
    }

    $instant_popup_builder_popup_type = sanitize_key((string) $instant_popup_builder_exten->popup_type);
    if ('' !== $instant_popup_builder_popup_type) {
        $instant_popup_builder_extensions[] = $instant_popup_builder_popup_type;
    }
}
$instant_popup_builder_extensions = array_values(array_unique($instant_popup_builder_extensions));
$instant_popup_builder_admin_request = new Instant_Popup_Builder_Admin_Request("Instant Popup Builder", INSTANT_POPUP_BUILDER_VERSION);
$instant_popup_builder_page_url = esc_url(menu_page_url('instant-popup-builder', false));
// var_dump($rows);
$instant_popup_builder_current_slug = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';

// Pro extensions

// Icon mapping for each extension type
$instant_popup_builder_extension_icons = [
    'video' => 'fa-video',
    'image_gallery' => 'fa-images',
    'subscription' => 'fa-envelope',
    'exit' => 'fa-sign-out-alt',
    'scroll' => 'fa-scroll',
    'adblock' => 'fa-shield-alt',
    'inactivity' => 'fa-clock',
    'smart' => 'fa-brain',
    'woocommerce' => 'fa-cart-shopping',
    'pdf' => 'fa-file-pdf',
    'analytics' => 'fa-chart-line',
    'advanced-closing' => 'fa-xmark',
    'advanced-triggers' => 'fa-sliders',
    'targeting' => 'fa-crosshairs',
    'geo-targeting' => 'fa-globe',
    'language-targeting' => 'fa-language',
    'scheduling' => 'fa-calendar',
    'contact' => 'fa-address-card',
    'age_verification' => 'fa-id-card',
    'recent_orders' => 'fa-receipt',
    'subscribe_to_download' => 'fa-download',
    'countdown_timer' => 'fa-clock',
    'social_share' => 'fa-share-nodes',
    'login_signup' => 'fa-right-to-bracket',
    'spin_to_win' => 'fa-dharmachakra',
    'announcement_bar' => 'fa-bullhorn',
];

$instant_popup_builder_pro_extensions = [
    'video' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/video-popup/',
        'title' => 'Video Popup',
        'desc' => 'Create Video Popup with ease',
    ],
    'image_gallery' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/image-gallery/',
        'title' => 'Image Gallery',
        'desc' => 'Create elegant image gallery lightbox popups',
    ],
    'subscription' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/subscription-pro/',
        'title' => 'Subscription',
        'desc' => 'Capture Users email, send email campaigns',
    ],
    'exit' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/exit-intent/',
        'title' => 'Exit intent',
        'desc' => 'Engage visitors before they leave',
    ],
    'scroll' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/scroll-trigger/',
        'title' => 'Scroll Trigger',
        'desc' => 'Trigger popup on scroll',
    ],
    'adblock' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/adblock-trigger/',
        'title' => 'AdBlock',
        'desc' => 'Detect AdBlock users and show targeted popup',
    ],
    'inactivity' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/inactivity-trigger/',
        'title' => 'Inactivity Trigger',
        'desc' => 'Trigger popup after user inactivity',
    ],
    'smart' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/smart-popup-ai/',
        'title' => 'Smart Popup',
        'desc' => 'AI-powered popup selection based on user behavior',
    ],
    'woocommerce' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/woocommerce/',
        'title' => 'WooCommerce',
        'desc' => 'Trigger popup with WooCommerce cart, checkout, and more',
    ],
    'pdf' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/pdf-popup/',
        'title' => 'PDF Popup',
        'desc' => 'Create PDF Popup',
    ],
    'analytics' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/analytics/',
        'title' => 'Analytics',
        'desc' => 'Analytics with AI insights',
    ],
    'advanced-closing' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/advanced-closing/',
        'title' => 'Advanced Closing',
        'desc' => 'Custom close controls, auto-close, countdown, and mobile swipe-to-close',
    ],
    'advanced-triggers' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/advanced-triggers/',
        'title' => 'Advanced Triggers',
        'desc' => 'Page depth, element visibility, referrer, and form abandonment triggers',
    ],
    'targeting' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/device-targeting/',
        'title' => 'Device Targeting',
        'desc' => 'Trigger popup based on device, OS, browser, and more',
    ],
    'geo-targeting' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/geo-targeting/',
        'title' => 'Geo Targeting',
        'desc' => 'Target by country, state/province, city, and IP',
    ],
    'language-targeting' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/language-targeting/',
        'title' => 'Language Targeting',
        'desc' => 'Show popups based on browser/device language (not IP-based)',
    ],
    'scheduling' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/scheduling/',
        'title' => 'Scheduling',
        'desc' => 'Schedule popup and recurring campaigns',
    ],
    'contact' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/contact-form/',
        'title' => 'Contact Form',
        'desc' => 'Create contact form popup with fields & Vlidation',
    ],
    'age_verification' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/age-verification/',
        'title' => 'Age Verification',
        'desc' => 'Verify user age before site access',
    ],
    'recent_orders' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/recent-orders/',
        'title' => 'Recent Orders',
        'desc' => 'Display recent purchases and live sales feed',
    ],
    'subscribe_to_download' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/subscribe-to-download/',
        'title' => 'Subscribe to Download',
        'desc' => 'Enable secure file downloads after email subscription',
    ],
    'countdown_timer' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/countdown-timer/',
        'title' => 'Countdown Timer',
        'desc' => 'Add urgency to subscription popups with a customizable countdown overlay',
    ],
    'social_share' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/social-share/',
        'title' => 'Social Share Popup',
        'desc' => 'Let visitors share the current page with one click',
    ],
    'login_signup' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/sign-up-login-popup/',
        'title' => 'Sign Up / Login Popup',
        'desc' => 'Let visitors log in or register inside a popup',
    ],
    'spin_to_win' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/spin-to-win/',
        'title' => 'Spin-to-Win Popup',
        'desc' => 'Gamified prize wheel with email capture and coupons',
    ],
    'announcement_bar' => [
        'url' => 'https://instantpopupbuilder.com/add-ons/announcement-bar/',
        'title' => 'Announcement Bar',
        'desc' => 'Persistent top or bottom announcement strip with CTAs and optional countdown',
    ],

];

$instant_popup_builder_is_trigger = get_option('instant_popup_builder_exit');

$instant_popup_builder_allowed_tags['input'] = array(
    'type' => array(),
    'value' => array(),
    'name' => array(),
    'id' => array(),
    'class' => array(),
    'placeholder' => array(),
    'disabled' => array(),
    'readonly' => array(),
    'maxlength' => array(),
    'size' => array(),
    'style' => array(),
    'checked' => array(),
    // Add any other attributes you want to allow here
);
$instant_popup_builder_allowed_tags['div'] = [
    'class' => [],
    'id' => [],
    'style' => [],
    'data-type' => [],
    'data-modal' => [],
    'data-ext-type' => []
];
$instant_popup_builder_allowed_tags['img'] = [
    'src' => [],
    'id' => [],
    'alt' => []
];

$instant_popup_builder_allowed_tags['label'] = [
    'class' => [],
    'id' => [],
    'style' => [],
    'for' => []
];
$instant_popup_builder_allowed_tags['label'] = [
    'class' => [],
    'id' => [],
    'style' => [],
    'for' => []
];
$instant_popup_builder_allowed_tags['p'] = [];
$instant_popup_builder_allowed_tags['h3'] = [];
$instant_popup_builder_allowed_tags['i'] = [
    'class' => [],
    'id' => [],
    'style' => [],
];
$instant_popup_builder_allowed_tags['a'] = [
    'href' => [],
    'target' => [],
    'class' => [],
    'id' => [],
];

if (!function_exists('instant_popup_builder_is_active_signal')) {
    function instant_popup_builder_is_active_signal($value)
    {
        if (is_bool($value)) {
            return $value;
        }

        $value = strtolower(trim((string) $value));
        return '' !== $value && !in_array($value, ['0', 'no', 'false', 'deactivate', 'inactive'], true);
    }
}

if (!function_exists('instant_popup_builder_has_pro_extension_signal')) {
    function instant_popup_builder_has_pro_extension_signal($extension_key, $extension_settings, $instant_popup_builder_extensions, $instant_popup_builder_is_active)
    {
        $aliases = isset($extension_settings['aliases']) ? $extension_settings['aliases'] : [$extension_key];

        foreach ($aliases as $alias) {
            if (in_array($alias, $instant_popup_builder_extensions, true) || in_array($alias, $instant_popup_builder_is_active, true)) {
                return true;
            }
        }

        if (!empty($extension_settings['active_options'])) {
            foreach ($extension_settings['active_options'] as $option_name) {
                if (instant_popup_builder_is_active_signal(get_option($option_name))) {
                    return true;
                }
            }
        }

        if (!function_exists('is_plugin_active')) {
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
        }

        if (!empty($extension_settings['plugin_paths'])) {
            foreach ($extension_settings['plugin_paths'] as $plugin_path) {
                if (is_plugin_active($plugin_path)) {
                    return true;
                }
            }
        }

        if (!empty($extension_settings['constants'])) {
            foreach ($extension_settings['constants'] as $constant_name) {
                if (defined($constant_name)) {
                    return true;
                }
            }
        }

        if (!empty($extension_settings['classes'])) {
            foreach ($extension_settings['classes'] as $class_name) {
                if (class_exists($class_name, false)) {
                    return true;
                }
            }
        }

        return false;
    }
}

if (!function_exists('instant_popup_builder_is_pro_extension_owned')) {
    function instant_popup_builder_is_pro_extension_owned($extension_key, $extension_settings, $instant_popup_builder_extensions, $instant_popup_builder_is_active)
    {
        $license_option = isset($extension_settings['license_option']) ? $extension_settings['license_option'] : '';
        if ('' === $license_option || get_option($license_option) !== 'yes') {
            return false;
        }

        return instant_popup_builder_has_pro_extension_signal($extension_key, $extension_settings, $instant_popup_builder_extensions, $instant_popup_builder_is_active);
    }
}

$instant_popup_builder_pro_extension_status = [
    'video' => [
        'license_option' => 'video_license_active',
        'aliases' => ['video'],
        'plugin_paths' => ['instant-popup-video/instant-popup-video.php'],
        'constants' => ['INSTANT_POPUP_VIDEO_VERSION'],
        'classes' => ['Instant_Popup_Video'],
    ],
    'image_gallery' => [
        'license_option' => 'image_gallery_license_active',
        'aliases' => ['image_gallery'],
        'plugin_paths' => ['instant-popup-image-gallery/instant-popup-image-gallery.php'],
        'constants' => ['INSTANT_POPUP_IMAGE_GALLERY_VERSION'],
        'classes' => ['Instant_Popup_Image_Gallery'],
    ],
    'subscription' => [
        'license_option' => 'subscription_license_active',
        'aliases' => ['subscription'],
        'active_options' => ['instant_popup_subscription_activated'],
        'plugin_paths' => ['instant-popup-subscription/instant-popup-subscription.php'],
        'constants' => ['Instant_Popup_Subscription_VERSION'],
        'classes' => ['Instant_Popup_Subscription'],
    ],
    'exit' => [
        'license_option' => 'exit_intent_license_active',
        'aliases' => ['exit', 'exit_intent'],
        'active_options' => ['instant_popup_builder_exit'],
        'plugin_paths' => ['instant-popup-exit-intent/instant-popup-exit-intent.php'],
        'constants' => ['INSTANT_POPUP_EXIT_INTENT_VERSION'],
        'classes' => ['Instant_Popup_Exit_Intent'],
    ],
    'scroll' => [
        'license_option' => 'scroll_license_active',
        'aliases' => ['scroll'],
        'active_options' => ['instant_popup_builder_scroll_plugin'],
        'plugin_paths' => ['instant-popup-scroll-trigger/instant-popup-scroll-trigger.php'],
        'constants' => ['INSTANT_POPUP_SCROLL_TRIGGER_VERSION'],
        'classes' => ['Instant_Popup_Scroll_Trigger'],
    ],
    'adblock' => [
        'license_option' => 'adblock_license_active',
        'aliases' => ['adblock'],
        'active_options' => ['instant_popup_builder_adblock_plugin'],
        'plugin_paths' => ['instant-popup-adblock/instant-popup-adblock.php'],
        'constants' => ['INSTANT_POPUP_ADBLOCK_VERSION'],
        'classes' => ['Instant_Popup_Adblock'],
    ],
    'inactivity' => [
        'license_option' => 'inactivity_license_active',
        'aliases' => ['inactivity'],
        'active_options' => ['instant_popup_builder_inactivity_plugin'],
        'plugin_paths' => ['instant-popup-inactivity-trigger/instant-popup-inactivity-trigger.php'],
        'constants' => ['INSTANT_POPUP_INACTIVITY_TRIGGER_VERSION'],
        'classes' => ['Instant_Popup_Inactivity_Trigger'],
    ],
    'smart' => [
        'license_option' => 'smart_license_active',
        'aliases' => ['smart'],
        'active_options' => ['instant_popup_builder_smart_plugin'],
        'plugin_paths' => ['instant-popup-smart-popup/instant-popup-smart-popup.php'],
        'constants' => ['INSTANT_POPUP_SMART_POPUP_VERSION'],
        'classes' => ['Instant_Popup_Smart_Popup'],
    ],
    'woocommerce' => [
        'license_option' => 'woocommerce_license_active',
        'aliases' => ['woocommerce'],
        'active_options' => ['instant_popup_woocommerce_plugin'],
        'plugin_paths' => ['instant-popup-woocommerce/instant-popup-woocommerce.php'],
        'constants' => ['INSTANT_POPUP_WOOCOMMERCE_VERSION'],
        'classes' => ['Instant_Popup_WooCommerce'],
    ],
    'pdf' => [
        'license_option' => 'pdf_license_active',
        'aliases' => ['pdf'],
        'plugin_paths' => ['instant-popup-pdf/instant-popup-pdf.php'],
        'constants' => ['INSTANT_POPUP_PDF_VERSION'],
        'classes' => ['Instant_Popup_PDF'],
    ],
    'analytics' => [
        'license_option' => 'analytics_license_active',
        'aliases' => ['analytics'],
        'plugin_paths' => ['instant-popup-analytics/instant-popup-analytics.php'],
        'constants' => ['INSTANT_POPUP_ANALYTICS_VERSION'],
        'classes' => ['Instant_Popup_Analytics_Advanced'],
    ],
    'advanced-closing' => [
        'license_option' => 'advanced_closing_license_active',
        'aliases' => ['advanced_closing', 'advanced-closing'],
        'plugin_paths' => ['instant-popup-advanced-closing/instant-popup-advanced-closing.php'],
        'constants' => ['INSTANT_POPUP_ADVANCED_CLOSING_VERSION'],
        'classes' => ['Instant_Popup_Advanced_Closing_Addon'],
    ],
    'advanced-triggers' => [
        'license_option' => 'advanced_triggers_license_active',
        'aliases' => ['advanced_triggers', 'advanced-triggers'],
        'plugin_paths' => ['instant-popup-advanced-triggers/instant-popup-advanced-triggers.php'],
        'constants' => ['INSTANT_POPUP_ADVANCED_TRIGGERS_VERSION'],
        'classes' => ['Instant_Popup_Advanced_Triggers'],
    ],
    'targeting' => [
        'license_option' => 'custom_targeting_license_active',
        'aliases' => ['targeting', 'custom_targeting'],
        'active_options' => ['instant_popup_custom_targeting_activated'],
        'plugin_paths' => ['instant-popup-custom-targeting/instant-popup-custom-targeting.php'],
        'constants' => ['INSTANT_POPUP_CUSTOM_TARGETING_VERSION'],
        'classes' => ['Instant_Popup_Custom_Targeting', 'Instant_Popup_Custom_Targeting_Admin'],
    ],
    'geo-targeting' => [
        'license_option' => 'geo_license_active',
        'aliases' => ['geo-targeting', 'geo_targeting', 'geotargeting'],
        'plugin_paths' => ['instant-popup-geo-targeting/instant-popup-geo-targeting.php'],
        'constants' => ['INSTANT_POPUP_GEO_TARGETING_VERSION'],
        'classes' => ['Instant_Popup_Geo_Targeting'],
    ],
    'language-targeting' => [
        'license_option' => 'language_targeting_license_active',
        'aliases' => ['language-targeting', 'language_targeting'],
        'plugin_paths' => ['instant-popup-language-targeting/instant-popup-language-targeting.php'],
        'constants' => ['INSTANT_POPUP_LANGUAGE_TARGETING_VERSION'],
        'classes' => ['Instant_Popup_Language_Targeting'],
    ],
    'scheduling' => [
        'license_option' => 'scheduling_license_active',
        'aliases' => ['scheduling'],
        'active_options' => ['instant_popup_scheduling_plugin_active'],
        'plugin_paths' => ['instant-popup-scheduling/instant-popup-scheduling.php'],
        'constants' => ['INSTANT_POPUP_SCHEDULING_VERSION'],
        'classes' => ['Instant_Popup_Scheduling'],
    ],
    'contact' => [
        'license_option' => 'contact_from_license_active',
        'aliases' => ['contact', 'contact_form'],
        'active_options' => ['instant_popup_contact_form_plugin'],
        'plugin_paths' => ['instant-popup-contact-form/instant-popup-contact-form.php'],
        'constants' => ['INSTANT_POPUP_CONTACT_FORM_VERSION'],
        'classes' => ['Instant_Popup_Contact_Form'],
    ],
    'age_verification' => [
        'license_option' => 'age_verification_license_active',
        'aliases' => ['age_verification'],
        'plugin_paths' => ['instant-popup-age-verification/instant-popup-age-verification.php'],
        'constants' => ['INSTANT_POPUP_AGE_VERIFICATION_VERSION'],
        'classes' => ['Instant_Popup_Age_Verification'],
    ],
    'recent_orders' => [
        'license_option' => 'recent_orders_license_active',
        'aliases' => ['recent_orders'],
        'plugin_paths' => ['instant-popup-recent-orders/instant-popup-recent-orders.php'],
        'constants' => ['INSTANT_POPUP_RECENT_ORDERS_VERSION'],
        'classes' => ['Instant_Popup_Recent_Orders'],
    ],
    'subscribe_to_download' => [
        'license_option' => 'subscribe_to_download_license_active',
        'aliases' => ['subscribe_to_download'],
        'active_options' => ['ipb_subscribe_to_download_enabled'],
        'plugin_paths' => ['instant-popup-subscribe-to-download/instant-popup-subscribe-to-download.php'],
        'constants' => ['INSTANT_POPUP_SUBSCRIBE_TO_DOWNLOAD_VERSION'],
        'classes' => ['Instant_Popup_Subscribe_To_Download_Admin'],
    ],
    'countdown_timer' => [
        'license_option' => 'countdown_timer_license_active',
        'aliases' => ['countdown_timer'],
        'active_options' => ['ipb_countdown_timer_enabled'],
        'plugin_paths' => ['instant-popup-countdown-timer/instant-popup-countdown-timer.php'],
        'constants' => ['INSTANT_POPUP_COUNTDOWN_TIMER_VERSION'],
        'classes' => ['Instant_Popup_Countdown_Timer'],
    ],
    'social_share' => [
        'license_option' => 'social_share_popup_license_active',
        'aliases' => ['social_share'],
        'active_options' => ['ipb_social_share_popup_enabled'],
        'plugin_paths' => ['instant-popup-social-share/instant-popup-social-share.php'],
        'constants' => ['INSTANT_POPUP_SOCIAL_SHARE_VERSION'],
        'classes' => ['Instant_Popup_Social_Share'],
    ],
    'login_signup' => [
        'license_option' => 'login_signup_popup_license_active',
        'aliases' => ['login_signup'],
        'active_options' => ['ipb_login_signup_popup_enabled'],
        'plugin_paths' => ['instant-popup-login-signup/instant-popup-login-signup.php'],
        'constants' => ['INSTANT_POPUP_LOGIN_SIGNUP_VERSION'],
        'classes' => ['Instant_Popup_Login_Signup'],
    ],
    'spin_to_win' => [
        'license_option' => 'spin_to_win_popup_license_active',
        'aliases' => ['spin_to_win'],
        'active_options' => ['ipb_spin_to_win_popup_enabled'],
        'plugin_paths' => ['instant-popup-spin-to-win/instant-popup-spin-to-win.php'],
        'constants' => ['INSTANT_POPUP_SPIN_TO_WIN_VERSION'],
        'classes' => ['Instant_Popup_Spin_To_Win'],
    ],
    'announcement_bar' => [
        'license_option' => 'announcement_bar_popup_license_active',
        'aliases' => ['announcement_bar'],
        'active_options' => ['ipb_announcement_bar_popup_enabled'],
        'plugin_paths' => ['instant-popup-announcement-bar/instant-popup-announcement-bar.php'],
        'constants' => ['INSTANT_POPUP_ANNOUNCEMENT_BAR_VERSION'],
        'classes' => ['Instant_Popup_Announcement_Bar'],
    ],
];

?>

<?php Instant_Popup_Builder_Admin::ipb_top_header(); ?>

<?php
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- GET parameter used for display purposes only
if (isset($_GET['type']) && !empty($_GET['type']) && !isset($_POST['instant_popup_builder_submit'])) {

    $instant_popup_builder_name = sanitize_text_field(wp_unslash($_GET['type']));
    Class_instant_popup_builder_manager::create_popup(
    isset( $_GET['type'] ) ? sanitize_text_field( wp_unslash( $_GET['type'] ) ) : ''
);
} elseif (isset($_POST['instant_popup_builder_submit']) && isset($_POST['_wpnonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_wpnonce'])), 'instant_popup_nonce')) {
 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $instant_popup_builder_admin_request->ipb_check_popup_submt_request() returns safe HTML
   echo  $instant_popup_builder_admin_request->ipb_check_popup_submt_request();
    // if(isset($req['message'])   ){

    //         echo wp_kses_post($req['message']);
    // }
    // // var_dump($rows);
    // // $current_slug = $_GET['page'];
    // if (isset($req['id']) && !empty($req['id'])) {

    //     $id = intval($req['id']);
    //     $result = $wpdb->get_results($wpdb->prepare("SELECT * FROM  {$wpdb->prefix}instant_popup_builder WHERE id = %d", $id));
    //     if (isset($result[0]->type)) {

    //         Class_instant_popup_builder_manager::edit_popup($result[0]->type);
    //     }
    // }
} else { ?>

    <?php

?>
    <!-- updated code -->
    <div class="ipb_wrapper">
        <div class="ipb_extensions">
            <a href="javascript:void" id="ipb_ext_btn">Your Extensions</a>
        </div>
        <div class="ipb_new_heading">
            <h3>Choose Popup</h3>
        </div>
        <div class="ipb_installed_popup">

            <?php foreach ($instant_popup_builder_popups as $instant_popup_builder_popup) {
                echo wp_kses($instant_popup_builder_popup->render_html(), $instant_popup_builder_allowed_tags);
            } ?>
        </div>

        <div class="ipb_middle_btns">
            <div class="ipb_ext_search">
                <span class="s_icon">
                    <i class="fa fa-search"></i>
                </span>
                <input type="text" name="search_ipb_extension" id="search_ipb_extension" placeholder="Search here ...">
            </div>
            <!-- <div class="ipb_show_more">
                <p>Show All <span><i class="fa-solid fa-chevron-down"></i></span></p>
            </div> -->
            <div class="ipb_pro_ext">
                <a href="https://instantpopupbuilder.com/extensions/" target="_blank" id="ipb_ext_btn"><i class="fa-solid fa-plus"></i> Pro Extension</a>
            </div>
        </div>

        <div class="ipb_installed_popup pro_ext">

            <?php foreach ($instant_popup_builder_pro_extensions as $instant_popup_builder_index => $instant_popup_builder_extension):
                $instant_popup_builder_extension_settings = isset($instant_popup_builder_pro_extension_status[$instant_popup_builder_index]) ? $instant_popup_builder_pro_extension_status[$instant_popup_builder_index] : [];
                if (instant_popup_builder_is_pro_extension_owned($instant_popup_builder_index, $instant_popup_builder_extension_settings, $instant_popup_builder_extensions, $instant_popup_builder_is_active)) {
                    continue;
                }
                ?>

                <div class="ipb_grid" data-ext-type="<?php echo esc_attr($instant_popup_builder_index); ?>">
                    <div class="thumb_header">
                        <div class="thumb">
                            <i class="fa-solid <?php echo esc_attr(isset($instant_popup_builder_extension_icons[$instant_popup_builder_index]) ? $instant_popup_builder_extension_icons[$instant_popup_builder_index] : 'fa-code'); ?>"></i>
                        </div>
                        <div class="read_more">
                            <a href="<?php echo esc_url($instant_popup_builder_extension['url']); ?>" target="_blank" class="pro_btn">GET NOW</a>
                        </div>
                    </div>
                    <div class="ipd_content">
                        <h3><?php echo esc_html($instant_popup_builder_extension['title']); ?></h3>
                        <p><?php echo esc_html($instant_popup_builder_extension['desc']); ?></p>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    </div>

    <!-- Template Selection Modal -->
    <div id="subscription-template-modal" class="modal template-selection-modal" style="display: none;">
        <div class="modal-content">
            <div class="modal-header">
                <h3>Choose Subscription Template</h3>
                <span class="close-modal">&times;</span>
            </div>
            <div class="modal-body" id="template-selection-content">
                <!-- Template selection content will be loaded here -->
            </div>
        </div>
    </div>

<?php } ?>
