<?php
/**
 * Nav Menu
 *
 * @since   1.0.0
 * @ignore
 * @access  private
 *
 * @package SplendorStudio\Framework\API\Nav-Menu
 */
final class Fancify_Lite_Nav_Menu extends Fancify_Lite_Controller {

	/**
	 * Nav menu constructor.
	 *
	 * @since 1.0.0
	 */
	public function __construct() {
		$this->register_hook_callbacks();
	}

	/**
	 * Register hook.
	 *
	 * @since 1.0.0
	 */
	public function register_hook_callbacks() {
		Fancify_Lite_Actions::add_smart_action( 'after_setup_theme', array( $this, 'register_nav_menus' ) );
		Fancify_Lite_Actions::add_smart_action( 'after_setup_theme', array( $this, 'register_default_menu' ) );
	}

	/**
	 * Echo no menu notice.
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	function fancify_lite_no_menu_notice() {
		fancify_lite_open_markup_e( 'fancify_lite_no_menu_notice', 'p', array( 'class' => 'fancify-alert fancify-alert-warning' ) );

		fancify_lite_output_e( 'fancify_lite_no_menu_notice_text', esc_html__( 'Whoops, your site does not have a menu!', 'fancify-lite' ) );

		fancify_lite_close_markup_e( 'fancify_lite_no_menu_notice', 'p' );
	}

	/**
	 * Register default menu.
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	function register_default_menu() {
		// Stop here if a menu already exists or doing ajax.
		if ( wp_doing_ajax() || wp_get_nav_menus() ) {
			return;
		}

		$name = __( 'Navigation', 'fancify-lite' );

		// Set up a default menu if it doesn't exist.
		if ( ! wp_get_nav_menu_object( $name ) ) {
			wp_update_nav_menu_item(
				wp_create_nav_menu( $name ),
				0,
				array(
					'menu-item-title'   => __( 'Home', 'fancify-lite' ),
					'menu-item-classes' => 'home',
					'menu-item-url'     =>  esc_url( home_url( '/' ) ),
					'menu-item-status'  => 'publish',
				)
			);
		}
	}

	/**
	 * Register nav menus.
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	function register_nav_menus() {
		register_nav_menus( array(
			'primary' => __( 'Primary Menu', 'fancify-lite' ),
		) );
	}

}

Fancify_Lite_Nav_Menu::get_instance();