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

        // If the demo import is completed, display the "View Site" button
        if ($automobile_car_dealer_demo_import_completed) {
        echo '<p class="notice-text">' . esc_html__('Your demo import has been completed successfully.', 'automobile-car-dealer') . '</p>';
        echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('VIEW SITE', 'automobile-car-dealer') . '</a></span>';
        }

        if (isset($_POST['submit'])) {

            // Check if ace-post-type-builder is installed and activated
            if (!is_plugin_active('ace-post-type-builder/ace-post-type-builder.php')) {
                // Install the plugin if it doesn't exist
                $automobile_car_dealer_plugin_slug = 'ace-post-type-builder';
                $automobile_car_dealer_plugin_file = 'ace-post-type-builder/ace-post-type-builder.php';

                // Check if plugin is installed
                $automobile_car_dealer_installed_plugins = get_plugins();
                if (!isset($automobile_car_dealer_installed_plugins[$automobile_car_dealer_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
                    $automobile_car_dealer_upgrader = new Plugin_Upgrader();
                    $automobile_car_dealer_upgrader->install('https://downloads.wordpress.org/plugin/ace-post-type-builder.latest-stable.zip');
                }
                // Activate the plugin
                activate_plugin($automobile_car_dealer_plugin_file);
            }

            // ------- Create Nav Menu --------
            $automobile_car_dealer_menuname = 'Main Menus';
            $automobile_car_dealer_bpmenulocation = 'primary';
            $automobile_car_dealer_menu_exists = wp_get_nav_menu_object($automobile_car_dealer_menuname);

            if (!$automobile_car_dealer_menu_exists) {
                $automobile_car_dealer_menu_id = wp_create_nav_menu($automobile_car_dealer_menuname);

                // Create Home Page
                $automobile_car_dealer_home_title = 'HOME';
                $automobile_car_dealer_home = array(
                    'post_type' => 'page',
                    'post_title' => $automobile_car_dealer_home_title,
                    'post_content' => '',
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'home'
                );
                $automobile_car_dealer_home_id = wp_insert_post($automobile_car_dealer_home);
                // Assign Home Page Template
                add_post_meta($automobile_car_dealer_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', $automobile_car_dealer_home_id);
                update_option('show_on_front', 'page');
                // Add Home Page to Menu
                wp_update_nav_menu_item($automobile_car_dealer_menu_id, 0, array(
                    'menu-item-title' => __('Home', 'automobile-car-dealer'),
                    'menu-item-classes' => 'home',
                    'menu-item-url' => home_url('/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $automobile_car_dealer_home_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create About Us Page with Dummy Content
                $automobile_car_dealer_about_title = 'ABOUT';
                $automobile_car_dealer_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.';
                $automobile_car_dealer_about = array(
                    'post_type' => 'page',
                    'post_title' => $automobile_car_dealer_about_title,
                    'post_content' => $automobile_car_dealer_about_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'about-us'
                );
                $automobile_car_dealer_about_id = wp_insert_post($automobile_car_dealer_about);
                // Add About Us Page to Menu
                wp_update_nav_menu_item($automobile_car_dealer_menu_id, 0, array(
                    'menu-item-title' => __('About Us', 'automobile-car-dealer'),
                    'menu-item-classes' => 'about-us',
                    'menu-item-url' => home_url('/about-us/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $automobile_car_dealer_about_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Pages Page with Dummy Content
                $automobile_car_dealer_cars_title = 'CARS';
                $automobile_car_dealer_cars_content = 'Explore all the cars 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 carsly 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.';
                $automobile_car_dealer_cars = array(
                    'post_type' => 'page',
                    'post_title' => $automobile_car_dealer_cars_title,
                    'post_content' => $automobile_car_dealer_cars_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'cars'
                );
                $automobile_car_dealer_cars_id = wp_insert_post($automobile_car_dealer_cars);
                // Add Pages Page to Menu
                wp_update_nav_menu_item($automobile_car_dealer_menu_id, 0, array(
                    'menu-item-title' => __('Cars', 'automobile-car-dealer'),
                    'menu-item-classes' => 'cars',
                    'menu-item-url' => home_url('/cars/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $automobile_car_dealer_cars_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Pages Page with Dummy Content
                $automobile_car_dealer_gallery_title = 'GALLERY';
                $automobile_car_dealer_gallery_content = 'Explore all the gallery 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 galleryly 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.';
                $automobile_car_dealer_gallery = array(
                    'post_type' => 'page',
                    'post_title' => $automobile_car_dealer_gallery_title,
                    'post_content' => $automobile_car_dealer_gallery_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'gallery'
                );
                $automobile_car_dealer_gallery_id = wp_insert_post($automobile_car_dealer_gallery);
                // Add Pages Page to Menu
                wp_update_nav_menu_item($automobile_car_dealer_menu_id, 0, array(
                    'menu-item-title' => __('Gallery', 'automobile-car-dealer'),
                    'menu-item-classes' => 'gallery',
                    'menu-item-url' => home_url('/gallery/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $automobile_car_dealer_gallery_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Pages Page with Dummy Content
                $automobile_car_dealer_brand_title = 'BRAND';
                $automobile_car_dealer_brand_content = 'Explore all the brand 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 brandly 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.';
                $automobile_car_dealer_brand = array(
                    'post_type' => 'page',
                    'post_title' => $automobile_car_dealer_brand_title,
                    'post_content' => $automobile_car_dealer_brand_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'brand'
                );
                $automobile_car_dealer_brand_id = wp_insert_post($automobile_car_dealer_brand);
                // Add Pages Page to Menu
                wp_update_nav_menu_item($automobile_car_dealer_menu_id, 0, array(
                    'menu-item-title' => __('Brand', 'automobile-car-dealer'),
                    'menu-item-classes' => 'brand',
                    'menu-item-url' => home_url('/brand/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $automobile_car_dealer_brand_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));


                // Create Pages Page with Dummy Content
                $automobile_car_dealer_news_title = 'NEWS';
                $automobile_car_dealer_news_content = 'Explore all the news 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 newsly 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.';
                $automobile_car_dealer_news = array(
                    'post_type' => 'page',
                    'post_title' => $automobile_car_dealer_news_title,
                    'post_content' => $automobile_car_dealer_news_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'news'
                );
                $automobile_car_dealer_news_id = wp_insert_post($automobile_car_dealer_news);
                // Add Pages Page to Menu
                wp_update_nav_menu_item($automobile_car_dealer_menu_id, 0, array(
                    'menu-item-title' => __('News', 'automobile-car-dealer'),
                    'menu-item-classes' => 'news',
                    'menu-item-url' => home_url('/news/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $automobile_car_dealer_news_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Blog Page 
                $automobile_car_dealer_blog_page_title = 'Blog';
                $automobile_car_dealer_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($automobile_car_dealer_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ));
                if (!$automobile_car_dealer_blog_page_query->have_posts()) {
                    $automobile_car_dealer_blog_page = array(
                    'post_type'   => 'page',
                    'post_title'  => $automobile_car_dealer_blog_page_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    );
                    $automobile_car_dealer_blog_page_id = wp_insert_post($automobile_car_dealer_blog_page);
                    update_option('page_for_posts', $automobile_car_dealer_blog_page_id);

                    wp_update_nav_menu_item($automobile_car_dealer_menu_id, 0, array(
                    'menu-item-title'      => __('Blog', 'automobile-car-dealer'),
                    'menu-item-url'        => get_permalink($automobile_car_dealer_blog_page_id),
                    'menu-item-status'     => 'publish',
                    'menu-item-object-id'  => $automobile_car_dealer_blog_page_id,
                    'menu-item-object'     => 'page',
                    'menu-item-type'       => 'post_type',
                    ));
                }

                // Create Pages Page with Dummy Content
                $automobile_car_dealer_contact_title = 'CONTACT';
                $automobile_car_dealer_contact_content = 'Explore all the contact 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 contactly 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.';
                $automobile_car_dealer_contact = array(
                    'post_type' => 'page',
                    'post_title' => $automobile_car_dealer_contact_title,
                    'post_content' => $automobile_car_dealer_contact_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'contact'
                );
                $automobile_car_dealer_contact_id = wp_insert_post($automobile_car_dealer_contact);
                // Add Pages Page to Menu
                wp_update_nav_menu_item($automobile_car_dealer_menu_id, 0, array(
                    'menu-item-title' => __('Contact', 'automobile-car-dealer'),
                    'menu-item-classes' => 'contact',
                    'menu-item-url' => home_url('/contact/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $automobile_car_dealer_contact_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));


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

            // Set the demo import completion flag
    		update_option('automobile_car_dealer_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.', 'automobile-car-dealer') . '</p>';
    		echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('VIEW SITE', 'automobile-car-dealer') . '</a></span>';
            //end


            // Top Bar //
            set_theme_mod( 'automobile_car_dealer_email_icon', 'fas fa-envelope' );
            set_theme_mod( 'automobile_car_dealer_mail', 'xyz123@example.com' );
            set_theme_mod( 'automobile_car_dealer_phone_icon', 'fa fa-phone' );
            set_theme_mod( 'automobile_car_dealer_phone', '1234567890' );
            set_theme_mod( 'automobile_car_dealer_search_icon', 'fa fa-search' );
            set_theme_mod( 'automobile_car_dealer_button_link', '#' );
            set_theme_mod( 'automobile_car_dealer_appointment_icon', 'fas fa-calendar-alt' );

            // social icon
            set_theme_mod('automobile_car_dealer_cont_facebook', 'https://www.facebook.com' );
            set_theme_mod('automobile_car_dealer_facebook_icon', 'fab fa-facebook-f' );
            set_theme_mod('automobile_car_dealer_cont_twitter', 'https://www.twtter.com' );
            set_theme_mod('automobile_car_dealer_twitter_icon', 'fab fa-twitter' );
            set_theme_mod('automobile_car_dealer_instagram', 'https://www.instagram.com');
            set_theme_mod('automobile_car_dealer_instagram_icon', 'fab fa-instagram' );
            set_theme_mod('automobile_car_dealer_pinterest_icon', 'fab fa-pinterest' );
            set_theme_mod('automobile_car_dealer_pinterest', 'https://www.pinterest.com');
            set_theme_mod('automobile_car_dealer_tumblr_icon', 'fab fa-tumblr' );
            set_theme_mod('automobile_car_dealer_tumblr', 'https://www.tumblr.com');
            set_theme_mod('automobile_car_dealer_linkedin_icon', 'fab fa-linkedin-in');
            set_theme_mod('automobile_car_dealer_linkedin', 'https://www.linkedin.com');

            // slider section start //
            set_theme_mod('automobile_car_dealer_slider_hide', true);
            set_theme_mod('automobile_car_dealer_slider_button_link', '#');

            $automobile_car_dealer_slider_titles = array(
                'Find Your Dream Car with Us Today',
                'Premium Selection of New and Used Cars',
                'Affordable Deals on Your Favorite Cars',
                'Get Behind the Wheel of Quality Vehicles'
            );
            
            for ($automobile_car_dealer_i = 0; $automobile_car_dealer_i < count($automobile_car_dealer_slider_titles); $automobile_car_dealer_i++) {
                $automobile_car_dealer_slider_title = $automobile_car_dealer_slider_titles[$automobile_car_dealer_i];
                $automobile_car_dealer_slider_content = 'Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took.';
                
                // Create post object
                $automobile_car_dealer_my_post = array(
                    'post_title'    => wp_strip_all_tags($automobile_car_dealer_slider_title),
                    'post_content'  => $automobile_car_dealer_slider_content,
                    'post_status'   => 'publish',
                    'post_type'     => 'page',
                );
            
                // Insert the post into the database
                $automobile_car_dealer_post_id = wp_insert_post($automobile_car_dealer_my_post);
            
                if ($automobile_car_dealer_post_id) {
                    // Set the theme mod for the slider page
                    set_theme_mod('automobile_car_dealer_slider' . ($automobile_car_dealer_i + 1), $automobile_car_dealer_post_id);
            
                    $automobile_car_dealer_image_url = get_template_directory_uri() . '/images/slider' . ($automobile_car_dealer_i + 1) . '.png';
                    $automobile_car_dealer_image_id = media_sideload_image($automobile_car_dealer_image_url, $automobile_car_dealer_post_id, null, 'id');
            
                    if (!is_wp_error($automobile_car_dealer_image_id)) {
                        // Set the downloaded image as the post's featured image
                        set_post_thumbnail($automobile_car_dealer_post_id, $automobile_car_dealer_image_id);
                    }
                }
            }
            
            // event
            set_theme_mod('automobile_car_dealer_display_about_sec', true);
            set_theme_mod('automobile_car_dealer_sec_title', 'Our Projects');
            set_theme_mod('automobile_car_dealer_section_text', 'Lorem');

            // services single post
            $automobile_car_dealer_post_title = "OUR SERVICE";
            $automobile_car_dealer_post_content = 'Lorem Ipsum has been the industry\'s 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. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s.';
            $automobile_car_dealer_image_url = get_template_directory_uri() . '/images/post.png';

            // Create post object
            $automobile_car_dealer_post_data = array(
                'post_title'    => wp_strip_all_tags($automobile_car_dealer_post_title),
                'post_content'  => $automobile_car_dealer_post_content,
                'post_status'   => 'publish',
                'post_type'     => 'post', // Set post type to 'post'
            );
            set_theme_mod('automobile_car_dealer_project_single_post', $automobile_car_dealer_post_title);

            // Insert the post into the database
            $automobile_car_dealer_post_id = wp_insert_post($automobile_car_dealer_post_data);

            if (is_wp_error($automobile_car_dealer_post_id)) {
                error_log('Error creating post: ' . $automobile_car_dealer_post_id->get_error_message());
            } else {
                // Handle the featured image
                $automobile_car_dealer_image_id = media_sideload_image($automobile_car_dealer_image_url, $automobile_car_dealer_post_id, null, 'id');

                if (is_wp_error($automobile_car_dealer_image_id)) {
                    error_log('Error downloading image: ' . $automobile_car_dealer_image_id->get_error_message());
                } else {
                    // Assign featured image to post
                    set_post_thumbnail($automobile_car_dealer_post_id, $automobile_car_dealer_image_id);
                }
            }


            // categories
            set_theme_mod('automobile_car_dealer_project_category', 'postcategory2');
            // Define post category names and post titles
            $automobile_car_dealer_category_names = array('postcategory1', 'postcategory2', 'postcategory3', 'postcategory4');

            $automobile_car_dealer_title_array = array(
                array("Project Title 1", "Project Title 2", "Project Title 3", "Project Title 4"),
                array("Project Title 1", "Project Title 2", "Project Title 3", "Project Title 4"),
                array("Project Title 1", "Project Title 2", "Project Title 3", "Project Title 4"),
                array("Project Title 1", "Project Title 2", "Project Title 3", "Project Title 4")
            );

            $automobile_car_dealer_content_array = array(
                array(
                    "Lorem ipsum is simply dummy text of the printing and typesetting industry.",
                    "Lorem ipsum is simply dummy text of the printing and typesetting industry.",
                    "Lorem ipsum is simply dummy text of the printing and typesetting industry.",
                    "Lorem ipsum is simply dummy text of the printing and typesetting industry."
                ),
                array(
                    "Lorem ipsum is simply dummy text of the printing and typesetting industry.",
                    "Lorem ipsum is simply dummy text of the printing and typesetting industry",
                    "Lorem ipsum is simply dummy text of the printing and typesetting industry.",
                    "Lorem ipsum is simply dummy text of the printing and typesetting industry."
                ),
                array(
                    "Lorem ipsum is simply dummy text of the printing and typesetting industry.",
                    "Lorem ipsum is simply dummy text of the printing and typesetting industry.",
                    "Lorem ipsum is simply dummy text of the printing and typesetting industry.",
                    "Lorem ipsum is simply dummy text of the printing and typesetting industry."
                ),
                array(
                    "Lorem ipsum is simply dummy text of the printing and typesetting industry.",
                    "Lorem ipsum is simply dummy text of the printing and typesetting industry.",
                    "Lorem ipsum is simply dummy text of the printing and typesetting industry.",
                    "Lorem ipsum is simply dummy text of the printing and typesetting industry."
                )
            );

            foreach ($automobile_car_dealer_category_names as $automobile_car_dealer_index => $automobile_car_dealer_category_name) {
                // Create or retrieve the post category term ID
                $automobile_car_dealer_term = term_exists($automobile_car_dealer_category_name, 'category');
                if ($automobile_car_dealer_term === 0 || $automobile_car_dealer_term === null) {
                    // If the term does not exist, create it
                    $automobile_car_dealer_term = wp_insert_term($automobile_car_dealer_category_name, 'category');
                }
                if (is_wp_error($automobile_car_dealer_term)) {
                    error_log('Error creating category: ' . $automobile_car_dealer_term->get_error_message());
                    continue; // Skip to the next iteration if category creation fails
                }

                for ($automobile_car_dealer_i = 0; $automobile_car_dealer_i < 4; $automobile_car_dealer_i++) {
                    // Create post title and content
                    $automobile_car_dealer_title = $automobile_car_dealer_title_array[$automobile_car_dealer_index][$automobile_car_dealer_i];
                    $automobile_car_dealer_content = $automobile_car_dealer_content_array[$automobile_car_dealer_index][$automobile_car_dealer_i];

                    // Create post object
                    $automobile_car_dealer_my_post = array(
                        'post_title'    => wp_strip_all_tags($automobile_car_dealer_title),
                        'post_content'  => $automobile_car_dealer_content, // Unique content for each post
                        'post_status'   => 'publish',
                        'post_type'     => 'post', // Post type set to 'post'
                    );

                    // Insert the post into the database
                    $automobile_car_dealer_post_id = wp_insert_post($automobile_car_dealer_my_post);

                    if (is_wp_error($automobile_car_dealer_post_id)) {
                        error_log('Error creating post: ' . $automobile_car_dealer_post_id->get_error_message());
                        continue; // Skip to the next post if creation fails
                    }

                    // Assign the category to the post
                    wp_set_post_categories($automobile_car_dealer_post_id, array((int)$automobile_car_dealer_term['term_id']));

                    // Handle the featured image using media_sideload_image
                    $automobile_car_dealer_image_url = get_template_directory_uri() . '/images/post' . ($automobile_car_dealer_i + 1) . '.png';
                    $automobile_car_dealer_image_id = media_sideload_image($automobile_car_dealer_image_url, $automobile_car_dealer_post_id, null, 'id');

                    if (is_wp_error($automobile_car_dealer_image_id)) {
                        error_log('Error downloading image: ' . $automobile_car_dealer_image_id->get_error_message());
                        continue; // Skip to the next post if image download fails
                    }
                    // Assign featured image to post
                    set_post_thumbnail($automobile_car_dealer_post_id, $automobile_car_dealer_image_id);
                }
            }

            //Copyright Text
            set_theme_mod( 'automobile_car_dealer_footer_text', 'By Buywptemplate' );

        }
    ?>

    <form action="<?php echo esc_url(home_url()); ?>/wp-admin/themes.php?page=automobile-car-dealer-guide-page" method="POST" onsubmit="return validate(this);">
    <?php if (!get_option('automobile_car_dealer_demo_import_completed')) : ?>
        <form method="post">
        <p><?php esc_html_e('Click the below run importer button to import demo content','automobile-car-dealer'); ?></p>
            <input class= "run-import" type="submit" name="submit" value="<?php esc_attr_e('Run Importer','automobile-car-dealer'); ?>" class="button button-primary button-large">
        </form>
    <?php endif; ?>
    </form>
	<script type="text/javascript">
        function validate(valid) {
            if (confirm("Do you really want to import the theme demo content?")) {
                // Show loader
                document.getElementById('demo-import-loader').style.display = 'block';
                
                // Submit form
                document.forms[0].submit();
            } else {
                return false;
            }
        }
	</script>
</div>
