<?php

namespace Discountify\Core;

use Discountify\Utils\Singleton;

/**
 * Base Class
 *
 * @since 1.0.0
 */
class Core {

	use Singleton;

	/**
	 * Initialize all modules.
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	public function init() {
		if ( ! is_admin() ) {
			// Load frontend
			\Discountify\Core\Frontend\Frontend::instance()->init();
		} else {
			\Discountify\Core\Admin\Menus::instance()->init();
			// Ajax submit
			if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
				\Discountify\Core\Admin\Settings\Settings::instance()->init();
			}
			\Discountify\Core\Admin\Settings\Settings::instance()->rules_init();

			// BOGO: Admin order hooks.
			add_filter( 'woocommerce_hidden_order_itemmeta', function ( $hidden ) {
				$hidden[] = '_discountify_bogo_free';
				return $hidden;
			} );
			add_action( 'woocommerce_admin_order_item_headers', array( \Discountify\Core\Frontend\Frontend::instance(), 'bogo_admin_order_styles' ) );
			add_filter( 'woocommerce_order_item_display_meta_key', array( \Discountify\Core\Frontend\Frontend::instance(), 'format_order_item_meta_key' ), 10, 3 );
		}
	}
}
