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

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

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

        // Create Primary Menu
        $it_company_menuname       = 'Primary Menu';
        $it_company_bpmenulocation = 'primary';
        $it_company_menu_exists    = wp_get_nav_menu_object( $it_company_menuname );

        if ( ! $it_company_menu_exists ) {
            $it_company_menu_id = wp_create_nav_menu( $it_company_menuname );

            // Home Page
            $it_company_home_id = wp_insert_post( array(
                'post_type'    => 'page',
                'post_title'   => 'Home',
                'post_name'    => 'home',
                'post_status'  => 'publish',
                'post_author'  => 1
            ) );
            add_post_meta( $it_company_home_id, '_wp_page_template', 'page-template/custom-front-page.php' );
            wp_update_nav_menu_item( $it_company_menu_id, 0, array(
                'menu-item-title'     => 'Home',
                'menu-item-object-id' => $it_company_home_id,
                'menu-item-object'    => 'page',
                'menu-item-type'      => 'post_type',
                'menu-item-status'    => 'publish'
            ) );

            // Services Page
            $it_company_services_title = 'Services';
            $it_company_services_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.';
            $it_company_services_id = wp_insert_post( array(
                'post_type'    => 'page',
                'post_title'   => $it_company_services_title,
                'post_content' => $it_company_services_content,
                'post_name'    => 'services',
                'post_status'  => 'publish',
                'post_author'  => 1
            ) );
            wp_update_nav_menu_item( $it_company_menu_id, 0, array(
                'menu-item-title'     => 'Services',
                'menu-item-object-id' => $it_company_services_id,
                'menu-item-object'    => 'page',
                'menu-item-type'      => 'post_type',
                'menu-item-status'    => 'publish'
            ) );

            // Works Page
            $it_company_works_title = 'Works';
            $it_company_works_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.';
            $it_company_works_id = wp_insert_post( array(
                'post_type'    => 'page',
                'post_title'   => 'Works',
                'post_content' => $it_company_works_content,
                'post_name'    => 'works',
                'post_status'  => 'publish',
                'post_author'  => 1
            ) );
            wp_update_nav_menu_item( $it_company_menu_id, 0, array(
                'menu-item-title'     => $it_company_works_title,
                'menu-item-object-id' => $it_company_works_id,
                'menu-item-object'    => 'page',
                'menu-item-type'      => 'post_type',
                'menu-item-status'    => 'publish'
            ) );

            // Pages Page
            $it_company_pages_title = 'Pages';
            $it_company_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.';
            $it_company_pages_id = wp_insert_post( array(
                'post_type'    => 'page',
                'post_title'   => $it_company_pages_title,
                'post_content' => $it_company_pages_content,
                'post_name'    => 'pages',
                'post_status'  => 'publish',
                'post_author'  => 1
            ) );
            wp_update_nav_menu_item( $it_company_menu_id, 0, array(
                'menu-item-title'     => 'Pages',
                'menu-item-object-id' => $it_company_pages_id,
                'menu-item-object'    => 'page',
                'menu-item-type'      => 'post_type',
                'menu-item-status'    => 'publish'
            ) );

            // Blog Page (Posts Page)
            $it_company_blog_id = wp_insert_post( array(
                'post_type'    => 'page',
                'post_title'   => 'Blog',
                'post_name'    => 'blog',
                'post_status'  => 'publish',
                'post_author'  => 1
            ) );
            wp_update_nav_menu_item( $it_company_menu_id, 0, array(
                'menu-item-title'     => 'Blog',
                'menu-item-object-id' => $it_company_blog_id,
                'menu-item-object'    => 'page',
                'menu-item-type'      => 'post_type',
                'menu-item-status'    => 'publish'
            ) );

            // Contacts Page
            $it_company_contact_title = 'Contacts';
            $it_company_contact_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.';
            $it_company_contacts_id = wp_insert_post( array(
                'post_type'    => 'page',
                'post_title'   => $it_company_contact_title,
                'post_content' => $it_company_contact_content,
                'post_name'    => 'contacts',
                'post_status'  => 'publish',
                'post_author'  => 1
            ) );
            wp_update_nav_menu_item( $it_company_menu_id, 0, array(
                'menu-item-title'     => 'Contacts',
                'menu-item-object-id' => $it_company_contacts_id,
                'menu-item-object'    => 'page',
                'menu-item-type'      => 'post_type',
                'menu-item-status'    => 'publish'
            ) );
            // Assign the menu to the primary location if not already set
            if ( ! has_nav_menu( $it_company_bpmenulocation ) ) {
                $it_company_locations = get_theme_mod( 'nav_menu_locations', array() );
                $it_company_locations[ $it_company_bpmenulocation ] = $it_company_menu_id;
                set_theme_mod( 'nav_menu_locations', $it_company_locations );
            }

            // Set front page and posts page
            update_option( 'page_on_front', $it_company_home_id );
            update_option( 'show_on_front', 'page' );
            update_option( 'page_for_posts', $it_company_blog_id );
        }

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

        //Topbar
        set_theme_mod( 'it_company_top_header', true ); 
        set_theme_mod( 'it_company_question',  "Have Any Questions" ); 
        set_theme_mod( 'it_company_email', 'domain@gmail.com' );
        set_theme_mod( 'it_company_call_number', '123-456-7890' ); 
        set_theme_mod( 'it_company_facebook', 'facebook.com' );
        set_theme_mod( 'it_company_twitter', 'twitter.com' );
        set_theme_mod( 'it_company_youtube', 'youtube.com' );
        set_theme_mod( 'it_company_linkedin', 'linkedin.com' );

        //Slider
        set_theme_mod( 'it_company_slider_hide', true );
        
        $it_company_slider_titles = [
            'Smart IT Solutions for You',
            'Your Tech Partner, Always',
            'Innovating for a Better Tomorrow',
            'We Keep Your Business Connected',
        ];   

        for($it_company_i=1;$it_company_i<=4;$it_company_i++){
            $it_company_slider_title = $it_company_slider_titles[$it_company_i - 1];
            $it_company_slider_content = 'LOREM IPSUM DOLOR SIT AMET';
            // Create post object
            $it_company_my_post = array(
                'post_title'    => wp_strip_all_tags( $it_company_slider_title ),
                'post_content'  => $it_company_slider_content,
                'post_status'   => 'publish',
                'post_type'     => 'page',
            );

            // Insert the post into the database
            $it_company_post_id = wp_insert_post( $it_company_my_post );

            if ($it_company_post_id) {
                // Set the theme mod for the slider page
                set_theme_mod('it_company_slider_page' . $it_company_i, $it_company_post_id);

                $it_company_image_url = get_template_directory_uri().'/images/slider'.$it_company_i.'.png';

                $it_company_image_id = media_sideload_image($it_company_image_url, $it_company_post_id, null, 'id');

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

        // about us section
        set_theme_mod( 'it_company_about_us_hide', true ); 
        set_theme_mod( 'it_company_page_title', 'About Us' ); 
        set_theme_mod( 'it_company_about_button_label', 'KNOW MORE' ); 

        // left category
        $it_company_left_category_name = 'About Left';
        $it_company_left_category_term = term_exists( $it_company_left_category_name, 'category' );
        if ( ! $it_company_left_category_term ) {
            $it_company_left_category_term = wp_insert_term( $it_company_left_category_name, 'category' );
        }
        if ( ! is_wp_error( $it_company_left_category_term ) ) {
            $it_company_left_category_id = isset( $it_company_left_category_term['term_id'] ) ? (int) $it_company_left_category_term['term_id'] : $it_company_left_category_term;

            for ( $it_company_i = 1; $it_company_i <= 3; $it_company_i++ ) {
                $it_company_left_post_data = array(
                    'post_title'    => "Lorem Ipsum Dolor",
                    'post_content'  => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
                    'post_status'   => 'publish',
                    'post_type'     => 'post'
                );
                $it_company_left_post_id = wp_insert_post( $it_company_left_post_data );

                if ( ! is_wp_error( $it_company_left_post_id ) ) {
                    wp_set_post_categories( $it_company_left_post_id, array( $it_company_left_category_id ) );

                    $it_company_left_image_url = get_template_directory_uri().'/images/icon'.$it_company_i.'.png';
                    $it_company_left_image_id  = media_sideload_image( $it_company_left_image_url, $it_company_left_post_id, null, 'id' );

                    if ( ! is_wp_error( $it_company_left_image_id ) ) {
                        set_post_thumbnail( $it_company_left_post_id, $it_company_left_image_id );
                    }
                }
            }
            set_theme_mod( 'it_company_category', get_category( $it_company_left_category_id )->slug );
        }

        // center post
        $it_company_center_post_data = array(
            'post_title'    => 'About Our Company',
            'post_content'  => 'We are dedicated to providing exceptional IT services to help your business grow.',
            'post_status'   => 'publish',
            'post_type'     => 'post'
        );
        $it_company_center_post_id = wp_insert_post( $it_company_center_post_data );

        if ( ! is_wp_error( $it_company_center_post_id ) ) {
            $it_company_center_image_url = get_template_directory_uri().'/images/about-us.png';
            $it_company_center_image_id  = media_sideload_image( $it_company_center_image_url, $it_company_center_post_id, null, 'id' );

            if ( ! is_wp_error( $it_company_center_image_id ) ) {
                set_post_thumbnail( $it_company_center_post_id, $it_company_center_image_id );
            }
            set_theme_mod( 'it_company_about_setting', get_the_title( $it_company_center_post_id ) );
        }

        // right category
        $it_company_right_category_name = 'About Right';
        $it_company_right_category_term = term_exists( $it_company_right_category_name, 'category' );
        if ( ! $it_company_right_category_term ) {
            $it_company_right_category_term = wp_insert_term( $it_company_right_category_name, 'category' );
        }
        if ( ! is_wp_error( $it_company_right_category_term ) ) {
            $it_company_right_category_id = isset( $it_company_right_category_term['term_id'] ) ? (int) $it_company_right_category_term['term_id'] : $it_company_right_category_term;

            for ( $it_company_i = 1; $it_company_i <= 3; $it_company_i++ ) {
                $it_company_right_post_data = array(
                    'post_title'    => "Lorem Ipsum Dolor",
                    'post_content'  => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
                    'post_status'   => 'publish',
                    'post_type'     => 'post'
                );
                $it_company_right_post_id = wp_insert_post( $it_company_right_post_data );

                if ( ! is_wp_error( $it_company_right_post_id ) ) {
                    wp_set_post_categories( $it_company_right_post_id, array( $it_company_right_category_id ) );

                    $it_company_right_image_url = get_template_directory_uri().'/images/icons'.$it_company_i.'.png';
                    $it_company_right_image_id  = media_sideload_image( $it_company_right_image_url, $it_company_right_post_id, null, 'id' );

                    if ( ! is_wp_error( $it_company_right_image_id ) ) {
                        set_post_thumbnail( $it_company_right_post_id, $it_company_right_image_id );
                    }
                }
            }
            set_theme_mod( 'it_company_category1', get_category( $it_company_right_category_id )->slug );
        }

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

        }
    ?>

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