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

    // If the demo import is completed, display the "View Site" button
    if ($vw_pet_care_demo_import_completed) {
      echo '<p class="notice-text">' . esc_html__('Your demo import has been completed successfully.', 'vw-pet-care') . '</p>';
      echo '<span><a href="' . esc_url(home_url()) . '" class="run-import view-site" target="_blank">' . esc_html__('View Site', 'vw-pet-care') . '</a></span>';
    }

		// POST and update the customizer and other related data
        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
          $vw_pet_care_plugin_slug = 'woocommerce';
          $vw_pet_care_plugin_file = 'woocommerce/woocommerce.php';

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

        // ------- Create Nav Menu --------
            $vw_pet_care_menuname = 'Main Menus';
            $vw_pet_care_bpmenulocation = 'primary';
            $vw_pet_care_menu_exists = wp_get_nav_menu_object($vw_pet_care_menuname);

            if (!$vw_pet_care_menu_exists) {
                $vw_pet_care_menu_id = wp_create_nav_menu($vw_pet_care_menuname);

                // Create Home Page
                $vw_pet_care_home_title = 'Home';
                $vw_pet_care_home = array(
                    'post_type' => 'page',
                    'post_title' => $vw_pet_care_home_title,
                    'post_content' => '',
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'home'
                );
                $vw_pet_care_home_id = wp_insert_post($vw_pet_care_home);
                // Assign Home Page Template
                add_post_meta($vw_pet_care_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_pet_care_home_id);
                update_option('show_on_front', 'page');
                // Add Home Page to Menu
                wp_update_nav_menu_item($vw_pet_care_menu_id, 0, array(
                    'menu-item-title' => __('Home', 'vw-pet-care'),
                    'menu-item-classes' => 'home',
                    'menu-item-url' => home_url('/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $vw_pet_care_home_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Pages Page with Dummy Content
                $vw_pet_care_pages_title = 'Pages';
                $vw_pet_care_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_pet_care_pages = array(
                    'post_type' => 'page',
                    'post_title' => $vw_pet_care_pages_title,
                    'post_content' => $vw_pet_care_pages_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'pages'
                );
                $vw_pet_care_pages_id = wp_insert_post($vw_pet_care_pages);
                // Add Pages Page to Menu
                wp_update_nav_menu_item($vw_pet_care_menu_id, 0, array(
                    'menu-item-title' => __('Pages', 'vw-pet-care'),
                    'menu-item-classes' => 'pages',
                    'menu-item-url' => home_url('/pages/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $vw_pet_care_pages_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create About Us Page with Dummy Content
                $vw_pet_care_about_title = 'About Us';
                $vw_pet_care_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_pet_care_about = array(
                    'post_type' => 'page',
                    'post_title' => $vw_pet_care_about_title,
                    'post_content' => $vw_pet_care_about_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'about-us'
                );
                $vw_pet_care_about_id = wp_insert_post($vw_pet_care_about);
                // Add About Us Page to Menu
                wp_update_nav_menu_item($vw_pet_care_menu_id, 0, array(
                    'menu-item-title' => __('About Us', 'vw-pet-care'),
                    'menu-item-classes' => 'about-us',
                    'menu-item-url' => home_url('/about-us/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $vw_pet_care_about_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Services Page with Dummy Content
                $vw_pet_care_services_title = 'Services';
                $vw_pet_care_services_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br>
                We provide professional pet grooming, training, veterinary support, and wellness services to ensure your pets live a healthy and happy life.';

                $vw_pet_care_services = array(
                    'post_type'    => 'page',
                    'post_title'   => $vw_pet_care_services_title,
                    'post_content' => $vw_pet_care_services_content,
                    'post_status'  => 'publish',
                    'post_author'  => 1,
                    'post_slug'    => 'services'
                );

                $vw_pet_care_services_id = wp_insert_post($vw_pet_care_services);

                // Add Services Page to Menu
                wp_update_nav_menu_item($vw_pet_care_menu_id, 0, array(
                    'menu-item-title'     => __('Services', 'vw-pet-care'),
                    'menu-item-classes'  => 'services',
                    'menu-item-url'      => home_url('/services/'),
                    'menu-item-status'   => 'publish',
                    'menu-item-object-id'=> $vw_pet_care_services_id,
                    'menu-item-object'   => 'page',
                    'menu-item-type'     => 'post_type'
                ));

                // Create Adopt Page with Dummy Content
                $vw_pet_care_adopt_title = 'Adopt';
                $vw_pet_care_adopt_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br>
                Adopt a loving pet and give them a forever home. Our adoption process is simple and transparent.';

                $vw_pet_care_adopt = array(
                    'post_type'    => 'page',
                    'post_title'   => $vw_pet_care_adopt_title,
                    'post_content' => $vw_pet_care_adopt_content,
                    'post_status'  => 'publish',
                    'post_author'  => 1,
                    'post_slug'    => 'adopt'
                );

                $vw_pet_care_adopt_id = wp_insert_post($vw_pet_care_adopt);

                // Add Adopt Page to Menu
                wp_update_nav_menu_item($vw_pet_care_menu_id, 0, array(
                    'menu-item-title'     => __('Adopt', 'vw-pet-care'),
                    'menu-item-classes'  => 'adopt',
                    'menu-item-url'      => home_url('/adopt/'),
                    'menu-item-status'   => 'publish',
                    'menu-item-object-id'=> $vw_pet_care_adopt_id,
                    'menu-item-object'   => 'page',
                    'menu-item-type'     => 'post_type'
                ));

                // Create Rescue Page with Dummy Content
                $vw_pet_care_rescue_title = 'Rescue';
                $vw_pet_care_rescue_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br>
                We rescue abandoned, injured, and neglected animals and provide them with medical care and shelter.';

                $vw_pet_care_rescue = array(
                    'post_type'    => 'page',
                    'post_title'   => $vw_pet_care_rescue_title,
                    'post_content' => $vw_pet_care_rescue_content,
                    'post_status'  => 'publish',
                    'post_author'  => 1,
                    'post_slug'    => 'rescue'
                );

                $vw_pet_care_rescue_id = wp_insert_post($vw_pet_care_rescue);

                // Add Rescue Page to Menu
                wp_update_nav_menu_item($vw_pet_care_menu_id, 0, array(
                    'menu-item-title'     => __('Rescue', 'vw-pet-care'),
                    'menu-item-classes'  => 'rescue',
                    'menu-item-url'      => home_url('/rescue/'),
                    'menu-item-status'   => 'publish',
                    'menu-item-object-id'=> $vw_pet_care_rescue_id,
                    'menu-item-object'   => 'page',
                    'menu-item-type'     => 'post_type'
                ));

                // Create Shop Page with Dummy Content
                $vw_pet_care_shop_title = 'Shop';
                $vw_pet_care_shop_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br>
                Shop premium pet food, toys, accessories, grooming products, and care essentials.';

                $vw_pet_care_shop = array(
                    'post_type'    => 'page',
                    'post_title'   => $vw_pet_care_shop_title,
                    'post_content' => $vw_pet_care_shop_content,
                    'post_status'  => 'publish',
                    'post_author'  => 1,
                    'post_slug'    => 'shop'
                );

                $vw_pet_care_shop_id = wp_insert_post($vw_pet_care_shop);

                // Add Shop Page to Menu
                wp_update_nav_menu_item($vw_pet_care_menu_id, 0, array(
                    'menu-item-title'     => __('Shop', 'vw-pet-care'),
                    'menu-item-classes'  => 'shop',
                    'menu-item-url'      => home_url('/shop/'),
                    'menu-item-status'   => 'publish',
                    'menu-item-object-id'=> $vw_pet_care_shop_id,
                    'menu-item-object'   => 'page',
                    'menu-item-type'     => 'post_type'
                ));

                 // Create Blog Page 
                $vw_pet_care_blog_page_title = 'Blog';
                $vw_pet_care_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($vw_pet_care_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ));
                if (!$vw_pet_care_blog_page_query->have_posts()) {
                    $vw_pet_care_blog_page = array(
                    'post_type'   => 'page',
                    'post_title'  => $vw_pet_care_blog_page_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    );
                    $vw_pet_care_blog_page_id = wp_insert_post($vw_pet_care_blog_page);
                    update_option('page_for_posts', $vw_pet_care_blog_page_id);
                    wp_update_nav_menu_item($vw_pet_care_menu_id, 0, array(
                    'menu-item-title'      => __('Blog', 'vw-pet-care'),
                    'menu-item-url'        => get_permalink($vw_pet_care_blog_page_id),
                    'menu-item-status'     => 'publish',
                    'menu-item-object-id'  => $vw_pet_care_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_pet_care_bpmenulocation)) {
                    $locations = get_theme_mod('nav_menu_locations'); // Use 'nav_menu_locations' to get locations array
                    if (empty($locations)) {
                        $locations = array();
                    }
                    $locations[$vw_pet_care_bpmenulocation] = $vw_pet_care_menu_id;
                    set_theme_mod('nav_menu_locations', $locations);
                }

        }  


        // Set the demo import completion flag
        update_option('vw_pet_care_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-pet-care') . '</p>';
        echo '<span><a href="' . esc_url(home_url()) . '" class="run-import view-site" target="_blank">' . esc_html__('View Site', 'vw-pet-care') . '</a></span>';

        //end     

        // Top Bar start //
            set_theme_mod('vw_pet_care_topbar_hide_show',true);
            set_theme_mod( 'vw_pet_care_total_order', 'Welcome to pets WordPress Theme' ); 
            set_theme_mod( 'vw_pet_care_phone_number_text', 'Phone:' );
            set_theme_mod( 'vw_pet_care_phone_number', '+0123456789' ); 
            set_theme_mod( 'vw_pet_care_phone_icon', 'fas fa-phone' ); 
            set_theme_mod( 'vw_pet_care_search_topbar_icon', 'fas fa-search' );
            set_theme_mod( 'vw_pet_care_cart_topbar_icon', 'fas fa-shopping-cart' );
            set_theme_mod( 'vw_pet_care_topbar_button_label', 'Join Rescue Team' );
            set_theme_mod( 'vw_pet_care_topbar_button_url', '#' );
            set_theme_mod( 'vw_pet_care_topbar_icon', 'fas fa-long-arrow-alt-right' );


        // slider section start //   
            set_theme_mod('vw_pet_care_slider_hide_show',true);
            set_theme_mod( 'vw_pet_care_banner_image', get_template_directory_uri().'/assets/images/defaultbanner.png');

            set_theme_mod( 'vw_pet_care_slide_number', '3' );
        for($vw_pet_care_i=1; $vw_pet_care_i<=3; $vw_pet_care_i++) {
            set_theme_mod( 'vw_pet_care_designation_small_text'.$vw_pet_care_i, 'WELCOME TO PETS HOME' );
            set_theme_mod( 'vw_pet_care_tagline_title'.$vw_pet_care_i, 'We love pets because they love us to' ); 
            set_theme_mod( 'vw_pet_care_designation_text'.$vw_pet_care_i, 'It i a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.' );
            set_theme_mod( 'vw_pet_care_banner_button_label'.$vw_pet_care_i, 'Discover More' ); 
            set_theme_mod( 'vw_pet_care_top_button_url'.$vw_pet_care_i, '#' );

            set_theme_mod( 'vw_pet_care_banner_background_image_sec'.$vw_pet_care_i, get_template_directory_uri().'/assets/images/slider'.$vw_pet_care_i.'.png' );                       
        }  

        // Popular Section start //
            set_theme_mod( 'vw_pet_care_services_small_title', 'What We Offer For You' ); 
            set_theme_mod( 'vw_pet_care_services_heading', 'Our Services' );
            set_theme_mod( 'vw_pet_care_service_background_icon', 'fas fa-paw' );

        // select Post Box
        $vw_pet_care_service_title_array = array("Pet Grooming", "Vaccination", "Vaternary", "Healthy Meal");

        $vw_pet_care_service_icon_array = array("fa-solid fa-dog", "fa-solid fa-syringe", "fa-solid fa-user-doctor", "fa-solid fa-bowl-food");

        for ($vw_pet_care_i = 1; $vw_pet_care_i <= 4; $vw_pet_care_i++) {

            // title setting
            $theme_mod_key = 'vw_pet_care_service_service_top_icon' . $vw_pet_care_i;
            $theme_mod_value = $vw_pet_care_service_icon_array[$vw_pet_care_i - 1];
            set_theme_mod($theme_mod_key, $theme_mod_value); 

            set_theme_mod( 'vw_pet_care_service_button_label'.$vw_pet_care_i, 'Know More' );
            set_theme_mod( 'vw_pet_care_service_button_arrow_icon'.$vw_pet_care_i, 'fas fa-long-arrow-alt-right' );

            // Create post
            $vw_pet_care_title = $vw_pet_care_service_title_array[$vw_pet_care_i - 1];
            $vw_pet_care_content = 'Lorem Ipsum is simply dummy text of the printing and type setting industry.';            
            $vw_pet_care_my_post = array(
                 'post_title'   => wp_strip_all_tags($vw_pet_care_title),
                 'post_content' => $vw_pet_care_content,
                 'post_status'  => 'publish',
                 'post_type'    => 'post',
            );
            $vw_pet_care_post_id = wp_insert_post($vw_pet_care_my_post);         
            set_theme_mod('vw_pet_care_services_category' . $vw_pet_care_i, $vw_pet_care_post_id);
        }                   
    }
  ?>
  
	<form action="<?php echo esc_url(home_url()); ?>/wp-admin/themes.php?page=vw_pet_care_guide" method="POST" onsubmit="return validate(this);">
    <?php if (!get_option('vw_pet_care_demo_import_completed')) : ?>
        <form method="post">
        <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 Pet Care','vw-pet-care'); ?></p>
            <input class= "run-import" type="submit" name="submit" value="<?php esc_attr_e('Run Importer','vw-pet-care'); ?>" class="button button-primary button-large">
        </form>
    <?php endif; ?>
    </form>
    <script type="text/javascript">
        function validate(valid) {
             if(confirm("Do you really want to import the theme demo content?")){
                document.forms[0].submit();
            }
            else {
                return false;
            }
        }
    </script>
</div>

