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

        // If the demo import is completed, display the "View Site" button
        if ($repair_shop_demo_import_completed) {
        echo '<p class="notice-text">' . esc_html__('Your demo import has been completed successfully.', 'repair-shop') . '</p>';
        echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('View Site', 'repair-shop') . '</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
          $repair_shop_plugin_slug = 'ibtana-visual-editor';
          $repair_shop_plugin_file = 'ibtana-visual-editor/plugin.php';

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

        // ------- Create Nav Menu --------
        $repair_shop_menuname = 'Main Menus';
        $repair_shop_bpmenulocation = 'primary';
        $repair_shop_menu_exists = wp_get_nav_menu_object($repair_shop_menuname);

        if (!$repair_shop_menu_exists) {
            $repair_shop_menu_id = wp_create_nav_menu($repair_shop_menuname);

            // Create Home Page
            $repair_shop_home_title = 'Home';
            $repair_shop_home = array(
                'post_type' => 'page',
                'post_title' => $repair_shop_home_title,
                'post_content' => '',
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'home'
            );
            $repair_shop_home_id = wp_insert_post($repair_shop_home);
            // Assign Home Page Template
            add_post_meta($repair_shop_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', $repair_shop_home_id);
            update_option('show_on_front', 'page');
            // Add Home Page to Menu
            wp_update_nav_menu_item($repair_shop_menu_id, 0, array(
                'menu-item-title' => __('Home', 'repair-shop'),
                'menu-item-classes' => 'home',
                'menu-item-url' => home_url('/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $repair_shop_home_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create About with Dummy Content
            $repair_shop_pages_title = 'About Us';
            $repair_shop_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.';
            $repair_shop_pages = array(
                'post_type' => 'page',
                'post_title' => $repair_shop_pages_title,
                'post_content' => $repair_shop_pages_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'pages'
            );
            $repair_shop_pages_id = wp_insert_post($repair_shop_pages);
            // Add Pages Page to Menu
            wp_update_nav_menu_item($repair_shop_menu_id, 0, array(
                'menu-item-title' => __('About Us', 'repair-shop'),
                'menu-item-classes' => 'pages',
                'menu-item-url' => home_url('/pages/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $repair_shop_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create About Us Page with Dummy Content
            $repair_shop_about_title = 'Services';
            $repair_shop_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.';
            $repair_shop_about = array(
                'post_type' => 'page',
                'post_title' => $repair_shop_about_title,
                'post_content' => $repair_shop_about_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'about-us'
            );
            $repair_shop_about_id = wp_insert_post($repair_shop_about);
            // Add About Us Page to Menu
            wp_update_nav_menu_item($repair_shop_menu_id, 0, array(
                'menu-item-title' => __('Services', 'repair-shop'),
                'menu-item-classes' => 'about-us',
                'menu-item-url' => home_url('/about-us/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $repair_shop_about_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create About Us Page with Dummy Content
            $repair_shop_about_title = 'Product';
            $repair_shop_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.';
            $repair_shop_about = array(
                'post_type' => 'page',
                'post_title' => $repair_shop_about_title,
                'post_content' => $repair_shop_about_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'about-us'
            );
            $repair_shop_about_id = wp_insert_post($repair_shop_about);
            // Add About Us Page to Menu
            wp_update_nav_menu_item($repair_shop_menu_id, 0, array(
                'menu-item-title' => __('Product', 'repair-shop'),
                'menu-item-classes' => 'about-us',
                'menu-item-url' => home_url('/about-us/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $repair_shop_about_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create About Us Page with Dummy Content
            $repair_shop_about_title = 'Pages';
            $repair_shop_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.';
            $repair_shop_about = array(
                'post_type' => 'page',
                'post_title' => $repair_shop_about_title,
                'post_content' => $repair_shop_about_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'about-us'
            );
            $repair_shop_about_id = wp_insert_post($repair_shop_about);
            // Add About Us Page to Menu
            wp_update_nav_menu_item($repair_shop_menu_id, 0, array(
                'menu-item-title' => __('Pages', 'repair-shop'),
                'menu-item-classes' => 'about-us',
                'menu-item-url' => home_url('/about-us/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $repair_shop_about_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

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

                $repair_shop_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($repair_shop_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ));
                if (!$repair_shop_blog_page_query->have_posts()) {
                    $repair_shop_blog_page = array(
                        'post_type'   => 'page',
                        'post_title'  => $repair_shop_blog_page_title,
                        'post_status' => 'publish',
                        'post_author' => 1,
                    );
                    $repair_shop_blog_page_id = wp_insert_post($repair_shop_blog_page);
                    update_option('page_for_posts', $repair_shop_blog_page_id);

                    wp_update_nav_menu_item($repair_shop_menu_id, 0, array(
                        'menu-item-title'      => __('Blog', 'repair-shop'),
                        'menu-item-url'        => get_permalink($repair_shop_blog_page_id),
                        'menu-item-status'     => 'publish',
                        'menu-item-object-id'  => $repair_shop_blog_page_id,
                        'menu-item-object'     => 'page',
                        'menu-item-type'       => 'post_type',
                    ));
                }

            // Create About Us Page with Dummy Content
            $repair_shop_about_title = 'Contact';
            $repair_shop_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.';
            $repair_shop_about = array(
                'post_type' => 'page',
                'post_title' => $repair_shop_about_title,
                'post_content' => $repair_shop_about_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'about-us'
            );
            $repair_shop_about_id = wp_insert_post($repair_shop_about);
            // Add About Us Page to Menu
            wp_update_nav_menu_item($repair_shop_menu_id, 0, array(
                'menu-item-title' => __('Contact', 'repair-shop'),
                'menu-item-classes' => 'about-us',
                'menu-item-url' => home_url('/about-us/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $repair_shop_about_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Set the menu location if it's not already set
            if (!has_nav_menu($repair_shop_bpmenulocation)) {
                $repair_shop_locations = get_theme_mod('nav_menu_locations'); // Use 'nav_menu_locations' to get locations array
                if (empty($repair_shop_locations)) {
                    $repair_shop_locations = array();
                }
                $repair_shop_locations[$repair_shop_bpmenulocation] = $repair_shop_menu_id;
                set_theme_mod('nav_menu_locations', $repair_shop_locations);
            }
        }

        // Set the demo import completion flag
		update_option('repair_shop_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.', 'repair-shop') . '</p>';
		echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('View Site', 'repair-shop') . '</a></span>';
        //end 

        // Topbar
        set_theme_mod( 'repair_shop_topbar_location_text', '351 Montreal Ave, Staten Island, NY 10306' );
        set_theme_mod( 'repair_shop_track_locatin_url', '#' );
        set_theme_mod( 'repair_shop_topbar_phone_number', '1234567890' );
        set_theme_mod( 'repair_shop_top_email_address', 'mobile@example.com' );

        // Slider Settings
        set_theme_mod( 'repair_shop_slide_number', '3' );
        for($repair_shop_i=1; $repair_shop_i<=3; $repair_shop_i++) {        
            set_theme_mod( 'repair_shop_slider_bg_img'.$repair_shop_i, get_template_directory_uri().'/assets/images/slider-bg' . $repair_shop_i . '.png' );
            set_theme_mod( 'repair_shop_slider_small_title'.$repair_shop_i, 'WE GIVE YOU THE BEST!' );
            set_theme_mod( 'repair_shop_slider_title'.$repair_shop_i, 'FAST REPAIR YOUR SMART MOBILES & TABLATES' );
            set_theme_mod( 'repair_shop_slider_text'.$repair_shop_i, 'Lorem Ipsum is simply dummy text of the printing and typesetting industry lorem Ipsum has been the industrys standard Lorem Ipsum is simply dummy text of the printing and typesetting industry lorem Ipsum has been the industrys standard' );     
            set_theme_mod( 'repair_shop_featured_image_sec'.$repair_shop_i, get_template_directory_uri().'/assets/images/slider' . $repair_shop_i . '.png' );

            // Define an array for button texts and links
            $repair_shop_buttons = array(
                array(
                    'text' => 'READ MORE',
                    'link' => '#read-more'
                ),
                array(
                    'text' => 'BOOK AN APPOINTMENT',
                    'link' => '#request-quote'
                )
            );

            for($repair_shop_j=1; $repair_shop_j<=2; $repair_shop_j++) {
                set_theme_mod('repair_shop_slider_button_text'.$repair_shop_i .$repair_shop_j, $repair_shop_buttons[$repair_shop_j - 1]['text']);
                set_theme_mod('repair_shop_slider_button_link'.$repair_shop_i .$repair_shop_j, $repair_shop_buttons[$repair_shop_j - 1]['link']);
            }
        }

        // Team Section
        set_theme_mod( 'repair_shop_special_heading', 'OUR GREAT TEAM MEMBER' );
        set_theme_mod( 'repair_shop_special_text', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry lorem Ipsum has been the industrys standard.' );
        set_theme_mod( 'repair_shop_about_side_text', 'OUR WORKERS' );

        set_theme_mod( 'repair_shop_profile_box', '4' );

        $repair_shop_profile_name_array = array("ARINA JAMES", "PETER WOOD","ARINA JAMES", "PETER WOOD");
        $repair_shop_designation_array = array("Managing Director", "Hardware Engineer", "Managing Director", "Hardware Engineer");
 
        for($repair_shop_k=1; $repair_shop_k<=4; $repair_shop_k++) {
            set_theme_mod( 'repair_shop_profile_image_sec'.$repair_shop_k, get_template_directory_uri().'/assets/images/Profile'.$repair_shop_k.'.png' );
            set_theme_mod( 'repair_shop_phone_number'.$repair_shop_k, '1234567890' );
            set_theme_mod( 'repair_shop_email_address'.$repair_shop_k, 'mobile@example.com' );
            set_theme_mod( 'repair_shop_profile_name_link'.$repair_shop_k, '#' );
            
            // Title
            $repair_shop_theme_mod_key = 'repair_shop_profile_name' . $repair_shop_k;
            $repair_shop_theme_mod_value = $repair_shop_profile_name_array[$repair_shop_k - 1];
            set_theme_mod($repair_shop_theme_mod_key, $repair_shop_theme_mod_value); 

            // Designation
            $repair_shop_theme_mod_key = 'repair_shop_designate_name' . $repair_shop_k;
            $repair_shop_theme_mod_value = $repair_shop_designation_array[$repair_shop_k - 1];
            set_theme_mod($repair_shop_theme_mod_key, $repair_shop_theme_mod_value);              
        }
        echo "<script>window.location.href='" . admin_url('themes.php?page=repair_shop_guide') . "';</script>";
        //Copyright Text
        set_theme_mod( 'repair_shop_footer_text', 'By VWThemes' );  
     
        }
    ?>
  
	<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 Repair Shop', 'repair-shop'); ?></p>
    <form action="<?php echo esc_url(home_url()); ?>/wp-admin/themes.php?page=repair_shop_guide" method="POST" onsubmit="return validate(this);">
        <?php if (!get_option('repair_shop_demo_import_completed')) : ?>
            <input class="run-import" type="submit" name="submit" value="<?php esc_attr_e('Run Importer', 'repair-shop'); ?>" class="button button-primary button-large">
        <?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>
