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

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

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

        // ------- Create Main Menu --------
        $industrial_manufacturing_menuname = 'Primary Menu';
        $industrial_manufacturing_bpmenulocation = 'primary';
        $industrial_manufacturing_menu_exists = wp_get_nav_menu_object( $industrial_manufacturing_menuname );
    
        if ( !$industrial_manufacturing_menu_exists ) {
            $industrial_manufacturing_menu_id = wp_create_nav_menu( $industrial_manufacturing_menuname );

            // Create Home Page
            $industrial_manufacturing_home_title = 'Home';
            $industrial_manufacturing_home = array(
                'post_type'    => 'page',
                'post_title'   => $industrial_manufacturing_home_title,
                'post_content' => '',
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'home'
            );
            $industrial_manufacturing_home_id = wp_insert_post($industrial_manufacturing_home);
            // Assign Home Page Template
            add_post_meta($industrial_manufacturing_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', $industrial_manufacturing_home_id);
            update_option('show_on_front', 'page');
            // Add Home Page to Menu
            wp_update_nav_menu_item($industrial_manufacturing_menu_id, 0, array(
                'menu-item-title' => __('Home', 'industrial-manufacturing'),
                'menu-item-classes' => 'home',
                'menu-item-url' => home_url('/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $industrial_manufacturing_home_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create a new Page 
            $industrial_manufacturing_pages_title = 'Pages';
            $industrial_manufacturing_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.';
            $industrial_manufacturing_pages = array(
                'post_type'    => 'page',
                'post_title'   => $industrial_manufacturing_pages_title,
                'post_content' => $industrial_manufacturing_pages_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'pages'
            );
            $industrial_manufacturing_pages_id = wp_insert_post($industrial_manufacturing_pages);
            // Add Pages Page to Menu
            wp_update_nav_menu_item($industrial_manufacturing_menu_id, 0, array(
                'menu-item-title' => __('Pages', 'industrial-manufacturing'),
                'menu-item-classes' => 'pages',
                'menu-item-url' => home_url('/pages/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $industrial_manufacturing_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create About Us Page with Dummy Content
            $industrial_manufacturing_about_title = 'About Us';
            $industrial_manufacturing_about_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.';
            $industrial_manufacturing_about = array(
                'post_type'    => 'page',
                'post_title'   => $industrial_manufacturing_about_title,
                'post_content' => $industrial_manufacturing_about_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'about-us'
            );
            $industrial_manufacturing_about_id = wp_insert_post($industrial_manufacturing_about);
            // Add About Us Page to Menu
            wp_update_nav_menu_item($industrial_manufacturing_menu_id, 0, array(
                'menu-item-title' => __('About Us', 'industrial-manufacturing'),
                'menu-item-classes' => 'about-us',
                'menu-item-url' => home_url('/about-us/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $industrial_manufacturing_about_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));
            // Create Blog Page only if it doesn't exist already
            $industrial_manufacturing_existing_blog_page = get_page_by_path('blog');
            if (!$industrial_manufacturing_existing_blog_page) {
                $industrial_manufacturing_blog_id = wp_insert_post(array(
                'post_type'    => 'page',
                'post_title'   => __('Blog', 'industrial-manufacturing'),
                'post_content' => '',
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_name'    => 'blog'
             ));
            } else {
                $industrial_manufacturing_blog_id = $industrial_manufacturing_existing_blog_page->ID;
            }
            // Assign as Posts Page
            update_option('page_for_posts', $industrial_manufacturing_blog_id);
            update_option('show_on_front', 'page');
            //Add to Menu (only if not already added)
            $industrial_manufacturing_menu_items = wp_get_nav_menu_items($industrial_manufacturing_menu_id);
            $industrial_manufacturing_blog_in_menu = false;
            if ($industrial_manufacturing_menu_items) {
                foreach ($industrial_manufacturing_menu_items as $industrial_manufacturing_item) {
                    if ((int) $industrial_manufacturing_item->object_id === (int) $industrial_manufacturing_blog_id) {
                        $industrial_manufacturing_blog_in_menu = true;
                        break;
                    }
                }
            }
            if (!$industrial_manufacturing_blog_in_menu) {
            wp_update_nav_menu_item($industrial_manufacturing_menu_id, 0, array(
                'menu-item-title'       => __('Blog', 'industrial-manufacturing'),
                'menu-item-url'         => home_url('/blog/'),
                'menu-item-status'      => 'publish',
                'menu-item-object-id'   => $industrial_manufacturing_blog_id,
                'menu-item-object'      => 'page',
                'menu-item-type'        => 'post_type',
                'menu-item-classes'     => 'industrial-manufacturing-blog-link'
            ));
            }
            // Assign the menu to the primary location if not already set
            if ( ! has_nav_menu( $industrial_manufacturing_bpmenulocation ) ) {
                $industrial_manufacturing_locations = get_theme_mod( 'nav_menu_locations' );
                if ( empty( $industrial_manufacturing_locations ) ) {
                    $industrial_manufacturing_locations = array();
                }
                $industrial_manufacturing_locations[ $industrial_manufacturing_bpmenulocation ] = $industrial_manufacturing_menu_id;
                set_theme_mod( 'nav_menu_locations', $industrial_manufacturing_locations );
            }
        }

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

        //Topbar
        set_theme_mod( 'industrial_manufacturing_top_header', true );
        set_theme_mod( 'industrial_manufacturing_call', '(012)0123456789' );
        set_theme_mod( 'industrial_manufacturing_mail_address', 'xyz123@sample.com' );
        set_theme_mod( 'industrial_manufacturing_timing', 'Mon-Fri,8am-7pm' );
        set_theme_mod( 'industrial_manufacturing_career_text', 'Careers' );
        set_theme_mod( 'industrial_manufacturing_career_url', '#' );
        set_theme_mod( 'industrial_manufacturing_faq_text', 'Faq' );
        set_theme_mod( 'industrial_manufacturing_faq_url', '#' );
        set_theme_mod( 'industrial_manufacturing_facebook_url', '#' );
        set_theme_mod( 'industrial_manufacturing_twitter_url', '#' );
        set_theme_mod( 'industrial_manufacturing_instagram_url', '#' );
        set_theme_mod( 'industrial_manufacturing_pinterest_url', '#' );

        //Header
        set_theme_mod( 'industrial_manufacturing_header_button_text', 'Get A Quote' );
        set_theme_mod( 'industrial_manufacturing_header_button_link', '#' );

        //Slider Section
        set_theme_mod( 'industrial_manufacturing_show_slider', true );
        set_theme_mod( 'industrial_manufacturing_slider_small_title', 'Get Solutions' );
        set_theme_mod( 'industrial_manufacturing_slider_button_label', 'Read More' );
        set_theme_mod( 'industrial_manufacturing_slider_button_link', '#' );

        $industrial_manufacturing_titles = array(
            'CRAZY ABOUT INDUSTRY',
            'POWERING THE FUTURE',
            'INDUSTRY SUCCESS'
        );
        
        for ($industrial_manufacturing_i = 1; $industrial_manufacturing_i <= 3; $industrial_manufacturing_i++) {
            // Fetch a different title for each slider
            $industrial_manufacturing_slider_title = $industrial_manufacturing_titles[$industrial_manufacturing_i - 1];
            $industrial_manufacturing_slider_content = 'Lorem Ipsum is simply dummy text';
        
            // Create post object
            $industrial_manufacturing_my_post = array(
                'post_title'    => wp_strip_all_tags($industrial_manufacturing_slider_title),
                'post_content'  => $industrial_manufacturing_slider_content,
                'post_status'   => 'publish',
                'post_type'     => 'page',
            );
        
            // Insert the post into the database
            $industrial_manufacturing_post_id = wp_insert_post($industrial_manufacturing_my_post);
        
            if ($industrial_manufacturing_post_id) {
                // Set the theme mod for the slider page
                set_theme_mod('industrial_manufacturing_slidersettings_page' . $industrial_manufacturing_i, $industrial_manufacturing_post_id);
        
                $industrial_manufacturing_image_url = get_template_directory_uri() . '/images/banner' . $industrial_manufacturing_i . '.png';
        
                $industrial_manufacturing_image_id = media_sideload_image($industrial_manufacturing_image_url, $industrial_manufacturing_post_id, null, 'id');
        
                if (!is_wp_error($industrial_manufacturing_image_id)) {
                    // Set the downloaded image as the post's featured image
                    set_post_thumbnail($industrial_manufacturing_post_id, $industrial_manufacturing_image_id);
                }
            }
        }
        
        $industrial_manufacturing_demo_slider_list_texts = array(
            'Quality Control System, 100% Satisfication Guarantee',
            'Highly Professional Staff, Accurate Testing Process',
            'Workmanship, Professional and Qualified',
        );
    
        // Loop through and set the theme mods for each slider list text
        foreach ( $industrial_manufacturing_demo_slider_list_texts as $industrial_manufacturing_index => $industrial_manufacturing_text ) {
            set_theme_mod( 'industrial_manufacturing_slider_list_text' . ($industrial_manufacturing_index + 1), $industrial_manufacturing_text );
        }

        //About Section
        set_theme_mod( 'industrial_manufacturing_small_title', 'About Us' );
        set_theme_mod( 'industrial_manufacturing_experince_text', '40 Years Of Experience' );
        set_theme_mod( 'industrial_manufacturing_representative_number', '(012)012345678' );
        set_theme_mod( 'industrial_manufacturing_representative_text', 'Our Representative' );
        set_theme_mod( 'industrial_manufacturing_representative_img', esc_url( get_template_directory_uri().'/images/about-man.png'));

        // Define the content for the About Page
        $industrial_manufacturing_slider_title = 'High Quality Projects & Innovative Design!';
        $industrial_manufacturing_slider_content = '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, 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. ';

        // Create a new page
        $industrial_manufacturing_my_post = array(
            'post_title'    => wp_strip_all_tags( $industrial_manufacturing_slider_title ),
            'post_content'  => $industrial_manufacturing_slider_content,
            'post_status'   => 'publish',
            'post_type'     => 'page',
        );

        // Insert the post into the database
        $industrial_manufacturing_post_id = wp_insert_post( $industrial_manufacturing_my_post );

        if ( $industrial_manufacturing_post_id && !is_wp_error( $industrial_manufacturing_post_id ) ) {
            // Set the theme mod for the About Page
            set_theme_mod( 'industrial_manufacturing_about_page', $industrial_manufacturing_post_id );

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

            // Download and set the image as the featured image
            $industrial_manufacturing_image_id = media_sideload_image( $industrial_manufacturing_image_url, $industrial_manufacturing_post_id, null, 'id' );

            if ( !is_wp_error( $industrial_manufacturing_image_id ) ) {
                set_post_thumbnail( $industrial_manufacturing_post_id, $industrial_manufacturing_image_id );
            }
        }

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

        }
    ?>

    <form action="<?php echo esc_url(home_url()); ?>/wp-admin/themes.php?page=industrial_manufacturing_guide" method="POST" onsubmit="return validate(this);">
    <?php if (!get_option('industrial_manufacturing_demo_import_completed')) : ?>
        <div class="demo-btn">
            <p><?php esc_html_e( 'Click the below run importer button to import demo content', 'industrial-manufacturing' ); ?></p>
            <button id="import-button" type="submit" name="submit" class="import-btn run-import button-large">
                <?php esc_html_e('Demo Importer', 'industrial-manufacturing'); ?>
                    <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>
