<?php
/**
 * Event details component (date, time, location)
 */
if (!defined('ABSPATH')) exit;

// Get date/time settings
$em_start_date = $event_settings['em_start_date'] ?? '';
$em_end_date = $event_settings['em_end_date'] ?? '';
$em_start_time = $event_settings['em_start_time'] ?? '';
$em_end_time = $event_settings['em_end_time'] ?? '';
$em_venue = $event_settings['em_venue'] ?? '';
$em_venuee_phone = $event_settings['em_venuee_phone'] ?? '';
$em_venuee_email = $event_settings['em_venuee_email'] ?? '';

// Get heading settings
$em_date_time_heading = $event_settings['em_date_time_heading'] ?? 'Date & Time';
$em_location_heading = $event_settings['em_location_heading'] ?? 'Location';

// Format dates
$em_date_format = get_option('date_format');
$em_time_format = get_option('time_format');
$em_start_date_val = !empty($em_start_date) ? date_i18n($em_date_format, strtotime($em_start_date)) : '';
$em_end_date_val = !empty($em_end_date) ? date_i18n($em_date_format, strtotime($em_end_date)) : '';
$em_start_time_val = !empty($em_start_time) ? date_i18n($em_time_format, strtotime($em_start_time)) : '';
$em_end_time_val = !empty($em_end_time) ? date_i18n($em_time_format, strtotime($em_end_time)) : '';

// Check if magazine layout
$layout_preference = $event_settings['em_layout_preference'] ?? 'default';
$rounded_class = ($layout_preference === 'magazine') ? 'em-rounded-2xl' : '';
$grid_classes = ($layout_preference === 'magazine') ? 'em-grid em-grid-cols-1 em-gap-4 em-text-sm' : 'em-grid em-grid-cols-2 sm:em-grid-cols-2 em-gap-4 em-text-sm';
?>

<!-- Details Section - New Design -->
<section class="em-bg-white em-p-5 em-border em-border-slate-200 em-shadow-sm em-animate-fade-in em-animate-delay-100 <?php echo esc_attr($rounded_class); ?>">
    <?php ?>
    <div class="<?php echo esc_attr($grid_classes); ?>">
        <!-- Date & Time -->
        <?php if (!empty($em_start_date_val) || !empty($em_start_time_val)): ?>
            <div class="em-flex em-items-center em-gap-3">
                <svg class="em-w-5 em-h-5 em-text-indigo-500 em-flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"></path>
                </svg>
                <div>
                    <?php if (!empty($em_start_date_val)): ?>
                        <p class="em-font-semibold em-text-slate-800">
                            <?php echo esc_html($em_start_date_val); ?>
                            <?php if ($em_start_date_val != $em_end_date_val && !empty($em_end_date_val)): ?>
                                - <?php echo esc_html($em_end_date_val); ?>
                            <?php endif; ?>
                        </p>
                    <?php endif; ?>
                    <?php if (!empty($em_start_time_val)): ?>
                        <p class="em-text-slate-500">
                            <?php echo esc_html($em_start_time_val); ?>
                            <?php if (!empty($em_end_time_val)): ?>
                                – <?php echo esc_html($em_end_time_val); ?>
                            <?php endif; ?>
                        </p>
                    <?php endif; ?>
                </div>
            </div>
        <?php endif; ?>

        <!-- Location -->
        <?php if (!empty($em_venue)): ?>
            <div class="em-flex em-items-center em-gap-3">
                <svg class="em-w-5 em-h-5 em-text-indigo-500 em-flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path>
                    <path stroke-linecap="round" stroke-linejoin="round" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"></path>
                </svg>
                <div>
                    <p class="em-font-semibold em-text-slate-800"><?php echo esc_html($em_venue); ?></p>
                    <?php if (!empty($em_venuee_phone) || !empty($em_venuee_email)): ?>
                        <p class="em-text-slate-500">
                            <?php if (!empty($em_venuee_phone)): ?>
                                <?php echo esc_html($em_venuee_phone); ?>
                            <?php endif; ?>
                            <?php if (!empty($em_venuee_phone) && !empty($em_venuee_email)): ?> | <?php endif; ?>
                            <?php if (!empty($em_venuee_email)): ?>
                                <?php echo esc_html($em_venuee_email); ?>
                            <?php endif; ?>
                        </p>
                    <?php else: ?>
                        <p class="em-text-slate-500">Contact details available upon registration</p>
                    <?php endif; ?>
                </div>
            </div>
        <?php endif; ?>
    </div>
</section>


