<?php
/*
* @packge Meditest Extra
* @since 1.0.0
 */
function meditest_import()
{
  return array(

    array(
      'import_file_name'             => __('Meditest Demo', 'meditest-extra'),
      'page_title'                   => __('Import Demo Data', 'meditest-extra'),
      'local_import_file'            => MEDITEST_EXTRA_ROOT_PATH . '/demo/meditest-demo-data.xml',
      'local_import_widget_file'     => MEDITEST_EXTRA_ROOT_PATH . '/demo/meditest-widgets.wie',
      'local_import_customizer_file' =>  MEDITEST_EXTRA_ROOT_PATH . '/demo/meditest-customizer.dat',
      'import_preview_image_url'     => 'https://splendidwebz.com/demo-img/meditest.png',
      'import_notice'                => __('This import maybe finish on 2-3 minutes', 'meditest-extra'),
      'preview_url'                  => 'https://codeindeed.com/meditest',

    ),


  );
}
add_filter('pt-ocdi/import_files', 'meditest_import');


add_action('pt-ocdi/after_import',  'meditest_after_import');

if (!function_exists('meditest_after_import')) :
  function meditest_after_import($selected_import)
  {

    if ('Meditest Demo' === $selected_import['import_file_name']) {

      $main_menu = get_term_by('name', 'Main Menu', 'nav_menu');

      set_theme_mod('nav_menu_locations', array(
        'primary' => $main_menu->term_id,
      ));

      //Set Front page

      $front_page_id = get_page_by_title('Home');
      $blog_page_id  = get_page_by_title('Blog');

      update_option('show_on_front', 'page');
      update_option('page_on_front', $front_page_id->ID);
      update_option('page_for_posts', $blog_page_id->ID);
    }


    // Path to the options data file
    $options_data_file = MEDITEST_EXTRA_ROOT_PATH . '/demo/meditest-options-data.json';

    var_dump($options_data_file);

    // Check if the options data file exists
    if (file_exists($options_data_file)) {
      // Read the options data
      $options_data = json_decode(file_get_contents($options_data_file), true);

      // Apply the options data using Codestar functions
      if (function_exists('cs_set_option')) {
        foreach ($options_data as $option_key => $option_value) {
          cs_set_option($option_key, $option_value);
        }
      }
    }

    // Reset site permalink
    global $wp_rewrite;
    $wp_rewrite->set_permalink_structure('/%postname%/');

    // Flushing rewrite rules
    flush_rewrite_rules();
  }
endif;
