<?php
$duration = get_post_meta(get_the_ID(), '_trip_duration', true);
$desc = get_post_meta(get_the_ID(), '_trip_short_desc', true);
$terms_destination = get_the_terms(get_the_ID(), 'trip_destination');
$currency = (get_option('_webforia_trip_currency') == 'IDR') ? 'Rp' : '$';
$starter_price = get_post_meta(get_the_ID(), '_trip_price_min', true);
$price = wp_sprintf('<span class="rt-price__currency">%s</span>%s', $currency, number_format($starter_price, 0, ',', '.'));
$price_total = get_post_meta(get_the_ID(), '_trip_image_gallery_count', true);
?>
<div class="rt-trip-info border rounded-md is-layout-flow py-40 px-40">
    <h3 class="wp-block-heading"><?php echo __('Trip Info', 'jelajah-text') ?></h3>

    <?php if ($price): ?>
        <div class="rt-trip-price mt-30">
            <?php if ($price_total > 1): ?>
                <span class="rt-trip-price__label"><?php echo __('From:', 'jelajah-text') ?></span>
            <?php endif ?>
            <span class="rt-trip-price__amount has-large-font-size"><strong><?php echo $price ?></strong></span>
        </div>
    <?php endif ?>

    <?php if ($desc) : ?>
        <div class="rt-trip-desc mt-30"><?php echo $desc ?></div>
    <?php endif ?>

    <?php if ($terms_destination && !is_wp_error($terms_destination)) : ?>
        <div class="rt-trip-destination has-meta-color has-link-meta-color">
            <div class="is-layout-flex gap-20">
                <i class="rt-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-geo-alt" viewBox="0 0 16 16">
                        <path d="M12.166 8.94c-.524 1.062-1.234 2.12-1.96 3.07A32 32 0 0 1 8 14.58a32 32 0 0 1-2.206-2.57c-.726-.95-1.436-2.008-1.96-3.07C3.304 7.867 3 6.862 3 6a5 5 0 0 1 10 0c0 .862-.305 1.867-.834 2.94M8 16s6-5.686 6-10A6 6 0 0 0 2 6c0 4.314 6 10 6 10" />
                        <path d="M8 8a2 2 0 1 1 0-4 2 2 0 0 1 0 4m0 1a3 3 0 1 0 0-6 3 3 0 0 0 0 6" />
                    </svg>
                </i>
                <span><?php echo __('Destination:', 'jelajah-text') ?></span>
                <div class="wp-block-post-terms is-style-dot-separator flex-1">
                    <?php foreach ($terms_destination as $term) : ?>
                        <a class="<?php echo 'destination-' . esc_attr($term->slug) ?>" href="<?php echo esc_url(get_tag_link($term->term_id)) ?>">
                            <?php echo $term->name ?>
                        </a>
                        <span class="wp-block-post-terms__separator">•</span>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
    <?php endif ?>

    <?php if ($duration): ?>
        <div class="rt-trip-duration has-meta-color has-link-meta-color mt-20">
            <div class="is-layout-flex gap-20">
                <i class="rt-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-clock" viewBox="0 0 16 16">
                        <path d="M8 3.5a.5.5 0 0 0-1 0V9a.5.5 0 0 0 .252.434l3.5 2a.5.5 0 0 0 .496-.868L8 8.71z" />
                        <path d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m7-8A7 7 0 1 1 1 8a7 7 0 0 1 14 0" />
                    </svg>
                </i>
                <?php echo wp_sprintf(__('Duration: %s Days', 'jelajah-text'), $duration) ?>
            </div>
        </div>
    <?php endif ?>

    <?php rt_get_template_part('single-trip/action-button') ?>
</div>