<?php
/**
 * WeMeet webex single Template sidebar
 *
 * @package WeMeet
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

?>


<div class="wemeet-sidebar-col">
	<div class="wemeet-sidebar">
		<div class="wemeet-single-widget wemeet-single-widget-countdown">
			<h4 class="wemeet-widget-title"><?php esc_html_e( 'Time to go', 'wemeet' ); ?></h4>
			<div class="wemeet-widget-inner">
				<?php if ( ! isset( $webex_response['errors'] ) ) { ?>
					<?php if ( 'end' !== $meeting_status ) { ?>
						<?php if ( $is_schedule ) { ?>
							<div class="wemeet_start_time" data-meeting-start-time="<?php echo esc_attr( $next_meeting_time ); ?>" data-meeting-time-offset="<?php echo esc_attr( $gmt_offset_val ); ?>" > </div>
							<?php } else { ?>
								<span class="wemeet-countdown-wrapper">
									<span class="wemeet-countdown-value"><?php esc_html_e( 'Meeting is running', 'wemeet' ); ?></span>
									<span class="wemeet-countdown-label"><?php esc_html_e( 'The meeting is started and running', 'wemeet' ); ?></span>
								</span>
							<?php } ?>
					<?php } else { ?>
						<span class="wemeet-countdown-wrapper">
							<span class="wemeet-countdown-value"><?php esc_html_e( 'Meeting is finished', 'wemeet' ); ?></span>
							<span class="wemeet-countdown-label"><?php esc_html_e( 'This meeting has been ended by the host.', 'wemeet' ); ?></span>
						</span>
					<?php } ?>
				<?php } else { ?>
					<span class="wemeet-countdown-wrapper">
							<span class="wemeet-countdown-label"><?php echo esc_html( $response_message ); ?></span>
					</span>

				<?php } ?>
			</div>
		</div>

		<?php if ( ! isset( $webex_response['errors'] ) ) { ?>
			<?php if ( current_user_can( 'manage_options' ) || current_user_can( 'tutor_instructor' ) ) { ?>
				<div class="wemeet-single-widget wemeet-single-widget-host-actions">
					<div class="wemeet-widget-inner">
						<?php if ( 'end' !== $meeting_status ) { ?>
						<button  class="wemeet-meeting-status" data-meeting-status="end" data-post-id="<?php echo esc_attr( $post->ID ); ?>" data-meeting-id="<?php echo esc_attr( $meeting_id ); ?>"><?php esc_html_e( 'End Meeting ?', 'wemeet' ); ?>
						</button>
					<?php } else { ?>
						<button  class="wemeet-meeting-status" data-meeting-status="resume" data-post-id="<?php echo esc_attr( $post->ID ); ?>" data-meeting-id="<?php echo esc_attr( $meeting_id ); ?>"><?php esc_html_e( 'Enable Meeting Join ?', 'wemeet' ); ?>
						</button>
					<?php } ?>
						<p><?php esc_html_e( 'You are seeing this because you are the author of this meeting', 'wemeet' ); ?></p>
					</div>
				</div>
			<?php } ?>
		<?php } ?>
			
		<div class="wemeet-single-widget wemeet-single-widget-detail">
			<h4 class="wemeet-widget-title"><?php esc_html_e( 'Details', 'wemeet' ); ?></h4>
			<div class="wemeet-widget-inner">
				<dl>
					<dt><?php esc_html_e( 'Topic:', 'wemeet' ); ?></dt>
					<dd><?php echo esc_html( the_title() ); ?></dd>
					<dt><?php esc_html_e( 'Hosted By:', 'wemeet' ); ?></dt>
					<dd>
					<?php
						$author_id = get_post_field( 'post_author', $post->ID );
						$author_name = get_the_author_meta( 'display_name', $author_id );
						echo esc_html( $author_name );
					?>
					</dd>

					<dt><?php esc_html_e( 'Start Time:', 'wemeet' ); ?></dt>
					<dd class="mhbu-tm">
					<?php

					echo esc_html( gmdate( 'l, F j, Y g:i A', strtotime( $start_time ) ) );

					?>
					</dd>

					<dt><?php esc_html_e( 'Duration:', 'wemeet' ); ?></dt>
					<dd class="wemeet-duration">
						<?php
						if ( 60 <= $meeting_duration ) {
							$hours   = floor( $meeting_duration / 60 );
							$minutes = $meeting_duration % 60;

							// Get the correct translation for "hour" or "hours".
							$hour_text   = ( 1 == $hours ) ? __( 'hour', 'wemeet' ) : __( 'hours', 'wemeet' );
							$minute_text = ( 1 == $minutes ) ? __( 'minute', 'wemeet' ) : __( 'minutes', 'wemeet' );

							// Print hours.
							echo esc_html( number_format_i18n( $hours ) ) . ' ' . esc_html( $hour_text );

							// Print minutes if greater than 0.
							if ( $minutes > 0 ) {
								echo ' ' . esc_html( number_format_i18n( $minutes ) ) . ' ' . esc_html( $minute_text );
							}
						} else {
							// Get the correct translation for "minute" or "minutes".
							$minute_text = ( 1 == $meeting_duration ) ? __( 'minute', 'wemeet' ) : __( 'minutes', 'wemeet' );

							// Print minutes only.
							echo esc_html( number_format_i18n( $meeting_duration ) ) . ' ' . esc_html( $minute_text );
						}
						?>
					</dd>

					<dt><?php esc_html_e( 'Current Timezone:', 'wemeet' ); ?></dt>
					<dd class="wemeet-tz">
					<?php
						echo esc_html( $time_zone );
					?>
					</dd>
					
				</dl>
			</div>
		</div>

		<?php
		if ( $is_pr_avaliable && ! empty( $integration_settings ) && ! empty( $integration_settings['google_calendar'] ) ) {
				require_once WEMEET_PRO_INCLUDES . '/Templates/sidebars/wemeet-calander.php';
		}
		?>

		<div class="wemeet-buy-btn-wpapper">
			<?php
			if ( ! empty( $product_id ) && 'yes' === $meeting_as_product && ! current_user_can( 'manage_options' ) ) {
				$product_link = get_permalink( $product_id );
				?>
				<a href="<?php echo esc_url( $product_link ); ?>" class="wemeet-buy-button" target="__blank"> <?php esc_attr_e( 'Buy Now !', 'wemeet' ); ?></a>
			
			<?php } ?>
		</div>
	</div>
</div>
