<?php
/**
 * Accommodation single page
 *
 */

inoby_enqueue_parted_style("accommodation", "post_types");
inoby_enqueue_parted_script("accommodation", "post_types");

get_header();

$accommodation_banner_place = rwmb_meta("accommodation_banner_place");
$accommodation_google_maps = rwmb_meta("accommodation_google_maps");
$banner_img = rwmb_meta("accommodation_banner_img", ["limit" => 1, "size" => "banner-img"]);
$image = reset($banner_img);
$gallery_images = rwmb_meta("accommodation_gallery", ["size" => "large"]);
$accommodation_status_heading = rwmb_meta("accommodation_status_heading");
$accommodation_status_text = rwmb_meta("accommodation_status_text");
$accommodation_facilities_heading = rwmb_meta("accommodation_facilities_heading");
$accommodation_facilities_text = rwmb_meta("accommodation_facilities_text");
$facilities = rwmb_meta("accommodation_facilities", ["size" => "facilities-icon"]);
$label = rwmb_meta("accommodation_label");
$reservation_id = wpbs_get_current_post_calendar_id();
$main_color = rwmb_meta("accommodation_main_color");
?>

<main id="primary" class="site-main">

  <?php while (have_posts()): ?>
  <?php the_post(); ?>

  <div class="single-header">
    <div class="container">
      <div class="row single-header-info">
        <div class="col-8 col-sm-12">
          <h2 class="page-title"><?php the_title(); ?></h2>
        </div>
        <div class="col-4 col-sm-12">
          <div class="location">
            <?php
            if (!empty($accommodation_banner_place)) {
              echo '<span class="place">' . $accommodation_banner_place . "</span>";
            }
            if (!empty($accommodation_google_maps)) { ?>
            <a target="_blank" href="<?= $accommodation_google_maps ?>"><?= __("Zobraziť na mape", "inoby") ?></a>
            <?php }
            ?>
          </div>
        </div>
      </div>
      <?php if (!empty($image)) { ?>
      <div class="row single-header-gal">
        <div class="col-12 single-header-gal-col">
          <a class="gallery-img main-image" href="<?= $image["full_url"] ?>"
            style="background: center / cover no-repeat url(<?= $image["url"] ?>);">
          </a>
          <?php if (!empty($gallery_images)) { ?>
          <?php foreach ($gallery_images as $image) {
            echo '<a class="gallery-img" href="' . $image["full_url"] . '" style="background: center / cover no-repeat url(' . $image["url"] . ');"></a>';
          } ?>
          <?php } ?>
        </div>
      </div>
      <?php } ?>
    </div>
  </div>

  <section class="facilities">
    <div class="status">
      <?php
      if (!empty($accommodation_status_heading)) {
        echo "<h3>" . $accommodation_status_heading . "</h3>";
      }
      if (!empty($accommodation_status_text)) {
        echo "<p>" . $accommodation_status_text . "</p>";
      }
      ?>
    </div>
    <div class="facilities-info-wrap">
      <?php
      if (!empty($accommodation_facilities_heading)) {
        echo "<h3>" . $accommodation_facilities_heading . "</h3>";
      }
      if (!empty($facilities)) { ?>
      <div class="facilities-wrap">
        <?php foreach ($facilities as $facility) {
          echo '<div class="facility-item">';
          echo wp_get_attachment_image($facility["accommodation_facilities_icon"][0], "icon");
          echo $facility["accommodation_facilities_text"];
          echo "</div>";
        } ?>
      </div>
      <?php }
      if (!empty($accommodation_facilities_text)) {
        echo "<p>" . $accommodation_facilities_text . "</p>";
      }
      ?>
    </div>
  </section>

  <section class="booking">
    <div class="container">
      <div class="row">
        <div class="col-12">
          <div id="reservation-form">
            <?= do_shortcode(
              '[wpbs id="' .
                $reservation_id .
                '" title="no" legend="yes" legend_position="top" display="2" year="0" month="0" language="sk" start="1" dropdown="yes" jump="no" history="3" tooltip="2" highlighttoday="no" weeknumbers="no" show_prices="no" form_id="1" auto_pending="yes" selection_type="multiple" selection_style="split" minimum_days="0" maximum_days="0" booking_start_day="0" booking_end_day="0" show_date_selection="no"]'
            ) ?>
          </div>
        </div>
      </div>
    </div>
  </section>

  <button id="reservation-trigger" class="button"><?= __(apply_filters("accomodation_cta_text", "Rezervácia"), "inoby") ?></button>
  <section class="booking-mobile">
    <div class="close-btn">✕</div>
    <?= do_shortcode(
      '[wpbs id="' .
        $reservation_id .
        '" title="no" legend="yes" legend_position="top" display="1" year="0" month="0" language="sk" start="1" dropdown="yes" jump="no" history="3" tooltip="2" highlighttoday="no" weeknumbers="no" show_prices="no" form_id="1" auto_pending="yes" selection_type="multiple" selection_style="split" minimum_days="0" maximum_days="0" booking_start_day="0" booking_end_day="0" show_date_selection="no"]'
    ) ?>
  </section>

  <?php do_action("inoby_after_single_accomodation");endwhile; ?>

</main>

<?php get_footer();
