<?php
$calendar = mb_get_block_field("calendar_ics") ?? "";
$view = mb_get_block_field("calendar_ics_view") ?? "month";
$count =
  mb_get_block_field("calendar_ics_posts") ?? false
    ? mb_get_block_field("calendar_ics_posts")
    : 4;
$desc = mb_get_block_field("calendar_ics_desc") ?? 1 ? true : false;
$organizer = mb_get_block_field("calendar_ics_organizer") ?? 1 ? true : false;

if (is_admin()) {
  echo '<span style="display:block;margin:0 auto;font-size:60px;width:60px;height:60px;" class="dashicon dashicons dashicons-calendar-alt"></span>';
}

if ($calendar) { ?>
<section <?= inoby_block_attrs($attributes, [
  "class" => "component-calendar",
]) ?>>
  <div class="container">
    <div class="row">
      <div class="col-12">
        <?php if ($view == "month"): ?>
        <div class="component-calendar-wrap month-view">
          <?php echo do_shortcode(
            '[ics_calendar url="' .
              $calendar .
              '" view="month" compact="false" monthnav="compact" hidealldayindicator="true"]',
          ); ?>
        </div>
        <div class="component-subscribe">
          <?php echo '<a class="button" href="webcal:' .
            $calendar .
            '">' .
            __("Odoberať", "inoby") .
            "</a>"; ?>
        </div>
        <?php endif; ?>
        <?php if ($view == "list"): ?>
        <div class="component-calendar-wrap list-view">
          <?php echo do_shortcode(
            '[ics_calendar url="' .
              $calendar .
              '" htmltagtitle="h3" view="list" count="' .
              $count .
              '" eventdesc="' .
              $desc .
              '" eventdl="false" compact="true" location="true" organizer="' .
              $organizer .
              '" resources="false" title="false" format="l d.m Y" timeformat="H:i"]',
          ); ?>
        </div>
        <?php endif; ?>
      </div>
    </div>
  </div>
</section>
<?php }
