<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Prevent direct access to the script.
}
$profile_id    = ! empty( $args['profile_id'] ) ? $args['profile_id'] : '';
$profile_type  = ! empty( $args['profile_type'] ) ? $args['profile_type'] : '';
$platform_type = ! empty( $args['platform_type'] ) ? $args['platform_type'] : '';
$credit_system = ! empty( $args['credit_system'] ) ? $args['credit_system'] : '';

$wallet_balance        = gigneo_profile_stat( 'wallet_balance', $profile_id );
$total_withdrawals     = gigneo_profile_stat( 'total_withdrawals', $profile_id );
$requested_withdrawals = gigneo_profile_stat( 'requested_withdrawals', $profile_id );
?>
<div id="gn-wallet-stats" class="gn-dashboard-section gn-section-wallet-stats">
	<div class="gn-head">
		<div class="gn-heading-info">
			<h2 class="gn-title"><?php echo esc_html__( 'Wallet', 'gigneo' ); ?></h2>
			<p class="gn-description"><?php echo esc_html__( 'Track your balance and transaction summary.', 'gigneo' ); ?></p>
		</div>
		<button class="gn-btn gn-btn-md gn-btn-outline-grey" type="button" data-gn-modal-toggle="gn-deposit-funds">
			<i class="hi hi-plus" aria-hidden="true"></i>
			<?php echo esc_html__( 'Add funds', 'gigneo' ); ?>
		</button>
	</div>
	<div class="gn-stat-cards">
		<div class="gn-stat-card gn-wallet-balance">
			<div class="gn-head">
				<span class="gn-icon">
					<i class="hi hi-banknotes" aria-hidden="true"></i>
				</span>
			</div>
			<h3 class="gn-value"><?php echo esc_html( gigneo_price_format( $wallet_balance['lifetime'], true ) ); ?></h3>
			<h6 class="gn-label"><?php echo esc_html__( 'Wallet balance', 'gigneo' ); ?>
				<span class="gn-stat-change gn-<?php echo esc_attr( $wallet_balance['trend'] ); ?>">
					<?php echo esc_html( number_format( $wallet_balance['percentage'] ) . '%' ); ?>
				</span>
			</h6>
		</div>
		<?php
		if ( 'freelancer' === $profile_type ) {
			$total_earning = gigneo_profile_stat( 'total_earning', $profile_id );
			?>
			<div class="gn-stat-card gn-total-earnings">
				<div class="gn-head">
				<span class="gn-icon">
					<i class="hi hi-currency-dollar" aria-hidden="true"></i>
				</span>
				</div>
				<h3 class="gn-value"><?php echo esc_html( gigneo_price_format( $total_earning['lifetime'], true ) ); ?></h3>
				<h6 class="gn-label"><?php echo esc_html__( 'Total earnings', 'gigneo' ); ?>
					<span class="gn-stat-change gn-<?php echo esc_attr( $total_earning['trend'] ); ?>">
					<?php echo esc_html( number_format( $total_earning['percentage'] ) . '%' ); ?>
				</span>
				</h6>
			</div>
			<?php
		} else {
			$total_spending = gigneo_profile_stat( 'total_spending', $profile_id );
			?>
			<div class="gn-stat-card gn-total-spending">
				<div class="gn-head">
				<span class="gn-icon">
					<i class="hi hi-briefcase" aria-hidden="true"></i>
				</span>
				</div>
				<h3 class="gn-value"><?php echo esc_html( gigneo_price_format( $total_spending['lifetime'], true ) ); ?></h3>
				<h6 class="gn-label"><?php echo esc_html__( 'Total spending', 'gigneo' ); ?>
					<span class="gn-stat-change gn-<?php echo esc_attr( $total_spending['trend'] ); ?>">
					<?php echo esc_html( number_format( $total_spending['percentage'] ) . '%' ); ?>
				</span>
				</h6>
			</div>
		<?php } ?>
		<div class="gn-stat-card gn-total-withdrawals">
			<div class="gn-head">
				<span class="gn-icon">
					<i class="hi hi-credit-card" aria-hidden="true"></i>
				</span>
			</div>
			<h3 class="gn-value"><?php echo esc_html( gigneo_price_format( $total_withdrawals['lifetime'], true ) ); ?></h3>
			<h6 class="gn-label"><?php echo esc_html__( 'Total withdrawals', 'gigneo' ); ?>
				<span class="gn-stat-change gn-<?php echo esc_attr( $total_withdrawals['trend'] ); ?>">
					<?php echo esc_html( number_format( $total_withdrawals['percentage'] ) . '%' ); ?>
				</span>
			</h6>
		</div>
		<div class="gn-stat-card gn-requested-withdrawals">
			<div class="gn-head">
				<span class="gn-icon">
					<i class="hi hi-document-currency-dollar" aria-hidden="true"></i>
				</span>
			</div>
			<h3 class="gn-value"><?php echo esc_html( gigneo_price_format( $requested_withdrawals['lifetime'], true ) ); ?></h3>
			<h6 class="gn-label"><?php echo esc_html__( 'Requested withdrawals', 'gigneo' ); ?>
				<span class="gn-stat-change gn-<?php echo esc_attr( $requested_withdrawals['trend'] ); ?>">
					<?php echo esc_html( number_format( $requested_withdrawals['percentage'] ) . '%' ); ?>
				</span>
			</h6>
		</div>
	</div>
</div>
