<?php

// Prevent Direct Access
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// Import demos
function maxo_demo_import() {

	$en = (MAXO_IS_RTL ? '' : '-en');

	return [
		[
			'import_file_name'           => esc_html__('Demo Content Import', 'maxo-fa'),
			'import_file_url'            => 'https://v3dboy.ir/previews/wordpress/maxo/demo-data'.$en.'/demo-content.xml',
			'import_widget_file_url'     => 'https://v3dboy.ir/previews/wordpress/maxo/demo-data'.$en.'/widgets.wie',
			'import_customizer_file_url' => 'https://v3dboy.ir/previews/wordpress/maxo/demo-data'.$en.'/customizer.dat',
			'import_preview_image_url'   => get_theme_file_uri('screenshot.png'),
			'preview_url'                => 'https://v3dboy.ir/previews/wordpress/maxo',
		],
	];
}

add_filter( 'ocdi/import_files', 'maxo_demo_import' );

// After import
function maxo_after_demo_import() {

	$main_menu = get_term_by('name', MAXO_IS_RTL ? 'فهرست سرصفحه' : 'Header Menu', 'nav_menu');
	$front_page = get_page_by_title(MAXO_IS_RTL ? 'خانه' : 'Home');
	$blog_page  = get_page_by_title(MAXO_IS_RTL ? 'بلاگ' : 'Blog');

	set_theme_mod('nav_menu_locations', [
        'header_menu' => $main_menu->term_id,
    ]);

	update_option('show_on_front', 'page');
    update_option('page_on_front', $front_page->ID);
    update_option('page_for_posts', $blog_page->ID);
}

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