<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
$profile_id = get_the_ID();

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

$profile_type  = gigneo_profile_type( $profile_id );
$user_id       = get_post_field( 'post_author', $profile_id );
$profile_name  = gigneo_profile_name( $profile_id );
$date_format   = get_option( 'date_format' );
$platform_type = gigneo_platform_type();

$listing_post_type = 'freelancer' === $profile_type ? 'service' : 'job';

$listing_args = array(
	'post_type'      => "gigneo_{$listing_post_type}",
	'post_status'    => 'publish',
	'author'         => $user_id,
	'posts_per_page' => -1,
	'fields'         => 'ids',
	'no_found_rows'  => true,
);

$listing = get_posts( $listing_args );

$portfolio    = gigneo_post_meta( $profile_id, '_gigneo_pm_portfolio' );
$skills       = gigneo_post_meta( $profile_id, '_gigneo_pm_skills' );
$education    = gigneo_post_meta( $profile_id, '_gigneo_pm_education' );
$experience   = gigneo_post_meta( $profile_id, '_gigneo_pm_experience' );
$awards       = gigneo_post_meta( $profile_id, '_gigneo_pm_awards' );
$licenses     = gigneo_post_meta( $profile_id, '_gigneo_pm_licenses' );
$certificates = gigneo_post_meta( $profile_id, '_gigneo_pm_certificates' );
$faqs         = gigneo_post_meta( $profile_id, '_gigneo_pm_faqs' );
?>
<div class="gn-single gn-profile-single gn-profile-single-layout-1">
	<div class="gn-main">
		<div class="gn-head">
			<?php
			//Media
			gigneo_load_template(
				'single/profile/parts/media',
				true,
				array(
					'profile_id'   => $profile_id,
					'profile_type' => $profile_type,
				)
			);
			?>
		</div>
		<div class="gn-body">
			<div class="gn-single-menu-wrapper">
				<div class="gn-single-menu">
					<a href="#gn-overview" class="gn-menu-item gn-overiview gn-active"><?php esc_html_e( 'Overview', 'gigneo' ); ?></a>
					<?php if ( ! empty( $listing ) ) { ?>
						<a href="#gn-<?php echo esc_attr( 'freelancer' === $profile_type ? 'services' : 'jobs' ); ?>" class="gn-tab-item gn-jobs"><?php echo 'freelancer' === $profile_type ? esc_html__( 'Services', 'gigneo' ) : esc_html__( 'Jobs', 'gigneo' ); ?></a>
						<?php
					}
					if ( ! empty( $portfolio ) ) {
						?>
						<a href="#gn-portfolio" class="gn-menu-item gn-profiltio"><?php esc_html_e( 'Portfolio', 'gigneo' ); ?></a>
						<?php
					}
					?>
					<a href="#gn-reviews" class="gn-menu-item gn-reviews"><?php esc_html_e( 'Reviews', 'gigneo' ); ?></a>
					<?php if ( ! empty( $education ) || ! empty( $experience ) || ! empty( $awards ) || ! empty( $licenses ) || ! empty( $certificates ) ) { ?>
						<a href="#gn-credentials" class="gn-menu-label-item gn-credentials"><?php esc_html_e( 'Credentials', 'gigneo' ); ?></a>
						<?php
					}
					if ( ! empty( $faqs ) ) {
						?>
						<a href="#gn-faqs" class="gn-menu-item gn-faqs"><?php esc_html_e( 'FAQs', 'gigneo' ); ?></a>
					<?php } ?>
				</div>
			</div>
			<div class="gn-single-content-wrapper">
				<?php
				//Overview
				gigneo_load_template(
					'single/profile/parts/overview',
					true,
					array(
						'profile_id'   => $profile_id,
						'profile_type' => $profile_type,
					)
				);

				//Services/Jobs
				$listing_type = 'freelancer' === $profile_type ? 'services' : 'jobs';
				gigneo_load_template(
					"single/profile/parts/{$listing_type}",
					true,
					array(
						'profile_id'   => $profile_id,
						'profile_type' => $profile_type,
						'listing'      => $listing,
					)
				);

				//Portfolio
				gigneo_load_template(
					'single/profile/parts/portfolio',
					true,
					array(
						'profile_id'   => $profile_id,
						'profile_type' => $profile_type,
						'portfolio'    => $portfolio,
						'date_format'  => $date_format,
					)
				);
				//Skills
				gigneo_load_template(
					'single/profile/parts/skills',
					true,
					array(
						'profile_id'   => $profile_id,
						'profile_type' => $profile_type,
						'skills'       => $skills,
					)
				);
				//Reviews
				gigneo_load_template(
					'single/profile/parts/reviews',
					true,
					array(
						'profile_id'   => $profile_id,
						'profile_type' => $profile_type,
					)
				);
				//Address
				gigneo_load_template(
					'single/profile/parts/address',
					true,
					array(
						'profile_id'   => $profile_id,
						'profile_type' => $profile_type,
					)
				);
				?>
				<div id="gn-credentials" class="gn-credentials-wrapper">
					<?php
					//Education
					gigneo_load_template(
						'single/profile/parts/education',
						true,
						array(
							'profile_id'   => $profile_id,
							'profile_type' => $profile_type,
							'education'    => $education,
							'date_format'  => $date_format,
						)
					);
					//Experience
					gigneo_load_template(
						'single/profile/parts/experience',
						true,
						array(
							'profile_id'   => $profile_id,
							'profile_type' => $profile_type,
							'experience'   => $experience,
							'date_format'  => $date_format,
						)
					);
					//Awards
					gigneo_load_template(
						'single/profile/parts/awards',
						true,
						array(
							'profile_id'   => $profile_id,
							'profile_type' => $profile_type,
							'awards'       => $awards,
							'date_format'  => $date_format,
						)
					);
					//License
					gigneo_load_template(
						'single/profile/parts/licenses',
						true,
						array(
							'profile_id'   => $profile_id,
							'profile_type' => $profile_type,
							'licenses'     => $licenses,
							'date_format'  => $date_format,
						)
					);
					//Certificates
					gigneo_load_template(
						'single/profile/parts/certificates',
						true,
						array(
							'profile_id'   => $profile_id,
							'profile_type' => $profile_type,
							'certificates' => $certificates,
							'date_format'  => $date_format,
						)
					);
					//FAQs
					gigneo_load_template(
						'single/profile/parts/faqs',
						true,
						array(
							'profile_id'   => $profile_id,
							'profile_type' => $profile_type,
							'faqs'         => $faqs,
						)
					);
					?>
				</div>
			</div>
		</div>
	</div>
	<div class="gn-aside">
		<?php
		//Vacation
		do_action( 'gigneo_single_profile_layout_1_vacation_notice', $profile_id, $profile_type, $platform_type, $date_format );
		//Info
		gigneo_load_template(
			'single/profile/parts/info',
			true,
			array(
				'profile_id'    => $profile_id,
				'profile_type'  => $profile_type,
				'platform_type' => $platform_type,
				'listing'       => $listing,
			)
		);

		//Video
		gigneo_load_template(
			'single/profile/parts/intro',
			true,
			array(
				'profile_id'   => $profile_id,
				'profile_type' => $profile_type,
				'profile_name' => $profile_name,
			)
		);

		if ( 'freelancer' === $profile_type ) {
			gigneo_load_template(
				'single/profile/parts/intro',
				true,
				array(
					'profile_id'   => $profile_id,
					'profile_type' => $profile_type,
				)
			);
		}

		gigneo_load_template(
			'single/profile/parts/languages',
			true,
			array(
				'profile_id'   => $profile_id,
				'profile_type' => $profile_type,
			)
		);
		gigneo_load_template(
			'single/profile/parts/socials',
			true,
			array(
				'profile_id'   => $profile_id,
				'profile_type' => $profile_type,
			)
		);
		?>
	</div>
</div>
<?php
do_action( 'gigneo_profile_layout_after', $profile_id );
?>
