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

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

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

        // ------- Create Nav Menu --------
        $laundry_business_menuname = 'Main Menus';
        $laundry_business_bpmenulocation = 'primary';
        $laundry_business_menu_exists = wp_get_nav_menu_object($laundry_business_menuname);

        if (!$laundry_business_menu_exists) {
            $laundry_business_menu_id = wp_create_nav_menu($laundry_business_menuname);

            // Create Home Page
            $laundry_business_home_title = 'Home';
            $laundry_business_home = array(
                'post_type' => 'page',
                'post_title' => $laundry_business_home_title,
                'post_content' => '',
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'home'
            );
            $laundry_business_home_id = wp_insert_post($laundry_business_home);
            // Assign Home Page Template
            add_post_meta($laundry_business_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', $laundry_business_home_id);
            update_option('show_on_front', 'page');
            // Add Home Page to Menu
            wp_update_nav_menu_item($laundry_business_menu_id, 0, array(
                'menu-item-title' => __('Home', 'laundry-business'),
                'menu-item-classes' => 'home',
                'menu-item-url' => home_url('/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $laundry_business_home_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create About Us Page with Dummy Content
            $laundry_business_pages_title = 'About Us';
            $laundry_business_pages_content = '
            About Us 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.';
            $laundry_business_pages = array(
                'post_type' => 'page',
                'post_title' => $laundry_business_pages_title,
                'post_content' => $laundry_business_pages_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'explore'
            );
            $laundry_business_pages_id = wp_insert_post($laundry_business_pages);
            // Add Pages Page to Menu
            wp_update_nav_menu_item($laundry_business_menu_id, 0, array(
                'menu-item-title' => __('About Us', 'laundry-business'),
                'menu-item-classes' => 'explore',
                'menu-item-url' => home_url('/about/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $laundry_business_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create Services Page with Dummy Content
            $laundry_business_about_title = 'Services';
            $laundry_business_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.';
            $laundry_business_about = array(
                'post_type' => 'page',
                'post_title' => $laundry_business_about_title,
                'post_content' => $laundry_business_about_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'ervices'
            );
            $laundry_business_about_id = wp_insert_post($laundry_business_about);
            // Add About Us Page to Menu
            wp_update_nav_menu_item($laundry_business_menu_id, 0, array(
                'menu-item-title' => __('Services', 'laundry-business'),
                'menu-item-classes' => 'services',
                'menu-item-url' => home_url('/services/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $laundry_business_about_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

             // Create Pages Page with Dummy Content
            $laundry_business_pages_title = 'Pages';
            $laundry_business_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.';
            $laundry_business_pages = array(
                'post_type' => 'page',
                'post_title' => $laundry_business_pages_title,
                'post_content' => $laundry_business_pages_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'pages'
            );
            $laundry_business_pages_id = wp_insert_post($laundry_business_pages);
            // Add Pages Page to Menu
            wp_update_nav_menu_item($laundry_business_menu_id, 0, array(
                'menu-item-title' => __('Pages', 'laundry-business'),
                'menu-item-classes' => 'pages',
                'menu-item-url' => home_url('/pages/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $laundry_business_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

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

                $laundry_business_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($laundry_business_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ));
                if (!$laundry_business_blog_page_query->have_posts()) {
                    $laundry_business_blog_page = array(
                        'post_type'   => 'page',
                        'post_title'  => $laundry_business_blog_page_title,
                        'post_status' => 'publish',
                        'post_author' => 1,
                    );
                    $laundry_business_blog_page_id = wp_insert_post($laundry_business_blog_page);
                    update_option('page_for_posts', $laundry_business_blog_page_id);

                    wp_update_nav_menu_item($laundry_business_menu_id, 0, array(
                        'menu-item-title'      => __('Blog', 'laundry-business'),
                        'menu-item-url'        => get_permalink($laundry_business_blog_page_id),
                        'menu-item-status'     => 'publish',
                        'menu-item-object-id'  => $laundry_business_blog_page_id,
                        'menu-item-object'     => 'page',
                        'menu-item-type'       => 'post_type',
                    ));
                }

             // Create Contact Page with Dummy Content
            $laundry_business_pages_title = 'Contact';
            $laundry_business_pages_content = '
            Contact 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.';
            $laundry_business_pages = array(
                'post_type' => 'page',
                'post_title' => $laundry_business_pages_title,
                'post_content' => $laundry_business_pages_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'Contact'
            );
            $laundry_business_pages_id = wp_insert_post($laundry_business_pages);
            // Add Contact Page to Menu
            wp_update_nav_menu_item($laundry_business_menu_id, 0, array(
                'menu-item-title' => __('Contact', 'laundry-business'),
                'menu-item-classes' => 'contact',
                'menu-item-url' => home_url('/shop/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $laundry_business_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

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

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

        // Banner section 
        set_theme_mod('laundry_business_hide_show_banner_section',true);   
        set_theme_mod('laundry_business_banner_title','Effortless Laundry for Busy Urban Living');
        set_theme_mod('laundry_business_banner_text','Lorem Ipsum is simply dummy text of the printing and typesetting industry.'); 
        set_theme_mod('laundry_business_banner_first_button_label','Read More');  
        set_theme_mod('laundry_business_banner_first_button_url','#');
        set_theme_mod('laundry_business_banner_review_img1',get_template_directory_uri().'/assets/images/review2.png');
        set_theme_mod('laundry_business_banner_review_img2',get_template_directory_uri().'/assets/images/review3.png');  
        set_theme_mod('laundry_business_banner_review_img3',get_template_directory_uri().'/assets/images/review4.png');  
        set_theme_mod('laundry_business_banner_review_img4',get_template_directory_uri().'/assets/images/review1.png');  
        set_theme_mod('laundry_business_banner_review_img5',get_template_directory_uri().'/assets/images/review5.png'); 
        set_theme_mod('laundry_business_banner_review_count','120K+');  
        set_theme_mod('laundry_business_banner_review_text','Reviews');  
        set_theme_mod('laundry_business_banner_bottom_img', get_template_directory_uri().'/assets/images/image.png');  
        set_theme_mod('laundry_business_banner_background_img','');
        set_theme_mod('laundry_business_social_icons','fa-hands-bubbles');
        set_theme_mod('laundry_business_social_icons','fa-shirt');
        set_theme_mod('laundry_business_header_button_label','Appointment');
        set_theme_mod('laundry_business_banner_first_button_url','#');

        // Services SEction
        set_theme_mod('laundry_business_services_section_hide_show', true);
        set_theme_mod('laundry_business_services_section_title', 'Professional laundry Services');
        set_theme_mod('laundry_business_services_section_text', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.');
        set_theme_mod('laundry_business_services_number', 2);

        $laundry_business_tabs = array('Commercial', 'Residential');
        $laundry_business_titles = array(
            // Tab 1 → Commercial (5 posts)
            array( "Wash & Fold", "Wash & Iron","Dry Cleaning","Commercial Laundry","Steam Press"),
            // Tab 2 → Residential (5 posts)
            array( "Home Laundry","Premium Wash","Quick Service","Iron Only","Express Cleaning")
           );

        foreach ($laundry_business_tabs as $laundry_business_tab_index => $laundry_business_tab_name) {

            // Create or get category
            $laundry_business_term = term_exists($laundry_business_tab_name, 'category');
            if (!$laundry_business_term) {
                $laundry_business_term = wp_insert_term($laundry_business_tab_name, 'category');
            }

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

            $laundry_business_term_id = is_array($laundry_business_term) ? $laundry_business_term['term_id'] : $laundry_business_term;

            // Set tab name
            set_theme_mod('laundry_business_services_text' . ($laundry_business_tab_index + 1), $laundry_business_tab_name);

            // Set 5 posts per tab
            set_theme_mod('laundry_business_services_post_count' . ($laundry_business_tab_index + 1), 5);

            // Create posts
            foreach ($laundry_business_titles[$laundry_business_tab_index] as $laundry_business_i => $laundry_business_title) {

                $laundry_business_post_id = wp_insert_post(array(
                    'post_title'   => wp_strip_all_tags($laundry_business_title),
                    'post_content' => 'Lorem Ipsum is simply dummy text of the printing and type setting industry.',
                    'post_status'  => 'publish',
                    'post_type'    => 'post',
                ));

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

                // Assign category
                wp_set_post_categories($laundry_business_post_id, array($laundry_business_term_id));
                
                $laundry_business_image_url = get_template_directory_uri() . '/assets/images/service' . ($laundry_business_i + 1) . '.png';
                $laundry_business_image_id = media_sideload_image($laundry_business_image_url, $laundry_business_post_id, null, 'id');

                if (!is_wp_error($laundry_business_image_id)) {
                    set_post_thumbnail($laundry_business_post_id, $laundry_business_image_id);
                }
                set_theme_mod(
                    'laundry_business_services_category' . ($laundry_business_i + 1) . ($laundry_business_tab_index + 1),
                    $laundry_business_post_id
                );
                set_theme_mod(
                    'laundry_business_single_icon' . ($laundry_business_i + 1) . ($laundry_business_tab_index + 1),
                    'fa-solid fa-shirt'
                );
             }
        }
    } 
    ?>
  
    <form action="<?php echo esc_url(home_url()); ?>/wp-admin/themes.php?page=laundry_business_guide" method="POST" onsubmit="return validate(this);">
        <?php if (!get_option('laundry_business_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 Laundry Business', 'laundry-business'); ?></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 Laundry Business', 'laundry-business'); ?></p>
            <input class="run-import" type="submit" name="submit" value="<?php esc_attr_e('Run Importer', 'laundry-business'); ?>" 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>
