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

use Gigneo\Notifications;

$platform_access  = gigneo_user_have_access();
$user_id          = get_current_user_id();
$user_info        = get_userdata( $user_id );
$user_menu        = gigneo_option( '_gigneo_ts_auth_user_menu' );
$auth_popup       = gigneo_option( '_gigneo_ts_auth_popup' );
$register_disable = ! empty( gigneo_option( '_gigneo_ts_disable_registration' ) );
$login_page_id    = gigneo_option( '_gigneo_ts_template_login' );
$register_page_id = gigneo_option( '_gigneo_ts_template_register' );

$login_text    = gigneo_option( '_gigneo_ts_auth_login_button' );
$register_text = gigneo_option( '_gigneo_ts_auth_register_button' );
$login_icon    = gigneo_option( '_gigneo_ts_auth_login_button_icon' );
$register_icon = gigneo_option( '_gigneo_ts_auth_register_button_icon' );

$editor_preview_action = ! empty( $args['preview_type'] ) && 'action' === $args['preview_type'];
$editor_preview_menu   = ! empty( $args['preview_type'] ) && 'menu' === $args['preview_type'];

?>
<div class="gn-action-menu-wrapper">
	<?php
	if ( ! is_user_logged_in() || $editor_preview_action ) {
		?>
		<div class="gn-user-auth-buttons">
			<?php
			if ( $auth_popup ) {
				if ( ! empty( $login_text ) ) {
					?>
					<button type="button" class="gn-btn gn-btn-outline-grey gn-login-btn gn-login-popup-toggle">
						<?php
						echo esc_html( $login_text );
						if ( ! empty( $login_icon ) ) {
							?>
							<i class="<?php echo esc_attr( $login_icon ); ?>" aria-hidden="true"></i>
							<?php
						}
						?>
					</button>
					<?php
				}
				if ( ! $register_disable && ! empty( $register_text ) ) {
					?>
					<button type="button" class="gn-btn gn-btn-primary gn-register-btn gn-register-popup-toggle">
						<?php
						echo esc_html( $register_text );
						if ( ! empty( $register_icon ) ) {
							?>
							<i class="<?php echo esc_attr( $register_icon ); ?>" aria-hidden="true"></i>
							<?php
						}
						?>
					</button>
					<?php
				}
			} else {
				if ( ! empty( $login_text ) ) {
					?>
					<a href="<?php echo esc_url( ! empty( $login_page_id ) ? get_permalink( $login_page_id ) : '' ); ?>"
						class="gn-btn gn-btn-outline-grey gn-login-btn">
						<?php echo esc_html( $login_text ); ?>
					</a>
					<?php
				}
				if ( ! $register_disable && ! empty( $register_text ) ) {
					?>
					<a href="<?php echo esc_url( ! empty( $register_page_id ) ? get_permalink( $register_page_id ) : '' ); ?>"
						class="gn-btn gn-btn-primary gn-register-btn">
						<?php echo esc_html( $register_text ); ?>
					</a>
				<?php } ?>
			<?php } ?>
		</div>
		<?php
	} elseif ( $platform_access || $editor_preview_menu ) {

			$profile_id           = gigneo_active_profile_id();
			$profile_type         = gigneo_profile_type( $profile_id );
			$display_name         = gigneo_profile_name( $profile_id );
			$thumbnail_id         = ! empty( $profile_id ) ? get_post_thumbnail_id( $profile_id ) : '';
			$user_menu            = gigneo_user_menu_list( $profile_type );
			$unread_notifications = Notifications::get_unread_notification_count();
		?>
		<div class="gn-user-notifications">
				<?php do_action( 'gigneo_before_user_notification' ); ?>
				<div class="gn-user-notification">
					<div class="gn-icon">
						<i class="hi hi-bell-alert"></i>
						<span class="gn-count"><?php echo ! empty( $unread_notifications ) ? esc_html( $unread_notifications ) : ''; ?></span>
					</div>
					<?php gigneo_load_template( 'dropdown/notification' ); ?>
				</div>
				<?php do_action( 'gigneo_after_user_notification' ); ?>
			</div>
			<div class="gn-user-action-menu">
				<figure class="gn-user-avatar">
					<?php gigneo_attachment_image_src( $thumbnail_id, 'medium', 'profile' ); ?>
				</figure>
				<?php gigneo_load_template( 'dropdown/user-menu' ); ?>
			</div>
			<?php

	}
	?>
</div>
