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

        // If the demo import is completed, display the "View Site" button
        if ($landscape_architecture_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.', 'landscape-architecture' ) . '</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
    if ( isset( $_POST['submit'] ) ) {
        echo '<div class="plugin-notice">';
            // Check if woocommerce is installed and activated
            if (!is_plugin_active('woocommerce/woocommerce.php')) {
                // Install the plugin if it doesn't exist
                $landscape_architecture_plugin_slug = 'woocommerce';
                $landscape_architecture_plugin_file = 'woocommerce/woocommerce.php';

                // Check if plugin is installed
                $landscape_architecture_installed_plugins = get_plugins();
                if (!isset($landscape_architecture_installed_plugins[$landscape_architecture_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
                    $landscape_architecture_upgrader = new Plugin_Upgrader();
                    $landscape_architecture_upgrader->install('https://downloads.wordpress.org/plugin/woocommerce.latest-stable.zip');
                }
                // Activate the plugin
                activate_plugin($landscape_architecture_plugin_file);
            }

            // 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
                $landscape_architecture_plugin_slug = 'classic-blog-grid';
                $landscape_architecture_plugin_file = 'classic-blog-grid/classic-blog-grid.php';
            
                // Check if Classic Blog Grid is installed and activated
                if ( ! is_plugin_active( $landscape_architecture_plugin_file ) ) {
            
                    // Check if Classic Blog Grid is installed
                    $landscape_architecture_installed_plugins = get_plugins();
                    if ( ! isset( $landscape_architecture_installed_plugins[ $landscape_architecture_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
                        $landscape_architecture_upgrader = new Plugin_Upgrader();
                        $landscape_architecture_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( $landscape_architecture_plugin_file );
                }
            }
        echo '</div>';
        // ------- Create Main Menu --------
        $landscape_architecture_menuname = 'Primary Menu';
        $landscape_architecture_bpmenulocation = 'primary';
        $landscape_architecture_menu_exists = wp_get_nav_menu_object( $landscape_architecture_menuname );
    
        if ( !$landscape_architecture_menu_exists ) {
            $landscape_architecture_menu_id = wp_create_nav_menu( $landscape_architecture_menuname );

            // Create Home Page
            $landscape_architecture_home_title = 'Home';
            $landscape_architecture_home = array(
                'post_type'    => 'page',
                'post_title'   => $landscape_architecture_home_title,
                'post_content' => '',
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'home'
            );
            $landscape_architecture_home_id = wp_insert_post($landscape_architecture_home);
            // Assign Home Page Template
            add_post_meta($landscape_architecture_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', $landscape_architecture_home_id);
            update_option('show_on_front', 'page');
            // Add Home Page to Menu
            wp_update_nav_menu_item($landscape_architecture_menu_id, 0, array(
                'menu-item-title' => __('Home', 'landscape-architecture'),
                'menu-item-classes' => 'home',
                'menu-item-url' => home_url('/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $landscape_architecture_home_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create a new Page 
            $landscape_architecture_pages_title = 'Pages';
            $landscape_architecture_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>';
            $landscape_architecture_pages = array(
                'post_type'    => 'page',
                'post_title'   => $landscape_architecture_pages_title,
                'post_content' => $landscape_architecture_pages_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'pages'
            );
            $landscape_architecture_pages_id = wp_insert_post($landscape_architecture_pages);
            // Add Pages Page to Menu
            wp_update_nav_menu_item($landscape_architecture_menu_id, 0, array(
                'menu-item-title' => __('Pages', 'landscape-architecture'),
                'menu-item-classes' => 'pages',
                'menu-item-url' => home_url('/pages/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $landscape_architecture_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create About Us Page with Dummy Content
            $landscape_architecture_about_title = 'About Us';
            $landscape_architecture_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>';
            $landscape_architecture_about = array(
                'post_type'    => 'page',
                'post_title'   => $landscape_architecture_about_title,
                'post_content' => $landscape_architecture_about_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'about-us'
            );
            $landscape_architecture_about_id = wp_insert_post($landscape_architecture_about);
            // Add About Us Page to Menu
            wp_update_nav_menu_item($landscape_architecture_menu_id, 0, array(
                'menu-item-title' => __('About Us', 'landscape-architecture'),
                'menu-item-classes' => 'about-us',
                'menu-item-url' => home_url('/about-us/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $landscape_architecture_about_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( $landscape_architecture_bpmenulocation ) ) {
                $landscape_architecture_locations = get_theme_mod( 'nav_menu_locations' );
                if ( empty( $landscape_architecture_locations ) ) {
                    $landscape_architecture_locations = array();
                }
                $landscape_architecture_locations[ $landscape_architecture_bpmenulocation ] = $landscape_architecture_menu_id;
                set_theme_mod( 'nav_menu_locations', $landscape_architecture_locations );
            }
        }

        //Logo
        set_theme_mod( 'landscape_architecture_the_custom_logo', esc_url( get_template_directory_uri().'/images/Logo.png'));

        //Header
        set_theme_mod( 'landscape_architecture_phone_number', '+1 234 567 890');
        set_theme_mod( 'landscape_architecture_email_address', 'xyz@example.com');

        //Social Media
        set_theme_mod( 'landscape_architecture_fb_link', '#');
        set_theme_mod( 'landscape_architecture_twitt_link', '#');
        set_theme_mod( 'landscape_architecture_linked_link', '#');
        set_theme_mod( 'landscape_architecture_rss_link', '#');
        set_theme_mod( 'landscape_architecture_youtube_link', '#');

        //Slider Section
        set_theme_mod( 'landscape_architecture_hide_categorysec', true);
        set_theme_mod( 'landscape_architecture_button_text', 'Read More');
        set_theme_mod( 'landscape_architecture_button_link_slider', '#');

        $landscape_architecture_featured_category_id = wp_create_category('Architecture');
        set_theme_mod('landscape_architecture_slidersection', $landscape_architecture_featured_category_id);

        $landscape_architecture_titles = array(
            'TRANSFORMING OUTDOOR SPACES INTO MASTERPIECES', 
            'A PERSPECTIVE IN LANDSCAPE ARCHITECT DESIGN',
            'CREATING HARMONY BETWEEN NATURE AND DESIGN.'       
        );        
        $landscape_architecture_content = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.';

        for ($landscape_architecture_i = 0; $landscape_architecture_i < 3; $landscape_architecture_i++) {
            set_theme_mod('landscape_architecture_title' . ($landscape_architecture_i + 1), $landscape_architecture_titles[$landscape_architecture_i]);

            $landscape_architecture_my_post = array(
                'post_title'    => wp_strip_all_tags($landscape_architecture_titles[$landscape_architecture_i]),
                'post_content'  => $landscape_architecture_content,
                'post_status'   => 'publish',
                'post_type'     => 'post',
                'post_category' => array($landscape_architecture_featured_category_id),
            );

            $landscape_architecture_post_id = wp_insert_post($landscape_architecture_my_post);

            if (!is_wp_error($landscape_architecture_post_id)) {
                $landscape_architecture_image_url = get_template_directory_uri() . '/images/slider-image' . ($landscape_architecture_i + 1) . '.png';
                $landscape_architecture_image_id = media_sideload_image($landscape_architecture_image_url, $landscape_architecture_post_id, null, 'id');
                if (!is_wp_error($landscape_architecture_image_id)) {
                    set_post_thumbnail($landscape_architecture_post_id, $landscape_architecture_image_id);
                } else {
                    error_log('Failed to set post thumbnail for post ID: ' . $landscape_architecture_post_id);
                }
            } else {
                error_log('Failed to create post: ' . print_r($landscape_architecture_post_id, true));
            }
        }

        //Services Section
        set_theme_mod( 'landscape_architecture_headingtext1', 'WHO AM I');
        set_theme_mod( 'landscape_architecture_headingtext_para', 'Our Services');
        set_theme_mod( 'landsclandscape_architecture_blog_countape_architecture_blog_count', '3');

        $landscape_architecture_featured_category_id = wp_create_category('Services');
        set_theme_mod('landscape_architecture_blog_cat', $landscape_architecture_featured_category_id);

        $landscape_architecture_titles = array('Garden Design & Planning', 'Horticultural Services', 'Construction Oversight');
        $landscape_architecture_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, when an unknown printer took a galley of type and scrambled it to make a type specimen book.';

        for ($landscape_architecture_i = 0; $landscape_architecture_i < 3; $landscape_architecture_i++) {
            set_theme_mod('landscape_architecture_title' . ($landscape_architecture_i + 1), $landscape_architecture_titles[$landscape_architecture_i]);

            $landscape_architecture_my_post = array(
                'post_title'    => wp_strip_all_tags($landscape_architecture_titles[$landscape_architecture_i]),
                'post_content'  => $landscape_architecture_content,
                'post_status'   => 'publish',
                'post_type'     => 'post',
                'post_category' => array($landscape_architecture_featured_category_id),
            );

            $landscape_architecture_post_id = wp_insert_post($landscape_architecture_my_post);

            if (!is_wp_error($landscape_architecture_post_id)) {
                $landscape_architecture_image_url = get_template_directory_uri() . '/images/service' . ($landscape_architecture_i + 1) . '.png';
                $landscape_architecture_image_id = media_sideload_image($landscape_architecture_image_url, $landscape_architecture_post_id, null, 'id');
                if (!is_wp_error($landscape_architecture_image_id)) {
                    set_post_thumbnail($landscape_architecture_post_id, $landscape_architecture_image_id);
                } else {
                    error_log('Failed to set post thumbnail for post ID: ' . $landscape_architecture_post_id);
                }
            } else {
                error_log('Failed to create post: ' . print_r($landscape_architecture_post_id, true));
            }
        }

        // Show success message and the "View Site" button
        update_option('landscape_architecture_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.', 'landscape-architecture' ) . '</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('landscape_architecture_demo_import_completed')) : ?>
                <span><?php echo esc_html( 'Click on the below content to get demo content installed.', 'landscape-architecture' ); ?></span>
                <br><br>
                <hr><br>
                <b class="note"><?php echo esc_html('Note :', 'landscape-architecture' ); ?></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.', 'landscape-architecture' ); ?></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','landscape-architecture'); ?>" 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>