<?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 = $args['credit_system'] ?? false;

$active_order_count = gigneo_profile_stat( 'active_orders_count', $profile_id );
?>
<div class="gn-dashboard-section gn-section-intro">
	<div class="gn-left-area">
		<div class="gn-info">
			<h2 class="gn-title">
				<?php
				printf(
				// translators: %s is the profile name.
					esc_html__( 'Welcome, %s!', 'gigneo' ),
					esc_html( gigneo_profile_name( $profile_id ) )
				)
				?>
				<span class="gn-hand-icon">👋</span>
			</h2>
			<p class="gn-description"><?php echo esc_html__( 'Here’s a quick overview of your work.', 'gigneo' ); ?></p>
		</div>
		<div class="gn-actions">
			<button class="gn-btn gn-btn-primary gn-btn-md" 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>
			<?php
			if ( 'freelancer' === $profile_type ) {
				if ( 'jobs' !== $platform_type ) {
					?>
					<a href="<?php echo esc_url( gigneo_dashboard_url( 'service', 'list' ) ); ?>" class="gn-btn gn-btn-outline-grey gn-btn-md">
						<?php echo esc_html__( 'View services', 'gigneo' ); ?>
					</a>
					<?php
				} else {
					$jobs_page_id  = gigneo_option( '_gigneo_ts_template_jobs' );
					$jobs_page_url = ! empty( $jobs_page_id ) ? get_permalink( $jobs_page_id ) : home_url();
					?>
					<a href="<?php echo esc_url( $jobs_page_url ); ?>" class="gn-btn gn-btn-outline-grey gn-btn-md">
						<?php echo esc_html__( 'Brows Jobs', 'gigneo' ); ?>
					</a>
					<?php
				}
			} elseif ( 'services' !== $platform_type ) {
				?>
					<a href="<?php echo esc_url( gigneo_dashboard_url( 'job', 'list' ) ); ?>" class="gn-btn gn-btn-outline-grey gn-btn-md">
						<?php echo esc_html__( 'View Jobs', 'gigneo' ); ?>
					</a>
					<?php
			} else {
				$services_page_id  = gigneo_option( '_gigneo_ts_template_services' );
				$services_page_url = ! empty( $services_page_id ) ? get_permalink( $services_page_id ) : home_url();
				?>
				<a href="<?php echo esc_url( $services_page_url ); ?>" class="gn-btn gn-btn-outline-grey gn-btn-md">
				<?php echo esc_html__( 'Brows Services', 'gigneo' ); ?>
				</a>
				<?php

			}
			?>
		</div>
	</div>
	<div class="gn-right-area">
		<div class="gn-stat-cards">
			<?php
			if ( 'jobs' !== $platform_type && 'freelancer' === $profile_type ) {
				$active_service_count = gigneo_profile_stat( 'active_services_count', $profile_id );
				?>
				<div class="gn-stat-card gn-active-services">
					<div class="gn-head">
					<span class="gn-icon">
						<i class="hi hi-briefcase" aria-hidden="true"></i>
					</span>
						<a href="<?php echo esc_url( gigneo_dashboard_url( 'service', 'list' ) ); ?>" class="gn-link">
							<i class="hi hi-arrow-up-right" aria-hidden="true"></i>
						</a>
					</div>
					<h3 class="gn-value"><?php echo esc_html( $active_service_count['lifetime'] ); ?></h3>
					<h6 class="gn-label">
						<?php echo esc_html__( 'Active services', 'gigneo' ); ?>
						<span class="gn-stat-change gn-<?php echo esc_attr( $active_service_count['trend'] ); ?>">
							<?php echo esc_html( number_format( $active_service_count['percentage'] ) . '%' ); ?>
						</span>
					</h6>
				</div>
				<?php
			} elseif ( 'services' !== $platform_type && 'employer' === $profile_type ) {
				$active_jobs_count = gigneo_profile_stat( 'active_jobs_count', $profile_id );
				?>
				<div class="gn-stat-card gn-active-jobs">
					<div class="gn-head">
					<span class="gn-icon">
						<i class="hi hi-briefcase" aria-hidden="true"></i>
					</span>
						<a href="<?php echo esc_url( gigneo_dashboard_url( 'job', 'list' ) ); ?>" class="gn-link">
							<i class="hi hi-arrow-up-right" aria-hidden="true"></i>
						</a>
					</div>
					<h3 class="gn-value"><?php echo esc_html( $active_jobs_count['lifetime'] ); ?></h3>
					<h6 class="gn-label">
						<?php echo esc_html__( 'Active jobs', 'gigneo' ); ?>
						<span class="gn-stat-change gn-<?php echo esc_attr( $active_jobs_count['trend'] ); ?>">
							<?php echo esc_html( number_format( $active_jobs_count['percentage'] ) . '%' ); ?>
						</span>
					</h6>
				</div>
			<?php } ?>
			<div class="gn-stat-card gn-active-orders">
				<div class="gn-head">
					<span class="gn-icon">
						<i class="hi hi-folder" aria-hidden="true"></i>
					</span>
					<a href="<?php echo esc_url( gigneo_dashboard_url( 'order', ( 'both' !== $platform_type ? $platform_type : 'service' ) . '-list' ) ); ?>" class="gn-link">
						<i class="hi hi-arrow-up-right" aria-hidden="true"></i>
					</a>
				</div>
				<h3 class="gn-value"><?php echo esc_html( $active_order_count['lifetime'] ); ?></h3>
				<h6 class="gn-label">
					<?php echo esc_html__( 'Active orders', 'gigneo' ); ?>
					<span class="gn-stat-change gn-<?php echo esc_attr( $active_order_count['trend'] ); ?>">
						<?php echo esc_html( number_format( $active_order_count['percentage'] ) . '%' ); ?>
					</span>
				</h6>
			</div>
			<?php
			//Completed orders
			if ( 'both' !== $platform_type ) {
				$completed_order_count = gigneo_profile_stat( 'completed_orders_count', $profile_id );
				?>
				<div class="gn-stat-card gn-completed-orders">
					<div class="gn-head">
					<span class="gn-icon">
						<i class="hi hi-trophy" aria-hidden="true"></i>
					</span>
						<a href="<?php echo esc_url( gigneo_dashboard_url( 'order', ( 'both' !== $platform_type ? $platform_type : 'service' ) . '-list' ) ); ?>" class="gn-link">
							<i class="hi hi-arrow-up-right" aria-hidden="true"></i>
						</a>
					</div>
					<h3 class="gn-value"><?php echo esc_html( $completed_order_count['lifetime'] ); ?></h3>
					<h6 class="gn-label">
						<?php echo esc_html__( 'Completed orders', 'gigneo' ); ?>
						<span class="gn-stat-change gn-<?php echo esc_attr( $completed_order_count['trend'] ); ?>">
							<?php echo esc_html( number_format( $completed_order_count['percentage'] ) . '%' ); ?>
						</span>
					</h6>
				</div>
				<?php
			}
			//Available credits or success rate
			if ( $credit_system ) {
				$available_credit = gigneo_profile_stat( 'available_credits', $profile_id );
				?>
				<div class="gn-stat-card gn-available-credits">
					<div class="gn-head">
					<span class="gn-icon">
						<i class="hi hi-credit-card" aria-hidden="true"></i>
					</span>
						<a href="<?php echo esc_url( gigneo_dashboard_url( 'account', 'credits' ) ); ?>" class="gn-link">
							<i class="hi hi-arrow-up-right" aria-hidden="true"></i>
						</a>
					</div>
					<h3 class="gn-value"><?php echo esc_html( $available_credit['lifetime'] ); ?></h3>
					<h6 class="gn-label">
						<?php echo esc_html__( 'Available credits', 'gigneo' ); ?>
						<span class="gn-stat-change gn-<?php echo esc_attr( $available_credit['trend'] ); ?>">
							<?php echo esc_html( number_format( $available_credit['percentage'] ) . '%' ); ?>
						</span>
					</h6>
				</div>
				<?php
			} else {
				$success_rate = gigneo_profile_stat( 'success_rate', $profile_id );
				?>
				<div class="gn-stat-card gn-success-rate">
					<div class="gn-head">
					<span class="gn-icon">
						<i class="hi hi-bolt" aria-hidden="true"></i>
					</span>
						<a href="<?php echo esc_url( gigneo_dashboard_url( 'order', ( 'both' !== $platform_type ? $platform_type : 'service' ) . '-list' ) ); ?>" class="gn-link">
							<i class="hi hi-arrow-up-right" aria-hidden="true"></i>
						</a>
					</div>
					<h3 class="gn-value"><?php echo esc_html( $success_rate['lifetime'] ); ?></h3>
					<h6 class="gn-label">
						<?php echo esc_html__( 'Success rate', 'gigneo' ); ?>
						<span class="gn-stat-change gn-<?php echo esc_attr( $success_rate['trend'] ); ?>">
							<?php echo esc_html( number_format( $success_rate['percentage'] ) . '%' ); ?>
						</span>
					</h6>
				</div>
			<?php } ?>
		</div>
	</div>
</div>
