<?php
/*
Plugin Name: Pollbolt - AI Forms, Polls, Quizzes
Description: Embed PollBolt surveys via iframe in WordPress. Works with Elementor and standard WordPress editor.
Version: 1.0.0
Requires at least: 5.0
Requires PHP: 7.2
Author: PollBolt Team
Author URI: https://www.pollbolt.com
License: GPL v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: pollbolt-ai-forms-polls-quizzes
Domain Path: /languages

Usage in standard WordPress editor:
1. Create a shortcode for your survey in the PollBolt settings page
2. Use one of these methods to embed your survey:
   a) Direct shortcode: [pollbolt_XXXX] (where XXXX is the unique ID)
   b) Generic shortcode with ID parameter: [pollbolt id="pollbolt_XXXX"]
   c) Custom shortcode widget from WordPress Blocks
3. The survey will be automatically embedded with responsive iframe

Usage in Elementor:
1. Create a shortcode for your survey in the PollBolt settings page
2. Add the PollBolt widget to your Elementor page
3. Select your survey from the dropdown list
4. The survey will be automatically embedded with responsive iframe
*/

// Prevent direct access to this file
if (!defined('ABSPATH')) {
    exit;
}

// Load textdomain
function pollbolt_load_textdomain() {
    // Translation is automatically handled by WordPress since version 4.6
    // Text domain is defined in header and translation files are loaded automatically
}
add_action('plugins_loaded', 'pollbolt_load_textdomain');

// Create database table on activation
function pollbolt_activate() {
    global $wpdb;
    $table_name = $wpdb->prefix . 'pollbolt_surveys';
    
    $charset_collate = $wpdb->get_charset_collate();

    $sql = "CREATE TABLE IF NOT EXISTS $table_name (
        id mediumint(9) NOT NULL AUTO_INCREMENT,
        name varchar(255) NOT NULL,
        url text NOT NULL,
        shortcode varchar(255) NOT NULL,
        created_at datetime DEFAULT CURRENT_TIMESTAMP,
        PRIMARY KEY  (id)
    ) $charset_collate;";

    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    dbDelta($sql);
}
register_activation_hook(__FILE__, 'pollbolt_activate');

// Register PollBolt shortcode
function pollbolt_shortcode_handler($atts, $content = null, $tag = '') {
    global $wpdb;
    
    // Convert attributes to array if they are not an array
    if (!is_array($atts)) {
        $atts = array();
    }
    
    // Instead of current_filter(), use the provided shortcode tag
    $current_shortcode = $tag;
    
    // List of WordPress system filters to ignore
    $system_filters = array(
        'the_content', 
        'the_excerpt', 
        'widget_text_content', 
        'widget_text', 
        'widget_custom_html_content'
    );
    
    // Check if this is a WordPress system filter
    if (in_array($current_shortcode, $system_filters)) {

        return '';  // Skip processing for system filters
    }
    
    // Check if this is an Elementor system shortcode
    if (strpos($current_shortcode, 'wp_ajax_elementor') !== false) {

        return '';
    }
    
    // Determine survey URL
    $url = '';
    $table_name = $wpdb->prefix . 'pollbolt_surveys';
    $shortcode_id = '';
    
    // If survey ID is directly specified (for standard editor)
    if (!empty($atts['id'])) {
        $shortcode_id = sanitize_text_field($atts['id']);

    } 
    // If this is a custom shortcode (not standard pollbolt)
    elseif ($current_shortcode !== 'pollbolt' && strpos($current_shortcode, 'pollbolt_') === 0) {
        $shortcode_id = $current_shortcode;

    }
    
    // Find survey by shortcode ID
    if ($shortcode_id) {
        // Direct database query is necessary here as we need to query custom database table
        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
        $survey = $wpdb->get_row($wpdb->prepare(
            "SELECT * FROM " . esc_sql($table_name) . " WHERE shortcode = %s",
            $shortcode_id
        ));
        
        if ($survey) {
            $url = $survey->url;

        } else {

            return '<p>' . esc_html__('Survey not found for shortcode ID: ', 'pollbolt-ai-forms-polls-quizzes') . esc_html($shortcode_id) . '</p>';
        }
    }
    // If direct URL is specified
    elseif (!empty($atts['url'])) {
        $url = esc_url_raw($atts['url']);

    }
    // If nothing is specified and using standard shortcode
    else {

        return '<p>' . esc_html__('Please provide a PollBolt survey URL using the url attribute, specify a survey ID, or use a specific shortcode', 'pollbolt-ai-forms-polls-quizzes') . '</p>';
    }

    // Get other attributes with defaults
    $atts = shortcode_atts(array(
        'height' => '500px',
        'width' => '100%'
    ), $atts);

    // Generate unique ID for iframe
    $iframe_id = 'pollbolt-frame-' . uniqid();

    // Add parameters to URL
    if (strpos($url, '?') === false) {
        $url .= '?';
    } else {
        $url .= '&';
    }
    $url .= 'embedded=true&hideScroll=true&autoresize=true';

    // Add required scripts and styles
    wp_enqueue_script('pollbolt-resize', plugins_url('js/pollbolt-resize.js', __FILE__), array('jquery'), '1.0.0', true);
    
    // Enqueue dynamic styles for container width
    wp_register_style('pollbolt-dynamic-styles', false, array(), '1.0.0');
    wp_enqueue_style('pollbolt-dynamic-styles');
    wp_add_inline_style('pollbolt-dynamic-styles', '
        .pollbolt-iframe {
            border: none !important;
            background: transparent !important;
            scrollbar-width: none !important;
            -ms-overflow-style: none !important;
            overflow: hidden !important;
            height: 100% !important;
        }
        .pollbolt-iframe::-webkit-scrollbar {
            display: none !important;
            width: 0 !important;
            height: 0 !important;
        }
        .pollbolt-container {
            width: 100%;
            max-width: ' . esc_attr($atts['width']) . ';
            margin: 0 auto;
            overflow: hidden;
            height: 100%;
        }
        .elementor-widget-container .pollbolt-container,
        .elementor-widget-container .pollbolt-iframe {
            height: 100% !important;
        }
        /* Important for stretching in Elementor */
        .elementor-widget-container {
            height: 100%;
        }
        .elementor-widget {
            height: 100%;
        }
        .elementor-widget-wrap {
            height: 100%;
        }
    ');

    // Generate iframe HTML
    $output = sprintf(
        '<div class="pollbolt-container">
            <iframe id="%s" 
                    src="%s" 
                    width="%s" 
                    height="100%%" 
                    frameborder="0" 
                    class="pollbolt-iframe" 
                    scrolling="no" 
                    allow="fullscreen">
            </iframe>
        </div>',
        esc_attr($iframe_id),
        esc_url($url),
        esc_attr($atts['width'])
    );

    return $output;
}

// Register the default pollbolt shortcode
add_shortcode('pollbolt', 'pollbolt_shortcode_handler');

// Function to register dynamic shortcodes for each survey
function pollbolt_register_survey_shortcodes() {
    global $wpdb;
    $table_name = $wpdb->prefix . 'pollbolt_surveys';
    
    // Check if table exists
    // Direct database query is necessary to check if custom table exists
    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    $table_exists = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table_name)) === $table_name;
    
    if (!$table_exists) {

        pollbolt_activate();
    }
    
    // Get all shortcodes from the database
    // Direct database query is necessary to get data from custom database table
    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    $surveys = $wpdb->get_results("SELECT id, shortcode FROM " . esc_sql($table_name));
    
    foreach ($surveys as $survey) {
        add_shortcode($survey->shortcode, 'pollbolt_shortcode_handler');
    }
}
add_action('init', 'pollbolt_register_survey_shortcodes', 20); // Increase priority to ensure registration after Elementor

