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

        // If the demo import is completed, display the "View Site" button
        if ($ecommerce_landing_page_demo_import_completed) {
        echo '<p class="notice-text">' . esc_html__('Your demo import has been completed successfully.', 'ecommerce-landing-page') . '</p>';
        echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('View Site', 'ecommerce-landing-page') . '</a></span>';
        echo '<span><a href="'. esc_url(admin_url('customize.php') ) .'" class="button button-primary demo-btn" target=_blank>'. esc_html__( 'Customize Your Site', 'master-education' ) .'</a></span>';
        echo '<span><a href="'. esc_url( 'https://preview.vwthemesdemo.com/docs/master-education-free-doc/' ) .'" class="button button-primary doc-btn" target=_blank>'. esc_html__( 'Free Theme Documentation', 'master-education' ) .'</a></span>';
        }

		//POST and update the customizer and other related data
        if (isset($_POST['submit'])) {

            // Check if ibtana visual editor is installed and activated
            if (!is_plugin_active('ibtana-visual-editor/plugin.php')) {
              // Install the plugin if it doesn't exist
              $master_education_plugin_slug = 'ibtana-visual-editor';
              $master_education_plugin_file = 'ibtana-visual-editor/plugin.php';

              // Check if plugin is installed
              $master_education_installed_plugins = get_plugins();
              if (!isset($master_education_installed_plugins[$master_education_plugin_file])) {
                  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');

                  // Install the plugin
                  $master_education_upgrader = new Plugin_Upgrader();
                  $master_education_upgrader->install('https://downloads.wordpress.org/plugin/ibtana-visual-editor.latest-stable.zip');
              }
              // Activate the plugin
              activate_plugin($master_education_plugin_file);
            }


            // ------- Create Nav Menu --------
            $ecommerce_landing_page_menuname = 'Main Menus';
            $ecommerce_landing_page_bpmenulocation = 'primary';
            $ecommerce_landing_page_menu_exists = wp_get_nav_menu_object($ecommerce_landing_page_menuname);

            if (!$ecommerce_landing_page_menu_exists) {
                $ecommerce_landing_page_menu_id = wp_create_nav_menu($ecommerce_landing_page_menuname);

                // Create Home Page
                $ecommerce_landing_page_home_title = 'Home';
                $ecommerce_landing_page_home = array(
                    'post_type' => 'page',
                    'post_title' => $ecommerce_landing_page_home_title,
                    'post_content' => '',
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'home'
                );
                $ecommerce_landing_page_home_id = wp_insert_post($ecommerce_landing_page_home);
                // Assign Home Page Template
                add_post_meta($ecommerce_landing_page_home_id, '_wp_page_template', 'page-template/custom-home-page.php');
                // Update options to set Home Page as the front page
                update_option('page_on_front', $ecommerce_landing_page_home_id);
                update_option('show_on_front', 'page');
                // Add Home Page to Menu
                wp_update_nav_menu_item($ecommerce_landing_page_menu_id, 0, array(
                    'menu-item-title' => __('Home', 'ecommerce-landing-page'),
                    'menu-item-classes' => 'home',
                    'menu-item-url' => home_url('/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $ecommerce_landing_page_home_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Pages Page with Dummy Content
                $ecommerce_landing_page_pages_title = 'Pages';
                $ecommerce_landing_page_pages_content = 'Explore all the pages we have on our website. Find information about our services, company, and more.
                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.<br>
                All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.';
                $ecommerce_landing_page_pages = array(
                    'post_type' => 'page',
                    'post_title' => $ecommerce_landing_page_pages_title,
                    'post_content' => $ecommerce_landing_page_pages_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'pages'
                );
                $ecommerce_landing_page_pages_id = wp_insert_post($ecommerce_landing_page_pages);
                // Add Pages Page to Menu
                wp_update_nav_menu_item($ecommerce_landing_page_menu_id, 0, array(
                    'menu-item-title' => __('Pages', 'ecommerce-landing-page'),
                    'menu-item-classes' => 'pages',
                    'menu-item-url' => home_url('/pages/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $ecommerce_landing_page_pages_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create About Us Page with Dummy Content
                $ecommerce_landing_page_about_title = 'About Us';
                $ecommerce_landing_page_about_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam...<br>
                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.<br>
                There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which dont look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isnt anything embarrassing hidden in the middle of text.<br>
                 All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.';
                $ecommerce_landing_page_about = array(
                    'post_type' => 'page',
                    'post_title' => $ecommerce_landing_page_about_title,
                    'post_content' => $ecommerce_landing_page_about_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'about-us'
                );
                $ecommerce_landing_page_about_id = wp_insert_post($ecommerce_landing_page_about);
                // Add About Us Page to Menu
                wp_update_nav_menu_item($ecommerce_landing_page_menu_id, 0, array(
                    'menu-item-title' => __('About Us', 'ecommerce-landing-page'),
                    'menu-item-classes' => 'about-us',
                    'menu-item-url' => home_url('/about-us/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $ecommerce_landing_page_about_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));
                
                 /*  Create Courses Page */
                $ecommerce_landing_page_services_title = 'Courses';
                $ecommerce_landing_page_services_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br>
                We offer a wide range of ecommerce services including product management, order fulfillment, payment integration, and customer support solutions.';

                $ecommerce_landing_page_services = array(
                    'post_type'    => 'page',
                    'post_title'   => $ecommerce_landing_page_services_title,
                    'post_content' => $ecommerce_landing_page_services_content,
                    'post_status'  => 'publish',
                    'post_author'  => 1,
                    'post_slug'    => 'services'
                );
                $ecommerce_landing_page_services_id = wp_insert_post($ecommerce_landing_page_services);

                wp_update_nav_menu_item($ecommerce_landing_page_menu_id, 0, array(
                    'menu-item-title'  => __('Courses', 'ecommerce-landing-page'),
                    'menu-item-classes'=> 'services',
                    'menu-item-url'    => home_url('/services/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $ecommerce_landing_page_services_id,
                    'menu-item-object' => 'page',
                    'menu-item-type'   => 'post_type'
                ));

                /*  Create Teachers Page  */
                $ecommerce_landing_page_experts_title = 'Teachers';
                $ecommerce_landing_page_experts_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br>
                Our expert team consists of ecommerce strategists, developers, designers, and digital marketers with years of industry experience.';

                $ecommerce_landing_page_experts = array(
                    'post_type'    => 'page',
                    'post_title'   => $ecommerce_landing_page_experts_title,
                    'post_content' => $ecommerce_landing_page_experts_content,
                    'post_status'  => 'publish',
                    'post_author'  => 1,
                    'post_slug'    => 'experts'
                );
                $ecommerce_landing_page_experts_id = wp_insert_post($ecommerce_landing_page_experts);

                wp_update_nav_menu_item($ecommerce_landing_page_menu_id, 0, array(
                    'menu-item-title'  => __('Teachers', 'ecommerce-landing-page'),
                    'menu-item-classes'=> 'experts',
                    'menu-item-url'    => home_url('/experts/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $ecommerce_landing_page_experts_id,
                    'menu-item-object' => 'page',
                    'menu-item-type'   => 'post_type'
                ));

                // Create Blog Page 
                $ecommerce_landing_page_blog_page_title = 'Blog';
                $ecommerce_landing_page_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($ecommerce_landing_page_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ));
                if (!$ecommerce_landing_page_blog_page_query->have_posts()) {
                    $ecommerce_landing_page_blog_page = array(
                    'post_type'   => 'page',
                    'post_title'  => $ecommerce_landing_page_blog_page_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    );
                    $ecommerce_landing_page_blog_page_id = wp_insert_post($ecommerce_landing_page_blog_page);
                    update_option('page_for_posts', $ecommerce_landing_page_blog_page_id);
                    wp_update_nav_menu_item($ecommerce_landing_page_menu_id, 0, array(
                    'menu-item-title'      => __('Blog', 'ecommerce-landing-page'),
                    'menu-item-url'        => get_permalink($ecommerce_landing_page_blog_page_id),
                    'menu-item-status'     => 'publish',
                    'menu-item-object-id'  => $ecommerce_landing_page_blog_page_id,
                    'menu-item-object'     => 'page',
                    'menu-item-type'       => 'post_type',
                    ));
                }

                // Set the menu location if it's not already set
                if (!has_nav_menu($ecommerce_landing_page_bpmenulocation)) {
                    $locations = get_theme_mod('nav_menu_locations'); // Use 'nav_menu_locations' to get locations array
                    if (empty($locations)) {
                        $locations = array();
                    }
                    $locations[$ecommerce_landing_page_bpmenulocation] = $ecommerce_landing_page_menu_id;
                    set_theme_mod('nav_menu_locations', $locations);
                }
        }
            // Set the demo import completion flag
    		update_option('ecommerce_landing_page_demo_import_completed', true);
    		// Display success message and "View Site" button
    		echo '<p class="notice-text">' . esc_html__('Your demo import has been completed successfully.', 'ecommerce-landing-page') . '</p>';
    		echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('View Site', 'ecommerce-landing-page') . '</a></span>';
            echo '<span><a href="'. esc_url(admin_url('customize.php') ) .'" class="button button-primary demo-btn" target=_blank>'. esc_html__( 'Customize Your Site', 'master-education' ) .'</a></span>';
            echo '<span><a href="'. esc_url( 'https://preview.vwthemesdemo.com/docs/master-education-free-doc/' ) .'" class="button button-primary doc-btn" target=_blank>'. esc_html__( 'Free Theme Documentation', 'master-education' ) .'</a></span>';
            //end

            // Top Bar //
            set_theme_mod('ecommerce_landing_page_topbar_myaccount_icon', 'fas fa-user' );
            set_theme_mod('master_education_top_myaccount_icon_url', '#' );

            // Banner Section
            set_theme_mod( 'master_education_tagline_title1', 'Welcome' );
            set_theme_mod( 'master_education_banner_image', get_theme_file_uri().'/assets/images/banner-img1.png');
            set_theme_mod( 'master_education_banner_image1', get_theme_file_uri().'/assets/images/banner-img2.png');
            set_theme_mod( 'master_education_banner_image2', get_theme_file_uri().'/assets/images/banner-img3.png');
            set_theme_mod( 'master_education_banner_image3', get_theme_file_uri().'/assets/images/banner-img4.png');
            set_theme_mod( 'ecommerce_landing_page_tagline_title', 'Providing Best Education For Brighter future' );
            set_theme_mod( 'ecommerce_landing_page_designation_text', 'All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary,' );
            set_theme_mod( 'ecommerce_landing_page_banner_button_label', 'Get Our Services' );           
            set_theme_mod( 'ecommerce_landing_page_top_button_url', '#' );

            // About Section
            set_theme_mod( 'master_education_about_sub_title', 'About Us' );           
            set_theme_mod( 'master_education_about_main_title', 'Know About Histudy Learning Platform' );
            set_theme_mod( 'master_education_about_desc_text', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since 1966, when designers at Letraset and James Mosley, the librarian at St Bride Printing Library, took a 1914 Cicero translation and scrambled it to make dummy text for Letraset\'s Body Type sheets.' );
            
            $master_education_about_bottom_icons = array(
                'fa-solid fa-heart',
                'fa-solid fa-book-open',
            );

            $master_education_about_bottom_titles = array(
                'Flexible Classes',
                'Learn From Anywhere',
            );

            $master_education_about_bottom_descs = array(
                'It is a long established fact that a reader will be distracted by this on  looking at its layout.',
                'It is a long established fact that a reader will be distracted by this on  looking at its layout.',
            );

            for ( $master_education_i = 1; $master_education_i <= 2; $master_education_i++ ) {
                set_theme_mod(
                    'master_education_about_bottom_box_icon' . $master_education_i,
                    $master_education_about_bottom_icons[ $master_education_i - 1 ]
                );

                set_theme_mod(
                    'master_education_about_bottom_title' . $master_education_i,
                    $master_education_about_bottom_titles[ $master_education_i - 1 ]
                );

                set_theme_mod(
                    'master_education_about_bottom_desc' . $master_education_i,
                    $master_education_about_bottom_descs[ $master_education_i - 1 ]
                );
            }

            set_theme_mod( 'master_education_about_img1', get_theme_file_uri().'/assets/images/about-img1.png');
            set_theme_mod( 'master_education_about_img2', get_theme_file_uri().'/assets/images/about-img2.png');
            set_theme_mod( 'master_education_about_img3', get_theme_file_uri().'/assets/images/about-img3.png');

            // Latest News And Blog Section
            set_theme_mod('ecommerce_landing_page_latest_news_blog_heading', 'Latest News & Blogs' );
            set_theme_mod('ecommerce_landing_page_latest_news_blog_small_title', 'Lorem ipsum is simply dummy text' );
            set_theme_mod('ecommerce_landing_page_latest_post_author_icon', 'fas fa-user' );
            set_theme_mod('ecommerce_landing_page_latest_post_comments_icon', 'fas fa-comment' );
            set_theme_mod('ecommerce_landing_page_events_category', 'wiredheadphones' );
            
                // Define post category names and post titles
                $ecommerce_landing_page_category_names = array('wiredheadphones', 'postcategory2', 'postcategory3');
                $ecommerce_landing_page_title_array = array(
                    array("Lorem ipsum is simply dummy text of the printing and typesetting industry ", "Lorem ipsum is simply dummy text of the printing and typesetting industry", "Lorem ipsum is simply dummy text of the printing and typesetting industry"),
                    array("Wireless Headphones", "Wireless Headphones", "Wireless Headphones"),
                    array("Wireless Headphones", "Wireless Headphones", "Wireless Headphones")
                );
    
                foreach ($ecommerce_landing_page_category_names as $ecommerce_landing_page_index => $ecommerce_landing_page_category_name) {
                    // Create or retrieve the post category term ID
                    $ecommerce_landing_page_term = term_exists($ecommerce_landing_page_category_name, 'category');
                    if ($ecommerce_landing_page_term === 0 || $ecommerce_landing_page_term === null) {
                        // If the term does not exist, create it
                        $ecommerce_landing_page_term = wp_insert_term($ecommerce_landing_page_category_name, 'category');
                    }
                    if (is_wp_error($ecommerce_landing_page_term)) {
                        error_log('Error creating category: ' . $ecommerce_landing_page_term->get_error_message());
                        continue; // Skip to the next iteration if category creation fails
                    }
    
                    for ($ecommerce_landing_page_i = 0; $ecommerce_landing_page_i < 3; $ecommerce_landing_page_i++) {
                        // Create post content
                        $ecommerce_landing_page_title = $ecommerce_landing_page_title_array[$ecommerce_landing_page_index][$ecommerce_landing_page_i];
    
                        // Create post post object
                        $ecommerce_landing_page_my_post = array(
                            'post_title'    => wp_strip_all_tags($ecommerce_landing_page_title),
                            'post_status'   => 'publish',
                            'post_type'     => 'post', // Post type set to 'post'
                        );
    
                        // Insert the post into the database
                        $ecommerce_landing_page_post_id = wp_insert_post($ecommerce_landing_page_my_post);
    
                        update_post_meta($ecommerce_landing_page_post_id, 'ecommerce_landing_page_date', "25 Jan");
    
                        if (is_wp_error($ecommerce_landing_page_post_id)) {
                            error_log('Error creating post: ' . $ecommerce_landing_page_post_id->get_error_message());
                            continue; // Skip to the next post if creation fails
                        }
    
                        // Assign the category to the post
                        wp_set_post_categories($ecommerce_landing_page_post_id, array((int)$ecommerce_landing_page_term['term_id']));
    
                        // Handle the featured image using media_sideload_image
                        $ecommerce_landing_page_image_url = get_theme_file_uri() . '/assets/images/blog' . ($ecommerce_landing_page_i + 1) . '.png';
                        $ecommerce_landing_page_image_id = media_sideload_image($ecommerce_landing_page_image_url, $ecommerce_landing_page_post_id, null, 'id');
    
                        if (is_wp_error($ecommerce_landing_page_image_id)) {
                            error_log('Error downloading image: ' . $ecommerce_landing_page_image_id->get_error_message());
                            continue; // Skip to the next post if image download fails
                        }
                        // Assign featured image to post
                        set_post_thumbnail($ecommerce_landing_page_post_id, $ecommerce_landing_page_image_id);
                    }
                } 

            // Latest News And Blog Section
            set_theme_mod('master_education_feature_courses_tagline_title1', 'Our Service' );
            set_theme_mod('master_education_feature_courses_tagline_title', 'We Serve the Best Work' );
            set_theme_mod('ecommerce_landing_page_feature_category', 'postcategory1' );
            
                // Define post category names and post titles
                $master_education_category_names = array('postcategory1', 'postcategory2');
                $master_education_title_array = array(
                    array("Custom Software Development", "Web Development and Design", "Data Analytics and Business Intelligence"),
                    array("Custom Software Development", "Web Development and Design", "Data Analytics and Business Intelligence")
                );
    
                foreach ($master_education_category_names as $master_education_index => $master_education_category_name) {
                    // Create or retrieve the post category term ID
                    $master_education_term = term_exists($master_education_category_name, 'category');
                    if ($master_education_term === 0 || $master_education_term === null) {
                        // If the term does not exist, create it
                        $master_education_term = wp_insert_term($master_education_category_name, 'category');
                    }
                    if (is_wp_error($master_education_term)) {
                        error_log('Error creating category: ' . $master_education_term->get_error_message());
                        continue; // Skip to the next iteration if category creation fails
                    }
    
                    for ($master_education_i = 0; $master_education_i < 3; $master_education_i++) {
                        // Create post content
                        $master_education_title = $master_education_title_array[$master_education_index][$master_education_i];
                        $master_education_content = '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.';
    
                        // Create post post object
                        $master_education_my_post = array(
                            'post_title'    => wp_strip_all_tags($master_education_title),
                            'post_content'  => $master_education_content,
                            'post_status'   => 'publish',
                            'post_type'     => 'post', // Post type set to 'post'
                        );
    
                        // Insert the post into the database
                        $master_education_post_id = wp_insert_post($master_education_my_post);
    
                        if (is_wp_error($master_education_post_id)) {
                            error_log('Error creating post: ' . $master_education_post_id->get_error_message());
                            continue; // Skip to the next post if creation fails
                        }
    
                        // Assign the category to the post
                        wp_set_post_categories($master_education_post_id, array((int)$master_education_term['term_id']));
    
                        // Handle the featured image using media_sideload_image
                        $master_education_image_url = get_theme_file_uri() . '/assets/images/post' . ($master_education_i + 1) . '.png';
                        $master_education_image_id = media_sideload_image($master_education_image_url, $master_education_post_id, null, 'id');
    
                        if (is_wp_error($master_education_image_id)) {
                            error_log('Error downloading image: ' . $master_education_image_id->get_error_message());
                            continue; // Skip to the next post if image download fails
                        }
                        // Assign featured image to post
                        set_post_thumbnail($master_education_post_id, $master_education_image_id);
                    }
                } 
                        echo "<script>window.location.href='" . admin_url('themes.php?page=master_education_guide') . "';</script>";  
                        //Copyright Text
                        set_theme_mod( 'ecommerce_landing_page_footer_text', 'By VWThemes' );
        }
    ?>

    <form action="<?php echo esc_url(home_url()); ?>/wp-admin/themes.php?page=master_education_guide" method="POST" onsubmit="return validate(this);">
        <?php if (!get_option('ecommerce_landing_page_demo_import_completed')) : ?>
            <form method="post">   
            <p class="run-import-text"><?php esc_html_e('Click On The Below Run Importer Button To Import Demo Content Of Master Education', 'master-education'); ?></p>
                <p><?php esc_html_e('Please back up your website if it’s already live with data. This importer will overwrite your existing settings with the new customizer values for Master Education', 'master-education'); ?></p>
                <input class="run-import" type="submit" name="submit" value="<?php esc_attr_e('Run Importer', 'master-education'); ?>" class="button button-primary button-large">
          </form> 
        <?php endif; ?>
        <div id="spinner" style="display:none;">         
            <img src="<?php echo esc_url(get_theme_file_uri()); ?>/assets/images/spinner.png" alt="" />
        </div>
    </form>
    <script type="text/javascript">
        function validate(form) {
            if (confirm("Do you really want to import the theme demo content?")) {
                // Show the spinner
                document.getElementById('spinner').style.display = 'block';
                // Allow the form to be submitted
                return true;
            } 
            else {
                return false;
            }
        }
    </script>
</div>
