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

    // If the demo import is completed, display the "View Site" button
    if ($book_publisher_agency_demo_import_completed) {
      echo '<p class="notice-text">' . esc_html__('Your demo import has been completed successfully.', 'book-publisher-agency') . '</p>';
      echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('View Site', 'book-publisher-agency') . '</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
          $book_publisher_agency_plugin_slug = 'ibtana-visual-editor';
          $book_publisher_agency_plugin_file = 'ibtana-visual-editor/plugin.php';

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

		  // ------- Create Nav Menu --------
            $book_publisher_agency_menuname = 'Main Menus';
            $book_publisher_agency_bpmenulocation = 'primary';
            $book_publisher_agency_menu_exists = wp_get_nav_menu_object($book_publisher_agency_menuname);

            if (!$book_publisher_agency_menu_exists) {
                $book_publisher_agency_menu_id = wp_create_nav_menu($book_publisher_agency_menuname);

                // Create Home Page
                $book_publisher_agency_home_title = 'Home';
                $book_publisher_agency_home = array(
                    'post_type' => 'page',
                    'post_title' => $book_publisher_agency_home_title,
                    'post_content' => '',
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'home'
                );
                $book_publisher_agency_home_id = wp_insert_post($book_publisher_agency_home);
                // Assign Home Page Template
                add_post_meta($book_publisher_agency_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', $book_publisher_agency_home_id);
                update_option('show_on_front', 'page');
                // Add Home Page to Menu
                wp_update_nav_menu_item($book_publisher_agency_menu_id, 0, array(
                    'menu-item-title' => __('Home', 'book-publisher-agency'),
                    'menu-item-classes' => 'home',
                    'menu-item-url' => home_url('/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $book_publisher_agency_home_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Pages Page with Dummy Content
                $book_publisher_agency_pages_title = 'Pages';
                $book_publisher_agency_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.';
                $book_publisher_agency_pages = array(
                    'post_type' => 'page',
                    'post_title' => $book_publisher_agency_pages_title,
                    'post_content' => $book_publisher_agency_pages_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'pages'
                );
                $book_publisher_agency_pages_id = wp_insert_post($book_publisher_agency_pages);
                // Add Pages Page to Menu
                wp_update_nav_menu_item($book_publisher_agency_menu_id, 0, array(
                    'menu-item-title' => __('Pages', 'book-publisher-agency'),
                    'menu-item-classes' => 'pages',
                    'menu-item-url' => home_url('/pages/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $book_publisher_agency_pages_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create About Us Page with Dummy Content
                $book_publisher_agency_about_title = 'About Us';
                $book_publisher_agency_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.';
                $book_publisher_agency_about = array(
                    'post_type' => 'page',
                    'post_title' => $book_publisher_agency_about_title,
                    'post_content' => $book_publisher_agency_about_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'about-us'
                );
                $book_publisher_agency_about_id = wp_insert_post($book_publisher_agency_about);
                // Add About Us Page to Menu
                wp_update_nav_menu_item($book_publisher_agency_menu_id, 0, array(
                    'menu-item-title' => __('About Us', 'book-publisher-agency'),
                    'menu-item-classes' => 'about-us',
                    'menu-item-url' => home_url('/about-us/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $book_publisher_agency_about_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));
                 
                // Create Services Page with Dummy Content
                    $book_publisher_agency_services_title = 'Services';
                    $book_publisher_agency_services_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Our publishing services include editing, proofreading, book design, printing, and distribution.<br><br>
                    We help authors transform manuscripts into professionally published books with end-to-end support.';

                    $book_publisher_agency_services = array(
                        'post_type'    => 'page',
                        'post_title'   => $book_publisher_agency_services_title,
                        'post_content' => $book_publisher_agency_services_content,
                        'post_status'  => 'publish',
                        'post_author'  => 1,
                        'post_slug'    => 'services'
                    );
                    $book_publisher_agency_services_id = wp_insert_post($book_publisher_agency_services);

                    // Add Services Page to Menu
                    wp_update_nav_menu_item($book_publisher_agency_menu_id, 0, array(
                        'menu-item-title'  => __('Services', 'book-publisher-agency'),
                        'menu-item-classes'=> 'services',
                        'menu-item-url'    => home_url('/services/'),
                        'menu-item-status' => 'publish',
                        'menu-item-object-id' => $book_publisher_agency_services_id,
                        'menu-item-object' => 'page',
                        'menu-item-type'   => 'post_type'
                    ));

                    // Create Project Page with Dummy Content
                    $book_publisher_agency_project_title = 'Projects';
                    $book_publisher_agency_project_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Our completed and ongoing publishing projects are showcased here.<br><br>
                    Explore books, magazines, and digital publications created in collaboration with our authors.';

                    $book_publisher_agency_project = array(
                        'post_type'    => 'page',
                        'post_title'   => $book_publisher_agency_project_title,
                        'post_content' => $book_publisher_agency_project_content,
                        'post_status'  => 'publish',
                        'post_author'  => 1,
                        'post_slug'    => 'projects'
                    );
                    $book_publisher_agency_project_id = wp_insert_post($book_publisher_agency_project);

                    // Add Project Page to Menu
                    wp_update_nav_menu_item($book_publisher_agency_menu_id, 0, array(
                        'menu-item-title'  => __('Projects', 'book-publisher-agency'),
                        'menu-item-classes'=> 'projects',
                        'menu-item-url'    => home_url('/projects/'),
                        'menu-item-status' => 'publish',
                        'menu-item-object-id' => $book_publisher_agency_project_id,
                        'menu-item-object' => 'page',
                        'menu-item-type'   => 'post_type'
                    ));

                    // Create Team Page with Dummy Content
                    $book_publisher_agency_team_title = 'Our Team';
                    $book_publisher_agency_team_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Meet our experienced editors, designers, marketers, and publishing experts.<br><br>
                    Our team is passionate about bringing stories to life and supporting authors worldwide.';

                    $book_publisher_agency_team = array(
                        'post_type'    => 'page',
                        'post_title'   => $book_publisher_agency_team_title,
                        'post_content' => $book_publisher_agency_team_content,
                        'post_status'  => 'publish',
                        'post_author'  => 1,
                        'post_slug'    => 'team'
                    );
                    $book_publisher_agency_team_id = wp_insert_post($book_publisher_agency_team);

                    // Add Team Page to Menu
                    wp_update_nav_menu_item($book_publisher_agency_menu_id, 0, array(
                        'menu-item-title'  => __('Team', 'book-publisher-agency'),
                        'menu-item-classes'=> 'team',
                        'menu-item-url'    => home_url('/team/'),
                        'menu-item-status' => 'publish',
                        'menu-item-object-id' => $book_publisher_agency_team_id,
                        'menu-item-object' => 'page',
                        'menu-item-type'   => 'post_type'
                    ));

                    // Create Contact Us Page with Dummy Content
                    $book_publisher_agency_contact_title = 'Contact Us';
                    $book_publisher_agency_contact_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Get in touch with us for publishing inquiries, submissions, or collaborations.<br><br>
                    You can contact us via email, phone, or by using the contact form on this page.';

                    $book_publisher_agency_contact = array(
                        'post_type'    => 'page',
                        'post_title'   => $book_publisher_agency_contact_title,
                        'post_content' => $book_publisher_agency_contact_content,
                        'post_status'  => 'publish',
                        'post_author'  => 1,
                        'post_slug'    => 'contact-us'
                    );
                    $book_publisher_agency_contact_id = wp_insert_post($book_publisher_agency_contact);

                    // Add Contact Us Page to Menu
                    wp_update_nav_menu_item($book_publisher_agency_menu_id, 0, array(
                        'menu-item-title'  => __('Contact Us', 'book-publisher-agency'),
                        'menu-item-classes'=> 'contact-us',
                        'menu-item-url'    => home_url('/contact-us/'),
                        'menu-item-status' => 'publish',
                        'menu-item-object-id' => $book_publisher_agency_contact_id,
                        'menu-item-object' => 'page',
                        'menu-item-type'   => 'post_type'
                    ));

                    // Create Blog Page 
                    $book_publisher_agency_blog_page_title = 'Blog';
                    $book_publisher_agency_blog_page_query = new WP_Query(array(
                        'post_type'      => 'page',
                        'name'           => sanitize_title($book_publisher_agency_blog_page_title),
                        'post_status'    => 'publish',
                        'posts_per_page' => 1
                    ));
                    if (!$book_publisher_agency_blog_page_query->have_posts()) {
                        $book_publisher_agency_blog_page = array(
                            'post_type'   => 'page',
                            'post_title'  => $book_publisher_agency_blog_page_title,
                            'post_status' => 'publish',
                            'post_author' => 1,
                        );
                        $book_publisher_agency_blog_page_id = wp_insert_post($book_publisher_agency_blog_page);
                        update_option('page_for_posts', $book_publisher_agency_blog_page_id);
                        wp_update_nav_menu_item($book_publisher_agency_menu_id, 0, array(
                            'menu-item-title'      => __('Blog', 'book-publisher-agency'),
                            'menu-item-url'        => get_permalink($book_publisher_agency_blog_page_id),
                            'menu-item-status'     => 'publish',
                            'menu-item-object-id'  => $book_publisher_agency_blog_page_id,
                            'menu-item-object'     => 'page',
                            'menu-item-type'       => 'post_type',
                        ));
                    }

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

        // Set the demo import completion flag
        update_option('book_publisher_agency_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.', 'book-publisher-agency') . '</p>';
        echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('View Site', 'book-publisher-agency') . '</a></span>';

        //end     

        // Top Bar start //
        set_theme_mod( 'book_publisher_agency_topbar_add_text_icon', 'fa-solid fa-bullhorn' ); 
        set_theme_mod( 'book_publisher_agency_topbar_add_text', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.' );
        

        // slider section start //  
        set_theme_mod( 'cricket_league_banner_image', get_template_directory_uri().'/assets/images/banner.png');

        set_theme_mod( 'book_publisher_agency_slide_number', '3' );
        for($book_publisher_agency_i=1; $book_publisher_agency_i<=3; $book_publisher_agency_i++) {
            set_theme_mod( 'book_publisher_agency_banner_background_image_sec'.$book_publisher_agency_i, get_template_directory_uri().'/assets/images/man'.$book_publisher_agency_i.'.png' );
            
            set_theme_mod( 'book_publisher_agency_designation_small_text'.$book_publisher_agency_i, 'PUBLISHING HOUSE' );
            set_theme_mod( 'book_publisher_agency_tagline_title'.$book_publisher_agency_i, 'The new novel From John Verma' );
            set_theme_mod( 'book_publisher_agency_designation_text'.$book_publisher_agency_i, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua' );    
            set_theme_mod( 'book_publisher_agency_slider_button_label1'.$book_publisher_agency_i, 'READ MORE' );
            set_theme_mod( 'book_publisher_agency_slider_button_url1'.$book_publisher_agency_i, '#' );  
            set_theme_mod( 'book_publisher_agency_banner_button_label2'.$book_publisher_agency_i, 'CONTACT US' );
            set_theme_mod( 'book_publisher_agency_top_button_url2'.$book_publisher_agency_i, '#' );          
        }  

        // Contact Section start //
        set_theme_mod( 'book_publisher_agency_contact_text', 'For Any Help or Queries Please Contact Us' ); 
        set_theme_mod( 'book_publisher_agency_phone_icon', 'fa-solid fa-phone' );
        set_theme_mod( 'book_publisher_agency_phone_number', '+00 987 654 1230' );
        set_theme_mod( 'book_publisher_agency_email_address_icon', 'fa-solid fa-envelope-open-text' );
        set_theme_mod( 'book_publisher_agency_email_address', 'xyz123@gmail.com' );
        set_theme_mod( 'book_publisher_agency_trusted_text', '(TRUSTED BY 5M+ BUSINESS)' );

        set_theme_mod( 'book_publisher_agency_book_icon', 'fa-solid fa-book' );
        set_theme_mod( 'book_publisher_agency_book', 'Book' );
        set_theme_mod( 'book_publisher_agency_creative_icon', 'fa-solid fa-book-open-reader' );
        set_theme_mod( 'book_publisher_agency_creative', 'Creative' );
        set_theme_mod( 'book_publisher_agency_lakebook_icon', 'fa-solid fa-book-open' );
        set_theme_mod( 'book_publisher_agency_lakebook', 'Lake Book' );
        set_theme_mod( 'book_publisher_agency_publish_icon', 'fa-solid fa-book-journal-whills' );
        set_theme_mod( 'book_publisher_agency_publish', 'Publish' );

        // Featured Section 
        set_theme_mod( 'book_publisher_agency_section_title1', 'FEATURED PUBLICATION' );
        set_theme_mod( 'book_publisher_agency_feature_courses_tagline_title', 'EXPLORE OUR PUBLICATION' );
        set_theme_mod( 'book_publisher_agency_featured_button_label', 'View All Publication' );
        set_theme_mod( 'book_publisher_agency_featured_button_url', '#' );
        set_theme_mod( 'book_publisher_agency_publish', 'Publish' );
        set_theme_mod( 'book_publisher_agency_publish', 'Publish' );
        set_theme_mod( 'book_publisher_agency_publish', 'Publish' );

        $book_publisher_agency_featured_text_array = array("Book Title1", "Book Title2");

         for($book_publisher_agency_i=1; $book_publisher_agency_i<=2; $book_publisher_agency_i++) {
            set_theme_mod( 'book_publisher_agency_featured_background_image_sec'.$book_publisher_agency_i, get_template_directory_uri().'/assets/images/book'.$book_publisher_agency_i.'.png' );
            
            // set_theme_mod( 'book_publisher_agency_feature_featured_tagline_title'.$book_publisher_agency_i, 'Book Title' );
            // title setting
            $book_publisher_agency_theme_mod_key = 'book_publisher_agency_feature_featured_tagline_title' . $book_publisher_agency_i;
            $book_publisher_agency_theme_mod_value = $book_publisher_agency_featured_text_array[$book_publisher_agency_i - 1];
            set_theme_mod($book_publisher_agency_theme_mod_key, $book_publisher_agency_theme_mod_value); 

            set_theme_mod( 'book_publisher_agency_book_title_url1'.$book_publisher_agency_i, '#' );    
            set_theme_mod( 'book_publisher_agency_featured_title1'.$book_publisher_agency_i, 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.' );            
        }
        echo "<script>window.location.href='" . admin_url('themes.php?page=book_publisher_agency_guide') . "';</script>";
         //Copyright Text
        set_theme_mod( 'book_publisher_agency_footer_text', 'By VWThemes' );             
    }
  ?>
  
	<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 Book Publisher Agency', 'book-publisher-agency'); ?></p>
    <form action="<?php echo esc_url(home_url()); ?>/wp-admin/themes.php?page=book_publisher_agency_guide" method="POST" onsubmit="return validate(this);">
        <?php if (!get_option('book_publisher_agency_demo_import_completed')) : ?>
            <input class="run-import" type="submit" name="submit" value="<?php esc_attr_e('Run Importer', 'book-publisher-agency'); ?>" class="button button-primary button-large">
        <?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?")) {
                document.getElementById('spinner').style.display = 'block';
                return true;
            } 
            else {
                return false;
            }
        }
    </script>
</div>