// Check if Elementor is installed and activated
function pollbolt_check_elementor_dependency() {
    // Check if Elementor is activated
    if (!did_action('elementor/loaded')) {
        // Instead of deactivating the plugin, just add a warning
        add_action('admin_notices', 'pollbolt_elementor_recommendation_notice');
    }
}
add_action('admin_init', 'pollbolt_check_elementor_dependency');

// Admin notice recommending Elementor
function pollbolt_elementor_recommendation_notice() {
    $message = sprintf(
        /* translators: %s: Link to install Elementor plugin */
        esc_html__('PollBolt works best with Elementor. For better visual editing experience, %s', 'pollbolt-ai-forms-polls-quizzes'),
        '<a href="' . esc_url(admin_url('plugin-install.php?s=elementor&tab=search&type=term')) . '">' . esc_html__('please consider installing Elementor', 'pollbolt-ai-forms-polls-quizzes') . '</a>'
    );
    
    echo '<div class="notice notice-info is-dismissible"><p>' . wp_kses_post($message) . '</p></div>';
}

// Enqueue Font Awesome
function pollbolt_enqueue_font_awesome() {
    wp_enqueue_style('font-awesome', plugins_url('css/font-awesome.min.css', __FILE__), array(), '1.0.0');
    
    // Add inline CSS for font-face declarations
    $font_face_css = '
        @font-face {
            font-family: "Font Awesome 6 Free";
            font-style: normal;
            font-weight: 900;
            font-display: block;
            src: url("' . esc_url(plugins_url('css/webfonts/fa-solid-900.woff2', __FILE__)) . '") format("woff2");
        }
        
        @font-face {
            font-family: "Font Awesome 6 Free";
            font-style: normal;
            font-weight: 400;
            font-display: block;
            src: url("' . esc_url(plugins_url('css/webfonts/fa-regular-400.woff2', __FILE__)) . '") format("woff2");
        }
        
        @font-face {
            font-family: "Font Awesome 6 Brands";
            font-style: normal;
            font-weight: 400;
            font-display: block;
            src: url("' . esc_url(plugins_url('css/webfonts/fa-brands-400.woff2', __FILE__)) . '") format("woff2");
        }
    ';
    
    wp_add_inline_style('font-awesome', $font_face_css);
}
add_action('admin_enqueue_scripts', 'pollbolt_enqueue_font_awesome');
add_action('wp_enqueue_scripts', 'pollbolt_enqueue_font_awesome');

// Custom icon for admin menu
function pollbolt_admin_menu_icon_css() {
    wp_enqueue_style('pollbolt-admin-styles', plugins_url('css/admin-styles.css', __FILE__), array(), '1.0.0');
}
add_action('admin_head', 'pollbolt_admin_menu_icon_css');

// Add menu item to WordPress admin panel
function pollbolt_add_admin_menu() {
    add_menu_page(
        'PollBolt Settings', // Page title
        'PollBolt', // Menu title
        'manage_options', // Capability
        'pollbolt-settings', // Menu slug
        'pollbolt_settings_page', // Function to display the page
        'none', // Placeholder for icon, real icon is added via CSS
        30 // Menu position
    );
}
add_action('admin_menu', 'pollbolt_add_admin_menu');

// Add AJAX handler for form submission
function pollbolt_handle_form_submission() {
    // Security check
    check_ajax_referer('pollbolt_add_survey', 'security');
    
    // Check user permissions
    if (!current_user_can('manage_options')) {
        wp_send_json_error(array('message' => esc_html__('You do not have permission to perform this action.', 'pollbolt-ai-forms-polls-quizzes')));
        return;
    }
    
    global $wpdb;
    $table_name = $wpdb->prefix . 'pollbolt_surveys';
    
    // Get form data
    $name = isset($_POST['survey_name']) ? sanitize_text_field(wp_unslash($_POST['survey_name'])) : '';
    $url = isset($_POST['survey_url']) ? esc_url_raw(wp_unslash($_POST['survey_url'])) : '';
    $shortcode = 'pollbolt_' . wp_rand(1000, 9999);
    
    // Insert record
    // Direct database query is necessary to insert into custom database table
    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    $result = $wpdb->insert(
        $table_name,
        array(
            'name' => $name,
            'url' => $url,
            'shortcode' => $shortcode
        ),
        array('%s', '%s', '%s')
    );
    
    if ($result === false) {
        wp_send_json_error(array(
            'message' => esc_html__('Error creating shortcode. Please try again.', 'pollbolt-ai-forms-polls-quizzes'),
            'db_error' => $wpdb->last_error
        ));
        return;
    }
    
    // Get data of the new record
    $new_id = $wpdb->insert_id;
    // Direct database query is necessary to get data from custom database table
    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    $survey = $wpdb->get_row($wpdb->prepare(
        "SELECT * FROM " . esc_sql($table_name) . " WHERE id = %d",
        $new_id
    ));
    
    // Send success response
    wp_send_json_success(array(
        'message' => esc_html__('Shortcode generated successfully!', 'pollbolt-ai-forms-polls-quizzes'),
        'survey' => $survey
    ));
}
add_action('wp_ajax_pollbolt_add_survey', 'pollbolt_handle_form_submission');

