<?php

use Gigneo\Modules;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$profile_id    = $args['profile_id'] ?? '';
$profile_type  = $args['profile_type'] ?? '';
$platform_type = $args['platform_type'] ?? '';
$listing       = $args['listing'] ?? array();

if ( empty( $profile_id ) ) {
	return;
}

$profile          = get_post( $profile_id );
$user_id          = get_post_field( 'post_author', $profile_id );
$user             = get_userdata( $user_id );
$online           = gigneo_online_status( $profile_id );
$profile_name     = gigneo_profile_name( $profile_id );
$thumbnail_id     = get_post_thumbnail_id( $profile_id );
$last_activity    = gigneo_post_meta( $profile_id, '_gigneo_pm_last_activity' );
$date_format      = get_option( 'date_format' );
$time_format      = get_option( 'time_format' );
$date_time_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
$online           = gigneo_online_status( $profile_id );
$member_since     = gmdate( $date_format, strtotime( $user->user_registered ) );
$member_since     = gigneo_datetime( $member_since, 'F Y' );

$active_profile_id   = gigneo_active_profile_id();
$active_profile_type = gigneo_profile_type( $active_profile_id );
?>
<div class="gn-section gn-section-profile-info">
	<div class="gn-head">
		<div class="gn-profile">
			<figure class="gn-avatar gn-<?php echo esc_attr( $online ? 'online' : 'offline' ); ?>">
				<?php gigneo_attachment_image_src( $thumbnail_id, 'thumbnail', 'profile', '', '', $profile_id ); ?>
				
			</figure>
			<div class="gn-info">
				<div class="gn-name-wrapper">
					<h5 class="gn-name"><?php echo esc_html( $profile_name ); ?></h5>
					<?php gigneo_verification_badge( $profile_id, true ); ?>
				</div>
				<div class="gn-rating">
					<i class="hi hi-star-alt gn-filled"></i>
					<?php echo esc_html( gigneo_profile_rating( $profile_id, 'average' ) ); ?>
					<span class="gn-count">(<?php echo esc_html( gigneo_profile_rating( $profile_id ) ); ?>)</span>
				</div>
			</div>
		</div>
		<div class="gn-actions">
			<button type="button" class="gn-save-btn gn-btn gn-btn-outline-grey" data-gn-id="<?php echo esc_attr( $profile_id ); ?>" data-gn-type="<?php echo esc_attr( $profile_type ); ?>"><?php gigneo_saved_icon( true ); ?></button>
			<?php if ( in_array( 'report_abuse', gigneo_active_modules() ) ) { ?>
				<button class="gn-report-btn gn-btn gn-btn-outline-grey"
						data-gn-id="<?php echo esc_attr( $profile_id ); ?>"
						data-gn-type="profile"
						data-gn-modal-toggle="gn-profile-report-abuse-modal"
						aria-label="<?php esc_attr_e( 'Report abuse', 'gigneo' ); ?>">
					<i class="hi hi-flag" aria-hidden="true"></i>
				</button>
			<?php } ?>
		</div>
	</div>
	<div class="gn-body">
		<ul class="gn-meta">
			<li class="gn-status">
				<span class="gn-label"><?php echo esc_html__( 'Status', 'gigneo' ); ?></span>
				<span class="gn-value gn-<?php echo esc_attr( $online ? 'online' : 'offline' ); ?>"><?php echo $online ? esc_html__( 'Online', 'gigneo' ) : esc_html__( 'Offline', 'gigneo' ); ?></span>
			</li>
			<li class="gn-last-activity">
				<?php
				$time_diff = human_time_diff( (int) $last_activity, time() );
				?>
				<span class="gn-label"><?php esc_html_e( 'Last active', 'gigneo' ); ?></span>
				<span class="gn-value">
					<?php
					// translators: %s: human-readable time difference.
					printf( esc_html__( '%s ago', 'gigneo' ), esc_html( $time_diff ) );
					?>
				</span>
			</li>
			<li class="gn-member-since">
				<span class="gn-label"><?php echo esc_html__( 'Member since', 'gigneo' ); ?></span>
				<span class="gn-value"><?php echo esc_html( $member_since ); ?></span>
			</li>
		</ul>
	</div>
	<div class="gn-footer">
		<?php if ( 'freelancer' === $profile_type && 'jobs' !== $platform_type && ! empty( $listing ) ) { ?>
			<a href="#gn-services" class="gn-btn gn-btn-primary gn-btn-md"><?php echo esc_html__( 'View services', 'gigneo' ); ?></a>
		<?php } ?>
		<?php if ( 'employer' === $profile_type && 'services' !== $platform_type && ! empty( $listing ) ) { ?>
			<a href="#gn-jobs" class="gn-btn gn-btn-primary gn-btn-md"><?php echo esc_html__( 'View jobs', 'gigneo' ); ?></a>
		<?php } ?>
		<?php
		do_action(
			'gigneo_action_buttons',
			array(
				'member_id'           => $profile_id,
				'profile_id'          => $active_profile_id,
				'profile_type'        => $profile_type,
				'active_profile_type' => $active_profile_type,
				'context'             => 'profile_info',
			)
		);
		?>
	</div>
</div>
