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

    // If the demo import is completed, display the "View Site" button
    if ($courier_services_demo_import_completed) {
      echo '<p class="notice-text">' . esc_html__('Your demo import has been completed successfully.', 'courier-services') . '</p>';
      echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('VIEW SITE', 'courier-services') . '</a></span>';
      echo '<span><a href="'. esc_url(admin_url('customize.php') ) .'" class="button button-primary demo-btn" target=_blank>'. esc_html__( 'Customize Your Site', 'courier-services' ) .'</a></span>';
      echo '<span><a href="'. esc_url( 'https://preview.vwthemesdemo.com/docs/free-courier-services/' ) .'" class="button button-primary doc-btn" target=_blank>'. esc_html__( 'Free Theme Documentation', 'courier-services' ) .'</a></span>';
    }

		// POST and update the customizer and other related data
      if (isset($_POST['submit'])) {

    // Check if Contact Form 7 is installed and activated
    if (!is_plugin_active('contact-form-7/wp-contact-form-7.php')) {
      // Install the plugin if it doesn't exist
      $courier_services_plugin_slug = 'contact-form-7';
      $courier_services_plugin_file = 'contact-form-7/wp-contact-form-7.php';

      // Check if plugin is installed
      $courier_services_installed_plugins = get_plugins();
      if (!isset($courier_services_installed_plugins[$courier_services_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
          $courier_services_upgrader = new Plugin_Upgrader();
          $courier_services_upgrader->install('https://downloads.wordpress.org/plugin/contact-form-7.latest-stable.zip');
      }
      // Activate the plugin
      activate_plugin($courier_services_plugin_file);
    }

    // Check if ibtana visual editor is installed and activated
    if (!is_plugin_active('ibtana-visual-editor/plugin.php')) {
      // Install the plugin if it doesn't exist
      $courier_services_plugin_slug = 'ibtana-visual-editor';
      $courier_services_plugin_file = 'ibtana-visual-editor/plugin.php';

      // Check if plugin is installed
      $courier_services_installed_plugins = get_plugins();
      if (!isset($courier_services_installed_plugins[$courier_services_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
          $courier_services_upgrader = new Plugin_Upgrader();
          $courier_services_upgrader->install('https://downloads.wordpress.org/plugin/ibtana-visual-editor.latest-stable.zip');
      }
      // Activate the plugin
      activate_plugin($courier_services_plugin_file);
    }
      // Create / Get Menu FIRST
      $courier_services_menu_name = 'Primary Menu';

      $courier_services_menu = wp_get_nav_menu_object($courier_services_menu_name);

      if (!$courier_services_menu) {
          $courier_services_menu_id = wp_create_nav_menu($courier_services_menu_name);
      } else {
          $courier_services_menu_id = $courier_services_menu->term_id;
      } 
        // Create a front page and assign the template
        $courier_services_home_page = null;
        // Using WP_Query instead of get_page_by_title()
        $courier_services_home_query = new WP_Query(array(
           'post_type' => 'page',
           'title' => 'Home',
           'post_status' => 'publish',
           'posts_per_page' => 1
        ));
        if (!$courier_services_home_query->have_posts()) {
           $courier_services_home_title = 'Home';           
           // Create the page
           $courier_services_home = array(
               'post_type' => 'page',
               'post_title' => $courier_services_home_title,
               'post_status' => 'publish',
               'post_author' => 1,
               'post_slug' => 'home'
           );
           $courier_services_home_id = wp_insert_post($courier_services_home);
        } else {
           $courier_services_home_page = $courier_services_home_query->posts[0];
           $courier_services_home_id = $courier_services_home_page->ID;
        }

        // Set the home page template
        add_post_meta($courier_services_home_id, '_wp_page_template', 'page-template/custom-home-page.php');

        // Set the static front page
        update_option('page_on_front', $courier_services_home_id);
        update_option('show_on_front', 'page');

        // Create another page if needed
        $courier_services_page_query = new WP_Query(array(
           'post_type' => 'page',
           'title' => 'Page',
           'post_status' => 'publish',
           'posts_per_page' => 1
        ));
        
        if (!$courier_services_page_query->have_posts()) {
           $courier_services_page_title = 'Page';
           $courier_services_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.';
           
            $courier_services_page = array(
               'post_type' => 'page',
               'post_title' => $courier_services_page_title,
               'post_content' => $courier_services_content,
               'post_status' => 'publish',
               'post_author' => 1,
               'post_slug' => 'page'
            );
            $courier_services_page_id = wp_insert_post($courier_services_page);
        }       
        
          // Create another page if needed
            $courier_services_page_query = new WP_Query(array(
              'post_type' => 'page',
              'title' => 'About',
              'post_status' => 'publish',
              'posts_per_page' => 1
            ));

            if (!$courier_services_page_query->have_posts()) {
              $courier_services_page_title = 'About';
              $courier_services_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.';
           
            $courier_services_page = array(
               'post_type' => 'page',
               'post_title' => $courier_services_page_title,
               'post_content' => $courier_services_content,
               'post_status' => 'publish',
               'post_author' => 1,
               'post_slug' => 'page'
            );
            $courier_services_page_id = wp_insert_post($courier_services_page);
        }

         // Create another page if needed
            $courier_services_page_query = new WP_Query(array(
              'post_type' => 'page',
              'title' => 'Services',
              'post_status' => 'publish',
              'posts_per_page' => 1
            ));

            if (!$courier_services_page_query->have_posts()) {
              $courier_services_page_title = 'Services';
              $courier_services_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.';
           
            $courier_services_page = array(
               'post_type' => 'page',
               'post_title' => $courier_services_page_title,
               'post_content' => $courier_services_content,
               'post_status' => 'publish',
               'post_author' => 1,
               'post_slug' => 'page'
            );
            $courier_services_page_id = wp_insert_post($courier_services_page);
          }
            // Create Blog Page 
                $courier_services_blog_page_title = 'Blog';
                $courier_services_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($courier_services_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ));
                if (!$courier_services_blog_page_query->have_posts()) {
                    $courier_services_blog_page = array(
                        'post_type'   => 'page',
                        'post_title'  => $courier_services_blog_page_title,
                        'post_status' => 'publish',
                        'post_author' => 1,
                    );
                    $courier_services_blog_page_id = wp_insert_post($courier_services_blog_page);
                    update_option('page_for_posts', $courier_services_blog_page_id);
                    wp_update_nav_menu_item($courier_services_menu_id, 0, array(
                        'menu-item-title'      => __('Blog', 'courier-services'),
                        'menu-item-url'        => get_permalink($courier_services_blog_page_id),
                        'menu-item-status'     => 'publish',
                        'menu-item-object-id'  => $courier_services_blog_page_id,
                        'menu-item-object'     => 'page',
                        'menu-item-type'       => 'post_type',
                    ));   
                  }
        // Top Bar start //
        set_theme_mod( 'courier_services_topbar_location_icon', 'fa-solid fa-location-dot' ); 
        set_theme_mod( 'courier_services_topbar_location_text', ' 4b Walse Street , USA' );
        set_theme_mod( 'courier_services_email_address_icon', 'fa-solid fa-envelope' ); 
        set_theme_mod( 'courier_services_email_address', ' xyz123@gmail.com' );
        set_theme_mod( 'courier_services_topbar_time_icon', 'fa-solid fa-clock' ); 
        set_theme_mod( 'courier_services_topbar_time_text', ' Mon – Sun: 9.00 am – 10.00pm' );
        set_theme_mod( 'courier_services_get_a_quote_button_text', ' Get A Quote' );
        set_theme_mod( 'courier_services_get_a_quote_btn_link', '#' );


        // Set the demo import completion flag
    		update_option('courier_services_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.', 'courier-services') . '</p>';
    		echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('VIEW SITE', 'courier-services') . '</a></span>';
        echo '<span><a href="'. esc_url(admin_url('customize.php') ) .'" class="button button-primary demo-btn" target=_blank>'. esc_html__( 'Customize Your Site', 'courier-services' ) .'</a></span>';
        echo '<span><a href="'. esc_url( 'https://preview.vwthemesdemo.com/docs/free-courier-services/' ) .'" class="button button-primary doc-btn" target=_blank>'. esc_html__( 'Free Theme Documentation', 'courier-services' ) .'</a></span>';

        //end 

        // slider section start //         
        set_theme_mod( 'courier_services_slide_number', '3' );
        for($courier_services_i=1; $courier_services_i<=3; $courier_services_i++) {
            set_theme_mod( 'courier_services_banner_background_image_sec'.$courier_services_i, get_template_directory_uri().'/assets/images/banner'.$courier_services_i.'.png' );
            set_theme_mod( 'courier_services_designation_small_text'.$courier_services_i, 'THE BEST MOVING SERVICE EVER!' );
            set_theme_mod( 'courier_services_tagline_title'.$courier_services_i, 'Fast Shipping With Quality Service' );
            set_theme_mod( 'courier_services_designation_text'.$courier_services_i, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' );
            set_theme_mod( 'courier_services_slider_button_label1'.$courier_services_i, 'Explore More' );
            set_theme_mod( 'courier_services_slider_button_url1'.$courier_services_i, '#');

            // contact form shortcode
            $cf7title = "Contact Page";
            $cf7content = '
            <div class="contact-form-info">
              <div class="row">
                <div class="col-xl-2 col-lg-2 col-md-2 align-self-center pickup-address">
                  <div class="border-css">
                    <lable class="address" for="Pickup Address">Pickup Address</lable>
                    [text* text-339 class:form-control placeholder "Sending Form"]
                  </div>
                </div>
                <div class="col-xl-2 col-lg-2 col-md-2 align-self-center pickup-address">
                  <div class="border-css">
                    <lable class="address" for="Drop Address">Drop Address</lable>
                    [text* text-340 class:form-control placeholder "Sending to"]
                  </div>
                </div>
                <div class="col-xl-2 col-lg-2 col-md-2 align-self-center phone-numbers">
                  <div class="border-css">
                    <lable class="address" for="Phone Number">Phone Number</lable>
                    [tel* Entercontactdetails "Enter contact details"]
                  </div>
                </div>
                <div class="col-xl-4 col-lg-3  col-md-3 align-self-center dropdown-menus">
                  <div class="border-css">
                    <lable class="address" for="What Describes You Best?">What Describes You Best?</lable>
                    [select Dropdown "Small(1to 20 kg)" "Medium(1to 20 kg)" "Large(1to 20 kg)" "Extra Large (1to 20 kg)"]
                  </div>
                </div>
                <div class="col-xl-2 col-lg-3 col-md-3 align-self-center form-btn text-end">
                  <button type="submit" class="btn btn-appointment">Get an estimate<i class="fa-solid fa-arrow-right ms-2"></i></button>
                </div>
              </div>
            </div>
            [_site_title] "[your-subject]"
            [_site_title] <support@example.com>
            From: [your-name] <[your-email]>
            Subject: [your-subject]

            Message Body:
            [your-message]

            --
            This e-mail was sent from a contact form on [_site_title] ([_site_url])
            [_site_admin_email]
            Reply-To: [your-email]

            0
            0

            [_site_title] "[your-subject]"
            [_site_title] <support@example.com>
            Message Body:
            [your-message]

            --
            This e-mail was sent from a contact form on [_site_title] ([_site_url])
            [your-email]
            Reply-To: [_site_admin_email]

            0
            0
            Thank you for your message. It has been sent.
            There was an error trying to send your message. Please try again later.
            One or more fields have an error. Please check and try again.
            There was an error trying to send your message. Please try again later.
            You must accept the terms and conditions before sending your message.
            The field is required.
            The field is too long.
            The field is too short.
            There was an unknown error uploading the file.
            You are not allowed to upload files of this type.
            The file is too big.
            There was an error uploading the file.';

            $cf7_post = array(
            'post_title'    => wp_strip_all_tags( $cf7title ),
            'post_content'  => $cf7content,
            'post_status'   => 'publish',
            'post_type'     => 'wpcf7_contact_form',
            );
            // Insert the post into the database
            $cf7post_id = wp_insert_post( $cf7_post );

            add_post_meta($cf7post_id, "_form", '
            <div class="contact-form-info">
              <div class="row">
                <div class="col-xl-2 col-lg-2 col-md-2 align-self-center pickup-address">
                  <div class="border-css">
                    <lable class="address" for="Pickup Address">Pickup Address</lable>
                    [text* text-339 class:form-control placeholder "Sending Form"]
                  </div>
                </div>
                <div class="col-xl-2 col-lg-2 col-md-2 align-self-center pickup-address">
                  <div class="border-css">
                    <lable class="address" for="Drop Address">Drop Address</lable>
                    [text* text-340 class:form-control placeholder "Sending to"]
                  </div>
                </div>
                <div class="col-xl-2 col-lg-2 col-md-2 align-self-center phone-numbers">
                  <div class="border-css">
                    <lable class="address" for="Phone Number">Phone Number</lable>
                    [tel* Entercontactdetails "Enter contact details"]
                  </div>
                </div>
                <div class="col-xl-4 col-lg-3  col-md-3 align-self-center dropdown-menus">
                  <div class="border-css">
                    <lable class="address" for="What Describes You Best?">What Describes You Best?</lable>
                    [select Dropdown "Small(1to 20 kg)" "Medium(1to 20 kg)" "Large(1to 20 kg)" "Extra Large (1to 20 kg)"]
                  </div>
                </div>
                <div class="col-xl-2 col-lg-3 col-md-3 align-self-center form-btn text-end">
                  <button type="submit" class="btn btn-appointment">Get an estimate<i class="fa-solid fa-arrow-right ms-2"></i></button>
                </div>
              </div>
            </div>
            ');

            $cf7mail_data  = array('subject' => '[_site_title] "[your-subject]"',
                'sender' => '[_site_title] <support@example.com>',
                'body' => 'From: [your-name] <[your-email]>
            Subject: [your-subject]

            Message Body:
            [your-message]

            --
            This e-mail was sent from a contact form on [_site_title] ([_site_url])',
                'recipient' => '[_site_admin_email]',
                'additional_headers' => 'Reply-To: [your-email]',
                'attachments' => '',
                'use_html' => 0,
                'exclude_blank' => 0 );

            add_post_meta($cf7post_id, "_mail", $cf7mail_data);
                      // Gets term object from Tree in the database.
            $cf7shortcode = '[contact-form-7 id="'.$cf7post_id.'" title="'.$cf7title.'"]';
            set_theme_mod( 'courier_services_banner_form_shortcode',$cf7shortcode );
               
        }  

        // service section start //
        set_theme_mod( 'courier_services_section_title', 'Sevice' ); 
        set_theme_mod( 'courier_services_feature_courses_tagline_title', ' Trusted Logistic & Transport' );
        set_theme_mod( 'courier_services_claases_number', '3' );
        set_theme_mod( 'courier_services_single_icon1', 'fa-solid fa-truck' );
        set_theme_mod( 'courier_services_single_icon2', 'fa-solid fa-house-chimney' );
        set_theme_mod( 'courier_services_single_icon3', 'fa-solid fa-building' );

        // select Post Box
        $courier_services_title_array = array("Road Transport", "Ware Housing", "Commercial & Local");
        for ($courier_services_i = 1; $courier_services_i <= 3; $courier_services_i++) {
            // Create post
            $courier_services_title = $courier_services_title_array[$courier_services_i - 1];
            $courier_services_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.';            
            $courier_services_my_post = array(
                 'post_title'   => wp_strip_all_tags($courier_services_title),
                 'post_content' => $courier_services_content,
                 'post_status'  => 'publish',
                 'post_type'    => 'post',
            );
            $courier_services_post_id = wp_insert_post($courier_services_my_post);
            set_theme_mod('courier_services_services_category' . $courier_services_i, $courier_services_post_id);
            // Get image URL
            $courier_services_image_url = get_template_directory_uri() . '/assets/images/image' . $courier_services_i . '.png';
            $courier_services_image_data = wp_remote_get($courier_services_image_url);
            if (!is_wp_error($courier_services_image_data)) {
                 $courier_services_image_body = wp_remote_retrieve_body($courier_services_image_data);
                 $courier_services_upload_dir = wp_upload_dir();
                 $courier_services_image_name = 'image' . $courier_services_i . '.png';
                 $uploaded_file = wp_upload_bits($courier_services_image_name, null, $courier_services_image_body);
                 if (!$uploaded_file['error']) {
                     // Set attachment data
                     $attachment = array(
                         'post_mime_type' => $uploaded_file['type'],
                         'post_title'     => sanitize_file_name($courier_services_image_name),
                         'post_content'   => '',
                         'post_status'    => 'inherit',
                     );
                     $courier_services_attach_id = wp_insert_attachment($attachment, $uploaded_file['file'], $courier_services_post_id);
                     require_once(ABSPATH . 'wp-admin/includes/image.php');
                     $courier_services_attach_data = wp_generate_attachment_metadata($courier_services_attach_id, $uploaded_file['file']);
                     wp_update_attachment_metadata($courier_services_attach_id, $courier_services_attach_data);
                     set_post_thumbnail($courier_services_post_id, $courier_services_attach_id);
                 }
            }
          }        
          echo "<script>window.location.href='" . admin_url('themes.php?page=courier_services_guide') . "';</script>";
          //Copyright Text
          set_theme_mod( 'courier_services_footer_text', 'By VWThemes' );             
    }
  ?>
  
    <form action="<?php echo esc_url(home_url()); ?>/wp-admin/themes.php?page=courier_services_guide" method="POST" onsubmit="return validate(this);">
        <?php if (!get_option('courier_services_demo_import_completed')) : ?>
          <form method="post">
            <p class="run-import-text"><?php esc_html_e('Click On The Below Run Importer Button To Import Demo Content Of Courier Services', 'courier-services'); ?></p>
          	<p><?php esc_html_e('Please back up your website if it’s already live with data. This importer will overwrite your existing settings with the new customizer values for Courier Services', 'courier-services'); ?></p>
            <input class="run-import" type="submit" name="submit" value="<?php esc_attr_e('Run Importer', 'courier-services'); ?>" class="button button-primary button-large">
          </form>  
        <?php endif; ?>
        <div id="spinner" style="display:none;">         
            <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/spinner.png" alt="" />
        </div>
    </form>
    <script type="text/javascript">
        function validate(form) {
            if (confirm("Do you really want to import the theme demo content?")) {
                // Show the spinner
                document.getElementById('spinner').style.display = 'block';
                // Allow the form to be submitted
                return true;
            } 
            else {
                return false;
            }
        }
    </script>
</div>