// AJAX handler for getting forms list
function pollbolt_get_forms() {
    // Security check
    check_ajax_referer('pollbolt_get_forms', 'security');
    
    // Check user permissions
    if (!current_user_can('manage_options')) {
        wp_send_json_error(array('message' => esc_html__('You do not have permission to perform this action.', 'pollbolt-ai-forms-polls-quizzes')));
        return;
    }
    
    global $wpdb;
    $table_name = $wpdb->prefix . 'pollbolt_surveys';
    
    // Get all surveys
    // Direct database query is necessary to get data from custom database table
    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    $surveys = $wpdb->get_results("SELECT * FROM " . esc_sql($table_name) . " ORDER BY created_at DESC");
    
    // Generate HTML table
    ob_start();
    if (!empty($surveys)) {
        ?>
        <table class="wp-list-table widefat fixed striped" style="border: none;">
            <thead>
                <tr>
                    <th style="width: 25%;"><?php esc_html_e('Form Name', 'pollbolt-ai-forms-polls-quizzes'); ?></th>
                    <th style="width: 20%;"><?php esc_html_e('Shortcode', 'pollbolt-ai-forms-polls-quizzes'); ?></th>
                    <th style="width: 35%;"><?php esc_html_e('URL', 'pollbolt-ai-forms-polls-quizzes'); ?></th>
                    <th style="width: 20%;"><?php esc_html_e('Actions', 'pollbolt-ai-forms-polls-quizzes'); ?></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($surveys as $survey): ?>
                    <tr>
                        <td><strong><?php echo esc_html($survey->name); ?></strong></td>
                        <td>
                            <div class="shortcode-container" style="display: flex; align-items: center; gap: 10px;">
                                <code style="background: #f0f0f1; padding: 4px 8px; border-radius: 4px;">[<?php echo esc_html($survey->shortcode); ?>]</code>
                                <button type="button" class="button button-small copy-shortcode" 
                                        data-shortcode="[<?php echo esc_attr($survey->shortcode); ?>]"
                                        id="copy-btn-ajax-<?php echo esc_attr($survey->id); ?>"
                                        style="margin-left: 5px;">
                                    <i class="fa-solid fa-copy" style="font-size: 14px;"></i>
                                </button>
                            </div>
                        </td>
                        <td>
                            <a href="<?php echo esc_url($survey->url); ?>" target="_blank" style="text-decoration: none;">
                                <?php echo esc_url($survey->url); ?>
                                <span class="dashicons dashicons-external" style="font-size: 14px; width: 14px; height: 14px; vertical-align: middle;"></span>
                            </a>
                        </td>
                        <td>
                            <?php
                            $delete_url = wp_nonce_url(
                                add_query_arg(
                                    array(
                                        'action' => 'delete',
                                        'id' => $survey->id
                                    ),
                                    admin_url('admin.php?page=pollbolt-settings')
                                ),
                                'delete_survey'
                            );
                            ?>
                            <a href="<?php echo esc_url($delete_url); ?>" 
                               class="button button-link-delete" 
                               onclick="return confirm('<?php esc_attr_e('Are you sure you want to delete this form?', 'pollbolt-ai-forms-polls-quizzes'); ?>')">
                                <span class="dashicons dashicons-trash" style="color: #b32d2e;"></span>
                                <?php esc_html_e('Delete', 'pollbolt-ai-forms-polls-quizzes'); ?>
                            </a>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
        <?php
    } else {
        ?>
        <div style="padding: 30px 20px; text-align: center; background-color: #f8f9fa; border-radius: 4px; margin: 20px;">
            <i class="fa-solid fa-circle-info" style="font-size: 48px; color: #8c8f94; margin-bottom: 15px; display: block;"></i>
            <p style="font-size: 16px; color: #3c434a; margin-bottom: 15px;"><?php esc_html_e('No forms found. Add your first form using the form above!', 'pollbolt-ai-forms-polls-quizzes'); ?></p>
            <a href="#add-pollbolt-form" class="button button-primary" style="background-color: #2271b1; color: white; border-color: #2271b1; padding: 6px 14px; font-weight: 500; text-decoration: none; border-radius: 3px;">
                <i class="fa-solid fa-plus" style="margin-right: 5px;"></i>
                <?php esc_html_e('Add Your First Form', 'pollbolt-ai-forms-polls-quizzes'); ?>
            </a>
        </div>
        <?php
    }
    $html = ob_get_clean();
    
    // Send HTML
    wp_send_json_success(array(
        'html' => $html
    ));
}
add_action('wp_ajax_pollbolt_get_forms', 'pollbolt_get_forms');

// Helper function to get image URL
function pollbolt_get_image_url($image_name) {
    return plugins_url('images/' . $image_name, __FILE__);
}

