<?php

// Exit if accessed directly.
if (!defined('ABSPATH')) exit;

/**
 *  @return array
 */
function pedro_demo_import_files()
{
    return [
        [
           'import_file_name'              => __('Pedro Demo Import', 'pedro-demo-import'),
            'local_import_file'            => PEDRO_DEMO_URL . '/demo/pedro-content.xml',
            'local_import_widget_file'     => PEDRO_DEMO_URL . '/demo/pedro-widgets.wie',
            'local_import_customizer_file' => PEDRO_DEMO_URL . '/demo/pedro-customizer.dat',
            'import_preview_image_url'     => PEDRO_DEMO_URL . '/demo/demo.png',
            'import_notice'                => __('Please wait, your demo content is being imported.', 'pedro-demo-import'),
        ],
    ];
}
add_filter('ocdi/import_files', 'pedro_demo_import_files');



/**
 * Setup default pages and menu 
 * 
 * @return void
 */
function pedro_demo_after_import_setup() {
    $args = array(
        'post_type'      => 'page',
        'title'          => 'Home',
        'posts_per_page' => 1,      
    );

    $query = new WP_Query($args);

    if ($query->have_posts()) {
        $query->the_post();
        $home_page_id = get_the_ID();

        update_option('show_on_front', 'page');
        update_option('page_on_front', $home_page_id);
        
        wp_reset_postdata(); 
    }

    $menu_name = 'Primary Menu'; 
    $menu = wp_get_nav_menu_object($menu_name);

    if ($menu && isset($menu->term_id)) {
        $locations = get_theme_mod('nav_menu_locations', []); 
        $locations['primary_menu'] = $menu->term_id; 
        set_theme_mod('nav_menu_locations', $locations);
    }
}

add_action('ocdi/after_import', 'pedro_demo_after_import_setup');
