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

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

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

            // Check if Contact Form 7 is installed and activated
            if (!is_plugin_active('woocommerce/woocommerce.php')) {
              // Install the plugin if it doesn't exist
              $vw_tourism_plugin_slug = 'woocommerce';
              $vw_tourism_plugin_file = 'woocommerce/woocommerce.php';

              // Check if plugin is installed
              $vw_tourism_installed_plugins = get_plugins();
              if (!isset($vw_tourism_installed_plugins[$vw_tourism_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
                  $vw_tourism_upgrader = new Plugin_Upgrader();
                  $vw_tourism_upgrader->install('https://downloads.wordpress.org/plugin/woocommerce.latest-stable.zip');
              }
              // Activate the plugin
              activate_plugin($vw_tourism_plugin_file);
            }

            // 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
              $vw_tourism_plugin_slug = 'ibtana-visual-editor';
              $vw_tourism_plugin_file = 'ibtana-visual-editor/plugin.php';

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

            // ------- Create Nav Menu --------
            $vw_tourism_menuname = 'Main Menus';
            $vw_tourism_bpmenulocation = 'primary';
            $vw_tourism_menu_exists = wp_get_nav_menu_object($vw_tourism_menuname);

            if (!$vw_tourism_menu_exists) {
                $vw_tourism_menu_id = wp_create_nav_menu($vw_tourism_menuname);

                // Create Home Page
                $vw_tourism_home_title = 'Home';
                $vw_tourism_home = array(
                    'post_type' => 'page',
                    'post_title' => $vw_tourism_home_title,
                    'post_content' => '',
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'home'
                );
                $vw_tourism_home_id = wp_insert_post($vw_tourism_home);
                // Assign Home Page Template
                add_post_meta($vw_tourism_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', $vw_tourism_home_id);
                update_option('show_on_front', 'page');
                // Add Home Page to Menu
                wp_update_nav_menu_item($vw_tourism_menu_id, 0, array(
                    'menu-item-title' => __('Home', 'vw-tourism'),
                    'menu-item-classes' => 'home',
                    'menu-item-url' => home_url('/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $vw_tourism_home_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Pages Page with Dummy Content
                $vw_tourism_pages_title = 'Pages';
                $vw_tourism_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.';
                $vw_tourism_pages = array(
                    'post_type' => 'page',
                    'post_title' => $vw_tourism_pages_title,
                    'post_content' => $vw_tourism_pages_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'pages'
                );
                $vw_tourism_pages_id = wp_insert_post($vw_tourism_pages);
                // Add Pages Page to Menu
                wp_update_nav_menu_item($vw_tourism_menu_id, 0, array(
                    'menu-item-title' => __('Pages', 'vw-tourism'),
                    'menu-item-classes' => 'pages',
                    'menu-item-url' => home_url('/pages/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $vw_tourism_pages_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));
                
               // Create Destination Page with Dummy Content
                $vw_tourism_about_title = 'Destination';
                $vw_tourism_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.';
                $vw_tourism_about = array(
                    'post_type' => 'page',
                    'post_title' => $vw_tourism_about_title,
                    'post_content' => $vw_tourism_about_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'destination'
                );
                $vw_tourism_about_id = wp_insert_post($vw_tourism_about);
                // Add Destination Page to Menu
                wp_update_nav_menu_item($vw_tourism_menu_id, 0, array(
                    'menu-item-title' => __('Destination', 'vw-tourism'),
                    'menu-item-classes' => 'destination',
                    'menu-item-url' => home_url('/destination/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $vw_tourism_about_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create About Us Page with Dummy Content
                $vw_tourism_about_title = 'About Us';
                $vw_tourism_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.';
                $vw_tourism_about = array(
                    'post_type' => 'page',
                    'post_title' => $vw_tourism_about_title,
                    'post_content' => $vw_tourism_about_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'about-us'
                );
                $vw_tourism_about_id = wp_insert_post($vw_tourism_about);
                // Add About Us Page to Menu
                wp_update_nav_menu_item($vw_tourism_menu_id, 0, array(
                    'menu-item-title' => __('About Us', 'vw-tourism'),
                    'menu-item-classes' => 'about-us',
                    'menu-item-url' => home_url('/about-us/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $vw_tourism_about_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Blog Page 
                $vw_tourism_blog_page_title = 'Blog';
                $vw_tourism_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($vw_tourism_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ));
                if (!$vw_tourism_blog_page_query->have_posts()) {
                    $vw_tourism_blog_page = array(
                    'post_type'   => 'page',
                    'post_title'  => $vw_tourism_blog_page_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    );
                    $vw_tourism_blog_page_id = wp_insert_post($vw_tourism_blog_page);
                    update_option('page_for_posts', $vw_tourism_blog_page_id);
                    wp_update_nav_menu_item($vw_tourism_menu_id, 0, array(
                    'menu-item-title'      => __('Blog', 'vw-tourism'),
                    'menu-item-url'        => get_permalink($vw_tourism_blog_page_id),
                    'menu-item-status'     => 'publish',
                    'menu-item-object-id'  => $vw_tourism_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($vw_tourism_bpmenulocation)) {
                    $vw_tourism_locations = get_theme_mod('nav_menu_locations'); // Use 'nav_menu_locations' to get locations array
                    if (empty($vw_tourism_locations)) {
                        $vw_tourism_locations = array();
                    }
                    $vw_tourism_locations[$vw_tourism_bpmenulocation] = $vw_tourism_menu_id;
                    set_theme_mod('nav_menu_locations', $vw_tourism_locations);
                }
            }   

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

            // Top Bar //
            set_theme_mod( 'vw_tourism_search_open_icon', 'fas fa-search' ); 
            set_theme_mod( 'vw_tourism_search_close_icon', 'fa fa-window-close' );
            set_theme_mod( 'vw_tourism_myaccount_icon', 'fas fa-user' );    

            // slider section start //         
            set_theme_mod( 'vw_tourism_banner_image', get_template_directory_uri().'/assets/images/banner.png');
            set_theme_mod( 'vw_tourism_banner_top_text', 'Exclusive & Memorable' );
            set_theme_mod( 'vw_tourism_slider_main_title', 'FRANCE TOURISM' );
            set_theme_mod( 'vw_tourism_banner_bottom_text', 'Legal Assets Tourism LTD' );
            for($vw_tourism_i=1; $vw_tourism_i<=3; $vw_tourism_i++) {
                set_theme_mod( 'vw_tourism_service_banner_short_image'.$vw_tourism_i, get_template_directory_uri().'/assets/images/banner-left'.$vw_tourism_i.'.png' );
                set_theme_mod( 'vw_tourism_add_country_name'.$vw_tourism_i, 'Paris!' );               
            }  

            set_theme_mod( 'vw_tourism_service_banner_short_mid_image', get_template_directory_uri().'/assets/images/banner-middle.png');
            set_theme_mod( 'vw_tourism_add_mid_country_name', 'Paris!' );

            for($vw_tourism_i=1; $vw_tourism_i<=3; $vw_tourism_i++) {
                set_theme_mod( 'vw_tourism_service_banner_short_last_image'.$vw_tourism_i, get_template_directory_uri().'/assets/images/banner-right'.$vw_tourism_i.'.png' );
                set_theme_mod( 'vw_tourism_add_last_country_name'.$vw_tourism_i, 'Paris!' );              
            }  

            // Our Places Section //
            set_theme_mod( 'vw_tourism_feature_palces_section_text', 'Our Places' ); 
            set_theme_mod( 'vw_tourism_section_title', ' Our Popular Packages' );
            set_theme_mod( 'vw_tourism_services_number', '3' );            

            $vw_tourism_tab_text_array = array("Trending", "Duration", "Types");
            for($vw_tourism_tab_index=1; $vw_tourism_tab_index <= 3; $vw_tourism_tab_index++) {

              $theme_mod_key = 'vw_tourism_services_text' . $vw_tourism_tab_index;
              $theme_mod_value = $vw_tourism_tab_text_array[$vw_tourism_tab_index - 1];
              set_theme_mod($theme_mod_key, $theme_mod_value);
              // set_theme_mod($vw_tourism_services_text,$vw_tourism_tab_text_array);  

               set_theme_mod( 'vw_tourism_services_post_count' . $vw_tourism_tab_index, '4' ); 

               // select Post Box
                $vw_tourism_title_array = array("Lorem Ipsum is simply dummy text","Lorem Ipsum is simply dummy text","Lorem Ipsum is simply dummy text","Lorem Ipsum is simply dummy text");
                $vw_tourism_tag_array = array("PARIS TOUR","LYON TOUR","ROUEN TOUR","MARSEILLE TOUR");
                for ($vw_tourism_post_index = 1; $vw_tourism_post_index <= 4; $vw_tourism_post_index++) {

                    // Create post
                    $vw_tourism_title = $vw_tourism_title_array[$vw_tourism_post_index - 1];
                    $vw_tourism_tags = $vw_tourism_tag_array[$vw_tourism_post_index - 1];
                    // $vw_tourism_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.';            
                    $vw_tourism_my_post = array(
                         'post_title'   => wp_strip_all_tags($vw_tourism_title),
                         'post_status'  => 'publish',
                         'post_type'    => 'post',
                    );
                    $vw_tourism_post_id = wp_insert_post($vw_tourism_my_post);

                    // Check if the post was created successfully
                        if (!is_wp_error($vw_tourism_post_id)) {
                            // Set tags for the post
                            wp_set_post_tags($vw_tourism_post_id, $vw_tourism_tags);
                        }

                    set_theme_mod( 'vw_tourism_travel_name' .$vw_tourism_post_index . $vw_tourism_tab_index, 'Travel Name Here' ); 
                    set_theme_mod( 'vw_tourism_tour_title' .$vw_tourism_post_index . $vw_tourism_tab_index, 'FROM ILE DE FRANCE' ); 
                    set_theme_mod( 'vw_tourism_add_duration' .$vw_tourism_post_index . $vw_tourism_tab_index, '5 DAY 4 NIGHT' ); 
                    set_theme_mod( 'vw_tourism_tour_price' .$vw_tourism_post_index . $vw_tourism_tab_index, '$259.00' ); 
                    set_theme_mod('vw_tourism_services_category' . $vw_tourism_post_index . $vw_tourism_tab_index, $vw_tourism_post_id);
                    // Get image URL
                    $vw_tourism_image_url = get_template_directory_uri() . '/assets/images/image' . $vw_tourism_post_index . '.png';
                    $vw_tourism_image_data = wp_remote_get($vw_tourism_image_url);
                    if (!is_wp_error($vw_tourism_image_data)) {
                         $vw_tourism_image_body = wp_remote_retrieve_body($vw_tourism_image_data);
                         $vw_tourism_upload_dir = wp_upload_dir();
                         $vw_tourism_image_name = 'image' . $vw_tourism_post_index . '.png';
                         $uploaded_file = wp_upload_bits($vw_tourism_image_name, null, $vw_tourism_image_body);
                         if (!$uploaded_file['error']) {
                             // Set attachment data
                             $attachment = array(
                                 'post_mime_type' => $uploaded_file['type'],
                                 'post_title'     => sanitize_file_name($vw_tourism_image_name),
                                 'post_content'   => '',
                                 'post_status'    => 'inherit',
                             );
                             $vw_tourism_attach_id = wp_insert_attachment($attachment, $uploaded_file['file'], $vw_tourism_post_id);
                             require_once(ABSPATH . 'wp-admin/includes/image.php');
                             $vw_tourism_attach_data = wp_generate_attachment_metadata($vw_tourism_attach_id, $uploaded_file['file']);
                             wp_update_attachment_metadata($vw_tourism_attach_id, $vw_tourism_attach_data);
                             set_post_thumbnail($vw_tourism_post_id, $vw_tourism_attach_id);
                         }
                    }
                }  
            }  

            // Unique Offering Section//
            set_theme_mod( 'vw_tourism_special_text', 'ACTIVITY' ); 
            set_theme_mod( 'vw_tourism_special_heading', 'Unique Offering' );
            set_theme_mod( 'vw_tourism_offering_number', '6' ); 

            $vw_tourism_activity_text_array = array("Historical Places", "Exciting Baloon", "Hiking", "Magnificent Cities", "Rock Climbing", "Water Sports");

            $vw_tourism_activity_icon_array = array("fa-solid fa-building", "fa-solid fa-parachute-box", "fa-solid fa-person-hiking", "fa-solid fa-city", "fa-solid fa-mountain-sun", "fa-solid fa-person-snowboarding");

            for($vw_tourism_i=1; $vw_tourism_i <= 6; $vw_tourism_i++) {
                // title setting
                $theme_mod_key = 'vw_tourism_client_tagline_title' . $vw_tourism_i;
                $theme_mod_value = $vw_tourism_activity_text_array[$vw_tourism_i - 1];
                set_theme_mod($theme_mod_key, $theme_mod_value);  
                // title setting
                $theme_mod_key = 'vw_tourism_services_icon' . $vw_tourism_i;
                $theme_mod_value = $vw_tourism_activity_icon_array[$vw_tourism_i - 1];
                set_theme_mod($theme_mod_key, $theme_mod_value); 
                // paragraph setting
                set_theme_mod( 'vw_tourism_client_text'.$vw_tourism_i, 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.' ); 
            }

            //Copyright Text
            set_theme_mod( 'vw_tourism_footer_text', 'By VWThemes' );  
            set_theme_mod( 'vw_tourism_footer_support', 'Support' );
            set_theme_mod( 'vw_tourism_footer_support_link', '#' );      
            set_theme_mod( 'vw_tourism_footer_privacy_policy', 'Privacy' );
            set_theme_mod( 'vw_tourism_footer_privacy_policy_link', '#' );
            set_theme_mod( 'vw_tourism_footer_term_condition', 'Term & Condition' );
            set_theme_mod( 'vw_tourism_term_condition_link', '#' );   
            echo "<script>window.location.href='" . admin_url('themes.php?page=vw_tourism_guide') . "';</script>";   
        }
    ?>
  
    <form action="<?php echo esc_url(home_url()); ?>/wp-admin/themes.php?page=vw_tourism_guide" method="POST" onsubmit="return validate(this);">
        <?php if (!get_option('vw_tourism_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 vw tourism', 'vw-tourism'); ?></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 vw tourism', 'vw-tourism'); ?></p>
                <input class="run-import" type="submit" name="submit" value="<?php esc_attr_e('Run Importer', 'vw-tourism'); ?>" 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>