// Create settings page
function pollbolt_settings_page() {
    global $wpdb;
    $table_name = $wpdb->prefix . 'pollbolt_surveys';

    // Check if table exists
    // Direct database query is necessary to check if custom table exists
    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    $table_exists = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table_name)) === $table_name;
    
    // If table does not exist, create it
    if (!$table_exists) {
        pollbolt_activate();
    }

    // Variables to store data of just created survey
    $new_survey = null;
    $just_created = false;

    // Handle form submission
    if (isset($_POST['pollbolt_add_survey'])) {
        // Check nonce
        if (!isset($_POST['pollbolt_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['pollbolt_nonce'])), 'pollbolt_add_survey')) {
            add_settings_error(
                'pollbolt_messages',
                'pollbolt_message',
                esc_html__('Security check failed. Please try again.', 'pollbolt-ai-forms-polls-quizzes'),
                'error'
            );
        } else {
            $name = isset($_POST['survey_name']) ? sanitize_text_field(wp_unslash($_POST['survey_name'])) : '';
            $url = isset($_POST['survey_url']) ? esc_url_raw(wp_unslash($_POST['survey_url'])) : '';
            $shortcode = 'pollbolt_' . wp_rand(1000, 9999);

            // Check table structure
            // Direct database query is necessary to check custom table structure
            // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
            $columns = $wpdb->get_results("SHOW COLUMNS FROM " . esc_sql($table_name));
            $column_names = array();
            foreach ($columns as $column) {
                $column_names[] = $column->Field;
            }

            // Insert record
            // Direct database query is necessary to insert into custom database table
            // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
            $result = $wpdb->insert(
                $table_name,
                array(
                    'name' => $name,
                    'url' => $url,
                    'shortcode' => $shortcode
                ),
                array('%s', '%s', '%s')
            );

            if ($result === false) {

                add_settings_error(
                    'pollbolt_messages',
                    'pollbolt_message',
                    esc_html__('Error creating shortcode. Please try again.', 'pollbolt-ai-forms-polls-quizzes'),
                    'error'
                );
            } else {
                // Get ID of the newly inserted record
                $new_id = $wpdb->insert_id;
                
                // Get data of the new record for display
                if ($new_id) {
                    // Direct database query is necessary to get data from custom database table
                    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
                    $new_survey = $wpdb->get_row($wpdb->prepare(
                        "SELECT * FROM " . esc_sql($table_name) . " WHERE id = %d",
                        $new_id
                    ));
                    $just_created = true;
                    
                    add_settings_error(
                        'pollbolt_messages',
                        'pollbolt_message',
                        esc_html__('Shortcode generated successfully!', 'pollbolt-ai-forms-polls-quizzes'),
                        'updated'
                    );
                    
                    // Refresh page to ensure new shortcode is displayed
                    if (!headers_sent()) {
                        wp_redirect(admin_url('admin.php?page=pollbolt-settings&created=' . $new_id));
                        exit;
                    }
                }
            }
        }
    }

    // Handle deletion
    if (isset($_GET['action']) && sanitize_text_field(wp_unslash($_GET['action'])) === 'delete' && isset($_GET['id']) && check_admin_referer('delete_survey')) {
        $id = intval(sanitize_text_field(wp_unslash($_GET['id'])));
        // Direct database query is necessary to delete from custom database table
        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
        $wpdb->delete($table_name, array('id' => $id), array('%d'));
        
        add_settings_error(
            'pollbolt_messages',
            'pollbolt_message',
            esc_html__('Form deleted successfully!', 'pollbolt-ai-forms-polls-quizzes'),
            'updated'
        );
        
        // Redirect to settings page without parameters
        wp_redirect(admin_url('admin.php?page=pollbolt-settings'));
        exit;
    }

    // Get all surveys
    // Direct database query is necessary to get data from custom database table
    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    $surveys = $wpdb->get_results("SELECT * FROM " . esc_sql($table_name) . " ORDER BY created_at DESC");

    if (!current_user_can('manage_options')) {
        return;
    }
    
    // For debugging: display information about created shortcode, even if $just_created is not set
    if (isset($_POST['pollbolt_add_survey']) && isset($_POST['survey_name']) && isset($_POST['survey_url']) && isset($shortcode)) {
        $display_shortcode = $shortcode;
        $display_name = isset($_POST['survey_name']) ? sanitize_text_field(wp_unslash($_POST['survey_name'])) : '';
        $display_url = isset($_POST['survey_url']) ? esc_url_raw(wp_unslash($_POST['survey_url'])) : '';
    } else {
        $display_shortcode = '';
        $display_name = '';
        $display_url = '';
    }
    
    // If a new shortcode was created through form processing
    if ($just_created && $new_survey) {
        $display_shortcode = $new_survey->shortcode;
        $display_name = $new_survey->name;
        $display_url = $new_survey->url;
    }
    
    // Define active tab
    $active_tab = isset($_GET['tab']) ? sanitize_text_field(wp_unslash($_GET['tab'])) : 'settings';
    ?>
    <div class="wrap tab-container">
        <!-- Баннер -->
        <div class="pollbolt-banner" style="margin: 25px auto 15px auto;">
            <img src="<?php echo esc_url(pollbolt_get_image_url('banner_upgrade.webp')); ?>" alt="PollBolt Upgrade Banner" style="max-width: 100%; height: auto; display: block;">
        </div>
        
        <?php settings_errors('pollbolt_messages'); ?>
        
        <!-- Navigation tabs -->
        <h2 class="nav-tab-wrapper" style="padding-left: 20px; text-align: left;">
            <a href="?page=pollbolt-settings&tab=settings" class="nav-tab <?php echo esc_attr($active_tab == 'settings' ? 'nav-tab-active' : ''); ?>" style="margin-left: 0;"><?php esc_html_e('Poll\'s Settings', 'pollbolt-ai-forms-polls-quizzes'); ?></a>
            <a href="?page=pollbolt-settings&tab=how-to-use" class="nav-tab <?php echo esc_attr($active_tab == 'how-to-use' ? 'nav-tab-active' : ''); ?>"><?php esc_html_e('How to Use', 'pollbolt-ai-forms-polls-quizzes'); ?></a>
        </h2>
        
        <?php if ($active_tab == 'settings') : ?>
            <!-- Tab content "Poll's Settings" -->
            <div class="pollbolt-tab-content">
            <!-- Add New Form -->
            <div class="card" style="max-width: 1100px; width: 1100px; margin-bottom: 20px; padding: 20px; margin-left: auto; margin-right: auto; border-radius: 15px;">
                <h2 style="margin-top: 0;"><?php esc_html_e('Create New Form Shortcode', 'pollbolt-ai-forms-polls-quizzes'); ?></h2>
                <div id="pollbolt-form-messages"></div>
                <form id="pollbolt-add-form" method="post" action="<?php echo esc_url(admin_url('admin.php?page=pollbolt-settings')); ?>">
                    <?php wp_nonce_field('pollbolt_add_survey', 'pollbolt_nonce'); ?>
                    <table class="form-table">
                        <tr>
                            <th scope="row">
                                <label for="survey_name"><?php esc_html_e('Form Name', 'pollbolt-ai-forms-polls-quizzes'); ?></label>
                            </th>
                            <td>
                                <input type="text" name="survey_name" id="survey_name" class="regular-text" required 
                                       placeholder="<?php esc_attr_e('Enter a name for your form', 'pollbolt-ai-forms-polls-quizzes'); ?>">
                            </td>
                        </tr>
                        <tr>
                            <th scope="row">
                                <label for="survey_url"><?php esc_html_e('Form URL', 'pollbolt-ai-forms-polls-quizzes'); ?></label>
                            </th>
                            <td>
                                <input type="url" name="survey_url" id="survey_url" class="regular-text" required
                                       placeholder="<?php esc_attr_e('Enter the PollBolt form URL', 'pollbolt-ai-forms-polls-quizzes'); ?>">
                            </td>
                        </tr>
                    </table>
                    <p class="submit" style="padding: 0; margin-top: 20px;">
                        <button type="submit" name="pollbolt_add_survey" id="pollbolt-submit-btn" class="button button-primary" style="background-color: #000000 !important; color: #ffffff !important; border-color: #000000 !important;"><?php esc_html_e('Generate Shortcode', 'pollbolt-ai-forms-polls-quizzes'); ?></button>
                        <span class="spinner" id="pollbolt-spinner" style="float: none; margin-top: 0; visibility: hidden;"></span>
                    </p>
                </form>
            </div>

            <!-- Newly created form display -->
            <div id="pollbolt-new-shortcode-container" style="display: none; max-width: 1100px; width: 1100px; margin-bottom: 20px; margin-left: auto; margin-right: auto;">
                <div class="card" style="padding: 20px; background-color: #f0f6fc; border-left: 4px solid #2271b1; border-radius: 15px;">
                    <h2 style="margin-top: 0; color: #2271b1;"><?php esc_html_e('Your New Shortcode', 'pollbolt-ai-forms-polls-quizzes'); ?></h2>
                    <p id="pollbolt-new-form-name"></p>
                    
                    <div style="display: flex; align-items: center; gap: 10px; background: white; padding: 15px; border-radius: 4px; margin: 10px 0;">
                        <span style="font-weight: bold;"><?php esc_html_e('Shortcode:', 'pollbolt-ai-forms-polls-quizzes'); ?></span>
                        <code id="pollbolt-new-shortcode" style="background: #f0f0f1; padding: 8px 12px; border-radius: 4px; font-size: 16px;"></code>
                        <button type="button" class="button copy-shortcode" id="pollbolt-copy-btn"
                                style="margin-left: 10px;">
                            <i class="fa-solid fa-copy" style="margin-right: 5px;"></i>
                            <?php esc_html_e('Copy Shortcode', 'pollbolt-ai-forms-polls-quizzes'); ?>
                        </button>
                    </div>
                    
                    <p style="margin-top: 15px; margin-bottom: 5px;"><?php esc_html_e('Instructions:', 'pollbolt-ai-forms-polls-quizzes'); ?></p>
                    <ol style="margin-top: 5px;">
                        <li><?php esc_html_e('Copy the shortcode above', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                        <li><?php esc_html_e('Paste it into any post, page or widget where you want your form to appear', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                        <li><?php esc_html_e('Save or update your content', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                    </ol>
                </div>
            </div>

            <!-- List of all forms -->
            <div class="card" style="max-width: 1100px; width: 1100px; padding: 0; margin-bottom: 20px; margin-left: auto; margin-right: auto; border-radius: 15px;">
                <h2 class="pollbolt-card-header">
                    <i class="fa-solid fa-code" style="color: #3582c4; font-size: 18px;"></i>
                    <?php esc_html_e('Your Form Shortcodes', 'pollbolt-ai-forms-polls-quizzes'); ?>
                </h2>
                
                <div id="pollbolt-forms-table">
                    <?php if (!empty($surveys) || (isset($_POST['pollbolt_add_survey']) && !empty($display_shortcode))): ?>
                        <table class="pollbolt-shortcodes-table widefat fixed striped">
                            <thead>
                                <tr>
                                    <th style="width: 25%;"><?php esc_html_e('Form Name', 'pollbolt-ai-forms-polls-quizzes'); ?></th>
                                    <th style="width: 20%;"><?php esc_html_e('Shortcode', 'pollbolt-ai-forms-polls-quizzes'); ?></th>
                                    <th style="width: 35%;"><?php esc_html_e('URL', 'pollbolt-ai-forms-polls-quizzes'); ?></th>
                                    <th style="width: 20%;"><?php esc_html_e('Actions', 'pollbolt-ai-forms-polls-quizzes'); ?></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php 
                                // Create array to track already displayed shortcodes
                                $displayed_shortcodes = array();
                                
                                // If just created a new shortcode, show it first
                                if (isset($_POST['pollbolt_add_survey']) && !empty($display_shortcode)): 
                                    // Add shortcode to displayed list
                                    $displayed_shortcodes[] = $display_shortcode;
                                ?>
                                <tr>
                                    <td><span class="form-name"><?php echo esc_html($display_name); ?></span></td>
                                    <td>
                                        <div class="shortcode-container">
                                            <code class="shortcode-code">[<?php echo esc_html($display_shortcode); ?>]</code>
                                            <button type="button" class="button button-small copy-shortcode copy-button" 
                                                    data-shortcode="[<?php echo esc_attr($display_shortcode); ?>]"
                                                    id="copy-btn-new">
                                                <i class="fa-solid fa-copy" style="font-size: 14px;"></i>
                                            </button>
                                        </div>
                                    </td>
                                    <td>
                                        <a href="<?php echo esc_url($display_url); ?>" target="_blank" class="form-url">
                                            <?php echo esc_url($display_url); ?>
                                            <i class="fa-solid fa-arrow-up-right-from-square" style="font-size: 12px;"></i>
                                        </a>
                                    </td>
                                    <td>
                                        <div class="just-created">
                                            <i class="fa-solid fa-circle-check" style="color: inherit;"></i>
                                            <?php esc_html_e('Just Created', 'pollbolt-ai-forms-polls-quizzes'); ?>
                                        </div>
                                    </td>
                                </tr>
                                <?php endif; ?>
                                
                                <?php foreach ($surveys as $survey): 
                                    // Skip if this shortcode has already been displayed
                                    if (in_array($survey->shortcode, $displayed_shortcodes)) {
                                        continue;
                                    }
                                    // Add shortcode to displayed list
                                    $displayed_shortcodes[] = $survey->shortcode;
                                ?>
                                    <tr>
                                        <td><span class="form-name"><?php echo esc_html($survey->name); ?></span></td>
                                        <td>
                                            <div class="shortcode-container">
                                                <code class="shortcode-code">[<?php echo esc_html($survey->shortcode); ?>]</code>
                                                <button type="button" class="button button-small copy-shortcode copy-button" 
                                                        data-shortcode="[<?php echo esc_attr($survey->shortcode); ?>]"
                                                        id="copy-btn-ajax-<?php echo esc_attr($survey->id); ?>">
                                                    <i class="fa-solid fa-copy" style="font-size: 14px;"></i>
                                                </button>
                                            </div>
                                        </td>
                                        <td>
                                                    <a href="<?php echo esc_url($survey->url); ?>" target="_blank" class="form-url">
                                                        <?php echo esc_url($survey->url); ?>
                                                        <i class="fa-solid fa-arrow-up-right-from-square" style="font-size: 12px;"></i>
                                                    </a>
                                                </td>
                                        <td>
                                            <?php
                                            $delete_url = wp_nonce_url(
                                                add_query_arg(
                                                    array(
                                                        'action' => 'delete',
                                                        'id' => $survey->id
                                                    ),
                                                    admin_url('admin.php?page=pollbolt-settings')
                                                ),
                                                'delete_survey'
                                            );
                                            ?>
                                            <a href="<?php echo esc_url($delete_url); ?>" 
                                               class="delete-button" 
                                               onclick="return confirm('<?php esc_attr_e('Are you sure you want to delete this form?', 'pollbolt-ai-forms-polls-quizzes'); ?>')">
                                                <i class="fa-solid fa-trash" style="color: inherit;"></i>
                                                <?php esc_html_e('Delete', 'pollbolt-ai-forms-polls-quizzes'); ?>
                                            </a>
                                        </td>
                                    </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                    <?php else: ?>
                        <div style="padding: 30px 20px; text-align: center; background-color: #f8f9fa; border-radius: 4px; margin: 20px;">
                            <i class="fa-solid fa-circle-info" style="font-size: 48px; color: #8c8f94; margin-bottom: 15px; display: block;"></i>
                            <p style="font-size: 16px; color: #3c434a; margin-bottom: 15px;"><?php esc_html_e('No forms found. Add your first form using the form above!', 'pollbolt-ai-forms-polls-quizzes'); ?></p>
                            <a href="#add-pollbolt-form" class="button button-primary" style="background-color: #2271b1; color: white; border-color: #2271b1; padding: 6px 14px; font-weight: 500; text-decoration: none; border-radius: 3px;">
                                <i class="fa-solid fa-plus" style="margin-right: 5px;"></i>
                                <?php esc_html_e('Add Your First Form', 'pollbolt-ai-forms-polls-quizzes'); ?>
                            </a>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
            </div>
        <?php endif; ?>

        <?php if ($active_tab == 'how-to-use') : ?>
        <div class="card" style="max-width: 1100px; width: 1100px; margin-bottom: 20px; padding: 20px; margin-left: auto; margin-right: auto; border-radius: 15px;">
            <h2 style="margin-top: 0; margin-bottom: 25px; padding-bottom: 10px; border-bottom: 1px solid #f0f0f0;"><?php esc_html_e('Using PollBolt with WordPress', 'pollbolt-ai-forms-polls-quizzes'); ?></h2>
            
            <!-- Step 1: Create a survey on PollBolt.com -->
            <div class="method" style="margin-bottom: 30px;">
                <h3 style="margin-top: 0; display: flex; align-items: center;">
                    <i class="fa-solid fa-1" style="font-size: 18px; width: 26px; height: 26px; text-align: center; margin-right: 10px; background: #FFFD63; color: #333; border-radius: 50%; line-height: 26px;"></i>
                    <?php esc_html_e('Create a Survey on PollBolt.com', 'pollbolt-ai-forms-polls-quizzes'); ?>
                </h3>
                
                <p style="margin-top: 15px; font-size: 15px; line-height: 1.6;">
                    <?php esc_html_e('Before embedding a survey on your WordPress site, you need to create it on PollBolt.com:', 'pollbolt-ai-forms-polls-quizzes'); ?>
                </p>
                
                <ol style="margin-left: 15px; margin-top: 10px;">
                    <li style="margin-bottom: 8px;"><?php esc_html_e('Go to <a href="https://www.pollbolt.com" target="_blank" style="color: #2271b1; text-decoration: none; font-weight: 500;">PollBolt.com</a> and sign in to your account', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                    <li style="margin-bottom: 8px;"><?php esc_html_e('Create a new survey using the PollBolt form builder', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                    <li style="margin-bottom: 8px;"><?php esc_html_e('Customize your questions, design, and settings', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                    <li style="margin-bottom: 8px;"><?php esc_html_e('Save and publish your survey', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                    <li style="margin-bottom: 0;"><?php esc_html_e('Copy the survey URL from PollBolt.com', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                </ol>
                
                <div style="margin: 20px 0; display: flex; gap: 20px; flex-wrap: wrap;">
                    <div style="flex: 1; min-width: 300px;">
                        <img src="<?php echo esc_url(plugins_url('images/making_poll.png', __FILE__)); ?>" alt="PollBolt Form Builder Interface" style="max-width: 100%; height: auto; border: 1px solid #ddd; border-radius: 4px; box-shadow: 0 2px 5px rgba(0,0,0,0.05);">
                    </div>
                    <div style="flex: 1; min-width: 300px;">
                        <img src="<?php echo esc_url(plugins_url('images/share.png', __FILE__)); ?>" alt="PollBolt Share Options Panel" style="max-width: 100%; height: auto; border: 1px solid #ddd; border-radius: 4px; box-shadow: 0 2px 5px rgba(0,0,0,0.05);">
                    </div>
                </div>
                
                <div style="margin-top: 20px; padding: 12px 15px; background: rgba(255,255,255,0.7); border-radius: 4px; border-left: 3px solid #2271b1;">
                    <p style="margin: 0; display: flex; align-items: flex-start;">
                        <i class="fa-solid fa-circle-info" style="color: #2271b1; margin-right: 10px; margin-top: 3px;"></i>
                        <span><?php esc_html_e('After creating your survey, you\'ll need to add it to WordPress using the instructions below. You\'ll need the survey URL from PollBolt.com to create a shortcode in the "Poll\'s Settings" tab.', 'pollbolt-ai-forms-polls-quizzes'); ?></span>
                    </p>
                </div>
            </div>
            
            <!-- Step 2: Add the Survey to WordPress -->
            <div class="method" style="margin-bottom: 30px;">
                <h3 style="margin-top: 0; display: flex; align-items: center;">
                    <i class="fa-solid fa-2" style="font-size: 18px; width: 26px; height: 26px; text-align: center; margin-right: 10px; background: #FFFD63; color: #333; border-radius: 50%; line-height: 26px;"></i>
                    <?php esc_html_e('Add the Survey to WordPress', 'pollbolt-ai-forms-polls-quizzes'); ?>
                </h3>
                
                <p style="margin-top: 15px; font-size: 15px; line-height: 1.6;">
                    <?php esc_html_e('Once you have your survey URL, add it to WordPress:', 'pollbolt-ai-forms-polls-quizzes'); ?>
                </p>
                
                <ol style="margin-left: 15px; margin-top: 10px;">
                    <li style="margin-bottom: 8px;"><?php esc_html_e('Go to the "Poll\'s Settings" tab in PollBolt', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                    <li style="margin-bottom: 8px;"><?php esc_html_e('Enter a name for your form and paste the PollBolt survey URL', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                    <li style="margin-bottom: 0;"><?php esc_html_e('Click "Generate Shortcode" to create a shortcode for your survey', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                </ol>
                
                <div style="margin: 20px 0; text-align: center;">
                    <img src="<?php echo esc_url(plugins_url('images/shortcodes.png', __FILE__)); ?>" alt="PollBolt Form Shortcodes Admin Panel" style="max-width: 100%; height: auto; border: 1px solid #ddd; border-radius: 4px; box-shadow: 0 2px 5px rgba(0,0,0,0.05);">
                </div>
            </div>
            
            <!-- Step 3: Embed the Survey on Your Page -->
            <h3 style="margin-top: 30px; margin-bottom: 20px; display: flex; align-items: center;">
                <i class="fa-solid fa-3" style="font-size: 18px; width: 26px; height: 26px; text-align: center; margin-right: 10px; background: #FFFD63; color: #333; border-radius: 50%; line-height: 26px;"></i>
                <?php esc_html_e('Embed the Survey on Your Page', 'pollbolt-ai-forms-polls-quizzes'); ?>
            </h3>
            
            <p style="margin-bottom: 20px; font-size: 15px; line-height: 1.6;">
                <?php esc_html_e('Now that you have a shortcode, choose one of these methods to embed your survey:', 'pollbolt-ai-forms-polls-quizzes'); ?>
            </p>
            
            <div class="pollbolt-usage-tabs">
                <div class="nav-tabs-wrapper" style="border-bottom: 1px solid #ccc; margin-bottom: 30px; padding-bottom: 1px; display: flex; width: 100%; clear: both;">
                    <a href="#elementor" class="nav-tab nav-tab-active" data-tab="elementor" style="display: inline-block; padding: 10px 15px; text-decoration: none; border: 1px solid #ccc; border-bottom: none; margin-right: 5px; background: #f8f8f8; border-radius: 3px 3px 0 0; position: relative; bottom: -1px;"><?php esc_html_e('Elementor', 'pollbolt-ai-forms-polls-quizzes'); ?></a>
                    <a href="#standard-editor" class="nav-tab" data-tab="standard-editor" style="display: inline-block; padding: 10px 15px; text-decoration: none; border: 1px solid #ccc; border-bottom: none; margin-right: 5px; background: #f1f1f1; border-radius: 3px 3px 0 0; position: relative; bottom: -1px;"><?php esc_html_e('Standard Editor', 'pollbolt-ai-forms-polls-quizzes'); ?></a>
                </div>
                
                <!-- Elementor Tab Content -->
                <div id="elementor-content" class="tab-content" style="display: block; clear: both; padding-top: 5px;">
                    <div class="method" style="background: #f9f9f9; padding: 15px; margin-bottom: 20px; border-left: 4px solid #FFFD63; border-radius: 4px;">
                        <h4 style="margin-top: 0;"><?php esc_html_e('Using the PollBolt Widget in Elementor', 'pollbolt-ai-forms-polls-quizzes'); ?></h4>
                        <ol>
                            <li style="margin-bottom: 8px;"><?php esc_html_e('Open your page in Elementor editor', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                            <li style="margin-bottom: 8px;"><?php esc_html_e('Search for "PollBolt" in the widgets panel', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                            <li style="margin-bottom: 8px;"><?php esc_html_e('Drag the PollBolt widget to your page', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                            <li style="margin-bottom: 0;"><?php esc_html_e('Select your survey from the dropdown menu in the widget settings', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                        </ol>
                        <img src="<?php echo esc_url(plugins_url('images/widget_preview.webp', __FILE__)); ?>" alt="PollBolt Widget in Elementor" style="max-width: 50%; height: auto; border: 1px solid #ddd; border-radius: 4px; margin-top: 15px; box-shadow: 0 2px 5px rgba(0,0,0,0.05);">
                    </div>
                </div>
                
                <!-- Standard Editor Tab Content -->
                <div id="standard-editor-content" class="tab-content" style="display: none; clear: both; padding-top: 5px;">
                    <div class="method" style="background: #f9f9f9; padding: 15px; margin-bottom: 20px; border-left: 4px solid #FFFD63; border-radius: 4px;">
                        <h4 style="margin-top: 0;"><?php esc_html_e('Using the Shortcode Block (Recommended)', 'pollbolt-ai-forms-polls-quizzes'); ?></h4>
                        <ol>
                            <li style="margin-bottom: 8px;"><?php esc_html_e('Open your page in the WordPress Block Editor (Gutenberg)', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                            <li style="margin-bottom: 8px;"><?php esc_html_e('Add a "Shortcode" block where you want the survey to appear', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                            <li style="margin-bottom: 8px;"><?php esc_html_e('Copy and paste your generated shortcode from the "Poll\'s Settings" tab', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                            <li style="margin-bottom: 0;"><?php esc_html_e('Save and publish your page', 'pollbolt-ai-forms-polls-quizzes'); ?></li>
                        </ol>
                    </div>
                    
                    <div class="method" style="background: #f9f9f9; padding: 15px; margin-bottom: 20px; border-left: 4px solid #FFFD63; border-radius: 4px;">
                        <h4><?php esc_html_e('Available Shortcode Formats', 'pollbolt-ai-forms-polls-quizzes'); ?></h4>
                        <p><?php esc_html_e('You can use either of these formats with your generated shortcode ID:', 'pollbolt-ai-forms-polls-quizzes'); ?></p>
                        
                        <p><strong><?php esc_html_e('Direct Shortcode:', 'pollbolt-ai-forms-polls-quizzes'); ?></strong></p>
                        <div style="background: #f0f0f1; padding: 10px; border-radius: 4px; margin: 10px 0;">
                            <code>[pollbolt_3503]</code>
                        </div>
                        
                        <p><strong><?php esc_html_e('With Parameters:', 'pollbolt-ai-forms-polls-quizzes'); ?></strong></p>
                        <div style="background: #f0f0f1; padding: 10px; border-radius: 4px; margin: 10px 0;">
                            <code>[pollbolt id="pollbolt_3503" height="600px" width="100%"]</code>
                        </div>
                    </div>
                    
                    <div class="shortcodes-reference" style="margin-top: 30px; padding-top: 20px; border-top: 1px solid #eee;">
                        <h3><?php esc_html_e('Shortcode Reference', 'pollbolt-ai-forms-polls-quizzes'); ?></h3>
                        <table class="wp-list-table widefat fixed striped" style="border: none;">
                            <thead>
                                <tr>
                                    <th><?php esc_html_e('Parameter', 'pollbolt-ai-forms-polls-quizzes'); ?></th>
                                    <th><?php esc_html_e('Description', 'pollbolt-ai-forms-polls-quizzes'); ?></th>
                                    <th><?php esc_html_e('Example', 'pollbolt-ai-forms-polls-quizzes'); ?></th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td><code>id</code></td>
                                    <td><?php esc_html_e('The ID of your PollBolt survey shortcode', 'pollbolt-ai-forms-polls-quizzes'); ?></td>
                                    <td><code>[pollbolt id="pollbolt_3503"]</code></td>
                                </tr>
                                <tr>
                                    <td><code>height</code></td>
                                    <td><?php esc_html_e('Custom height for the survey iframe (default: 500px)', 'pollbolt-ai-forms-polls-quizzes'); ?></td>
                                    <td><code>[pollbolt id="pollbolt_3503" height="600px"]</code></td>
                                </tr>
                                <tr>
                                    <td><code>width</code></td>
                                    <td><?php esc_html_e('Custom width for the survey container (default: 100%)', 'pollbolt-ai-forms-polls-quizzes'); ?></td>
                                    <td><code>[pollbolt id="pollbolt_3503" width="800px"]</code></td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="card" style="max-width: 1100px; width: 1100px; margin-bottom: 20px; padding: 20px; margin-left: auto; margin-right: auto; border-radius: 15px;">
            <h2 style="margin-top: 0; margin-bottom: 20px; padding-bottom: 10px; border-bottom: 1px solid #f0f0f0;"><?php esc_html_e('About PollBolt', 'pollbolt-ai-forms-polls-quizzes'); ?></h2>
            
            <div style="display: flex; flex-wrap: wrap; gap: 15px; margin-bottom: 15px;">
                <!-- Верхний ряд (2 колонки) -->
                <!-- Блок 1: Создание форм -->
                <div style="flex: 1; min-width: 280px; background: #f2f7ff; padding: 15px; border-radius: 6px;">
                    <h3 style="margin-top: 0; font-size: 18px; margin-bottom: 12px;">
                        <?php esc_html_e('Create your next form in seconds', 'pollbolt-ai-forms-polls-quizzes'); ?>
                    </h3>
                    <p style="font-size: 14px; line-height: 1.5; margin-top: 0; margin-bottom: 12px;">
                        <?php esc_html_e('Let PollBolt write the questions for your forms, so you can focus on what really matters to you.', 'pollbolt-ai-forms-polls-quizzes'); ?>
                    </p>
                    <ul style="margin: 0 0 5px 0; padding-left: 0; list-style-type: none;">
                        <li style="font-size: 13px; margin-bottom: 6px; display: flex; align-items: flex-start;">
                            <i class="fa-solid fa-check-circle" style="margin-right: 8px; color: #4285F4; font-size: 14px; margin-top: 2px;"></i>
                            <span><?php esc_html_e('Describe what you need. AI handles the rest.', 'pollbolt-ai-forms-polls-quizzes'); ?></span>
                        </li>
                        <li style="font-size: 13px; margin-bottom: 6px; display: flex; align-items: flex-start;">
                            <i class="fa-solid fa-check-circle" style="margin-right: 8px; color: #4285F4; font-size: 14px; margin-top: 2px;"></i>
                            <span><?php esc_html_e('Smart templates for any use case.', 'pollbolt-ai-forms-polls-quizzes'); ?></span>
                        </li>
                        <li style="font-size: 13px; display: flex; align-items: flex-start;">
                            <i class="fa-solid fa-check-circle" style="margin-right: 8px; color: #4285F4; font-size: 14px; margin-top: 2px;"></i>
                            <span><?php esc_html_e('Adaptive logic built-in.', 'pollbolt-ai-forms-polls-quizzes'); ?></span>
                        </li>
                    </ul>
                </div>
                
                <!-- Блок 2: Аналитика -->
                <div style="flex: 1; min-width: 280px; background: #f7f2ff; padding: 15px; border-radius: 6px;">
                    <h3 style="margin-top: 0; font-size: 18px; margin-bottom: 12px;">
                        <?php esc_html_e('Analyze responses intelligently', 'pollbolt-ai-forms-polls-quizzes'); ?>
                    </h3>
                    <p style="font-size: 14px; line-height: 1.5; margin-top: 0; margin-bottom: 12px;">
                        <?php esc_html_e('Unlock deeper insights from your response data with our powerful AI-driven analytics platform.', 'pollbolt-ai-forms-polls-quizzes'); ?>
                    </p>
                    <ul style="margin: 0 0 5px 0; padding-left: 0; list-style-type: none;">
                        <li style="font-size: 13px; margin-bottom: 6px; display: flex; align-items: flex-start;">
                            <i class="fa-solid fa-chart-line" style="margin-right: 8px; color: #9C27B0; font-size: 14px; margin-top: 2px;"></i>
                            <span><?php esc_html_e('AI-driven trend detection.', 'pollbolt-ai-forms-polls-quizzes'); ?></span>
                        </li>
                        <li style="font-size: 13px; margin-bottom: 6px; display: flex; align-items: flex-start;">
                            <i class="fa-solid fa-chart-pie" style="margin-right: 8px; color: #9C27B0; font-size: 14px; margin-top: 2px;"></i>
                            <span><?php esc_html_e('Beautiful, shareable dashboards.', 'pollbolt-ai-forms-polls-quizzes'); ?></span>
                        </li>
                        <li style="font-size: 13px; display: flex; align-items: flex-start;">
                            <i class="fa-solid fa-lightbulb" style="margin-right: 8px; color: #9C27B0; font-size: 14px; margin-top: 2px;"></i>
                            <span><?php esc_html_e('Actionable recommendations.', 'pollbolt-ai-forms-polls-quizzes'); ?></span>
                        </li>
                    </ul>
                </div>
            </div>
            
            <div style="display: flex; flex-wrap: wrap; gap: 15px;">
                <!-- Нижний ряд (2 колонки) -->
                <!-- Блок 3: Интеграции -->
                <div style="flex: 1; min-width: 280px; background: #fff8e1; padding: 15px; border-radius: 6px;">
                    <h3 style="margin-top: 0; font-size: 18px; margin-bottom: 12px;">
                        <?php esc_html_e('Connect tools you already use', 'pollbolt-ai-forms-polls-quizzes'); ?>
                    </h3>
                    <p style="font-size: 14px; line-height: 1.5; margin-top: 0; margin-bottom: 12px;">
                        <?php esc_html_e('Seamlessly integrate with the tools you already use like Zapier, Slack, Google Sheets and many more.', 'pollbolt-ai-forms-polls-quizzes'); ?>
                    </p>
                    <ul style="margin: 0 0 5px 0; padding-left: 0; list-style-type: none;">
                        <li style="font-size: 13px; margin-bottom: 6px; display: flex; align-items: flex-start;">
                            <i class="fa-solid fa-bolt" style="margin-right: 8px; color: #FF9800; font-size: 14px; margin-top: 2px;"></i>
                            <span><?php esc_html_e('Build in seconds. No code. No friction.', 'pollbolt-ai-forms-polls-quizzes'); ?></span>
                        </li>
                        <li style="font-size: 13px; margin-bottom: 6px; display: flex; align-items: flex-start;">
                            <i class="fa-solid fa-wand-magic-sparkles" style="margin-right: 8px; color: #FF9800; font-size: 14px; margin-top: 2px;"></i>
                            <span><?php esc_html_e('Make it personal. Automatically.', 'pollbolt-ai-forms-polls-quizzes'); ?></span>
                        </li>
                        <li style="font-size: 13px; display: flex; align-items: flex-start;">
                            <i class="fa-solid fa-pen-to-square" style="margin-right: 8px; color: #FF9800; font-size: 14px; margin-top: 2px;"></i>
                            <span><?php esc_html_e('Design that feels like it belongs.', 'pollbolt-ai-forms-polls-quizzes'); ?></span>
                        </li>
                    </ul>
                </div>
                
                <!-- Блок 4: Размещение -->
                <div style="flex: 1; min-width: 280px; background: #e8f5e9; padding: 15px; border-radius: 6px;">
                    <h3 style="margin-top: 0; font-size: 18px; margin-bottom: 12px;">
                        <?php esc_html_e('Your form, everywhere it needs to be', 'pollbolt-ai-forms-polls-quizzes'); ?>
                    </h3>
                    <p style="font-size: 14px; line-height: 1.5; margin-top: 0; margin-bottom: 12px;">
                        <?php esc_html_e('Take your forms anywhere — from simple links to full website embeds, reach your audience wherever they are online.', 'pollbolt-ai-forms-polls-quizzes'); ?>
                    </p>
                    <ul style="margin: 0 0 5px 0; padding-left: 0; list-style-type: none;">
                        <li style="font-size: 13px; margin-bottom: 6px; display: flex; align-items: flex-start;">
                            <i class="fa-solid fa-link" style="margin-right: 8px; color: #4CAF50; font-size: 14px; margin-top: 2px;"></i>
                            <span><?php esc_html_e('Copy your link and share in seconds.', 'pollbolt-ai-forms-polls-quizzes'); ?></span>
                        </li>
                        <li style="font-size: 13px; margin-bottom: 6px; display: flex; align-items: flex-start;">
                            <i class="fa-solid fa-users" style="margin-right: 8px; color: #4CAF50; font-size: 14px; margin-top: 2px;"></i>
                            <span><?php esc_html_e('Reach your audience where they already are.', 'pollbolt-ai-forms-polls-quizzes'); ?></span>
                        </li>
                        <li style="font-size: 13px; display: flex; align-items: flex-start;">
                            <i class="fa-solid fa-code" style="margin-right: 8px; color: #4CAF50; font-size: 14px; margin-top: 2px;"></i>
                            <span><?php esc_html_e('Embed directly into your website.', 'pollbolt-ai-forms-polls-quizzes'); ?></span>
                        </li>
                    </ul>
                </div>
            </div>
            
            <div style="margin-top: 20px; text-align: center;">
                <a href="https://www.pollbolt.com" target="_blank" style="display: inline-block; background: #FFFD63; color: #333; text-decoration: none; padding: 10px 20px; border-radius: 4px; font-weight: bold; transition: all 0.2s ease; border: 1px solid rgba(0,0,0,0.1); font-size: 15px;">
                    <?php esc_html_e('Visit PollBolt.com', 'pollbolt-ai-forms-polls-quizzes'); ?>
                </a>
            </div>
        </div>
        <?php endif; ?>
    </div>
    <?php
}

// Add Elementor widget only if Elementor is activated
function pollbolt_elementor_widget_init() {
    // Check if Elementor is loaded
    if (!did_action('elementor/loaded')) {
        return;
    }
    
    // Function to register the widget
    function pollbolt_register_elementor_widget() {
        // Check if the class exists
        if (class_exists('Elementor\Widget_Base')) {
            // Create and register the widget
            require_once plugin_dir_path(__FILE__) . 'pollbolt-elementor-widget.php';
            
            // Register the widget in Elementor
            \Elementor\Plugin::instance()->widgets_manager->register(new PollBolt_Elementor_Widget());
        }
    }
    
    // Register the widget
    add_action('elementor/widgets/register', 'pollbolt_register_elementor_widget');
}
add_action('plugins_loaded', 'pollbolt_elementor_widget_init'); 

// Добавим функцию для регистрации стилей и скриптов в админке
function pollbolt_admin_enqueue_scripts($hook) {
    // Загружаем стили и скрипты только на странице настроек плагина
    if ($hook != 'toplevel_page_pollbolt-settings') {
        return;
    }
    
    // Подключаем CSS файлы для админки
    wp_enqueue_style('pollbolt-shortcode-table-styles', plugins_url('css/shortcode-table.css', __FILE__), array(), '1.0.0');
    
    // Подключаем JS файл для админки
    wp_enqueue_script('pollbolt-admin-scripts', plugins_url('js/admin-scripts.js', __FILE__), array('jquery'), '1.0.0', true);
}
add_action('admin_enqueue_scripts', 'pollbolt_admin_enqueue_scripts');