<?php
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 *
 * Handles destructive data reset operations.
 */
final class Sifency_Resetter {

	/**
	 * Resets all theme-related settings to their defaults.
	 *
	 * @return bool True on completion.
	 */
	public function reset_theme_data() {
		foreach ( Sifency_Demo_Helper::get_admin_option_keys() as $key ) {
			delete_option( $key );
		}
		remove_theme_mods();
		update_option( 'sidebars_widgets', [] );
		$menus = wp_get_nav_menus();
		foreach ( $menus as $menu ) {
			wp_delete_nav_menu( $menu->term_id );
		}

		if ( did_action( 'elementor/loaded' ) && class_exists( '\Elementor\Plugin' ) ) {
			$active_kit_id = \Elementor\Plugin::$instance->kits_manager->get_active_id();
			if ( $active_kit_id ) {
				update_post_meta( $active_kit_id, '_elementor_page_settings', [] );
				\Elementor\Plugin::$instance->files_manager->clear_cache();
			}
		}

		return true;
	}
}
