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

        // If the demo import is completed, display the "View Site" button
        if ($luxury_travel_demo_import_completed) {
        echo '<p class="notice-text">' . esc_html__('Your demo import has been completed successfully.', 'luxury-travel') . '</p>';
        echo '<span><a href="' . esc_url(home_url()) . '" class="import-btn site-btn" target="_blank">' . esc_html__('VISIT SITE', 'luxury-travel') . '</a></span>';
        echo '<span><a href="' . esc_url( admin_url('customize.php')) . '" class="import-btn site-btn" target="_blank">' . esc_html__('CUSTOMIZE', 'luxury-travel') . '</a></span>';
        }

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

        // Check if woocommerce is installed and activated
        if (!is_plugin_active('woocommerce/woocommerce.php')) {
            // Install the plugin if it doesn't exist
            $luxury_travel_plugin_slug = 'woocommerce';
            $luxury_travel_plugin_file = 'woocommerce/woocommerce.php';

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

        // ------- Create Main Menu --------
        $luxury_travel_menuname = 'Primary Menu';
        $luxury_travel_bpmenulocation = 'primary';
        $luxury_travel_menu_exists = wp_get_nav_menu_object( $luxury_travel_menuname );
    
        if ( !$luxury_travel_menu_exists ) {
            $luxury_travel_menu_id = wp_create_nav_menu( $luxury_travel_menuname );

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

            // Create a new Page 
            $luxury_travel_pages_title = 'Tours';
            $luxury_travel_pages_content = '<p>Explore all the pages we have on our website. Find information about our services, company, and more.</p>

                 Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960 with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<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.';
            $luxury_travel_pages = array(
                'post_type'    => 'page',
                'post_title'   => $luxury_travel_pages_title,
                'post_content' => $luxury_travel_pages_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'pages'
            );
            $luxury_travel_pages_id = wp_insert_post($luxury_travel_pages);
            // Add Pages Page to Menu
            wp_update_nav_menu_item($luxury_travel_menu_id, 0, array(
                'menu-item-title' => __('Tours', 'luxury-travel'),
                'menu-item-classes' => 'pages',
                'menu-item-url' => home_url('/pages/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $luxury_travel_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create About Us Page with Dummy Content
            $luxury_travel_about_title = 'Booking';
            $luxury_travel_about_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.';
            $luxury_travel_about = array(
                'post_type'    => 'page',
                'post_title'   => $luxury_travel_about_title,
                'post_content' => $luxury_travel_about_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'about-us'
            );
            $luxury_travel_about_id = wp_insert_post($luxury_travel_about);
            // Add About Us Page to Menu
            wp_update_nav_menu_item($luxury_travel_menu_id, 0, array(
                'menu-item-title' => __('Booking', 'luxury-travel'),
                'menu-item-classes' => 'about-us',
                'menu-item-url' => home_url('/about-us/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $luxury_travel_about_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));
            // Create Blog Page only if it doesn't exist already
            $luxury_travel_existing_blog_page = get_page_by_path('blog');
            if (!$luxury_travel_existing_blog_page) {
                $luxury_travel_blog_id = wp_insert_post(array(
                'post_type'    => 'page',
                'post_title'   => __('Blog', 'luxury-travel'),
                'post_content' => '',
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_name'    => 'blog'
             ));
            } else {
                $luxury_travel_blog_id = $luxury_travel_existing_blog_page->ID;
            }
            // Assign as Posts Page
            update_option('page_for_posts', $luxury_travel_blog_id);
            update_option('show_on_front', 'page');
            //Add to Menu (only if not already added)
            $luxury_travel_menu_items = wp_get_nav_menu_items($luxury_travel_menu_id);
            $luxury_travel_blog_in_menu = false;
            if ($luxury_travel_menu_items) {
                foreach ($luxury_travel_menu_items as $luxury_travel_item) {
                    if ((int) $luxury_travel_item->object_id === (int) $luxury_travel_blog_id) {
                        $luxury_travel_blog_in_menu = true;
                        break;
                    }
                }
            }
            if (!$luxury_travel_blog_in_menu) {
            wp_update_nav_menu_item($luxury_travel_menu_id, 0, array(
                'menu-item-title'       => __('Blog', 'luxury-travel'),
                'menu-item-url'         => home_url('/blog/'),
                'menu-item-status'      => 'publish',
                'menu-item-object-id'   => $luxury_travel_blog_id,
                'menu-item-object'      => 'page',
                'menu-item-type'        => 'post_type',
                'menu-item-classes'     => 'luxury-travel-blog-link'
            ));
            }
            // Create Shop Page only if it doesn't exist already
            $luxury_travel_existing_shop_page = get_page_by_path('shop');
            if (!$luxury_travel_existing_shop_page) {
            $luxury_travel_shop_id = wp_insert_post(array(
                'post_type'    => 'page',
                'post_title'   => __('Features', 'luxury-travel'),
                'post_content' => '',
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_name'    => 'shop' 
            ));
            } else {
                $luxury_travel_shop_id = $luxury_travel_existing_shop_page->ID;
            }
            // Assign as WooCommerce Shop Page
            update_option('woocommerce_shop_page_id', $luxury_travel_shop_id);
            // Add to Menu (only if not already added)
            $luxury_travel_menu_items = wp_get_nav_menu_items($luxury_travel_menu_id);
            $luxury_travel_shop_in_menu = false;

            if ($luxury_travel_menu_items) {
                foreach ($luxury_travel_menu_items as $luxury_travel_item) {
                    if ((int) $luxury_travel_item->object_id === (int) $luxury_travel_shop_id) {
                        $luxury_travel_shop_in_menu = true;
                        break;
                    }
                }
            }
            if (!$luxury_travel_shop_in_menu) {
            wp_update_nav_menu_item($luxury_travel_menu_id, 0, array(
                'menu-item-title'       => __('Features', 'luxury-travel'),
                'menu-item-url'         => home_url('/shop/'),
                'menu-item-status'      => 'publish',
                'menu-item-object-id'   => $luxury_travel_shop_id,
                'menu-item-object'      => 'page',
                'menu-item-type'        => 'post_type',
                'menu-item-classes'     => 'luxury-travel-shop-link'
            ));

             // Create About Us Page with Dummy Content
            $luxury_travel_about_title = 'Contact Us';
            $luxury_travel_about_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.';
            $luxury_travel_about = array(
                'post_type'    => 'page',
                'post_title'   => $luxury_travel_about_title,
                'post_content' => $luxury_travel_about_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'about-us'
            );
            $luxury_travel_about_id = wp_insert_post($luxury_travel_about);
            // Add About Us Page to Menu
            wp_update_nav_menu_item($luxury_travel_menu_id, 0, array(
                'menu-item-title' => __('Contact Us', 'luxury-travel'),
                'menu-item-classes' => 'about-us',
                'menu-item-url' => home_url('/about-us/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $luxury_travel_about_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));
            }
            // Assign the menu to the primary location if not already set
            if ( ! has_nav_menu( $luxury_travel_bpmenulocation ) ) {
                $luxury_travel_locations = get_theme_mod( 'nav_menu_locations' );
                if ( empty( $luxury_travel_locations ) ) {
                    $luxury_travel_locations = array();
                }
                $luxury_travel_locations[ $luxury_travel_bpmenulocation ] = $luxury_travel_menu_id;
                set_theme_mod( 'nav_menu_locations', $luxury_travel_locations );
            }
        }

        // Set the demo import completion flag
        update_option('luxury_travel_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.', 'luxury-travel') . '</p>';
        echo '<span><a href="' . esc_url(home_url()) . '" class="import-btn site-btn" target="_blank">' . esc_html__('VISIT SITE', 'luxury-travel') . '</a></span>';
        echo '<span><a href="' . esc_url( admin_url('customize.php')) . '" class="import-btn site-btn" target="_blank">' . esc_html__('CUSTOMIZE', 'luxury-travel') . '</a></span>';
        //end 

        //Topbar
        set_theme_mod( 'luxury_travel_search_placeholder', 'Search' );
        set_theme_mod( 'luxury_travel_call', '#' );
        set_theme_mod( 'luxury_travel_call_icon', 'fa fa-phone' );
        set_theme_mod( 'luxury_travel_mail', '#' );
        set_theme_mod( 'luxury_travel_mail', '#' );
      
        //Slider
        set_theme_mod( 'luxury_travel_show_slider', 'true' );
        set_theme_mod( 'luxury_travel_slidersettings', 'FIND OUT MORE' );
        set_theme_mod( 'luxury_travel_slider_button_link', '#' );
        set_theme_mod( 'luxury_travel_slider_button_label2', 'View More' );
        set_theme_mod( 'luxury_travel_slider_button_link2', '#' );
        
        $luxury_travel_slider_titles = [
           'Experience the World in Unmatched Luxury.',
            'Where Every Journey Becomes a Grand Story.',
          'Travel Beyond Expectations.',
            'Discover the Art of Luxurious Living.',
        ];   

        for($luxury_travel_i=1;$luxury_travel_i<=4;$luxury_travel_i++){
            $luxury_travel_slider_title = $luxury_travel_slider_titles[$luxury_travel_i - 1];
            $luxury_travel_slider_content = 'LOREM IPSUM DOLOR SIT AMET';
            // Create post object
            $luxury_travel_my_post = array(
                'post_title'    => wp_strip_all_tags( $luxury_travel_slider_title ),
                'post_content'  => $luxury_travel_slider_content,
                'post_status'   => 'publish',
                'post_type'     => 'page',
            );

        // Insert the post into the database
            $luxury_travel_post_id = wp_insert_post( $luxury_travel_my_post );

            if ($luxury_travel_post_id) {
                // Set the theme mod for the slider page
                set_theme_mod('luxury_travel_slidersettings_page' . $luxury_travel_i, $luxury_travel_post_id);

                $luxury_travel_image_url = get_template_directory_uri().'/images/slider'.$luxury_travel_i.'.jpg';

                $luxury_travel_image_id = media_sideload_image($luxury_travel_image_url, $luxury_travel_post_id, null, 'id');

                    if (!is_wp_error($luxury_travel_image_id)) {
                        // Set the downloaded image as the post's featured image
                        set_post_thumbnail($luxury_travel_post_id, $luxury_travel_image_id);
                    }
            }
        } 

        // social icons

        set_theme_mod( 'luxury_travel_show_icons', true );

        set_theme_mod( 'luxury_travel_facebook_url', '#' );
        set_theme_mod( 'luxury_travel_facebook_icon', 'fab fa-facebook-f' );

        set_theme_mod( 'luxury_travel_twitter_url', '#' );
        set_theme_mod( 'luxury_travel_twitter_icon', 'fab fa-twitter' );

        set_theme_mod( 'luxury_travel_insta_url', '#' );
        set_theme_mod( 'luxury_travel_insta_icon', 'fab fa-instagram' );

        set_theme_mod( 'luxury_travel_youtube_url', '#' );
        set_theme_mod( 'luxury_travel_youtube_icon', 'fab fa-youtube' );

        set_theme_mod( 'luxury_travel_pintrest_url', '#' );
        set_theme_mod( 'luxury_travel_pintrest_icon', 'fab fa-pinterest-p' );

        set_theme_mod( 'luxury_travel_social_icons_font_size', '15' );

        
        //Product Section
        set_theme_mod( 'luxury_travel_maintitle', 'DEALS AND DISCOUNT' );
        $luxury_travel_products = array(
            array(
                'title'        => 'Summer Travel Package',
                'regular'      => '120.00',
                'sale'         => '99.00',
                'image'        => get_template_directory_uri() . '/images/product1.png'
            ),
            array(
                'title'        => 'Holiday Discount Offer',
                'regular'      => '150.00',
                'sale'         => '120.00',
                'image'        => get_template_directory_uri() . '/images/product2.png'
            ),
            array(
                'title'        => 'Luxury Cruise Deal',
                'regular'      => '200.00',
                'sale'         => '170.00',
                'image'        => get_template_directory_uri() . '/images/product3.png'
            ),
            array(
                'title'        => 'Adventure Tour Sale',
                'regular'      => '180.00',
                'sale'         => '140.00',
                'image'        => get_template_directory_uri() . '/images/product4.png'
            ),
        );

        foreach ($luxury_travel_products as $luxury_travel_index => $luxury_travel_product) {

            $luxury_travel_post_id = wp_insert_post(array(
                'post_title'   => wp_strip_all_tags($luxury_travel_product['title']),
                'post_content' => 'Best deal for your next trip!',
                'post_status'  => 'publish',
                'post_type'    => 'product',
            ));

            if (is_wp_error($luxury_travel_post_id)) {
                continue;
            }

            update_post_meta($luxury_travel_post_id, '_regular_price', $luxury_travel_product['regular']);
            update_post_meta($luxury_travel_post_id, '_sale_price', $luxury_travel_product['sale']);
            update_post_meta($luxury_travel_post_id, '_price', $luxury_travel_product['sale']);

            include_once(ABSPATH . 'wp-admin/includes/image.php');
            include_once(ABSPATH . 'wp-admin/includes/file.php');
            include_once(ABSPATH . 'wp-admin/includes/media.php');

            $luxury_travel_tmp = download_url($luxury_travel_product['image']);

            if (is_wp_error($luxury_travel_tmp)) {
                continue;
            }

            $luxury_travel_file_array = array(
                'name'     => basename($luxury_travel_product['image']),
                'tmp_name' => $luxury_travel_tmp
            );

            $luxury_travel_image_id = media_handle_sideload($luxury_travel_file_array, $luxury_travel_post_id);

            if (!is_wp_error($luxury_travel_image_id)) {
                set_post_thumbnail($luxury_travel_post_id, $luxury_travel_image_id);
            }
        }

        $luxury_travel_query = new WP_Query(array(
            'post_type'      => 'page',
            'title'          => 'Products',
            'posts_per_page' => 1,
            'post_status'    => 'publish'
        ));

        $luxury_travel_page = ($luxury_travel_query->have_posts())
            ? $luxury_travel_query->posts[0]
            : false;

        if (!$luxury_travel_page) {

            $luxury_travel_page_id = wp_insert_post(array(
                'post_type'    => 'page',
                'post_title'   => 'Products',
                'post_content' => '[products limit="4" columns="4"]',
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_name'    => 'products'
            ));

        } else {
            $luxury_travel_page_id = $luxury_travel_page->ID;
        }

        

        set_theme_mod('luxury_travel_page0', $luxury_travel_page_id);


    // About Us section
    set_theme_mod( 'luxury_travel_about1', true );

     // Default About Section Title
    set_theme_mod( 'luxury_travel_sec1_title', 'About Us' );

    // Check if demo About post already exists (to avoid duplicates)
    $luxury_travel_existing_about = get_posts(array(
        'post_type'   => 'post',
        'post_status' => 'publish',
        'title'       => 'New Construction Project Management Service',
        'numberposts' => 1,
    ));

    if (!empty($luxury_travel_existing_about)) {
        // Use existing post (no duplication)
        $luxury_travel_about_post_id = $luxury_travel_existing_about[0]->ID;

    } else {
        // Create new demo post
        $luxury_travel_about_title = "Discover Exclusive Destinations";

    $luxury_travel_about_content = "At Luxury Travel, we craft unforgettable journeys for travelers who desire comfort, elegance, and curated experiences.
From private islands to 5-star resorts, exclusive safaris to personalized city tours, we ensure every moment of your trip reflects true sophistication.
Our team specializes in creating seamless itineraries that blend adventure, culture, and luxury—making every journey uniquely yours.";

    $luxury_travel_about_image_url = get_template_directory_uri() . '/images/postimg.png';

    // Insert Post
    $luxury_travel_about_post_data = array(
        'post_title'   => wp_strip_all_tags($luxury_travel_about_title),
        'post_content' => wp_kses_post($luxury_travel_about_content),
        'post_status'  => 'publish',
        'post_type'    => 'post',
    );

    $luxury_travel_about_post_id = wp_insert_post($luxury_travel_about_post_data);
    
    // Add Featured Image
    if (!is_wp_error($luxury_travel_about_post_id)) {

        $luxury_travel_image_id = media_sideload_image($luxury_travel_about_image_url, $luxury_travel_about_post_id, null, 'id');

        if (!is_wp_error($luxury_travel_image_id)) {
            set_post_thumbnail($luxury_travel_about_post_id, $luxury_travel_image_id);
        }
    }
}

// Save post ID to theme_mod
set_theme_mod('luxury_travel_about_setting', $luxury_travel_about_post_id);

        //Copyright Text
        set_theme_mod( 'luxury_travel_footer_text', 'By Themesglance' );

        }
    ?>

    <form action="<?php echo esc_url(home_url()); ?>/wp-admin/themes.php?page=luxury_travel_guide" method="POST" onsubmit="return validate(this);">
    <?php if (!get_option('luxury_travel_demo_import_completed')) : ?>
        <div class="demo-btn">
            <p><?php echo  esc_html_e( 'You are about to use the most easy to use and flexible WordPress theme.', 'luxury-travel' ); ?></p>
            <button id="import-button" type="submit" name="submit" class="import-btn run-import button-large">
                <?php esc_html_e('Run Importer', 'luxury-travel'); ?>
                    <span id="spinner" style="display: none;">
                        <img src="<?php echo esc_url(get_template_directory_uri()); ?>/images/spinner.gif" alt="Loading..." style="width:34px; height:34px; margin-left:10px;vertical-align: middle;" />
                    </span>
            </button>
        </div>
    <?php endif; ?>
    </form>
	<script type="text/javascript">
		function validate(valid) {
			 if(confirm("Do you really want to import the Demo Theme Content?")){
			    document.getElementById('spinner').style.display = 'inline-block';
			}
		    else {
			    return false;
		    }
		}
	</script>
</div>
