<?php
/**
 * Template part for displaying posts.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package Sparta
 */
$loop_event_style = get_theme_mod('loop_event_style', 'grid');
?>
<?php
if (is_single()) :
    ?>

    <?php if (has_post_thumbnail()): ?>
    <div class="row">
        <div class="col-md-12 vk-events-details-img">
            <?php the_post_thumbnail(); ?>
        </div>
    </div>
    <?php endif; ?>
    <div class="vk-event-details-body">
        <div class="row">
            <div class="col-lg-8">
                <div class="entry-header">
                    <?php the_title('<h2 class="entry-title single-event-title">', '</h2>'); ?>
                </div>
                <div class="entry-content">
                    <?php
                    echo '<h5 class="sparta-evemt-title">' . esc_html__('Event Description', 'sparta') . '</h5>';
                    espresso_get_template_part('content', 'espresso_events-details');
                    ?>
                </div>
                <?php
                echo '<h5 class="sparta-evemt-title">' . esc_html__('Pay for Ticket', 'sparta') . '</h5>';
                espresso_get_template_part('content', 'espresso_events-tickets');

                $people = get_post_meta($post->ID, 'sparta_event_people', true);

                if ($people) :

                    echo '<div class="event-meta-participant">';
                        echo '<h2 class="sparta-detail-title detail-page-title">' . esc_html__('Guests Participant', 'sparta') . '</h2>';
                        echo '<ul class="sparta-carousel row" >';
                        foreach ($people as $usrid) :
                            $author_obj = get_user_by('id', $usrid);
                            echo '<li class="col-md-3">';
                                echo '<img src="' . esc_url(get_avatar_url($usrid)) . ' " />';
                                echo '<h3 class="people-name">' . $author_obj->display_name . '</h3>';
                                $job_profile = get_the_author_meta('job_profile', $usrid);
                                if ($job_profile && $job_profile !== '') :
                                    echo '<h4 class="author-job">' . esc_html($job_profile) . '</h4>';
                                endif;
                            echo '</li>';
                        endforeach;

                        echo '</ul>';
                    echo '</div>';
                endif;
                ?>
            </div>
            <div class="col-lg-4">
                <div class="vk-event-details-body-right">
                    <?php
                    echo '<div class="sidebar-title">' . esc_html__('Information', 'sparta') . '</div>';

                    echo Sparta_Helper::sparta_espresso_event_dates_detail($post->ID);
                    espresso_get_template_part('content', 'espresso_events-venues');
                    ?>
                </div>
            </div>
        </div>
    </div>

<?php

else:

    $time_format = get_option('time_format');
    $datetimes = EEH_Event_View::get_all_date_obj($post->ID);
    $event_time_day = $event_time_year = '';
    if (is_array($datetimes) && !empty($datetimes)) {
        global $post;
        foreach ($datetimes as $datetime) {
            if ($datetime instanceof EE_Datetime) {
                $start = str_replace(' ', '&nbsp;', $datetime->get_i18n_datetime('DTT_EVT_start', 'j|F'));
                $datestart = explode("|", $start);
                $event_time_day = $datestart[0];
                $event_time_year = $datestart[1];
                $timerange = $datetime->time_range($time_format);
            }
        }
    }

    if ($loop_event_style === 'grid'): ?>
        <div class="vk-events-grid-content col-lg-6 col-md-6">
            <div class="vk-events-lists-content-item">
                <?php if (has_post_thumbnail()): ?>
                    <div class="vk-events-iem-img">
                        <?php
                        echo '<a href="' . esc_url(get_permalink()) . '" rel="bookmark">';
                        the_post_thumbnail('sparta-thumb-grid');
                        echo '</a>';
                        ?>
                    </div>
                <?php endif; ?>
                <div class="vk-events-lists-item-right">
                    <div class="vk-events-item-right-header">
                        <div class="vk-event-item-time">
                            <?php
                            echo '<ul class="vk-event-item-time-sub"><li><span>' . $event_time_day . '</span></li><li><span>' . $event_time_year . '</span></li></ul>';
                            ?>
                        </div>
                        <div class="vk-event-item-info">
                            <?php the_title('<h2><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>'); ?>
                            <ul>
                                <li>
                                    <div class="lst-event-location">
                                        <span class="ti-location-pin"></span><?php echo espresso_venue_address('inline', 0, false); ?>
                                    </div>
                                </li>
                                <li>
                                    <span class="ti-alarm-clock"></span> <?php echo '<span>' . esc_attr($timerange) . '</span>'; ?>
                                </li>

                            </ul>
                        </div>
                    </div>
                    <div class="vk-events-item-text">
                        <?php
                        if (is_archive() && has_excerpt()) :
                            echo '<p class="lst-event-des">';
                            espresso_get_template_part('content', 'espresso_events-venues');
                            printf(esc_html__('%s', 'sparta'), wp_trim_words(get_the_excerpt(), 35, '...'));
                            echo '</p>';
                        endif;
                        ?>
                    </div>
                    <div class="vk-events-item-btn">
                        <?php echo '<a href="' . esc_url(get_permalink()) . '" rel="bookmark">' . esc_html__('More information', 'sparta') . '</a>'; ?>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>

    <?php
    else:
        ?>
        <div class="vk-events-lists-content-item">
            <div class="row">
                <?php if (has_post_thumbnail()): ?>
                <div class="col-lg-5">
                    <div class="vk-events-iem-img">
                        <?php
                        echo '<a href="' . esc_url(get_permalink()) . '" rel="bookmark">';
                        the_post_thumbnail('sparta-thumb-list');
                        echo '</a>';
                        ?>
                    </div>
                </div>
                <div class="col-lg-7">
                    <?php
                    else: ?>
                    <div class="col-lg-12">
                        <?php
                        endif;
                        ?>
                        <div class="vk-events-lists-item-right">
                            <div class="vk-events-item-right-header">
                                <div class="vk-event-item-time">
                                    <?php
                                    echo '<ul class="vk-event-item-time-sub"><li><span>' . $event_time_day . '</span></li><li><span>' . $event_time_year . '</span></li></ul>';
                                    ?>
                                </div>
                                <div class="vk-event-item-info">
                                    <?php the_title('<h2><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>'); ?>
                                    <ul>
                                        <li>
                                            <div class="lst-event-location">
                                                <span class="ti-location-pin"></span><?php echo espresso_venue_address('inline', 0, false); ?>
                                            </div>

                                        </li>
                                        <li>
                                            <span class="ti-alarm-clock"></span> <?php echo esc_attr($timerange); ?>
                                        </li>

                                    </ul>
                                </div>
                            </div>
                            <div class="vk-events-item-text">
                                <?php
                                if (is_archive() && has_excerpt()) :
                                    echo '<p class="lst-event-des">';
                                    espresso_get_template_part('content', 'espresso_events-venues');
                                    printf(esc_html__('%s', 'sparta'), wp_trim_words(get_the_excerpt(), 35, '...'));
                                    echo '</p>';
                                endif;
                                ?>

                            </div>
                            <div class="vk-events-item-btn">
                                <?php echo '<a href="' . esc_url(get_permalink()) . '" rel="bookmark">' . esc_html__('More information', 'sparta') . '</a>'; ?>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
    <?php
    endif;

endif;
?>

