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

        // If the demo import is completed, display the "View Site" button
        if ($garden_farm_demo_import_completed) {
            echo '<br>';
            echo '<div class="success">Demo Import Successful</div>';
            echo '<br>';
            echo '<hr>';
            echo '<br>';
            echo '<span>' . esc_html__( 'You can now visit your site or customize it further.', 'garden-farm' ) . '</span>';
            echo '<br>';
            echo '<br>';
            echo '<br>';
            echo '<div class="view-site-btn">';
            echo '<a href="' . esc_url(home_url()) . '" class="button button-primary button-large" style="margin-top: 10px;" target="_blank">View Site</a>';
            echo '<a href="' . esc_url( admin_url('customize.php') ) . '" class="button button-primary button-large" style="margin-top: 10px;" target="_blank">Customize Demo Content</a>';
            echo '</div>';
        }
     // POST and update the customizer and other related data of Garden Farm
    if ( isset( $_POST['submit'] ) ) {
        echo '<div class="plugin-notice">';
            // Check if Classic Blog Grid plugin is installed
            if (!is_plugin_active('classic-blog-grid/classic-blog-grid.php')) {
                // Plugin slug and file path for Classic Blog Grid
                $garden_farm_plugin_slug = 'classic-blog-grid';
                $garden_farm_plugin_file = 'classic-blog-grid/classic-blog-grid.php';
            
                // Check if Classic Blog Grid is installed and activated
                if ( ! is_plugin_active( $garden_farm_plugin_file ) ) {
            
                    // Check if Classic Blog Grid is installed
                    $garden_farm_installed_plugins = get_plugins();
                    if ( ! isset( $garden_farm_installed_plugins[ $garden_farm_plugin_file ] ) ) {
            
                        // Include necessary files to install plugins
                        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' );
            
                        // Download and install Classic Blog Grid
                        $garden_farm_upgrader = new Plugin_Upgrader();
                        $garden_farm_upgrader->install( 'https://downloads.wordpress.org/plugin/classic-blog-grid.latest-stable.zip' );
                    }
            
                    // Activate the Classic Blog Grid plugin after installation (if needed)
                    activate_plugin( $garden_farm_plugin_file );
                }
            }
        echo '</div>';
        // ------- Create Main Menu --------
        $garden_farm_menuname = 'Primary Menu';
        $garden_farm_bpmenulocation = 'primary';
        $garden_farm_menu_exists = wp_get_nav_menu_object( $garden_farm_menuname );
    
        if ( !$garden_farm_menu_exists ) {
            $garden_farm_menu_id = wp_create_nav_menu( $garden_farm_menuname );

            // Create Home Page
            $garden_farm_home_title = 'Home';
            $garden_farm_home = array(
                'post_type'    => 'page',
                'post_title'   => $garden_farm_home_title,
                'post_content' => '',
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'home'
            );
            $garden_farm_home_id = wp_insert_post($garden_farm_home);
            // Assign Home Page Template
            add_post_meta($garden_farm_home_id, '_wp_page_template', 'templates/template-home-page.php');
            // Update options to set Home Page as the front page
            update_option('page_on_front', $garden_farm_home_id);
            update_option('show_on_front', 'page');
            // Add Home Page to Menu
            wp_update_nav_menu_item($garden_farm_menu_id, 0, array(
                'menu-item-title' => __('Home', 'garden-farm'),
                'menu-item-classes' => 'home',
                'menu-item-url' => home_url('/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $garden_farm_home_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create About Us Page with Dummy Content
            $garden_farm_about_title = 'About Us';
            $garden_farm_about_content = '<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.</P>'; // Dummy content shortened for brevity
            $garden_farm_about = array(
                'post_type'    => 'page',
                'post_title'   => $garden_farm_about_title,
                'post_content' => $garden_farm_about_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'about-us'
            );
            $garden_farm_about_id = wp_insert_post($garden_farm_about);
            // Add About Us Page to Menu
            wp_update_nav_menu_item($garden_farm_menu_id, 0, array(
                'menu-item-title' => __('About Us', 'garden-farm'),
                'menu-item-classes' => 'about-us',
                'menu-item-url' => home_url('/about-us/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $garden_farm_about_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create a new Page 
            $garden_farm_pages_title = 'Our Service';
            $garden_farm_pages_content = '<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.</p>';
            $garden_farm_pages = array(
                'post_type'    => 'page',
                'post_title'   => $garden_farm_pages_title,
                'post_content' => $garden_farm_pages_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'our-service'
            );
            $garden_farm_pages_id = wp_insert_post($garden_farm_pages);
            // Add Pages Page to Menu
            wp_update_nav_menu_item($garden_farm_menu_id, 0, array(
                'menu-item-title' => __('Our Service', 'garden-farm'),
                'menu-item-classes' => 'our-service',
                'menu-item-url' => home_url('/our-service/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $garden_farm_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create a new Page 
            $garden_farm_pages_title = 'Our Project';
            $garden_farm_pages_content = '<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.</p>';
            $garden_farm_pages = array(
                'post_type'    => 'page',
                'post_title'   => $garden_farm_pages_title,
                'post_content' => $garden_farm_pages_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'our-project'
            );
            $garden_farm_pages_id = wp_insert_post($garden_farm_pages);
            // Add Pages Page to Menu
            wp_update_nav_menu_item($garden_farm_menu_id, 0, array(
                'menu-item-title' => __('Our Project', 'garden-farm'),
                'menu-item-classes' => 'our-project',
                'menu-item-url' => home_url('/our-project/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $garden_farm_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create a new Page 
            $garden_farm_pages_title = 'Pages';
            $garden_farm_pages_content = '<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.</p>';
            $garden_farm_pages = array(
                'post_type'    => 'page',
                'post_title'   => $garden_farm_pages_title,
                'post_content' => $garden_farm_pages_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'pages'
            );
            $garden_farm_pages_id = wp_insert_post($garden_farm_pages);
            // Add Pages Page to Menu
            wp_update_nav_menu_item($garden_farm_menu_id, 0, array(
                'menu-item-title' => __('Pages', 'garden-farm'),
                'menu-item-classes' => 'pages',
                'menu-item-url' => home_url('/pages/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $garden_farm_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create Blogs Page with Dummy Content
            $garden_farm_about_title = 'Blog';
            $garden_farm_about_content = '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...';

            $garden_farm_about = array(
                'post_type'    => 'page',
                'post_title'   => $garden_farm_about_title,
                'post_content' => $garden_farm_about_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_name'    => 'blog' 
            );

            $garden_farm_about_id = wp_insert_post($garden_farm_about);

            // Add Blogs Page to Menu
            wp_update_nav_menu_item( $garden_farm_menu_id, 0, array(
                'menu-item-title'     => __( 'Blog', 'garden-farm' ),
                'menu-item-classes'  => 'blog',
                'menu-item-object-id'=> $garden_farm_about_id,
                'menu-item-object'   => 'page',
                'menu-item-type'     => 'post_type',
                'menu-item-status'   => 'publish'
            ));

            update_option( 'page_for_posts', $garden_farm_about_id );

            // Create a new Page 
            $garden_farm_pages_title = 'Contact';
            $garden_farm_pages_content = '<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.</p>';
            $garden_farm_pages = array(
                'post_type'    => 'page',
                'post_title'   => $garden_farm_pages_title,
                'post_content' => $garden_farm_pages_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'contact'
            );
            $garden_farm_pages_id = wp_insert_post($garden_farm_pages);
            // Add Pages Page to Menu
            wp_update_nav_menu_item($garden_farm_menu_id, 0, array(
                'menu-item-title' => __('Contact', 'garden-farm'),
                'menu-item-classes' => 'contact',
                'menu-item-url' => home_url('/contact/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $garden_farm_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Assign the menu to the primary location if not already set
            if ( ! has_nav_menu( $garden_farm_bpmenulocation ) ) {
                $garden_farm_locations = get_theme_mod( 'nav_menu_locations' );
                if ( empty( $garden_farm_locations ) ) {
                    $garden_farm_locations = array();
                }
                $garden_farm_locations[ $garden_farm_bpmenulocation ] = $garden_farm_menu_id;
                set_theme_mod( 'nav_menu_locations', $garden_farm_locations );
            }
        }

        // Header Section
        set_theme_mod( 'garden_farm_the_custom_logo', esc_url( get_template_directory_uri().'/images/Logo.png'));
        set_theme_mod( 'garden_farm_whatsapp_link', 'https://www.whatsapp.com' );
        set_theme_mod( 'garden_farm_fb_link', 'https://www.facebook.com' );
        set_theme_mod( 'garden_farm_youtube_link', 'https://www.youtube.com' );
        set_theme_mod( 'garden_farm_instagram_link', 'https://www.instagram.com' );
        set_theme_mod( 'garden_farm_phone_number', '+00 123 456 7890' );
        set_theme_mod( 'garden_farm_email_address', 'agriculture123@ex.com' );
        set_theme_mod( 'garden_farm_address_location', 'Yourlocation1234' );
        set_theme_mod( 'garden_farm_track_locatin_url', '#' );
        
        // Slider Section
        set_theme_mod( 'garden_farm_slider_subhead', 'We’re producing natural goods' );
        set_theme_mod( 'garden_farm_button_link_slider', '#' );
        set_theme_mod( 'garden_farm_slider_nav_img', get_template_directory_uri().'/images/nav-img.png' );

         // Create the 'Garden Farm' category and retrieve its ID
         $garden_farm_slider_category_id = wp_create_category('Garden Farm');
        
         // Set the slider category in theme mods
         set_theme_mod('garden_farm_slider_cat', 'Garden Farm');
         $garden_farm_titles = array(
            'Welcome to The Agriculture Farm',
            'Join us in celebrating farm',
            'Discover the essence of nature'        
        );
         // Create three posts and assign them to the 'Garden Farm' category
         for ($garden_farm_i = 1; $garden_farm_i <= 3; $garden_farm_i++) {
            $garden_farm_title = $garden_farm_titles[$garden_farm_i - 1];
             $garden_farm_content = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.';
             
             // Create the post object
             $garden_farm_my_post = array(
                 'post_title'    => wp_strip_all_tags($garden_farm_title),
                 'post_content'  => $garden_farm_content,
                 'post_status'   => 'publish',
                 'post_type'     => 'post',
                 'post_category' => array($garden_farm_slider_category_id),  // Use the category ID
             );
         
             // Insert the post into the database
             $garden_farm_post_id = wp_insert_post($garden_farm_my_post);
         
             // If the post was successfully created
             if ($garden_farm_post_id) {
                // Set the theme mod for the slider page
                set_theme_mod('garden_farm_slider_cat' . $garden_farm_i, $garden_farm_post_id);
  
                 $garden_farm_image_url = get_template_directory_uri().'/images/slider'.$garden_farm_i.'.png';
  
               $garden_farm_image_id = media_sideload_image($garden_farm_image_url, $garden_farm_post_id, null, 'id');
  
                   if (!is_wp_error($garden_farm_image_id)) {
                       // Set the downloaded image as the post's featured image
                       set_post_thumbnail($garden_farm_post_id, $garden_farm_image_id);
                   }
             }
         }

        // Team Section Settings
        set_theme_mod('garden_farm_our_team_text', 'OUR TEAMS');
        set_theme_mod('garden_farm_our_team_title', 'Our Best Farmer');

        // Create the 'Agriculture Farmer' category
        $garden_farm_featured_category_id = wp_create_category('Agriculture Farmer');

        // Set the created category in the theme mod
        set_theme_mod('garden_farm_posts', 'Agriculture Farmer');

        $garden_farm_titles = array('Kevin Martin', 'Shah Verma', 'Jessica Brown');
        $garden_farm_content = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys 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';

        // Define social media icons and their corresponding classes
        $garden_farm_social_media_icons = array(
            'facebook'  => 'fa-brands fa-facebook-f',
            'twitter'   => 'fa-brands fa-twitter',
            'instagram' => 'fa-brands fa-instagram',
            'youtube'   => 'fa-brands fa-youtube',
            'share'     => 'fa-solid fa-share',
        );

        // Create posts for each team member
        foreach ($garden_farm_titles as $garden_farm_index => $garden_farm_title) {
            $garden_farm_post_data = array(
                'post_title'   => wp_strip_all_tags($garden_farm_title),
                'post_content' => $garden_farm_content,
                'post_status'  => 'publish',
                'post_type'    => 'post',
                'post_category'=> array($garden_farm_featured_category_id),
            );

            $garden_farm_post_id = wp_insert_post($garden_farm_post_data);

            if (!is_wp_error($garden_farm_post_id)) {
                // Set the post thumbnail
                $garden_farm_image_url = get_template_directory_uri() . '/images/team/team' . ($garden_farm_index + 1) . '.png';
                $garden_farm_image_id = media_sideload_image($garden_farm_image_url, $garden_farm_post_id, null, 'id');
                if (!is_wp_error($garden_farm_image_id)) {
                    set_post_thumbnail($garden_farm_post_id, $garden_farm_image_id);
                }

                // Add social links and icons for each team member
                $garden_farm_social_links = array(
                    'facebook'  => 'https://facebook.com/' . strtolower($garden_farm_title),
                    'twitter'   => 'https://twitter.com/' . strtolower($garden_farm_title),
                    'instagram' => 'https://instagram.com/' . strtolower($garden_farm_title),
                    'youtube'   => 'https://youtube.com/' . strtolower($garden_farm_title),
                    'share'     => 'https://example.com/share/' . strtolower($garden_farm_title),
                );

                $garden_farm_social_index = 1;
                foreach ($garden_farm_social_links as $garden_farm_platform => $garden_farm_link) {
                    $garden_farm_social_link_id = 'garden_farm_social_link_' . $garden_farm_post_id . '_' . $garden_farm_social_index;
                    $garden_farm_social_icon_id = 'garden_farm_social_icon_' . $garden_farm_post_id . '_' . $garden_farm_social_index;

                    // Set the social link and icon for each platform
                    set_theme_mod($garden_farm_social_link_id, $garden_farm_link);
                    set_theme_mod($garden_farm_social_icon_id, $garden_farm_social_media_icons[$garden_farm_platform]);

                    $garden_farm_social_index++;
                }
            }
        }

        // Show success message and the "View Site" button
        update_option('garden_farm_demo_import_completed', true);
        echo '<br>';
        echo '<div class="success">Demo Import Successful</div>';
        echo '<br>';
        echo '<hr>';
        echo '<br>';
        echo '<span>' . esc_html__( 'You can now visit your site or customize it further.', 'garden-farm' ) . '</span>';
        echo '<br>';
    }
     ?>
    <ul>
        <li>
        <?php 
        // Check if the form is submitted
        if ( !isset( $_POST['submit'] ) ) : ?>
            <!-- Show demo importer form only if it's not submitted -->
            <?php if (!get_option('garden_farm_demo_import_completed')) : ?>
                <span><?php echo esc_html( 'Click on the below content to get demo content installed.', 'garden-farm' ); ?></span>
                <br><br>
                <hr><br>
                <b class="note"><?php echo esc_html('Note :', 'garden-farm' ); ?></b><br><br>
                <small><b><?php echo esc_html('Please take a backup if your website is already live with data. This importer will overwrite existing data.', 'garden-farm' ); ?></b></small><br><br>
                <form id="demo-importer-form" action="" method="POST" onsubmit="return runDemoImport();">
                    <input type="submit" name="submit" value="<?php echo esc_attr('Run Importer','garden-farm'); ?>" class="button button-primary button-large">
                </form>
                <script type="text/javascript">
                    function runDemoImport() {
                        if (confirm('Do you really want to do this?')) {
                            document.getElementById('demo-import-loader').style.display = 'block';
                            return true;
                        }
                        return false;
                    }
                </script>
             <?php endif; ?>
         <?php 
        endif; 

        // Show "View Site" button after form submission
        if ( isset( $_POST['submit'] ) ) {
        echo '<div class="view-site-btn">';
        echo '<a href="' . esc_url(home_url()) . '" class="button button-primary button-large" style="margin-top: 10px;" target="_blank">View Site</a>';
        echo '<a href="' . esc_url( admin_url('customize.php') ) . '" class="button button-primary button-large" style="margin-top: 10px;" target="_blank">Customize Demo Content</a>';
        echo '</div>';
        }
        ?>
        </li>
    </ul>
 </div>