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

        // If the demo import is completed, display the "View Site" button
        if ($immigration_consulting_demo_import_completed) {
        echo '<p class="notice-text">' . esc_html__('Your demo import has been completed successfully.', 'immigration-consulting') . '</p>';
        echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('View Site', 'immigration-consulting') . '</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', 'immigration-consulting' ) .'</a></span>';
        echo '<span><a href="'. esc_url( 'https://preview.vwthemesdemo.com/docs/free-immigration-consulting/' ) .'" class="button button-primary doc-btn" target=_blank>'. esc_html__( 'Free Theme Documentation', 'immigration-consulting' ) .'</a></span>';
    }

		// POST and update the customizer and other related data of THE COURIER SERVICESPRO
        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
          $immigration_consulting_plugin_slug = 'ibtana-visual-editor';
          $immigration_consulting_plugin_file = 'ibtana-visual-editor/plugin.php';

          // Check if plugin is installed
          $immigration_consulting_installed_plugins = get_plugins();
          if (!isset($immigration_consulting_installed_plugins[$immigration_consulting_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
              $immigration_consulting_upgrader = new Plugin_Upgrader();
              $immigration_consulting_upgrader->install('https://downloads.wordpress.org/plugin/ibtana-visual-editor.latest-stable.zip');
          }
          // Activate the plugin
          activate_plugin($immigration_consulting_plugin_file);
        }  

        // ------- Create Nav Menu --------
        $immigration_consulting_menuname = 'Main Menus';
        $immigration_consulting_bpmenulocation = 'primary';
        $immigration_consulting_menu_exists = wp_get_nav_menu_object($immigration_consulting_menuname);

        if (!$immigration_consulting_menu_exists) {
            $immigration_consulting_menu_id = wp_create_nav_menu($immigration_consulting_menuname);

            // Create Home Page
            $immigration_consulting_home_title = 'Home';
            $immigration_consulting_home = array(
                'post_type' => 'page',
                'post_title' => $immigration_consulting_home_title,
                'post_content' => '',
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'home'
            );
            $immigration_consulting_home_id = wp_insert_post($immigration_consulting_home);
            // Assign Home Page Template
            add_post_meta($immigration_consulting_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', $immigration_consulting_home_id);
            update_option('show_on_front', 'page');
            // Add Home Page to Menu
            wp_update_nav_menu_item($immigration_consulting_menu_id, 0, array(
                'menu-item-title' => __('Home', 'immigration-consulting'),
                'menu-item-classes' => 'home',
                'menu-item-url' => home_url('/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $immigration_consulting_home_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create Visa Page with Dummy Content
            $immigration_consulting_pages_title = 'Visa';
            $immigration_consulting_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.';
            $immigration_consulting_pages = array(
                'post_type' => 'page',
                'post_title' => $immigration_consulting_pages_title,
                'post_content' => $immigration_consulting_pages_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'pages'
            );
            $immigration_consulting_pages_id = wp_insert_post($immigration_consulting_pages);
            // Add Visa Page to Menu
            wp_update_nav_menu_item($immigration_consulting_menu_id, 0, array(
                'menu-item-title' => __('Visa', 'immigration-consulting'),
                'menu-item-classes' => 'pages',
                'menu-item-url' => home_url('/pages/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $immigration_consulting_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            $immigration_consulting_pages_title = 'Countries';
            $immigration_consulting_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.';
            $immigration_consulting_pages = array(
                'post_type' => 'page',
                'post_title' => $immigration_consulting_pages_title,
                'post_content' => $immigration_consulting_pages_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'pages'
            );
            $immigration_consulting_pages_id = wp_insert_post($immigration_consulting_pages);
            // Add Countries Page to Menu
            wp_update_nav_menu_item($immigration_consulting_menu_id, 0, array(
                'menu-item-title' => __('Countries', 'immigration-consulting'),
                'menu-item-classes' => 'pages',
                'menu-item-url' => home_url('/pages/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $immigration_consulting_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            $immigration_consulting_pages_title = 'Service';
            $immigration_consulting_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.';
            $immigration_consulting_pages = array(
                'post_type' => 'page',
                'post_title' => $immigration_consulting_pages_title,
                'post_content' => $immigration_consulting_pages_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'pages'
            );
            $immigration_consulting_pages_id = wp_insert_post($immigration_consulting_pages);
            // Add Service Page to Menu
            wp_update_nav_menu_item($immigration_consulting_menu_id, 0, array(
                'menu-item-title' => __('Service', 'immigration-consulting'),
                'menu-item-classes' => 'pages',
                'menu-item-url' => home_url('/pages/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $immigration_consulting_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create Blog Page 
                $immigration_consulting_blog_page_title = 'Blog';

                $immigration_consulting_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($immigration_consulting_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ));
                if (!$immigration_consulting_blog_page_query->have_posts()) {
                    $immigration_consulting_blog_page = array(
                        'post_type'   => 'page',
                        'post_title'  => $immigration_consulting_blog_page_title,
                        'post_status' => 'publish',
                        'post_author' => 1,
                    );
                    $immigration_consulting_blog_page_id = wp_insert_post($immigration_consulting_blog_page);
                    update_option('page_for_posts', $immigration_consulting_blog_page_id);

                    wp_update_nav_menu_item($immigration_consulting_menu_id, 0, array(
                        'menu-item-title'      => __('Blog', 'immigration-consulting'),
                        'menu-item-url'        => get_permalink($immigration_consulting_blog_page_id),
                        'menu-item-status'     => 'publish',
                        'menu-item-object-id'  => $immigration_consulting_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($immigration_consulting_bpmenulocation)) {
                $immigration_consulting_locations = get_theme_mod('nav_menu_locations'); // Use 'nav_menu_locations' to get locations array
                if (empty($immigration_consulting_locations)) {
                    $immigration_consulting_locations = array();
                }
                $immigration_consulting_locations[$immigration_consulting_bpmenulocation] = $immigration_consulting_menu_id;
                set_theme_mod('nav_menu_locations', $immigration_consulting_locations);
            }
        }

        // Set the demo import completion flag
		update_option('immigration_consulting_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.', 'immigration-consulting') . '</p>';
		echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('View Site', 'immigration-consulting') . '</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', 'immigration-consulting' ) .'</a></span>';
        echo '<span><a href="'. esc_url( 'https://preview.vwthemesdemo.com/docs/free-immigration-consulting/' ) .'" class="button button-primary doc-btn" target=_blank>'. esc_html__( 'Free Theme Documentation', 'immigration-consulting' ) .'</a></span>';
        //end 

        // Topbar
        set_theme_mod( 'immigration_consulting_topbar_text', 'Welcome to Immigration and Visa Consulting Company' );
        set_theme_mod( 'immigration_consulting_topbar_button_label', 'Book A Visit' );
        set_theme_mod( 'immigration_consulting_topbar_button_url', '#' );
        
        // Slider Settings
        set_theme_mod( 'immigration_consulting_banner_bg_img', get_template_directory_uri().'/assets/images/banner-img.png' );
        set_theme_mod( 'immigration_consulting_banner_title', 'World Most Trusted Immigration Company' );
        set_theme_mod( 'immigration_consulting_banner_text', 'Your Gateway to Global Opportunities – Simplifying Immigration with Expertise' );
        set_theme_mod( 'immigration_consulting_banner_button_label', 'Book A Visit' );
        set_theme_mod( 'immigration_consulting_banner_button_url', '#' );

        // Guidance Section
        set_theme_mod( 'immigration_consulting_guidance_bg_img', get_template_directory_uri().'/assets/images/guidance-bg.png' );
        set_theme_mod( 'immigration_consulting_guidance_section_title', 'Dependable and Trustworthy Visa & Immigration Guidance' );
        set_theme_mod( 'immigration_consulting_guidance_section_text', 'Our team of seasoned professionals understands the complexities of immigration laws and visa procedures' );
    
        $immigration_consulting_box_title = array('Choose your visa type', 'Contact our branch', 'Submit all your documents', 'Passport delivery'
        );
        for ($immigration_consulting_i = 0; $immigration_consulting_i < 4; $immigration_consulting_i++) {
            set_theme_mod('immigration_consulting_guidance_info_box_title' . ($immigration_consulting_i + 1), $immigration_consulting_box_title[$immigration_consulting_i]);
            set_theme_mod('immigration_consulting_guidance_info_box_title_link' . ($immigration_consulting_i + 1), '#');
            set_theme_mod('immigration_consulting_guidance_info_box_text' . ($immigration_consulting_i + 1), 'Determine the Visa type for your travel purpose');
        }

        echo "<script>window.location.href='" . admin_url('themes.php?page=immigration_consulting_guide') . "';</script>";
        //Copyright Text
        set_theme_mod( 'immigration_consulting_footer_text', 'By VWThemes' );  
    }
    ?>
  
    <form action="<?php echo esc_url(home_url()); ?>/wp-admin/themes.php?page=immigration_consulting_guide" method="POST" onsubmit="return validate(this);">
        <?php if (!get_option('immigration_consulting_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 immigration consulting', 'immigration-consulting'); ?></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 immigration consulting', 'immigration-consulting'); ?></p>
                <input class="run-import" type="submit" name="submit" value="<?php esc_attr_e('Run Importer', 'immigration-consulting'); ?>" class="button button-primary button-large">
        </form> 
        <?php endif; ?>
        <div id="spinner" style="display:none;">         
            <img src="<?php echo esc_url(get_template_directory_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>
