<?php

use Gigneo\Modules;

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

$service_id = get_the_ID();

$author_id                     = get_post_field( 'post_author', $service_id );
$author_profile_id             = gigneo_profile_id( $author_id, 'freelancer' );
$author_thumbnail_id           = get_post_thumbnail_id( $author_profile_id );
$author_online_status          = gigneo_online_status( $author_profile_id );
$author_profile_average_rating = gigneo_profile_rating( $author_profile_id, 'average' );
$author_profile_reviews        = gigneo_profile_rating( $author_profile_id );
$viewer_profile_id             = gigneo_active_profile_id();
$service_save_items            = ! empty( $viewer_profile_id ) ? gigneo_post_meta( $viewer_profile_id, '_gigneo_pm_saved_service' ) : array();
$active_class                  = ( ! empty( $service_save_items ) && in_array( $service_id, $service_save_items, true ) ) ? 'gn-saved' : '';
?>
<div class="gn-single gn-service-single gn-service-single-layout-1">
	<div class="gn-main">
		<div class="gn-head">
			<h2 class="gn-title"><?php echo esc_html( get_the_title( $service_id ) ); ?></h2>
			<div class="gn-actions">
				<div class="gn-author-info">
					<figure class="gn-avatar gn-<?php echo esc_attr( $author_online_status ? 'online' : 'offline' ); ?>">
						<?php gigneo_attachment_image_src( $author_thumbnail_id ?? 0, 'thumbnail', 'profile', '', '', $author_profile_id ); ?>
					</figure>
					<div class="gn-author-meta">
						<h4 class="gn-name"><?php echo esc_html( gigneo_profile_name( $author_profile_id ) ); ?></h4>
						<div class="gn-ratings">
							<i class="hi hi-star-alt" aria-hidden="true"></i>
							<?php echo esc_html( $author_profile_average_rating ?? 0 ); ?>
							<span class="gn-count">(<?php echo esc_html( $author_profile_reviews ?? 0 ); ?>)</span>
						</div>
					</div>
				</div>
					<div class="gn-action-buttons">
					<button class="gn-save-btn gn-btn gn-btn-outline-grey <?php echo esc_attr( $active_class ); ?>"
						data-gn-id="<?php echo intval( $service_id ); ?>"
						data-gn-type="service"
						aria-label="<?php esc_attr_e( 'Save', 'gigneo' ); ?>">
						<?php gigneo_saved_icon( true ); ?>
					</button>
						<?php if ( in_array( 'report_abuse', gigneo_active_modules(), true ) ) { ?>
							<button class="gn-report-btn gn-btn gn-btn-outline-grey"
									data-gn-id="<?php echo intval( $service_id ); ?>"
									data-gn-type="service"
									data-gn-modal-toggle="gn-service-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>
			<?php
			//Media
			gigneo_load_template( 'single/service/parts/media', true, array( 'p_id' => $service_id ) );
			?>
		</div>
		<div class="gn-body">
			<?php
			//Description
			gigneo_load_template( 'single/service/parts/description', true, array( 'p_id' => $service_id ) );

			//Attachments
			gigneo_load_template( 'single/service/parts/attachments', true, array( 'p_id' => $service_id ) );

			// Skills
			gigneo_load_template( 'single/service/parts/skills', true, array( 'p_id' => $service_id ) );

			//Locations
			gigneo_load_template( 'single/service/parts/locations', true, array( 'p_id' => $service_id ) );

			//Plans
			gigneo_load_template( 'single/service/parts/comparison', true, array( 'p_id' => $service_id ) );

			//FAQs
			gigneo_load_template( 'single/service/parts/faqs', true, array( 'p_id' => $service_id ) );

			//Reviews
			gigneo_load_template( 'single/service/parts/reviews', true, array( 'p_id' => $service_id ) );
			?>
		</div>
	</div>
	<div class="gn-aside">
		<?php
		//Vacation Notice
		do_action( 'gigneo_single_service_layout_1_vacation_notice', $service_id );
		?>
		<form id="gn-service-single-pricing-form" class="gn-service-single-pricing-form" method="get" action="/">
			<?php
			//Pricing
			gigneo_load_template( 'single/service/parts/pricing', true, array( 'p_id' => $service_id ) );
			?>
		</form>
	</div>
</div>
<?php
apply_filters( 'gigneo_service_report_abuse', $service_id );
?>
