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

        // If the demo import is completed, display the "View Site" button
        if ($business_association_demo_import_completed) {
        echo '<p class="notice-text">' . esc_html__('Your demo import has been completed successfully.', 'business-association') . '</p>';
        echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('View Site', 'business-association') . '</a></span>';
        echo '<span><a href="'. esc_url(admin_url('customize.php') ) .'" class="button button-primary demo-btn" target=_blank>'. esc_html__( 'Customize Your Site', 'business-association' ) .'</a></span>';
        echo '<span><a href="'. esc_url( 'https://preview.vwthemesdemo.com/docs/free-business-association/' ) .'" class="button button-primary doc-btn" target=_blank>'. esc_html__( 'Free Theme Documentation', 'business-association' ) .'</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
          $business_association_plugin_slug = 'ibtana-visual-editor';
          $business_association_plugin_file = 'ibtana-visual-editor/plugin.php';

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

        // ------- Create Nav Menu --------
        $business_association_menuname = 'Main Menus';
        $business_association_bpmenulocation = 'primary';
        $business_association_menu_exists = wp_get_nav_menu_object($business_association_menuname);

        if (!$business_association_menu_exists) {
            $business_association_menu_id = wp_create_nav_menu($business_association_menuname);

            // Create Home Page
            $business_association_home_title = 'Home';
            $business_association_home = array(
                'post_type' => 'page',
                'post_title' => $business_association_home_title,
                'post_content' => '',
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'home'
            );
            $business_association_home_id = wp_insert_post($business_association_home);
            // Assign Home Page Template
            add_post_meta($business_association_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', $business_association_home_id);
            update_option('show_on_front', 'page');
            // Add Home Page to Menu
            wp_update_nav_menu_item($business_association_menu_id, 0, array(
                'menu-item-title' => __('Home', 'business-association'),
                'menu-item-classes' => 'home',
                'menu-item-url' => home_url('/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $business_association_home_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create About Us Page with Dummy Content
            $business_association_pages_title = 'About Us';
            $business_association_pages_content = '
            About Us 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.';
            $business_association_pages = array(
                'post_type' => 'page',
                'post_title' => $business_association_pages_title,
                'post_content' => $business_association_pages_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'explore'
            );
            $business_association_pages_id = wp_insert_post($business_association_pages);
            // Add Pages Page to Menu
            wp_update_nav_menu_item($business_association_menu_id, 0, array(
                'menu-item-title' => __('About Us', 'business-association'),
                'menu-item-classes' => 'explore',
                'menu-item-url' => home_url('/about/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $business_association_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create About Us Page with Dummy Content
            $business_association_about_title = 'MemberShip';
            $business_association_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.';
            $business_association_about = array(
                'post_type' => 'page',
                'post_title' => $business_association_about_title,
                'post_content' => $business_association_about_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'memberShip'
            );
            $business_association_about_id = wp_insert_post($business_association_about);
            // Add About Us Page to Menu
            wp_update_nav_menu_item($business_association_menu_id, 0, array(
                'menu-item-title' => __('MemberShip', 'business-association'),
                'menu-item-classes' => 'memberShip',
                'menu-item-url' => home_url('/menres/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $business_association_about_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create Resouces Page with Dummy Content
            $business_association_pages_title = 'Resouces';
            $business_association_pages_content = '
            Resouces 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.';
            $business_association_pages = array(
                'post_type' => 'page',
                'post_title' => $business_association_pages_title,
                'post_content' => $business_association_pages_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'resouces'
            );
            $business_association_pages_id = wp_insert_post($business_association_pages);
            // Add Pages Page to Menu
            wp_update_nav_menu_item($business_association_menu_id, 0, array(
                'menu-item-title' => __('Resouces', 'business-association'),
                'menu-item-classes' => 'manga',
                'menu-item-url' => home_url('/resouces/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $business_association_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create Events Page with Dummy Content
            $business_association_pages_title = 'Events';
            $business_association_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.';
            $business_association_pages = array(
                'post_type' => 'page',
                'post_title' => $business_association_pages_title,
                'post_content' => $business_association_pages_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'shop'
            );
            $business_association_pages_id = wp_insert_post($business_association_pages);
            // Add Events Page to Menu
            wp_update_nav_menu_item($business_association_menu_id, 0, array(
                'menu-item-title' => __('Events', 'business-association'),
                'menu-item-classes' => 'events',
                'menu-item-url' => home_url('/events/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $business_association_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

             // Create Gallery Page with Dummy Content
            $business_association_pages_title = 'Gallery';
            $business_association_pages_content = '
            Gallery 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.';
            $business_association_pages = array(
                'post_type' => 'page',
                'post_title' => $business_association_pages_title,
                'post_content' => $business_association_pages_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'gallery'
            );
            $business_association_pages_id = wp_insert_post($business_association_pages);
            // Add Gallery Page to Menu
            wp_update_nav_menu_item($business_association_menu_id, 0, array(
                'menu-item-title' => __('Gallery', 'business-association'),
                'menu-item-classes' => 'sallery',
                'menu-item-url' => home_url('/gallery/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $business_association_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));
             // Create Contact Page with Dummy Content
            $business_association_pages_title = 'Contact';
            $business_association_pages_content = '
            Contact 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.';
            $business_association_pages = array(
                'post_type' => 'page',
                'post_title' => $business_association_pages_title,
                'post_content' => $business_association_pages_content,
                'post_status' => 'publish',
                'post_author' => 1,
                'post_slug' => 'Contact'
            );
            $business_association_pages_id = wp_insert_post($business_association_pages);
            // Add Contact Page to Menu
            wp_update_nav_menu_item($business_association_menu_id, 0, array(
                'menu-item-title' => __('Contact', 'business-association'),
                'menu-item-classes' => 'contact',
                'menu-item-url' => home_url('/shop/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $business_association_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

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

        // Set the demo import completion flag
		update_option('business_association_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.', 'business-association') . '</p>';
		echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('View Site', 'business-association') . '</a></span>';
        echo '<span><a href="'. esc_url(admin_url('customize.php') ) .'" class="button button-primary demo-btn" target=_blank>'. esc_html__( 'Customize Your Site', 'business-association' ) .'</a></span>';
        echo '<span><a href="'. esc_url( 'https://preview.vwthemesdemo.com/docs/free-business-association/' ) .'" class="button button-primary doc-btn" target=_blank>'. esc_html__( 'Free Theme Documentation', 'business-association' ) .'</a></span>';
        //end 

        // Banner section 
        set_theme_mod('business_association_hide_show_banner_section',true);   
        set_theme_mod('business_association_banner_title','Empowering Our Community of Professionals');
        set_theme_mod('business_association_banner_text','The UnityConnect Association connects industry leaders, professionals, and innovators to share knowledge, collaborate, and make an impact.'); 
        set_theme_mod('business_association_banner_first_button_label','Learn More');  
        set_theme_mod('business_association_banner_first_btn_icon','fas fa-arrow-right');  
        set_theme_mod('business_association_banner_first_button_url','#');  
        set_theme_mod('business_association_banner_second_button_label','Join Now');  
        set_theme_mod('business_association_banner_second_btn_icon','fas fa-arrow-right');  
        set_theme_mod('business_association_banner_second_button_url','#');  
        set_theme_mod('business_association_banner_review_img1',get_template_directory_uri().'/assets/images/img4.jpg');  
        set_theme_mod('business_association_banner_review_img2',get_template_directory_uri().'/assets/images/img3.jpg');  
        set_theme_mod('business_association_banner_review_img3',get_template_directory_uri().'/assets/images/img2.jpg');  
        set_theme_mod('business_association_banner_review_img4',get_template_directory_uri().'/assets/images/img1.jpg');  
        set_theme_mod('business_association_banner_review_text','Connect With Another professionals');


        for($business_association_i = 0; $business_association_i < 2; $business_association_i++) {
            set_theme_mod(
                'business_association_banner_right_imgbox_first'.$business_association_i,
                get_template_directory_uri().'/assets/images/left'.$business_association_i.'.png'
            );
        }

        for($business_association_j = 0; $business_association_j < 3; $business_association_j++) {
            set_theme_mod(
                'business_association_banner_right_imgbox_second'.$business_association_j,
                get_template_directory_uri().'/assets/images/middle'.$business_association_j.'.png'
            );
        }

        for($business_association_k = 0; $business_association_k < 2; $business_association_k++) {
            set_theme_mod(
                'business_association_banner_right_imgbox_third'.$business_association_k,
                get_template_directory_uri().'/assets/images/right'.$business_association_k.'.png'
            );
        }

        // Members Demo Data
        set_theme_mod('business_association_members_section_hide_show', true);
        set_theme_mod('business_association_members_section_text', 'What Our Members Say');
        set_theme_mod('business_association_members_section_title', 'Hear from our members about how the UnityConnect Association has made a difference in their professional journey.');
        $business_association_names = array(
            'Emily Robert',
            'Thompson-',
            'Jacob Martinez',
            'Emily Robert',
            'Thompson-',
        );

        $business_association_members_country = array(
            'United States',
            'Canada',
            'United States',
            'United States',
            'Canada'
        );

        $business_association_description = array(
            'The workshops were practical and boosted my confidence.',
            'Great mentor support and very organized sessions.',
            'Helped me improve my skills faster than expected.',
            'The workshops were practical and boosted my confidence.',
            'Great mentor support and very organized sessions.',
        );

        for ($business_association_p = 0; $business_association_p < 5; $business_association_p++) {

            set_theme_mod(
                'business_association_members_profile_img' . $business_association_p,
                get_template_directory_uri() . '/assets/images/member' . $business_association_p . '.png'
            );

            set_theme_mod(
                'business_association_members_name' . $business_association_p,
                $business_association_names[$business_association_p]
            );

            set_theme_mod(
                'business_association_members_country' . $business_association_p,
                $business_association_members_country[$business_association_p]
            );

            set_theme_mod(
                'business_association_members_description' . $business_association_p,
                $business_association_description[$business_association_p]
            );

            set_theme_mod(
                'business_association_member_ratings' . $business_association_p,
                '5'
            );
        }
        }

    ?>
  
    <form action="<?php echo esc_url(home_url()); ?>/wp-admin/themes.php?page=business_association_guide" method="POST" onsubmit="return validate(this);">
        <?php if (!get_option('business_association_demo_import_completed')) : ?>
        <form method="post">
            <p class="run-import-text"><?php esc_html_e('Click On The Below Run Importer Button To Import Demo Content Of Business Association', 'business-association'); ?></p>
            <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 Business Association', 'business-association'); ?></p>
            <input class="run-import" type="submit" name="submit" value="<?php esc_attr_e('Run Importer', 'business-association'); ?>" class="button button-primary button-large">
        </form>    
        <?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?")) {
                // Show the spinner
                document.getElementById('spinner').style.display = 'block';
                // Allow the form to be submitted
                return true;
            } 
            else {
                return false;
            }
        }
    </script>
</div>
