<?php
/**
 * Admin class.
 *
 * This class ties together all admin classes.
 *
 * @package     Hotel 26
 * @author      hotel 26 Software
 * @since       1.0.0
 */

/**
 * Do not allow direct script access.
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'Hotel_26_Admin' ) ) :

	/**
	 * Admin Class
	 */
	class Hotel_26_Admin {

		/**
		 * Primary class constructor.
		 *
		 * @since 1.0.0
		 */
		public function __construct() {

			/**
			 * Include admin files.
			 */
			$this->includes();

			/**
			 * Load admin assets.
			 */
			add_action( 'admin_enqueue_scripts', array( $this, 'load_assets' ) );

			/**
			 * Add filters for WordPress header and footer text.
			 */
			add_filter( 'admin_footer_text', array( $this, 'filter_admin_footer_text' ), 50 );

			/**
			 * Admin page header.
			 */
			add_action( 'in_admin_header', array( $this, 'admin_header' ), 100 );

			/**
			 * Admin page footer.
			 */
			add_action( 'in_admin_footer', array( $this, 'admin_footer' ), 100 );

			/**
			 * Add notices.
			 */
			add_action( 'admin_notices', array( $this, 'admin_notices' ) );

		}

		/**
		 * Includes files.
		 *
		 * @since 1.0.0
		 */
		private function includes() {

			/**
			 * Include helper functions.
			 */
			require_once get_template_directory() . '/inc/admin/helpers.php'; // phpcs:ignore

			/**
			 * Include hotel 26 welcome page.
			 */
			require_once get_template_directory() . '/inc/admin/class-hotel-26-dashboard.php'; // phpcs:ignore
			
			/**
			 * Include hotel 26 meta boxes.
			 */
			// require_once get_template_directory() . '/inc/admin/metabox/hotel-26-meta-boxes.php'; // phpcs:ignore
		}

		/**
		 * Load our required assets on admin pages.
		 *
		 * @since 1.0.0
		 * @param string $hook it holds the information about the current page.
		 */
		public function load_assets( $hook ) {

			/**
			 * Do not enqueue if we are not on one of our pages.
			 */

			// Script debug.
			$prefix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'dev/' : '';
			$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';

			/**
			 * Enqueue admin pages stylesheet.
			 */
			wp_enqueue_style(
				'hotel-26-admin-styles',
				HOTEL_26_PARENT_INC_URI . '/admin/assets/css/hotel-26-admin' . $suffix . '.css',
				false,
				HOTEL_26_THEME_VERSION
			);

			/**
			 * Enqueue admin pages script.
			 */
			wp_enqueue_script(
				'hotel-26-admin-script',
				HOTEL_26_PARENT_INC_URI . '/admin/assets/js/' . $prefix . 'hotel-26-admin' . $suffix . '.js',
				array( 'jquery', 'wp-util', 'updates' ),
				HOTEL_26_THEME_VERSION,
				true
			);

			/**
			 * Localize admin strings.
			 */
			$texts = array(
				'install'               => esc_html__( 'Install', 'hotel-26' ),
				'install-inprogress'    => esc_html__( 'Installing...', 'hotel-26' ),
				'activate-inprogress'   => esc_html__( 'Activating...', 'hotel-26' ),
				'deactivate-inprogress' => esc_html__( 'Deactivating...', 'hotel-26' ),
				'active'                => esc_html__( 'Active', 'hotel-26' ),
				'retry'                 => esc_html__( 'Retry', 'hotel-26' ),
				'please_wait'           => esc_html__( 'Please Wait...', 'hotel-26' ),
				'importing'             => esc_html__( 'Importing... Please Wait...', 'hotel-26' ),
				'currently_processing'  => esc_html__( 'Currently processing: ', 'hotel-26' ),
				'import'                => esc_html__( 'Import', 'hotel-26' ),
				'import_demo'           => esc_html__( 'Import Demo', 'hotel-26' ),
				'importing_notice'      => esc_html__( 'The demo importer is still working. Closing this window may result in failed import.', 'hotel-26' ),
				'import_complete'       => esc_html__( 'Import Complete!', 'hotel-26' ),
				'import_complete_desc'  => esc_html__( 'The demo has been imported.', 'hotel-26' ) . ' <a href="' . esc_url( get_home_url() ) . '">' . esc_html__( 'Visit site.', 'hotel-26' ) . '</a>',
			);

			$strings = array(
				'ajaxurl'       => admin_url( 'admin-ajax.php' ),
				'wpnonce'       => wp_create_nonce( 'hotel_26_nonce' ),
				'texts'         => $texts,
				'color_pallete' => array( '#3857f1', '#06cca6', '#2c2e3a', '#e4e7ec', '#f0b849', '#ffffff', '#000000' ),
			);

			$strings = apply_filters( 'hotel_26_admin_strings', $strings );

			wp_localize_script( 'hotel-26-admin-script', 'hotel_26_strings', $strings );
		}

		/**
		 * Filter WordPress footer left text to display our text.
		 *
		 * @since 1.0.0
		 * @param string $text Text that we're going to replace.
		 */
		public function filter_admin_footer_text( $text ) {

			if ( hotel_26_admin_page() ) {
				return;
			}

			return $text;
		}

		/**
		 * Outputs the page admin header.
		 *
		 * @since 1.0.0
		 */
		public function admin_header() {

			$base = get_current_screen()->base;

			if ( ! hotel_26_admin_page( $base ) ) {
				return;
			}
			?>
			<div class="hotel-26-websites">
				<div class="hotel-26-theme-header hotel-26-header-fixed">
					<div class="hotel-26-theme-title">
						<a href="<?php echo esc_url( admin_url( 'themes.php?page=hotel-26-dashboard' ) ); ?>" class="hotel-26-logo">
							<span class="hotel-26-logo-icon"><i class="dashicons-before dashicons-dashboard"></i> <span class="hotel-26-version hotel-26-cusror-off"><?php echo HOTEL_26_THEME_VERSION; ?></span></span>
							<img src="<?php echo esc_url( HOTEL_26_PARENT_URI . '/assets/images/logo.png' ); ?>" class="hotel-26-title">
						</a>
					</div>
					<div class="hotel-26-top-links">
						<ul>
							<li class="hotel-26-most-links">
								<a href="<?php echo esc_url( admin_url( 'customize.php' ) ); ?>" class="hotel-26-btn hotel-26-btn-fill"><?php esc_html_e( 'Customize', 'hotel-26' ); ?></a>
							</li>
						</ul>
					</div>
				</div>
			</div>
			<?php
		}

		/**
		 * Outputs the page admin footer.
		 *
		 * @since 1.0.0
		 */
		public function admin_footer() {

			$base = get_current_screen()->base;

			if ( ! hotel_26_admin_page( $base ) || hotel_26_admin_page( $base, 'hotel_26_wizard' ) ) {
				return;
			}
			?>
			<div class="hotel-26-websites">
				<div class="hotel-26-wpfooter">
					<div class="hotel-26-wpfooter-wrap">
						<ul class="hotel-26-footer">
							<li><p id="footer-ver" class="footer-ver text-left"><?php esc_html_e( 'Hotel 26 Theme v', 'hotel-26' ); ?><?php echo esc_html(HOTEL_26_THEME_VERSION); ?></p></li>
							<li>
								<span class="heart-icon dashicons dashicons-heart"></span>
								<a href="<?php echo esc_url( 'https://wordpress.org/support/theme/hotel-26/reviews/#new-post' ); ?>" target="_blank" class="hotel-26-review"><?php esc_html_e( 'Leave a Review', 'hotel-26' ); ?></a></li>
							<li>
								<p id="footer-right" class="footer-social text-right">
									<a href="#" target="_blank"><span class="dashicons dashicons-twitter"></span></a>
									<a href="#" target="_blank"><span class="dashicons dashicons-facebook"></span></a>
								</p>
							</li>
						</ul>
					</div>
				</div>
			</div>
			<?php
		}

		/**
		 * Admin Notices
		 *
		 * @since 1.0.0
		 */
		public function admin_notices() {

			$screen = get_current_screen();

			// Display on Dashboard, Themes and hotel 26 admin pages.
			if ( ! in_array( $screen->base, array( 'dashboard', 'themes' ), true ) && ! hotel_26_admin_page() ) {
				return;
			}
			
			// Display if not dismissed and not on hotel 26 plugins page.
			if ( ! hotel_26_is_notice_dismissed( 'hotel_26_notice_recommended-plugins' ) && ! hotel_26_admin_page( false, 'hotel-26-plugins' ) ) {

				$plugins = hotel_26_plugin_utilities()->get_recommended_plugins();
				$plugins = hotel_26_plugin_utilities()->get_deactivated_plugins( $plugins );

				$plugin_list = '';

				if ( is_array( $plugins ) && ! empty( $plugins ) ) {

					foreach ( $plugins as $slug => $plugin ) {

						$url = admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . esc_attr( $slug ) . '&TB_iframe=true&width=990&height=500' );

						$plugin_list .= '<a href="' . esc_url( $url ) . '" class="thickbox hotel-26-btn-active">' . esc_html( $plugin['name'] ) . '</a> ';
					}

					wp_enqueue_script( 'plugin-install' );
					add_thickbox();

					$plugin_list = trim( $plugin_list, ' ' );
					
					$message = wp_kses(
									sprintf(
										__(/* translators: 1: Theme Name */
											'Welcome! Thank you for choosing %1$s! <p>The Recommended Plugins page is your one-stop destination for powering up your website with everything it needs to perform at its best. Here, you’ll find all essential plugins carefully selected to enhance functionality, boost performance, and ensure a seamless user experience. Whether you\'re setting up your site for the first time or keeping it up to date, this page makes plugin management quick and effortless. Stay in control, avoid missing critical features, and keep your website running smoothly with just a few clicks—all from one convenient place.</p>',
											'hotel-26'
										),
										wp_get_theme()->get('Name')
									),
									hotel_26_get_allowed_html_tags()
								);


					$navigation_items = hotel_26_options()->get_navigation_items();

					hotel_26_print_notice(
						array(
							'type'        => 'info',
							'message'     => $message,
							'message_id'  => 'recommended-plugins',
							'expires'     => 7 * 24 * 60 * 60,
							'action_link' => $navigation_items['plugins']['url'],
							'action_text' => esc_html__( 'Install Now', 'hotel-26' ),
						)
					);
				}
			}
		}
	}
endif;
new Hotel_26_Admin();