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

        // If the demo import is completed, display the "View Site" button
        if ($home_repair_service_demo_import_completed) {
        echo '<p class="notice-text">' . esc_html__('Your demo import has been completed successfully.', 'home-repair-service') . '</p>';
        echo '<span><a href="' . esc_url(home_url()) . '" class="site-btn" target="_blank">' . esc_html__('VIEW SITE', 'home-repair-service') . '</a></span>';
        }
		
        if (isset($_POST['submit'])) {

            // ------- Create Nav Menu --------
            $home_repair_service_menuname = 'Main Menus';
            $home_repair_service_bpmenulocation = 'primary';
            $home_repair_service_menu_exists = wp_get_nav_menu_object($home_repair_service_menuname);

            if (!$home_repair_service_menu_exists) {
                $home_repair_service_menu_id = wp_create_nav_menu($home_repair_service_menuname);

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

                // Create Pages Page with Dummy Content
                $home_repair_service_about_title = 'About Us';
                $home_repair_service_about_content = 'Explore all the about 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 contactly 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.';
                $home_repair_service_about = array(
                    'post_type' => 'page',
                    'post_title' => $home_repair_service_about_title,
                    'post_content' => $home_repair_service_about_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'about'
                );
                $home_repair_service_about_id = wp_insert_post($home_repair_service_about);
                // Add Pages Page to Menu
                wp_update_nav_menu_item($home_repair_service_menu_id, 0, array(
                    'menu-item-title' => __('about', 'home-repair-service'),
                    'menu-item-classes' => 'about',
                    'menu-item-url' => home_url('/about/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $home_repair_service_about_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Pages Page with Dummy Content
                $home_repair_service_Services_title = 'Services Us';
                $home_repair_service_Services_content = 'Explore all the SErvices we have on our website. Find information Services 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 contactly 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.';
                $home_repair_service_services = array(
                    'post_type' => 'page',
                    'post_title' => $home_repair_service_services_title,
                    'post_content' => $home_repair_service_services_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'services'
                );
                $home_repair_service_services_id = wp_insert_post($home_repair_service_services);
                // Add Pages Page to Menu
                wp_update_nav_menu_item($home_repair_service_menu_id, 0, array(
                    'menu-item-title' => __('services', 'home-repair-service'),
                    'menu-item-classes' => 'services',
                    'menu-item-url' => home_url('/services/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $home_repair_service_services_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Portfolio Page with Dummy Content
                $home_repair_service_portfolio_title = 'Portfolio';
                $home_repair_service_portfolio_content = 'Explore all the portfolio we have on our website. Find information portfolio 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 contactly 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.';
                $home_repair_service_portfolio = array(
                    'post_type' => 'page',
                    'post_title' => $home_repair_service_portfolio_title,
                    'post_content' => $home_repair_service_portfolio_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'portfolio'
                );
                $home_repair_service_portfolio_id = wp_insert_post($home_repair_service_portfolio);
                // Add Portfolio Page to Menu
                wp_update_nav_menu_item($home_repair_service_menu_id, 0, array(
                    'menu-item-title' => __('portfolio', 'home-repair-service'),
                    'menu-item-classes' => 'portfolio',
                    'menu-item-url' => home_url('/portfolio/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $home_repair_service_portfolio_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Blog Page 
                $home_repair_service_blog_page_title = 'Blog';
                $home_repair_service_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($home_repair_service_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ));
                if (!$home_repair_service_blog_page_query->have_posts()) {
                    $home_repair_service_blog_page = array(
                    'post_type'   => 'page',
                    'post_title'  => $home_repair_service_blog_page_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    );
                    $home_repair_service_blog_page_id = wp_insert_post($home_repair_service_blog_page);
                    update_option('page_for_posts', $home_repair_service_blog_page_id);
                    wp_update_nav_menu_item($home_repair_service_menu_id, 0, array(
                    'menu-item-title'      => __('Blog', 'home-repair-service'),
                    'menu-item-url'        => get_permalink($home_repair_service_blog_page_id),
                    'menu-item-status'     => 'publish',
                    'menu-item-object-id'  => $home_repair_service_blog_page_id,
                    'menu-item-object'     => 'page',
                    'menu-item-type'       => 'post_type',
                    ));
                }

                // Create Pages Page with Dummy Content
                $home_repair_service_contact_title = 'Contact Us';
                $home_repair_service_contact_content = 'Explore all the contact 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 contactly 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.';
                $home_repair_service_contact = array(
                    'post_type' => 'page',
                    'post_title' => $home_repair_service_contact_title,
                    'post_content' => $home_repair_service_contact_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'contact'
                );
                $home_repair_service_contact_id = wp_insert_post($home_repair_service_contact);
                // Add Pages Page to Menu
                wp_update_nav_menu_item($home_repair_service_menu_id, 0, array(
                    'menu-item-title' => __('Contact', 'home-repair-service'),
                    'menu-item-classes' => 'contact',
                    'menu-item-url' => home_url('/contact/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $home_repair_service_contact_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));


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

            // Assign the menu to the theme location
            set_theme_mod('nav_menu_locations', [$home_repair_service_bpmenulocation => $home_repair_service_menu_id]);
                        
            // Set the demo import completion flag
    		update_option('home_repair_service_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.', 'home-repair-service') . '</p>';
    		echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('VIEW SITE', 'home-repair-service') . '</a></span>';
            //end

            //Header 
            set_theme_mod( 'home_repair_service_header_btn_text', 'Book Now' );
            set_theme_mod( 'home_repair_service_top_sidebar_text', 'Welcome To AC Repair' );
            set_theme_mod( 'home_repair_service_top_sidebar_phone_text', 'Call Us Now!' );
            set_theme_mod( 'home_repair_service_top_sidebar_phone_number', '+00 1234 567 890' );
            set_theme_mod( 'home_repair_service_top_sidebar_email_text', 'Email Us' );
            set_theme_mod( 'home_repair_service_top_sidebar_email_address', 'xyz123@example.com' );

            //Slider Section
            set_theme_mod( 'home_repair_service_slider_hide', true );

            $home_repair_service_slider_data = array(
                array(
                    'bg_image' => get_template_directory_uri() . '/images/slider1.png',
                    'small_text' => 'Welcome To AC Repair',
                    'title' => 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
                    'btn_text' => 'VIEW ALL SERVICES'
                ),
                array(
                    'bg_image' => get_template_directory_uri() . '/images/slider2.png',
                    'small_text' => 'Expert Home Repair Services',
                    'title' => 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
                    'btn_text' => 'VIEW ALL SERVICES'
                ),
                array(
                    'bg_image' => get_template_directory_uri() . '/images/slider3.png',
                    'small_text' => 'Reliable & Affordable Solutions',
                    'title' => 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
                    'btn_text' => 'VIEW ALL SERVICES'
                ),
            );            
        
            set_theme_mod('home_repair_service_slide_number', count($home_repair_service_slider_data));
        
            foreach ($home_repair_service_slider_data as $home_repair_service_index => $home_repair_service_data) {
                $home_repair_service_i = $home_repair_service_index + 1;
        
                set_theme_mod("home_repair_service_slider_bg_image$home_repair_service_i", $home_repair_service_data['bg_image']);
                set_theme_mod("home_repair_service_slider_title$home_repair_service_i", $home_repair_service_data['small_text']);
                set_theme_mod("home_repair_service_slider_desc_text$home_repair_service_i", $home_repair_service_data['title']);
                set_theme_mod("home_repair_service_slider_btn_text$home_repair_service_i", $home_repair_service_data['btn_text']);
            }

            set_theme_mod( 'home_repair_service_facebook_url', 'https://www.facebook.com' );
            set_theme_mod( 'home_repair_service_twitter_url', 'https://www.twtter.com' );
            set_theme_mod( 'home_repair_service_instagram_url', 'https://www.instagram.com' );
            set_theme_mod( 'home_repair_service_pinterest_url', 'https://www.pinterest.com' );
            set_theme_mod( 'home_repair_service_phone_text', 'Call Us Now!' );
            set_theme_mod( 'home_repair_service_phone_number', '+00 1234 567 890' );
            set_theme_mod( 'home_repair_service_email_address_text', 'Email Us' );
            set_theme_mod( 'home_repair_service_email_address1', 'xyz123@example.com' );
            set_theme_mod( 'home_repair_service_time_text', 'Our Timings' );
            set_theme_mod( 'home_repair_service_add_time', 'Monday-Friday: 10:00-19:00' );
            set_theme_mod( 'home_repair_service_video_button_text', 'Our Video' );
            set_theme_mod( 'home_repair_service_video_button_url', 'https://www.youtube.com/embed/9xwazD5SyVg' );
            
            //Team Section
            set_theme_mod( 'home_repair_service_section_title', 'Professional Technician Team' );
            set_theme_mod( 'home_repair_service_section_small_text', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.' );

            $home_repair_service_team_members = array(
                array(
                    'image' => get_template_directory_uri() . '/images/Team/team1.png',
                    'name' => 'JOASHAN.B.BROD',
                    'designation' => 'AC Repair',
                    'facebook' => 'https://www.facebook.com',
                    'twitter' => 'https://www.twtter.com',
                    'instagram' => 'https://www.instagram.com',
                    'pinterest' => 'https://www.pinterest.com',
                ),
                array(
                    'image' => get_template_directory_uri() . '/images/Team/team2.png',
                    'name' => 'RAKABUMING SUHU',
                    'designation' => 'Home Maintenance',
                    'facebook' => 'https://www.facebook.com',
                    'twitter' => 'https://www.twtter.com',
                    'instagram' => 'https://www.instagram.com',
                    'pinterest' => 'https://www.pinterest.com',
                ),
                array(
                    'image' => get_template_directory_uri() . '/images/Team/team3.png',
                    'name' => 'DUNITH WELLALAGE',
                    'designation' => 'Electrical Repair',
                    'facebook' => 'https://www.facebook.com',
                    'twitter' => 'https://www.twtter.com',
                    'instagram' => 'https://www.instagram.com',
                    'pinterest' => 'https://www.pinterest.com',
                ),
            );
        
            foreach ($home_repair_service_team_members as $home_repair_service_key => $home_repair_service_member) {
                $home_repair_service_index = $home_repair_service_key + 1;
                set_theme_mod('home_repair_service_team_image' . $home_repair_service_index, $home_repair_service_member['image']);
                set_theme_mod('home_repair_service_member_name' . $home_repair_service_index, $home_repair_service_member['name']);
                set_theme_mod('home_repair_service_add_designation' . $home_repair_service_index, $home_repair_service_member['designation']);
                set_theme_mod('home_repair_service_team_facebook_url' . $home_repair_service_index, $home_repair_service_member['facebook']);
                set_theme_mod('home_repair_service_team_twitter_url' . $home_repair_service_index, $home_repair_service_member['twitter']);
                set_theme_mod('home_repair_service_team_instagram_url' . $home_repair_service_index, $home_repair_service_member['instagram']);
                set_theme_mod('home_repair_service_team_pinterest_url' . $home_repair_service_index, $home_repair_service_member['pinterest']);
            }
           
            //Copyright Text
            set_theme_mod( 'home_repair_service_footer_text', 'By Buywptemplate' );

        }
    ?>

    <form action="<?php echo esc_url(home_url()); ?>/wp-admin/themes.php?page=home-repair-service-guide-page" method="POST" onsubmit="return validate(this);">
    <?php if (!get_option('home_repair_service_demo_import_completed')) : ?>
        <form method="post">
        <p><?php esc_html_e('Click the below run importer button to import demo content','home-repair-service'); ?></p>
            <input class= "run-import" type="submit" name="submit" value="<?php esc_attr_e('Run Importer','home-repair-service'); ?>" 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?")) {
                // Show loader
                document.getElementById('demo-import-loader').style.display = 'block';
                
                // Submit form
                document.forms[0].submit();
            } else {
                return false;
            }
	    }
	</script>
</div>
