<div class="theme-offer">
   <?php
        // Check if the demo import has been completed
        $classic_marketing_agency_demo_import_completed = get_option('classic_marketing_agency_demo_import_completed', false);

        // If the demo import is completed, display the "View Site" button
        if ($classic_marketing_agency_demo_import_completed) {
            echo '<br>';
            echo '<div class="success">Demo Import Successful</div>';
            echo '<br>';
            echo '<hr>';
            echo '<br>';
            echo '<span>' . esc_html__( 'You can now visit your site or customize it further.', 'classic-marketing-agency' ) . '</span>';
            echo '<br>';
            echo '<br>';
            echo '<br>';
            echo '<div class="view-site-btn">';
            echo '<a href="' . esc_url(home_url()) . '" class="button button-primary button-large" style="margin-top: 10px;" target="_blank">View Site</a>';
            echo '<a href="' . esc_url( admin_url('customize.php') ) . '" class="button button-primary button-large" style="margin-top: 10px;" target="_blank">Customize Demo Content</a>';
            echo '</div>';
        }
    if ( isset( $_POST['submit'] ) ) {
        echo '<div class="plugin-notice">';
            // Check if Classic Blog Grid plugin is installed
            if (!is_plugin_active('classic-blog-grid/classic-blog-grid.php')) {
                // Plugin slug and file path for Classic Blog Grid
                $classic_marketing_agency_plugin_slug = 'classic-blog-grid';
                $classic_marketing_agency_plugin_file = 'classic-blog-grid/classic-blog-grid.php';
            
                // Check if Classic Blog Grid is installed and activated
                if ( ! is_plugin_active( $classic_marketing_agency_plugin_file ) ) {
            
                    // Check if Classic Blog Grid is installed
                    $classic_marketing_agency_installed_plugins = get_plugins();
                    if ( ! isset( $classic_marketing_agency_installed_plugins[ $classic_marketing_agency_plugin_file ] ) ) {
            
                        // Include necessary files to install plugins
                        include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
                        include_once( ABSPATH . 'wp-admin/includes/file.php' );
                        include_once( ABSPATH . 'wp-admin/includes/misc.php' );
                        include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
            
                        // Download and install Classic Blog Grid
                        $classic_marketing_agency_upgrader = new Plugin_Upgrader();
                        $classic_marketing_agency_upgrader->install( 'https://downloads.wordpress.org/plugin/classic-blog-grid.latest-stable.zip' );
                    }
            
                    // Activate the Classic Blog Grid plugin after installation (if needed)
                    activate_plugin( $classic_marketing_agency_plugin_file );
                }
            }
        echo '</div>';
        // ------- Create Main Menu --------
        $classic_marketing_agency_menuname = 'Primary Menu';
        $classic_marketing_agency_bpmenulocation = 'primary';
        $classic_marketing_agency_menu_exists = wp_get_nav_menu_object( $classic_marketing_agency_menuname );
    
        if (!$classic_marketing_agency_menu_exists) {
            // Create a new menu
            $classic_marketing_agency_menu_id = wp_create_nav_menu($classic_marketing_agency_menuname);

            // Define pages to be created
            $classic_marketing_agency_pages = array(
                'home' => array(
                    'title' => 'Home',
                    'template' => '/templates/template-home-page.php'
                ),
                'blogs' => array(
                    'title' => 'Blogs',
                    'content' => ''
                ),
                'about' => array(
                    'title' => 'About',
                    'content' => '<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960 with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>'
                ),
                'our-project' => array(
                    'title' => 'Our Project',
                    'content' => '<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960 with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>'
                ),
                'services' => array(
                    'title' => 'Services',
                    'content' => '<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960 with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>'
                ),
                'pages' => array(
                    'title' => 'Pages',
                    'content' => '<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960 with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>'
                ),
                'contact' => array(
                    'title' => 'Contact',
                    'content' => '<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960 with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>'
                ),
            );

            $classic_marketing_agency_page_ids = array();

            // Loop through the pages and create them if they don’t exist
            foreach ($classic_marketing_agency_pages as $classic_marketing_agency_slug => $classic_marketing_agency_data) {
                $classic_marketing_agency_existing_page = get_page_by_path($classic_marketing_agency_slug);

                if ($classic_marketing_agency_existing_page) {
                    // If the page already exists, use its ID
                    $classic_marketing_agency_page_id = $classic_marketing_agency_existing_page->ID;
                } else {
                    // Create a new page
                    $classic_marketing_agency_page_data = array(
                        'post_type'    => 'page',
                        'post_title'   => $classic_marketing_agency_data['title'],
                        'post_content' => isset($classic_marketing_agency_data['content']) ? $classic_marketing_agency_data['content'] : '',
                        'post_status'  => 'publish',
                        'post_author'  => get_current_user_id(), // Set author dynamically
                        'post_name'    => $classic_marketing_agency_slug,
                    );

                    $classic_marketing_agency_page_id = wp_insert_post($classic_marketing_agency_page_data);

                    // Assign custom page template if specified
                    if (!empty($classic_marketing_agency_data['template'])) {
                        update_post_meta($classic_marketing_agency_page_id, '_wp_page_template', $classic_marketing_agency_data['template']);
                    }
                }

                // Store the page IDs
                $classic_marketing_agency_page_ids[$classic_marketing_agency_slug] = $classic_marketing_agency_page_id;
            }

            // Set homepage and blog page
            update_option('page_for_posts', $classic_marketing_agency_page_ids['blogs']);
            update_option('page_on_front', $classic_marketing_agency_page_ids['home']);
            update_option('show_on_front', 'page');

            // Define menu items
            $classic_marketing_agency_menu_items = array(
                'home',
                'blogs',
                'about',
                'services',
                'pages',
                'contact'
            );

            // Add menu items dynamically
            foreach ($classic_marketing_agency_menu_items as $classic_marketing_agency_slug) {
                wp_update_nav_menu_item($classic_marketing_agency_menu_id, 0, array(
                    'menu-item-title' => esc_html($classic_marketing_agency_pages[$classic_marketing_agency_slug]['title']),
                    'menu-item-url' => get_permalink($classic_marketing_agency_page_ids[$classic_marketing_agency_slug]),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $classic_marketing_agency_page_ids[$classic_marketing_agency_slug],
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type',
                ));
            }

            // Assign menu to theme location
            $classic_marketing_agency_locations = get_theme_mod('nav_menu_locations', array());
            $classic_marketing_agency_locations[$classic_marketing_agency_bpmenulocation] = $classic_marketing_agency_menu_id;
            set_theme_mod('nav_menu_locations', $classic_marketing_agency_locations);
        }

        //Logo
        set_theme_mod( 'classic_marketing_agency_the_custom_logo', esc_url( get_template_directory_uri().'/images/Logo.png'));

        //Topbar Section
        set_theme_mod( 'classic_marketing_agency_topbar', true);
        set_theme_mod( 'classic_marketing_agency_phone_number', '+123 456 7890');
        set_theme_mod( 'classic_marketing_agency_email_address', 'digitalmarketing123@example.com');

        //Social Media Section
        set_theme_mod( 'classic_marketing_agency_fb_link', '#');
        set_theme_mod( 'classic_marketing_agency_twitt_link', '#');
        set_theme_mod( 'classic_marketing_agency_linkedin_link', '#');
        set_theme_mod( 'classic_marketing_agency_insta_link', '#');
        set_theme_mod( 'classic_marketing_agency_behance_link', '#');

        //Slider Section
        set_theme_mod( 'classic_marketing_agency_slider', true);
        set_theme_mod( 'classic_marketing_agency_slider_small_title', 'WELCOME TO DIGITAL MARKETING');
        set_theme_mod( 'classic_marketing_agency_num_service_categories', 5);

        
        $classic_marketing_agency_slider_category_id = wp_create_category('Slider');

        // Set the category in theme mods for the slider section
        set_theme_mod('classic_marketing_agency_slider_catData', 'Slider'); // Update with correct category ID
        
        // Titles for the three posts
        $classic_marketing_agency_titles = array(
            'Let\'s Make Something Amazing Together',
            'Your Vision, Our Strategy',
            'Creative Ideas That Drive Results',
            'Building Brands That Matter',
            'We Turn Clicks Into Customers'
        );               
        // Create three demo posts and assign them to the 'Slider' category
        for ($classic_marketing_agency_i = 1; $classic_marketing_agency_i <= 5; $classic_marketing_agency_i++) {
            $classic_marketing_agency_title = $classic_marketing_agency_titles[$classic_marketing_agency_i - 1];
            $classic_marketing_agency_content = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.';
        
            // Prepare the post object
            $classic_marketing_agency_my_post = array(
                'post_title'    => wp_strip_all_tags($classic_marketing_agency_title),
                'post_content'  => $classic_marketing_agency_content,
                'post_status'   => 'publish',
                'post_type'     => 'post',
                'post_category' => array($classic_marketing_agency_slider_category_id),
            );
        
            // Insert the post into the database
            $classic_marketing_agency_post_id = wp_insert_post($classic_marketing_agency_my_post);
        
            // If the post was successfully created, set the featured image
            if ($classic_marketing_agency_post_id && !is_wp_error($classic_marketing_agency_post_id)) {
                // Set the image URL based on the current slider index
                $classic_marketing_agency_image_url = esc_url(get_stylesheet_directory_uri() . '/images/slider' . $classic_marketing_agency_i . '.png');
                $classic_marketing_agency_upload_dir = wp_upload_dir();
        
                // Download the image data using wp_remote_get()
                $classic_marketing_agency_response = wp_remote_get($classic_marketing_agency_image_url);
                if (!is_wp_error($classic_marketing_agency_response)) {
                    $classic_marketing_agency_image_data = wp_remote_retrieve_body($classic_marketing_agency_response);
        
                    if (!empty($classic_marketing_agency_image_data)) {
                        // Handle the file upload process
                        $classic_marketing_agency_image_name = 'slider' . $classic_marketing_agency_i . '.png';
                        $classic_marketing_agency_unique_file_name = wp_unique_filename($classic_marketing_agency_upload_dir['path'], $classic_marketing_agency_image_name);
                        $classic_marketing_agency_file = $classic_marketing_agency_upload_dir['path'] . '/' . $classic_marketing_agency_unique_file_name;
        
                        // Save the image file to the uploads directory
                        global $wp_filesystem;
                        WP_Filesystem();
                        $wp_filesystem->put_contents($classic_marketing_agency_file, $classic_marketing_agency_image_data);
        
                        // Check file type and prepare for attachment
                        $classic_marketing_agency_wp_filetype = wp_check_filetype($classic_marketing_agency_unique_file_name, null);
                        $classic_marketing_agency_attachment = array(
                            'post_mime_type' => $classic_marketing_agency_wp_filetype['type'],
                            'post_title'     => sanitize_file_name($classic_marketing_agency_unique_file_name),
                            'post_content'   => '',
                            'post_status'    => 'inherit',
                        );
        
                        // Insert the image into the media library and set it as the post's featured image
                        $classic_marketing_agency_attach_id = wp_insert_attachment($classic_marketing_agency_attachment, $classic_marketing_agency_file, $classic_marketing_agency_post_id);
                        $classic_marketing_agency_attach_data = wp_generate_attachment_metadata($classic_marketing_agency_attach_id, $classic_marketing_agency_file);
                        wp_update_attachment_metadata($classic_marketing_agency_attach_id, $classic_marketing_agency_attach_data);
                        set_post_thumbnail($classic_marketing_agency_post_id, $classic_marketing_agency_attach_id);
                    }
                }
            }
        }

        //Services Section
        set_theme_mod( 'classic_marketing_agency_disabled_pgboxes', true);
        set_theme_mod( 'classic_marketing_agency_headingtext1', 'OUR SERVICES');
        set_theme_mod( 'classic_marketing_agency_headingtext_para', 'Our Best Services');

        $classic_marketing_agency_slider_category_id = wp_create_category('Services');

        // Set the category in theme mods for the Services section
        set_theme_mod('classic_marketing_agency_blog_cat', 'Services'); // Update with correct category ID
        
        // Titles for the three posts
        $classic_marketing_agency_titles = array(
            'Marketing Research',
            'Web Developments',
            'Online Marketing',
        );        
        // Create three demo posts and assign them to the 'Services' category
        for ($classic_marketing_agency_i = 1; $classic_marketing_agency_i <= 3; $classic_marketing_agency_i++) {
            $classic_marketing_agency_title = $classic_marketing_agency_titles[$classic_marketing_agency_i - 1];
            $classic_marketing_agency_content = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.';
        
            // Prepare the post object
            $classic_marketing_agency_my_post = array(
                'post_title'    => wp_strip_all_tags($classic_marketing_agency_title),
                'post_content'  => $classic_marketing_agency_content,
                'post_status'   => 'publish',
                'post_type'     => 'post',
                'post_category' => array($classic_marketing_agency_slider_category_id),
            );
        
            // Insert the post into the database
            $classic_marketing_agency_post_id = wp_insert_post($classic_marketing_agency_my_post);
        
            // If the post was successfully created, set the featured image
            if ($classic_marketing_agency_post_id && !is_wp_error($classic_marketing_agency_post_id)) {
                // Set the image URL based on the current slider index
                $classic_marketing_agency_image_url = esc_url(get_stylesheet_directory_uri() . '/images/services' . $classic_marketing_agency_i . '.png');
                $classic_marketing_agency_upload_dir = wp_upload_dir();
        
                // Download the image data using wp_remote_get()
                $classic_marketing_agency_response = wp_remote_get($classic_marketing_agency_image_url);
                if (!is_wp_error($classic_marketing_agency_response)) {
                    $classic_marketing_agency_image_data = wp_remote_retrieve_body($classic_marketing_agency_response);
        
                    if (!empty($classic_marketing_agency_image_data)) {
                        // Handle the file upload process
                        $classic_marketing_agency_image_name = 'slider' . $classic_marketing_agency_i . '.png';
                        $classic_marketing_agency_unique_file_name = wp_unique_filename($classic_marketing_agency_upload_dir['path'], $classic_marketing_agency_image_name);
                        $classic_marketing_agency_file = $classic_marketing_agency_upload_dir['path'] . '/' . $classic_marketing_agency_unique_file_name;
        
                        // Save the image file to the uploads directory
                        global $wp_filesystem;
                        WP_Filesystem();
                        $wp_filesystem->put_contents($classic_marketing_agency_file, $classic_marketing_agency_image_data);
        
                        // Check file type and prepare for attachment
                        $classic_marketing_agency_wp_filetype = wp_check_filetype($classic_marketing_agency_unique_file_name, null);
                        $classic_marketing_agency_attachment = array(
                            'post_mime_type' => $classic_marketing_agency_wp_filetype['type'],
                            'post_title'     => sanitize_file_name($classic_marketing_agency_unique_file_name),
                            'post_content'   => '',
                            'post_status'    => 'inherit',
                        );
        
                        // Insert the image into the media library and set it as the post's featured image
                        $classic_marketing_agency_attach_id = wp_insert_attachment($classic_marketing_agency_attachment, $classic_marketing_agency_file, $classic_marketing_agency_post_id);
                        $classic_marketing_agency_attach_data = wp_generate_attachment_metadata($classic_marketing_agency_attach_id, $classic_marketing_agency_file);
                        wp_update_attachment_metadata($classic_marketing_agency_attach_id, $classic_marketing_agency_attach_data);
                        set_post_thumbnail($classic_marketing_agency_post_id, $classic_marketing_agency_attach_id);
                    }
                }
            }
        }

        set_theme_mod('classic_marketing_agency_num_services', 3);
    
        $classic_marketing_agency_reviewers = array(
            array(
                'image'  => get_template_directory_uri() . '/images/reviewer1.png',
                'name'   => 'William',
                'price'  => '$5,500.00',
                'rating' => 5,
            ),
            array(
                'image'  => get_template_directory_uri() . '/images/reviewer2.png',
                'name'   => 'Lily Turner',
                'price'  => '$5,100.00',
                'rating' => 4,
            ),
            array(
                'image'  => get_template_directory_uri() . '/images/reviewer3.png',
                'name'   => 'Sophia',
                'price'  => '$6,500.00',
                'rating' => 3,
            ),
        );
    
        // Set the number of services
        set_theme_mod('classic_marketing_agency_num_services', count($classic_marketing_agency_reviewers));
    
        // Loop through each reviewer and apply settings
        foreach ($classic_marketing_agency_reviewers as $classic_marketing_agency_index => $classic_marketing_agency_reviewer) {
            $classic_marketing_agency_i = $classic_marketing_agency_index + 1;
    
            set_theme_mod("classic_marketing_agency_reviewer_image{$classic_marketing_agency_i}", $classic_marketing_agency_reviewer['image']);
            set_theme_mod("classic_marketing_agency_reviwer_name{$classic_marketing_agency_i}", $classic_marketing_agency_reviewer['name']);
            set_theme_mod("classic_marketing_agency_courses_prices{$classic_marketing_agency_i}", $classic_marketing_agency_reviewer['price']);
            set_theme_mod("classic_marketing_agency_star_rating{$classic_marketing_agency_i}", $classic_marketing_agency_reviewer['rating']);
        }

        set_theme_mod( 'classic_marketing_agency_contact_us_text', 'View All');
        set_theme_mod( 'classic_marketing_agency_contact_us_url', '#');
        
        // Show success message and the "View Site" button
        update_option('classic_marketing_agency_demo_import_completed', true);
        echo '<br>';
        echo '<div class="success">Demo Import Successful</div>';
        echo '<br>';
        echo '<hr>';
        echo '<br>';
        echo '<span>' . esc_html__( 'You can now visit your site or customize it further.', 'classic-marketing-agency' ) . '</span>';
        echo '<br>';
    }
     ?>
    <ul>
        <li>
        <?php 
        // Check if the form is submitted
        if ( !isset( $_POST['submit'] ) ) : ?>
            <!-- Show demo importer form only if it's not submitted -->
            <?php if (!get_option('classic_marketing_agency_demo_import_completed')) : ?>
                <span><?php echo esc_html( 'Click on the below content to get demo content installed.', 'classic-marketing-agency' ); ?></span>
                <br><br>
                <hr><br>
                <b class="note"><?php echo esc_html('Note :', 'classic-marketing-agency' ); ?></b><br><br>
                <small><b><?php echo esc_html('Please take a backup if your website is already live with data. This importer will overwrite existing data.', 'classic-marketing-agency' ); ?></b></small><br><br>
                <form id="demo-importer-form" action="" method="POST" onsubmit="return runDemoImport();">
                    <input type="submit" name="submit" value="<?php echo esc_attr('Run Importer','classic-marketing-agency'); ?>" class="button button-primary button-large">
                </form>
                <script type="text/javascript">
                    function runDemoImport() {
                        if (confirm('Do you really want to do this?')) {
                            document.getElementById('demo-import-loader').style.display = 'block';
                            return true;
                        }
                        return false;
                    }
                </script>
             <?php endif; ?>
         <?php 
        endif; 

        // Show "View Site" button after form submission
        if ( isset( $_POST['submit'] ) ) {
        echo '<div class="view-site-btn">';
        echo '<a href="' . esc_url(home_url()) . '" class="button button-primary button-large" style="margin-top: 10px;" target="_blank">View Site</a>';
        echo '<a href="' . esc_url( admin_url('customize.php') ) . '" class="button button-primary button-large" style="margin-top: 10px;" target="_blank">Customize Demo Content</a>';
        echo '</div>';
        }
        ?>
        </li>
    </ul>
 </div>