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

        // If the demo import is completed, display the "View Site" button
        if ($cloud_storage_services_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.', 'cloud-storage-services' ) . '</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 Cloud Storage Services
    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
                $cloud_storage_services_plugin_slug = 'classic-blog-grid';
                $cloud_storage_services_plugin_file = 'classic-blog-grid/classic-blog-grid.php';
            
                // Check if Classic Blog Grid is installed and activated
                if ( ! is_plugin_active( $cloud_storage_services_plugin_file ) ) {
            
                    // Check if Classic Blog Grid is installed
                    $cloud_storage_services_installed_plugins = get_plugins();
                    if ( ! isset( $cloud_storage_services_installed_plugins[ $cloud_storage_services_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
                        $cloud_storage_services_upgrader = new Plugin_Upgrader();
                        $cloud_storage_services_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( $cloud_storage_services_plugin_file );
                }
            }
        echo '</div>';
        // ------- Create Main Menu --------
        $cloud_storage_services_menuname = 'Primary Menu'; 
        $cloud_storage_services_bpmenulocation = 'primary';
        $cloud_storage_services_menu_exists = wp_get_nav_menu_object($cloud_storage_services_menuname);

        if (!$cloud_storage_services_menu_exists) {
            // Create a new menu
            $cloud_storage_services_menu_id = wp_create_nav_menu($cloud_storage_services_menuname);

            // Define pages to be created
            $cloud_storage_services_pages = array(
                'home' => array(
                    'title' => 'Home',
                    'template' => '/templates/template-home-page.php'
                ),
                'about-us' => array(
                    'title' => 'About Us',
                    '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>'
                ),
                'services' => array(
                    'title' => 'Services',
                    '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>'
                ),
                'pages' => array(
                    'title' => '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>'
                ),
                'blogs' => array(
                    'title' => 'Blogs',
                    '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>'
                ),
                'contact-us' => array(
                    'title' => 'Contact Us',
                    '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>'
                )
            );

            $cloud_storage_services_page_ids = array();

            // Loop through the pages and create them if they don’t exist
            foreach ($cloud_storage_services_pages as $cloud_storage_services_slug => $cloud_storage_services_data) {
                $cloud_storage_services_existing_page = get_page_by_path($cloud_storage_services_slug);

                if ($cloud_storage_services_existing_page) {
                    // If the page already exists, use its ID
                    $cloud_storage_services_page_id = $cloud_storage_services_existing_page->ID;
                } else {
                    // Create a new page
                    $cloud_storage_services_page_data = array(
                        'post_type'    => 'page',
                        'post_title'   => $cloud_storage_services_data['title'],
                        'post_content' => isset($cloud_storage_services_data['content']) ? $cloud_storage_services_data['content'] : '',
                        'post_status'  => 'publish',
                        'post_author'  => get_current_user_id(), // Set author dynamically
                        'post_name'    => $cloud_storage_services_slug,
                    );

                    $cloud_storage_services_page_id = wp_insert_post($cloud_storage_services_page_data);

                    // Assign custom page template if specified
                    if (!empty($cloud_storage_services_data['template'])) {
                        update_post_meta($cloud_storage_services_page_id, '_wp_page_template', $cloud_storage_services_data['template']);
                    }
                }

                // Store the page IDs
                $cloud_storage_services_page_ids[$cloud_storage_services_slug] = $cloud_storage_services_page_id;
            }

            // Set homepage and blog page
            update_option('page_for_posts', $cloud_storage_services_page_ids['blogs']);
            update_option('page_on_front', $cloud_storage_services_page_ids['home']);
            update_option('show_on_front', 'page');

            // Define menu items
            $cloud_storage_services_menu_items = array(
                'home',
                'about-us',
                'services',
                'pages',
                'blogs',
                'contact-us',
            );

            // Add menu items dynamically
            foreach ($cloud_storage_services_menu_items as $cloud_storage_services_slug) {
                wp_update_nav_menu_item($cloud_storage_services_menu_id, 0, array(
                    'menu-item-title' => esc_html($cloud_storage_services_pages[$cloud_storage_services_slug]['title']),
                    'menu-item-url' => get_permalink($cloud_storage_services_page_ids[$cloud_storage_services_slug]),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $cloud_storage_services_page_ids[$cloud_storage_services_slug],
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type',
                ));
            }

            // Assign menu to theme location
            $cloud_storage_services_locations = get_theme_mod('nav_menu_locations', array());
            $cloud_storage_services_locations[$cloud_storage_services_bpmenulocation] = $cloud_storage_services_menu_id;
            set_theme_mod('nav_menu_locations', $cloud_storage_services_locations);
        }

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

        //Header Section       
        set_theme_mod('cloud_storage_services_header_btn_url', '#');   

        //Banner Section
        set_theme_mod( 'cloud_storage_services_banner', true);
        set_theme_mod( 'cloud_storage_services_banner_small_title', 'Welcome To CT-Cloud Storage');
        set_theme_mod( 'cloud_storage_services_banner_main_title', 'Access your data anytime, anywhere — protected and in sync.');
        set_theme_mod( 'cloud_storage_services_banner_left_btn_text', 'Explore More');
        set_theme_mod( 'cloud_storage_services_banner_right_btn_text', 'Get Started');
        set_theme_mod( 'cloud_storage_services_video_button_url', 'https://www.youtube.com/embed/QZH7vQRLumU?si=3Je9JDdYGiXdkhiS');
        set_theme_mod( 'cloud_storage_services_banner_upload_box_title', 'Buyer Profiles');
        set_theme_mod( 'cloud_storage_services_banner_upload_other_title', 'Other');
        set_theme_mod( 'cloud_storage_services_banner_other_buyers', '15');
        set_theme_mod( 'cloud_storage_services_banner_upload_business_title', 'Business');
        set_theme_mod( 'cloud_storage_services_banner_business_buyers', '50');
        set_theme_mod( 'cloud_storage_services_banner_upload_female_title', 'Female');
        set_theme_mod( 'cloud_storage_services_banner_female_buyers', '12');
        set_theme_mod( 'cloud_storage_services_banner_upload_male_title', 'Male');
        set_theme_mod( 'cloud_storage_services_banner_male_buyers', '33');
        set_theme_mod( 'cloud_storage_services_banner_review_count', '4.6k+');
        set_theme_mod( 'cloud_storage_services_banner_review_text', 'Trusted People');
        set_theme_mod( 'cloud_storage_services_banner_storage_title', 'Upload Files');
        set_theme_mod( 'cloud_storage_services_banner_storage_file_title', 'Storage');
        set_theme_mod( 'cloud_storage_services_banner_storage_files', '70');
        set_theme_mod( 'cloud_storage_services_banner_video_title', 'Videos');
        set_theme_mod( 'cloud_storage_services_banner_video_files', '80');
        set_theme_mod( 'cloud_storage_services_banner_images_title', 'Images');
        set_theme_mod( 'cloud_storage_services_banner_image_files', '90');
        set_theme_mod( 'cloud_storage_services_banner_graph_img', esc_url( get_template_directory_uri().'/images/banner.png'));

        //Team Section
        set_theme_mod( 'cloud_storage_services_disabled_team_section', true);
        set_theme_mod( 'cloud_storage_services_team_text', 'Meet Management Team');
        set_theme_mod( 'cloud_storage_services_team_title', 'Handles all of your file needs');
        set_theme_mod( 'cloud_storage_services_team_desc', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.');

        $cloud_storage_services_team_demo_data = array(
            array(
                'img'   => '/images/team/team1.png',
                'name'  => 'Paul Alexander',
                'role'  => 'CEO',
                'fb'    => 'https://www.facebook.com',
                'tw'    => 'https://www.twitter.com',
                'yt'    => 'https://www.youtube.com',
                'ig'    => 'https://www.instagram.com',
            ),
            array(
                'img'   => '/images/team/team2.png',
                'name'  => 'Jessica Johns',
                'role'  => 'Designer',
                'fb'    => 'https://www.facebook.com',
                'tw'    => 'https://www.twitter.com',
                'yt'    => 'https://www.youtube.com',
                'ig'    => 'https://www.instagram.com',
            ),
            array(
                'img'   => '/images/team/team3.png',
                'name'  => 'Sophia Brown',
                'role'  => 'Manager',
                'fb'    => 'https://www.facebook.com',
                'tw'    => 'https://www.twitter.com',
                'yt'    => 'https://www.youtube.com',
                'ig'    => 'https://www.instagram.com',
            ),
            array(
                'img'   => '/images/team/team4.png',
                'name'  => 'James Wilson',
                'role'  => 'Lead Developer',
                'fb'    => 'https://www.facebook.com',
                'tw'    => 'https://www.twitter.com',
                'yt'    => 'https://www.youtube.com',
                'ig'    => 'https://www.instagram.com',
            ),
            array(
                'img'   => '/images/team/team5.png',
                'name'  => 'Emma Davis',
                'role'  => 'UI/UX Designer',
                'fb'    => 'https://www.facebook.com',
                'tw'    => 'https://www.twitter.com',
                'yt'    => 'https://www.youtube.com',
                'ig'    => 'https://www.instagram.com',
            ),
            array(
                'img'   => '/images/team/team6.png',
                'name'  => 'Daniel Martinez',
                'role'  => 'Marketing Head',
                'fb'    => 'https://www.facebook.com',
                'tw'    => 'https://www.twitter.com',
                'yt'    => 'https://www.youtube.com',
                'ig'    => 'https://www.instagram.com',
            ),
        );

        for ($cloud_storage_services_i=0; $cloud_storage_services_i < count($cloud_storage_services_team_demo_data); $cloud_storage_services_i++) {
            set_theme_mod('cloud_storage_services_team_member_img'.$cloud_storage_services_i, get_template_directory_uri().$cloud_storage_services_team_demo_data[$cloud_storage_services_i]['img']);
            set_theme_mod('cloud_storage_services_team_member_name'.$cloud_storage_services_i, $cloud_storage_services_team_demo_data[$cloud_storage_services_i]['name']);
            set_theme_mod('cloud_storage_services_team_member_designation'.$cloud_storage_services_i, $cloud_storage_services_team_demo_data[$cloud_storage_services_i]['role']);
            set_theme_mod('cloud_storage_services_disabled_team_social_icon'.$cloud_storage_services_i, true);
            set_theme_mod('cloud_storage_services_facebook_url'.$cloud_storage_services_i, $cloud_storage_services_team_demo_data[$cloud_storage_services_i]['fb']);
            set_theme_mod('cloud_storage_services_twitter_url'.$cloud_storage_services_i, $cloud_storage_services_team_demo_data[$cloud_storage_services_i]['tw']);
            set_theme_mod('cloud_storage_services_youtube_url'.$cloud_storage_services_i, $cloud_storage_services_team_demo_data[$cloud_storage_services_i]['yt']);
            set_theme_mod('cloud_storage_services_instagram_url'.$cloud_storage_services_i, $cloud_storage_services_team_demo_data[$cloud_storage_services_i]['ig']);
        }

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



 