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

        // If the demo import is completed, display the "View Site" button
        if ($dry_cleaning_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.', 'dry-cleaning-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 Dry Cleaning Services
    if ( isset( $_POST['submit'] ) ) {

        // 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
            $dry_cleaning_services_plugin_slug = 'classic-blog-grid';
            $dry_cleaning_services_plugin_file = 'classic-blog-grid/classic-blog-grid.php';
        
            // Check if Classic Blog Grid is installed and activated
            if ( ! is_plugin_active( $dry_cleaning_services_plugin_file ) ) {
        
                // Check if Classic Blog Grid is installed
                $dry_cleaning_services_installed_plugins = get_plugins();
                if ( ! isset( $dry_cleaning_services_installed_plugins[ $dry_cleaning_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
                    $dry_cleaning_services_upgrader = new Plugin_Upgrader();
                    $dry_cleaning_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( $dry_cleaning_services_plugin_file );
            }
        }

        // ------- Create Main Menu --------
        $dry_cleaning_services_menuname = 'Primary Menu';
        $dry_cleaning_services_bpmenulocation = 'primary';
        $dry_cleaning_services_menu_exists = wp_get_nav_menu_object( $dry_cleaning_services_menuname );
    
        if ( !$dry_cleaning_services_menu_exists ) {
            $dry_cleaning_services_menu_id = wp_create_nav_menu( $dry_cleaning_services_menuname );

            // Create Home Page
            $dry_cleaning_services_home_title = 'Home';
            $dry_cleaning_services_home = array(
                'post_type'    => 'page',
                'post_title'   => $dry_cleaning_services_home_title,
                'post_content' => '',
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'home'
            );
            $dry_cleaning_services_home_id = wp_insert_post($dry_cleaning_services_home);
            // Assign Home Page Template
            add_post_meta($dry_cleaning_services_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', $dry_cleaning_services_home_id);
            update_option('show_on_front', 'page');
            // Add Home Page to Menu
            wp_update_nav_menu_item($dry_cleaning_services_menu_id, 0, array(
                'menu-item-title' => __('Home', 'dry-cleaning-services'),
                'menu-item-classes' => 'home',
                'menu-item-url' => home_url('/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $dry_cleaning_services_home_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create About Us Page with Dummy Content
            $dry_cleaning_services_about_title = 'About Us';
            $dry_cleaning_services_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>'; 
            $dry_cleaning_services_about = array(
                'post_type'    => 'page',
                'post_title'   => $dry_cleaning_services_about_title,
                'post_content' => $dry_cleaning_services_about_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'about-us'
            );
            $dry_cleaning_services_about_id = wp_insert_post($dry_cleaning_services_about);
            // Add About Us Page to Menu
            wp_update_nav_menu_item($dry_cleaning_services_menu_id, 0, array(
                'menu-item-title' => __('About Us', 'dry-cleaning-services'),
                'menu-item-classes' => 'about-us',
                'menu-item-url' => home_url('/about-us/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $dry_cleaning_services_about_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create a new Page 
            $dry_cleaning_services_pages_title = 'Services';
            $dry_cleaning_services_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>';
            $dry_cleaning_services_pages = array(
                'post_type'    => 'page',
                'post_title'   => $dry_cleaning_services_pages_title,
                'post_content' => $dry_cleaning_services_pages_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'services'
            );
            $dry_cleaning_services_pages_id = wp_insert_post($dry_cleaning_services_pages);
            // Add Pages Page to Menu
            wp_update_nav_menu_item($dry_cleaning_services_menu_id, 0, array(
                'menu-item-title' => __('Services', 'dry-cleaning-services'),
                'menu-item-classes' => 'services',
                'menu-item-url' => home_url('/services/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $dry_cleaning_services_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            // Create a new Page 
            $dry_cleaning_services_pages_title = 'Elements';
            $dry_cleaning_services_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>';
            $dry_cleaning_services_pages = array(
                'post_type'    => 'page',
                'post_title'   => $dry_cleaning_services_pages_title,
                'post_content' => $dry_cleaning_services_pages_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'elements'
            );
            $dry_cleaning_services_pages_id = wp_insert_post($dry_cleaning_services_pages);
            // Add Pages Page to Menu
            wp_update_nav_menu_item($dry_cleaning_services_menu_id, 0, array(
                'menu-item-title' => __('Elements', 'dry-cleaning-services'),
                'menu-item-classes' => 'elements',
                'menu-item-url' => home_url('/elements/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $dry_cleaning_services_pages_id,
                'menu-item-object' => 'page',
                'menu-item-type' => 'post_type'
            ));

            $dry_cleaning_services_about_title = 'Shop';
            $dry_cleaning_services_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...';

            $dry_cleaning_services_about = array(
                'post_type'    => 'page',
                'post_title'   => $dry_cleaning_services_about_title,
                'post_content' => $dry_cleaning_services_about_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_name'    => 'shop' 
            );

            $dry_cleaning_services_shop_id = wp_insert_post($dry_cleaning_services_about);

            // Add Blogs Page to Menu
            wp_update_nav_menu_item( $dry_cleaning_services_menu_id, 0, array(
                'menu-item-title'     => __( 'Shop', 'dry-cleaning-services' ),
                'menu-item-classes'  => 'shop',
                'menu-item-object-id'=> $dry_cleaning_services_shop_id,
                'menu-item-object'   => 'page',
                'menu-item-type'     => 'post_type',
                'menu-item-status'   => 'publish'
            ));
            if ( class_exists( 'WooCommerce' ) ) {
                update_option( 'woocommerce_shop_page_id', $dry_cleaning_services_shop_id );
            }

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

            $dry_cleaning_services_about = array(
                'post_type'    => 'page',
                'post_title'   => $dry_cleaning_services_about_title,
                'post_content' => $dry_cleaning_services_about_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_name'    => 'blogs' 
            );

            $dry_cleaning_services_about_id = wp_insert_post($dry_cleaning_services_about);

            // Add Blogs Page to Menu
            wp_update_nav_menu_item( $dry_cleaning_services_menu_id, 0, array(
                'menu-item-title'     => __( 'Blogs', 'dry-cleaning-services' ),
                'menu-item-classes'  => 'blogs',
                'menu-item-object-id'=> $dry_cleaning_services_about_id,
                'menu-item-object'   => 'page',
                'menu-item-type'     => 'post_type',
                'menu-item-status'   => 'publish'
            ));

            update_option( 'page_for_posts', $dry_cleaning_services_about_id );

            // Create a new Page 
            $dry_cleaning_services_pages_title = 'Contact';
            $dry_cleaning_services_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>';
            $dry_cleaning_services_pages = array(
                'post_type'    => 'page',
                'post_title'   => $dry_cleaning_services_pages_title,
                'post_content' => $dry_cleaning_services_pages_content,
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_slug'    => 'contact'
            );
            $dry_cleaning_services_pages_id = wp_insert_post($dry_cleaning_services_pages);
            // Add Pages Page to Menu
            wp_update_nav_menu_item($dry_cleaning_services_menu_id, 0, array(
                'menu-item-title' => __('Contact', 'dry-cleaning-services'),
                'menu-item-classes' => 'contact',
                'menu-item-url' => home_url('/contact/'),
                'menu-item-status' => 'publish',
                'menu-item-object-id' => $dry_cleaning_services_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( $dry_cleaning_services_bpmenulocation ) ) {
                $dry_cleaning_services_locations = get_theme_mod( 'nav_menu_locations' );
                if ( empty( $dry_cleaning_services_locations ) ) {
                    $dry_cleaning_services_locations = array();
                }
                $dry_cleaning_services_locations[ $dry_cleaning_services_bpmenulocation ] = $dry_cleaning_services_menu_id;
                set_theme_mod( 'nav_menu_locations', $dry_cleaning_services_locations );
            }
        }

        // Update customizer settings
        set_theme_mod( 'dry_cleaning_services_email_address', 'needhelp@example.com' );
        set_theme_mod( 'dry_cleaning_services_time', 'Mon-Fri 08:00 AM - 05:00 PM' );
        set_theme_mod( 'dry_cleaning_services_header_btn_text', 'ORDER SERVICE NOW' );
        set_theme_mod( 'dry_cleaning_services_header_btn_url', '#' );
        set_theme_mod( 'dry_cleaning_services_phone_number', '+12 34567890' );
    
        set_theme_mod( 'dry_cleaning_services_the_custom_logo', esc_url( get_template_directory_uri().'/images/Logo.png'));

        //social media
        //facebook link 
        set_theme_mod( 'dry_cleaning_services_fb_link', 'https://www.facebook.com/' );
        //twitter link
        set_theme_mod( 'dry_cleaning_services_twitt_link', 'https://www.twitter.com/' );    
        //linkedin
        set_theme_mod( 'dry_cleaning_services_linkedin_link', 'https://www.linkedin.com/' );
        //google
        set_theme_mod( 'dry_cleaning_services_google_link', 'https://www.google.com/' );

        // Slider settings
        set_theme_mod( 'dry_cleaning_services_slider_subhead', 'the best solution for dry cleaning' ); 
        set_theme_mod( 'dry_cleaning_services_button_text', 'Discover More');
        set_theme_mod( 'dry_cleaning_services_button_link_slider', '#');
        set_theme_mod( 'dry_cleaning_services_discount_text', '30%');
        
        // Create the 'Branding' category and retrieve its ID
        $dry_cleaning_services_slider_category_id = wp_create_category('Branding');
        
        // Set the slider category in theme mods
        set_theme_mod('dry_cleaning_services_slider_cat', 'Branding');

        $dry_cleaning_services_titles = array(
            'Laundry And Dry Cleaning Services',
            'Professional Care for Your Clothes',
            'Effortless Laundry Solutions, Just for You',
        );        
        // Create three posts and assign them to the 'Branding' category
        for ($dry_cleaning_services_i = 1; $dry_cleaning_services_i <= 3; $dry_cleaning_services_i++) {
            $dry_cleaning_services_title = $dry_cleaning_services_titles[$dry_cleaning_services_i - 1];
            $dry_cleaning_services_content = 'Morbi praesent nascetur maecenas ligula habitasse tellus duis quisque efficitur sollicitudin senectus.';
            
            // Create the post object
            $dry_cleaning_services_my_post = array(
                'post_title'    => wp_strip_all_tags($dry_cleaning_services_title),
                'post_content'  => $dry_cleaning_services_content,
                'post_status'   => 'publish',
                'post_type'     => 'post',
                'post_category' => array($dry_cleaning_services_slider_category_id),  // Use the category ID
            );
        
            // Insert the post into the database
            $dry_cleaning_services_post_id = wp_insert_post($dry_cleaning_services_my_post);
        
            // If the post was successfully created
            if ($dry_cleaning_services_post_id) {
                // Set the theme mod for the slider page
                set_theme_mod('dry_cleaning_services_slider_cat' . $dry_cleaning_services_i, $dry_cleaning_services_post_id);
  
                 $dry_cleaning_services_image_url = get_template_directory_uri().'/images/slider'.$dry_cleaning_services_i.'.png';
  
               $dry_cleaning_services_image_id = media_sideload_image($dry_cleaning_services_image_url, $dry_cleaning_services_post_id, null, 'id');
  
                   if (!is_wp_error($dry_cleaning_services_image_id)) {
                       // Set the downloaded image as the post's featured image
                       set_post_thumbnail($dry_cleaning_services_post_id, $dry_cleaning_services_image_id);
                   }
            }
        }

        // Services Section    
        set_theme_mod( 'dry_cleaning_services_service_text', 'OUR SERVICES');
        set_theme_mod( 'dry_cleaning_services_service_title', 'Services Were Offering');
                
        // Set the number of services
        set_theme_mod('dry_cleaning_services_claases_number', 3);

        // Titles, images, and icons for the services
        $dry_cleaning_services_service_titles = array('Curtains Laundry', 'Dry Cleaning', 'Stain Removals');
        $dry_cleaning_services_image_urls = array(
            get_template_directory_uri() . '/images/dry-services/dry-service1.png',
            get_template_directory_uri() . '/images/dry-services/dry-service2.png',
            get_template_directory_uri() . '/images/dry-services/dry-service3.png'
        );
        $dry_cleaning_services_service_icons = array('fa-solid fa-shirt', 'fa-solid fa-tshirt', 'fa-solid fa-tshirt');

        // Loop to create posts for each service
        for ($i = 0; $i < 3; $i++) {
            $title = $dry_cleaning_services_service_titles[$i];
            $content = 'Morbi praesent nascetur maecenas ligula habitasse tellus duis quisque efficitur sollicitudin senectus.';
            $icon = $dry_cleaning_services_service_icons[$i];

            // Create the post object
            $post_id = wp_insert_post(array(
                'post_title'    => wp_strip_all_tags($title),
                'post_content'  => $content,
                'post_status'   => 'publish',
                'post_type'     => 'post',
            ));

            // If the post was successfully created
            if ($post_id && !is_wp_error($post_id)) {
                // Set the theme mod for selecting this post
                set_theme_mod('dry_cleaning_services_select_post' . ($i + 1), $post_id);

                // Set the icon as a theme mod
                set_theme_mod('dry_cleaning_services_services_icon' . ($i + 1), $icon);

                // Handle the featured image using media_sideload_image
                $image_url = $dry_cleaning_services_image_urls[$i];
                $image_id = media_sideload_image($image_url, $post_id, null, 'id');

                if (!is_wp_error($image_id)) {
                    set_post_thumbnail($post_id, $image_id);
                } else {
                    error_log("Failed to download image for $title: " . $image_id->get_error_message());
                }
            } else {
                error_log("Failed to create post: " . print_r($post_id, true));
            }
        }

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