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

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

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

            // ------- Create Nav Menu --------
            $multipurpose_lawyer_menuname = 'Main Menus';
            $multipurpose_lawyer_bpmenulocation = 'primary';
            $multipurpose_lawyer_menu_exists = wp_get_nav_menu_object($multipurpose_lawyer_menuname);

            if (!$multipurpose_lawyer_menu_exists) {
                $multipurpose_lawyer_menu_id = wp_create_nav_menu($multipurpose_lawyer_menuname);

                // Create Home Page
                $multipurpose_lawyer_home_title = 'Home';
                $multipurpose_lawyer_home = array(
                    'post_type' => 'page',
                    'post_title' => $multipurpose_lawyer_home_title,
                    'post_content' => '',
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'home'
                );
                $multipurpose_lawyer_home_id = wp_insert_post($multipurpose_lawyer_home);
                // Assign Home Page Template
                add_post_meta($multipurpose_lawyer_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', $multipurpose_lawyer_home_id);
                update_option('show_on_front', 'page');
                // Add Home Page to Menu
                wp_update_nav_menu_item($multipurpose_lawyer_menu_id, 0, array(
                    'menu-item-title' => __('Home', 'multipurpose-lawyer'),
                    'menu-item-classes' => 'home',
                    'menu-item-url' => home_url('/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $multipurpose_lawyer_home_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Pages Page with Dummy Content
                $multipurpose_lawyer_pages_title = 'Pages';
                $multipurpose_lawyer_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.';
                $multipurpose_lawyer_pages = array(
                    'post_type' => 'page',
                    'post_title' => $multipurpose_lawyer_pages_title,
                    'post_content' => $multipurpose_lawyer_pages_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'pages'
                );
                $multipurpose_lawyer_pages_id = wp_insert_post($multipurpose_lawyer_pages);
                // Add Pages Page to Menu
                wp_update_nav_menu_item($multipurpose_lawyer_menu_id, 0, array(
                    'menu-item-title' => __('Pages', 'multipurpose-lawyer'),
                    'menu-item-classes' => 'pages',
                    'menu-item-url' => home_url('/pages/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $multipurpose_lawyer_pages_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create About Us Page with Dummy Content
                $multipurpose_lawyer_about_title = 'About Us';
                $multipurpose_lawyer_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.';
                $multipurpose_lawyer_about = array(
                    'post_type' => 'page',
                    'post_title' => $multipurpose_lawyer_about_title,
                    'post_content' => $multipurpose_lawyer_about_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'about-us'
                );
                $multipurpose_lawyer_about_id = wp_insert_post($multipurpose_lawyer_about);
                // Add About Us Page to Menu
                wp_update_nav_menu_item($multipurpose_lawyer_menu_id, 0, array(
                    'menu-item-title' => __('About Us', 'multipurpose-lawyer'),
                    'menu-item-classes' => 'about-us',
                    'menu-item-url' => home_url('/about-us/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $multipurpose_lawyer_about_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));
                // Create Blog Page only if it doesn't exist already
                $multipurpose_lawyer_existing_blog_page = get_page_by_path('blog');
                if (!$multipurpose_lawyer_existing_blog_page) {
                    $multipurpose_lawyer_blog_id = wp_insert_post(array(
                    'post_type'    => 'page',
                    'post_title'   => __('Blog', 'multipurpose-lawyer'),
                    'post_content' => '',
                    'post_status'  => 'publish',
                    'post_author'  => 1,
                    'post_name'    => 'blog'
                ));
                } else {
                    $multipurpose_lawyer_blog_id = $multipurpose_lawyer_existing_blog_page->ID;
                }
                // Assign as Posts Page
                update_option('page_for_posts', $multipurpose_lawyer_blog_id);
                update_option('show_on_front', 'page');
                //Add to Menu (only if not already added)
                $multipurpose_lawyer_menu_items = wp_get_nav_menu_items($multipurpose_lawyer_menu_id);
                $multipurpose_lawyer_blog_in_menu = false;
                if ($multipurpose_lawyer_menu_items) {
                    foreach ($multipurpose_lawyer_menu_items as $multipurpose_lawyer_item) {
                        if ((int) $multipurpose_lawyer_item->object_id === (int) $multipurpose_lawyer_blog_id) {
                            $multipurpose_lawyer_blog_in_menu = true;
                            break;
                        }
                    }
                }
                if (!$multipurpose_lawyer_blog_in_menu) {
                wp_update_nav_menu_item($multipurpose_lawyer_menu_id, 0, array(
                    'menu-item-title'       => __('Blog', 'multipurpose-lawyer'),
                    'menu-item-url'         => home_url('/blog/'),
                    'menu-item-status'      => 'publish',
                    'menu-item-object-id'   => $multipurpose_lawyer_blog_id,
                    'menu-item-object'      => 'page',
                    'menu-item-type'        => 'post_type',
                    'menu-item-classes'     => 'multipurpose-lawyer-blog-link'
                ));
                }
                // Set the menu location if it's not already set
                if (!has_nav_menu($multipurpose_lawyer_bpmenulocation)) {
                    $multipurpose_lawyer_locations = get_theme_mod('nav_menu_locations'); // Use 'nav_menu_locations' to get locations array
                    if (empty($multipurpose_lawyer_locations)) {
                        $multipurpose_lawyer_locations = array();
                    }
                    $multipurpose_lawyer_locations[$multipurpose_lawyer_bpmenulocation] = $multipurpose_lawyer_menu_id;
                    set_theme_mod('nav_menu_locations', $multipurpose_lawyer_locations);
                }
                
        }    

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

        // Topbar settings
        set_theme_mod('multipurpose_lawyer_welcome_text', 'Lorem ipsum dolor sit amet');
        set_theme_mod('multipurpose_lawyer_email', 'example@gmail.com');
        set_theme_mod('multipurpose_lawyer_request_text', 'FREE A REQUEST');
        set_theme_mod('multipurpose_lawyer_request_link', '#');

        //Slider
        set_theme_mod( 'multipurpose_lawyer_slider_hide_show', true );
        set_theme_mod( 'multipurpose_lawyer_slider_button_label', 'READ MORE' );
        set_theme_mod( 'multipurpose_lawyer_slider_button_link', '#' );


            $multipurpose_lawyer_slider_titles = [
                'Your Trusted Legal Partner for Every Need',
                'Expert Legal Solutions, Tailored to You',
                'Comprehensive Legal Services, Clear Guidance',
                'Defending Your Rights, Advancing Your Interests',

            ];     
            
            $multipurpose_lawyer_slider_contents = [
                'Your Trusted Legal Partner for Every Need, providing professional legal guidance and support across various fields of law',
                'Expert Legal Solutions, Tailored to You, offering personalized strategies to resolve your unique legal challenges',
                'Comprehensive Legal Services, Clear Guidance, helping you navigate complex legal matters with clarity and confidence',
                'Defending Your Rights, Advancing Your Interests, committed to protecting your legal rights and achieving your goals',
            ];  

        for($multipurpose_lawyer_i=1;$multipurpose_lawyer_i<=4;$multipurpose_lawyer_i++){
            $multipurpose_lawyer_slider_title = $multipurpose_lawyer_slider_titles[$multipurpose_lawyer_i - 1];
            $multipurpose_lawyer_slider_content = $multipurpose_lawyer_slider_contents[$multipurpose_lawyer_i - 1];
            // Create post object
            $multipurpose_lawyer_my_post = array(
            'post_title'    => wp_strip_all_tags( $multipurpose_lawyer_slider_title ),
            'post_content'  => $multipurpose_lawyer_slider_content,
            'post_status'   => 'publish',
            'post_type'     => 'page',
            );

            // Insert the post into the database
            $multipurpose_lawyer_post_id = wp_insert_post( $multipurpose_lawyer_my_post );

            if ($multipurpose_lawyer_post_id) {
                // Set the theme mod for the slider page
                set_theme_mod('multipurpose_lawyer_slidersettings_page' . $multipurpose_lawyer_i, $multipurpose_lawyer_post_id);

                $multipurpose_lawyer_image_url = get_template_directory_uri().'/images/slider'.$multipurpose_lawyer_i.'.png';

                $multipurpose_lawyer_image_id = media_sideload_image($multipurpose_lawyer_image_url, $multipurpose_lawyer_post_id, null, 'id');

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

        //Practice Section
        set_theme_mod( 'multipurpose_lawyer_practice_button_text', 'OUR PRACTICE' );
        set_theme_mod( 'multipurpose_lawyer_phone_text', 'LOREM IPSUM IS SIMPLY DUMMY TEXT' );
        set_theme_mod( 'multipurpose_lawyer_phone_no', '(123) 1234567890' );
        set_theme_mod('multipurpose_lawyer_practice_setting', 'Lorem Ipsum is simply dummy text of the printing');

        // Define the image URL
        $multipurpose_lawyer_service_image_url = get_template_directory_uri() . '/images/practice.png';

        // Define post details
        $multipurpose_lawyer_title = 'Lorem Ipsum is simply dummy text of the printing';
        $multipurpose_lawyer_content = "Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quisquam velit recusandae unde doloremque, veniam ullam.";
        $multipurpose_lawyer_post_data = array(
            'post_title'   => wp_strip_all_tags($multipurpose_lawyer_title),
            'post_content' => $multipurpose_lawyer_content, // Content doesn't need to be stripped
            'post_status'  => 'publish',
            'post_type'    => 'post',
        );

        // Insert the post
        $multipurpose_lawyer_post_id = wp_insert_post($multipurpose_lawyer_post_data);

        if (!is_wp_error($multipurpose_lawyer_post_id)) {
            // Add featured image
            $multipurpose_lawyer_image_id = media_sideload_image($multipurpose_lawyer_service_image_url, $multipurpose_lawyer_post_id, null, 'id');

            if (!is_wp_error($multipurpose_lawyer_image_id)) {
                // Set the featured image for the post
                set_post_thumbnail($multipurpose_lawyer_post_id, $multipurpose_lawyer_image_id);
            } else {
                error_log('Error downloading the image: ' . $multipurpose_lawyer_image_id->get_error_message());
            }

            // Save the post ID in the theme mod
            set_theme_mod('multipurpose_lawyer_practice_post_id', $multipurpose_lawyer_post_id);
        } else {
            error_log('Error creating the post: ' . $multipurpose_lawyer_post_id->get_error_message());
        }

        //About Section
        set_theme_mod('multipurpose_lawyer_about_setting', '20 YEARS EXPERIENCE');

        // Define the image URL
        $multipurpose_lawyer_service_image_url = get_template_directory_uri() . '/images/about.png';

        // Define post details
        $multipurpose_lawyer_title = '20 YEARS EXPERIENCE';
        $multipurpose_lawyer_content = "<P>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, </P><P>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.</P>";
        $multipurpose_lawyer_post_data = array(
            'post_title'   => wp_strip_all_tags($multipurpose_lawyer_title),
            'post_content' => $multipurpose_lawyer_content, // Content doesn't need to be stripped
            'post_status'  => 'publish',
            'post_type'    => 'post',
        );

        // Insert the post
        $multipurpose_lawyer_post_id = wp_insert_post($multipurpose_lawyer_post_data);

        if (!is_wp_error($multipurpose_lawyer_post_id)) {
            // Add featured image
            $multipurpose_lawyer_image_id = media_sideload_image($multipurpose_lawyer_service_image_url, $multipurpose_lawyer_post_id, null, 'id');

            if (!is_wp_error($multipurpose_lawyer_image_id)) {
                // Set the featured image for the post
                set_post_thumbnail($multipurpose_lawyer_post_id, $multipurpose_lawyer_image_id);
            } else {
                error_log('Error downloading the image: ' . $multipurpose_lawyer_image_id->get_error_message());
            }

            // Save the post ID in the theme mod
            set_theme_mod('multipurpose_lawyer_practice_post_id', $multipurpose_lawyer_post_id);
        } else {
            error_log('Error creating the post: ' . $multipurpose_lawyer_post_id->get_error_message());
        }

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

        }
    ?>

    <form action="<?php echo esc_url(home_url()); ?>/wp-admin/themes.php?page=multipurpose_lawyer_guide" method="POST" onsubmit="return validate(this);">
    <?php if (!get_option('multipurpose_lawyer_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.', 'multipurpose-lawyer' ); ?></p>
            <button id="import-button" type="submit" name="submit" class="import-btn run-import button-large">
                <?php esc_html_e('Run Importer', 'multipurpose-lawyer'); ?>
                    <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>

