<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', 'services-landing-page' ) .'</a></span>';
        echo '<span><a href="'. esc_url( 'https://preview.vwthemesdemo.com/docs/free-services-landing-page/' ) .'" class="button button-primary doc-btn" target=_blank>'. esc_html__( 'Free Theme Documentation', 'services-landing-page' ) .'</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
              $services_landing_page_plugin_slug = 'ibtana-visual-editor';
              $services_landing_page_plugin_file = 'ibtana-visual-editor/plugin.php';

              // Check if plugin is installed
              $services_landing_page_installed_plugins = get_plugins();
              if (!isset($services_landing_page_installed_plugins[$services_landing_page_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
                  $services_landing_page_upgrader = new Plugin_Upgrader();
                  $services_landing_page_upgrader->install('https://downloads.wordpress.org/plugin/ibtana-visual-editor.latest-stable.zip');
              }
              // Activate the plugin
              activate_plugin($services_landing_page_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 Services Page */
                $ecommerce_landing_page_services_title = 'Services';
                $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.<br>
                Our services are designed to help businesses grow faster, sell smarter, and deliver better customer experiences.';

                $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'  => __('Services', '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 Experts Page  */
                $ecommerce_landing_page_experts_title = 'Experts';
                $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.<br>
                We work collaboratively to deliver innovative solutions and measurable business results.';

                $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'  => __('Experts', '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', 'services-landing-page' ) .'</a></span>';
            echo '<span><a href="'. esc_url( 'https://preview.vwthemesdemo.com/docs/free-services-landing-page/' ) .'" class="button button-primary doc-btn" target=_blank>'. esc_html__( 'Free Theme Documentation', 'services-landing-page' ) .'</a></span>';
            //end


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

            // slider section start //
            set_theme_mod( 'ecommerce_landing_page_tagline_title', 'For All Your Big And Small Repaire & Maintenance Needs' );
            set_theme_mod( 'ecommerce_landing_page_designation_text', 'Lorem ipsum is simply dummy text of the printing and typesetting industry. ipsum is simply dummy text of the printing and typesetting industry.' );
            set_theme_mod( 'ecommerce_landing_page_banner_button_label', 'Get Free Quote' );           
            set_theme_mod( 'ecommerce_landing_page_top_button_url', '#' );

            set_theme_mod( 'services_landing_page_video_button_icon', 'fas fa-play' );
            set_theme_mod( 'services_landing_page_video_button_text', 'How We Work' );
            set_theme_mod( 'services_landing_page_video_button_url', '#' );
            set_theme_mod( 'services_landing_page_banner_image', get_theme_file_uri().'/assets/images/cleaner-free.png');
            set_theme_mod( 'services_landing_page_activecientcount_icon', 'fas fa-bolt' );
            set_theme_mod( 'services_landing_page_activecientcount_title', 'Bolt' );
            set_theme_mod( 'services_landing_page_activecientcount_icon1', 'fa-solid fa-fan' );
            set_theme_mod( 'services_landing_page_activecientcount_title1', 'Fan' );
            set_theme_mod( 'services_landing_page_activecientcount_icon2', 'fas fa-wrench' );
            set_theme_mod( 'services_landing_page_activecientcount_title2', 'Wrench' );
            set_theme_mod( 'services_landing_page_activecientcount_icon3', 'fas fa-screwdriver' );
            set_theme_mod( 'services_landing_page_activecientcount_title3', 'Screwdriver' );
            set_theme_mod( 'services_landing_page_activecientcount_icon4', 'fas fa-palette' );
            set_theme_mod( 'services_landing_page_activecientcount_title4', 'Palette' );
            set_theme_mod( 'services_landing_page_activecientcount_icon5', 'fas fa-gavel' );
            set_theme_mod( 'services_landing_page_activecientcount_title5', 'Gavel' );


            // 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);
                    }
                } 

            // About Section
            set_theme_mod( 'services_landing_page_service_banner_image', get_theme_file_uri().'/assets/images/man.png');
            set_theme_mod( 'services_landing_page_service_smallbanner_image', get_theme_file_uri().'/assets/images/girl.png');
            set_theme_mod( 'services_landing_page_professional_image', get_theme_file_uri().'/assets/images/engineer.png');
            set_theme_mod('services_landing_page_professional_title', 'Professional' );
            set_theme_mod('services_landing_page_service_title1', '20 year of experience in All Services & Maintenance' );
            set_theme_mod('services_landing_page_service_para', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy' );


            $services_landing_page_page_list_array = array("High quality tools and technology in use", "Regular solution give for home problems by handyman","Office Desk and Floor Cleaning Services", "Be accesible at desk and meeting in offices");

             for($services_landing_page_i=1; $services_landing_page_i<=4; $services_landing_page_i++) {
                // list icon and title setting
                $services_landing_page_theme_mod_key = 'services_landing_page_page_list' . $services_landing_page_i;
                $services_landing_page_theme_mod_value = $services_landing_page_page_list_array[$services_landing_page_i - 1];
                set_theme_mod($services_landing_page_theme_mod_key, $services_landing_page_theme_mod_value); 
    
                set_theme_mod( 'services_landing_page_list_icon'.$services_landing_page_i, 'fas fa-check' );            
            }

            set_theme_mod( 'services_landing_page_service_author_image', get_theme_file_uri().'/assets/images/profile.png');
            set_theme_mod('services_landing_page_author_title', 'James Bond' );
            set_theme_mod('services_landing_page_author_text', 'CEO' );
                
                    
            //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=services_landing_page_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 services landing page', 'services-landing-page'); ?></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 services landing page', 'services-landing-page'); ?></p>
                <input class="run-import" type="submit" name="submit" value="<?php esc_attr_e('Run Importer', 'services-landing-page'); ?>" 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>
