{* если сгруппировано *}
{if $is_grouped}
  <table class="calendar_week_type calendar_table">
    <tr>
      <th width="50">&nbsp;</th>
      {foreach from=$week_head key=shortname item=one_day name=header}
        <th style="width: 100px; min-width: 100px; padding: 5px;" group_key="{$shortname}" id="week_header{$shortname}">{$one_day|default:'&nbsp;'}</th>
      {/foreach}
    </tr>
    <tr>
      <th style="border-top: 1px solid transparent; border-left: 1px solid transparent; border-right: 1px solid transparent;">&nbsp;</th>
      <th colspan="7">&nbsp;</th>
    </tr>
    {foreach from=$week_days key=key item=day_info name=strings}
      <tr class="month_str{$smarty.foreach.strings.iteration}">
        <td class="week_time{if $smarty.foreach.strings.iteration eq $calendar.cur_week_day} today_day_week{/if}" id="week_time{$smarty.foreach.strings.iteration}">{$key}</td>
        {foreach from=$week_head key=shortname item=week_head_one_day name=header}
          {if !isset($day_info.data[$shortname])}
            <td class="week_top month_cell{$shortname}{if $smarty.foreach.strings.iteration eq $calendar.cur_week_day} today_day_week{/if}"
              id="cell_{$day_info.formatted_date}"
              onclick="addEvent('{$day_info.formatted_date|replace:'_':'.'}', event)" width="5000" style="position: relative; height: 150px;" ></td>
          {else}
            <td class="month_cell{$shortname}{if $smarty.foreach.strings.iteration eq $calendar.cur_week_day} today_day_week{/if}"
              id="cell_{$day_info.formatted_date}_{$shortname}"
              data-group-key="{$shortname}"
              data-group-name="{$week_head_one_day}"
              onclick="addEvent('{$day_info.formatted_date}_{$shortname}', event)"
              width="5000"
              style="position: relative; height: 150px;">
              {foreach from=$day_info.data[$shortname] item=one_event name=days_top key=week_day_num}
                {if $smarty.foreach.days_top.iteration lte 6}
                <div draggable="true"
                  event_length="{$one_event.length}"
                  is_background="{$one_event.background}"
                  class="calendar_event_line calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id} calendar_offset_{$one_event.line_id}_{$one_event.event_id} calendar_event_id{$one_event.event_id}"
                  id="calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id}_{$smarty.foreach.days_top.iteration}_{$shortname}"
                  style="top: 0; box-sizing: border-box; width: 100%;{if !$one_event.background} border: 1px solid {$one_event.color};{/if}"
                  data-date_field_id="{$one_event.date_field}"
                  data-period_field_id="{$one_event.period_field}"
                  data-event_id="{$one_event.event_id}"
                  data-line_id="{$one_event.line_id}"
                >
                  <div {if $config['display_calendar_events'] == '0'}onclick="viewOneEvent({$one_event.event_id}, {$one_event.line_id}, event); event.cancelBubble = true;"{/if}
                    onmouseover="highlightEvent(true, {$one_event.event_id}, {$one_event.line_id})"
                    onmouseout="highlightEvent(false, {$one_event.event_id}, {$one_event.line_id})"
                    id="c_event_layout{$one_event.event_id}_{$one_event.line_id}"
                    class="c_event_layout c_event_layout{$one_event.event_id}_{$one_event.line_id} c_event_layout{$one_event.event_id}"{if $one_event.background} style="padding: 1px 4px;"{/if}>
                    {if $one_event.data.mount_date && !$one_event.prev}{$one_event.data.mount_date}{/if}{$one_event.data.mount}
                    </div>
                    {if $config['display_calendar_events'] == '1'}
                      <div class="hoverEventBlock">
                          <div class="cal_event_header">
                              <b class="one_event_date_block"></b>
                          </div>
                          <div class="event_hover--block">
                              <div class="event_datefields"></div>
                              <div class="event_fields"></div>
                          </div>
                          <div class="cal_event_footer">
                              <a href="">Перейти к записи »</a>
                          </div>
                      </div>
                      <script>hoverEvent({$one_event.event_id}, {$one_event.line_id}, event, {$one_event.date_field});</script>
                  {/if}
                </div>
                {elseif $smarty.foreach.days_top.iteration eq 7}
                  <div class="hidden_items_events">
                      <a href="calendar.php?id={$calendar.id}&day={$day_info.day}&month={$day_info.month}&year={$day_info.year}"
                        onclick="event.cancelBubble = true;">{$lang.More} {{$day_info.data[$shortname]|@count} - 6}&raquo;
                      </a>
                  </div>
                {/if}
              {/foreach}

            </td>
          {/if}
        {/foreach}
      </tr>
    {/foreach}
  </table>
  <style>
.hidden_items_events {
  background-color: #fff;
  border-radius: 7px;
  bottom: 0;
  margin: 3px 3px 2px;
  z-index: 400;
}

.hidden_items_events:hover{
  background-color: #e9e9e9;
}

.hidden_items_events a {
  padding: 3px 7px;
}

.hidden_items_events a:hover{
  color: #484848;
}
</style>
{else}
  <table class="calendar_week_type calendar_table">
    <tr>
        <th>&nbsp;</th>
        {foreach from=$week_head key=shortname item=one_day name=header}
            <th id="week_header{$shortname}"{if $one_day.today} class="today_day_week"{/if}>{$shortname}, {$one_day.date}</th>
        {/foreach}
    </tr>

    <tr class="view_overperiod_events">
        <th style="border-top: 1px solid transparent; border-left: 1px solid transparent; border-bottom: 1px solid transparent;">
            &nbsp;</th>
        {foreach from=$overperiod_events key=weekday item=one_day}
            <td 
              id="week_overperiod{$weekday}" 
              style="vertical-align: top; position: relative;"
              class="overperiod_cells{if $weekday eq $calendar.cur_week_day} today_day_week{/if}"
            >
                {foreach from=$one_day item=one_event key=offset}
                  <div draggable="false" event_length="{$one_event.length}" is_background="{$one_event.background}"
                    style="margin-top: {($offset) * 17}px; {if !$one_event.background}border: 1px solid {$one_event.color}{else}opacity: 0.5{/if}"
                    class="calendar_event_line calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id} calendar_offset_{$one_event.line_id}_{$one_event.event_id} calendar_event_id{$one_event.event_id} unselectable"
                    id="calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id}_0_0"
                    data-date_field_id="{$one_event.date_field}"
                    data-period_field_id="{$one_event.period_field}"
                    data-event_id="{$one_event.event_id}"
                    data-line_id="{$one_event.line_id}"
                  >
                        <div {if $config['display_calendar_events'] == '0'}onclick="viewOneEvent({$one_event.event_id}, {$one_event.line_id}, event); event.cancelBubble = true;"{/if}
                            onmouseover="highlightEvent(true, {$one_event.event_id}, {$one_event.line_id})"
                            onmouseout="highlightEvent(false, {$one_event.event_id}, {$one_event.line_id})"
                            id="c_event_layout{$one_event.event_id}_{$one_event.line_id}_0_0"
                            class="c_event_layout c_event_layout{$one_event.event_id}_{$one_event.line_id} c_event_layout{$one_event.event_id}" {if $one_event.background} style="padding: 1px 4px;"{/if}>
                            {if $one_event.data.mount_date && !$one_event.prev}{$one_event.data.mount_date}{/if}{$one_event.data.mount}
                        </div>
                        {if $config['display_calendar_events'] == '1'}
                            <div class="hoverEventBlock">
                                <div class="cal_event_header">
                                    <b class="one_event_date_block"></b>
                                </div>
                                <div class="event_hover--block">
                                    <div class="event_datefields"></div>
                                    <div class="event_fields"></div>
                                </div>
                                <div class="cal_event_footer">
                                    <a href="">Перейти к записи »</a>
                                </div>
                            </div>
                            <script>hoverEvent({$one_event.event_id}, {$one_event.line_id}, event, {$one_event.date_field}, '0', '0');</script>
                        {/if}
                        <div class="prev_event_arrow"
                            style="z-index: 15; position: absolute; margin: -16px 0px 0px -1{if $one_event.background}6{else}7{/if}px; {if $one_event.prev}border: 8px solid transparent; border-right: 8px solid {if $one_event.background}rgba({$one_event.color_r}, {$one_event.color_g}, {$one_event.color_b}, 0.1){else}{$one_event.color}{/if}{/if}"></div>
                        <div class="next_event_arrow"
                            style="z-index: 15; position: absolute; margin: -16px 0px 0px 0px; {if $one_event.next}border: 8px solid transparent; border-left: 8px solid {if $one_event.background}rgba({$one_event.color_r}, {$one_event.color_g}, {$one_event.color_b}, 0.1){else}{$one_event.color}{/if}{/if}"></div>
                    </div>
                {/foreach}
                <div style="height: {($offset+1) * 17}px" class="overperiods_heights"></div>
            </td>
        {/foreach}
    </tr>

    <tr>
        <th style="border-top: 1px solid transparent; border-left: 1px solid transparent; border-right: 1px solid transparent;">
            &nbsp;</th>
        <th colspan="7">&nbsp;</th>
    </tr>

    {foreach from=$week_days key=hour item=one_day name=strings}
        <tr>
            <td class="week_time" id="week_time{$smarty.foreach.strings.iteration}"
                rowspan="2">{$hour}:00
            </td>
            {foreach from=$one_day item=day_data name=days_top key=week_day_num}
                <td class="week_top{if $day_data.today} today_day_week{/if}"
                    id="cell_{$day_data.day}_{$day_data.month}_{$day_data.year}_{$hour}_0"
                    onclick="addEvent('{$day_data.day}.{$day_data.month}.{$day_data.year} {$hour}:0', event)" style="position: relative;">
                    {if $day_data.current}
                        <div id="cur_time_line" offset="{$day_data.offset_time}"></div>
                        <span id="cur_time_line_arrow">▶</span>
                    {/if}
                    {assign var=has_events value=0}
                    {foreach from=$day_data.events key=min item=one_group_str}
                        {if !$min}
                            {assign var=has_events value=1}
                            {foreach from=$one_group_str item=one_event key=offset}
                              <div draggable="true" event_length="{$one_event.length}"
                                is_background="{$one_event.background}"
                                event_width="{$one_event.width}" event_offset="{$offset}"
                                all_event="{count($one_group_str)}" style="height: {$one_event.length * 20}px;margin-top: 0px; z-index: {if $offset == 1}16{else}{$offset + 13}{/if}; {if !$one_event.background}border: 1px solid {$one_event.color}{else}opacity: 0.5{/if}"
                                class="calendar_event_line calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id} calendar_offset_{$one_event.line_id}_{$one_event.event_id} calendar_event_id{$one_event.event_id}"
                                id="calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id}"
                                data-date_field_id="{$one_event.date_field}"
                                data-period_field_id="{$one_event.period_field}"
                                data-event_id="{$one_event.event_id}"
                                data-line_id="{$one_event.line_id}"
                              >
                                    <div {if $config['display_calendar_events'] == '0'}onclick="viewOneEvent({$one_event.event_id}, {$one_event.line_id}, event); event.cancelBubble = true;"{/if}
                                        onmouseover="highlightEvent(true, {$one_event.event_id}, {$one_event.line_id})"
                                        onmouseout="highlightEvent(false, {$one_event.event_id}, {$one_event.line_id})"
                                        {if $one_event.background}onmousemove="highlightEvent(false, {$one_event.event_id}, {$one_event.line_id})"{/if}
                                        id="c_event_layout{$one_event.event_id}_{$one_event.line_id}"
                                        class="c_event_layout c_event_layout{$one_event.event_id}_{$one_event.line_id} c_event_layout{$one_event.event_id}" {if $one_event.background} style="padding: 1px 4px;"{/if}>
                                        {if $one_event.data.mount_date}{$one_event.data.mount_date}{/if}{$one_event.data.mount}
                                    </div>
                                    {if $config['display_calendar_events'] == '1'}
                                        <div class="hoverEventBlock">
                                            <div class="cal_event_header">
                                                <b class="one_event_date_block"></b>
                                            </div>
                                            <div class="event_hover--block">
                                                <div class="event_datefields"></div>
                                                <div class="event_fields"></div>
                                            </div>
                                            <div class="cal_event_footer">
                                                <a href="">Перейти к записи »</a>
                                            </div>
                                        </div>
                                        <script>hoverEvent({$one_event.event_id}, {$one_event.line_id}, event, {$one_event.date_field});</script>
                                    {/if}
                                </div>
                            {/foreach}
                        {/if}
                    {/foreach}
                    &nbsp;
                </td>
            {/foreach}
        </tr>
        <tr>
            {foreach from=$one_day item=day_data name=days_bottom}
                <td class="week_bottom{if $day_data.today} today_day_week{/if}"
                    id="cell_{$day_data.day}_{$day_data.month}_{$day_data.year}_{$hour}_1"
                    onclick="addEvent('{$day_data.day}.{$day_data.month}.{$day_data.year} {$hour}:0', event)" style="position: relative;">
                    {assign var=has_events value=0}
                    {foreach from=$day_data.events key=min item=one_group_str}
                        {if $min}
                            {assign var=has_events value=1}
                            {foreach from=$one_group_str item=one_event key=offset}
                                <div 
                                  draggable="true" 
                                  event_length="{$one_event.length}"
                                  is_background="{$one_event.background}"
                                  event_width="{$one_event.width}" event_offset="{$offset}"
                                  all_event="{count($one_group_str)}" style="height: {$one_event.length * 20}px; margin-top: 0px; z-index: {if $offset == 1}16{else}{$offset + 13}{/if}; {if !$one_event.background}border: 1px solid {$one_event.color}{/if}"
                                  class="calendar_event_line calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id} calendar_offset_{$one_event.line_id}_{$one_event.event_id} calendar_event_id{$one_event.event_id}"
                                  id="calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id}"
                                  data-date_field_id="{$one_event.date_field}"
                                  data-period_field_id="{$one_event.period_field}"
                                  data-event_id="{$one_event.event_id}"
                                  data-line_id="{$one_event.line_id}"
                                >
                                    <div {if $config['display_calendar_events'] == '0'}onclick="viewOneEvent({$one_event.event_id}, {$one_event.line_id}, event); event.cancelBubble = true;"{/if}
                                        onmouseover="highlightEvent(true, {$one_event.event_id}, {$one_event.line_id})"
                                        onmouseout="highlightEvent(false, {$one_event.event_id}, {$one_event.line_id})"
                                        {if $one_event.background}onmousemove="highlightEvent(false, {$one_event.event_id}, {$one_event.line_id})"{/if}
                                        id="c_event_layout{$one_event.event_id}_{$one_event.line_id}"
                                        class="c_event_layout c_event_layout{$one_event.event_id}_{$one_event.line_id} c_event_layout{$one_event.event_id}"{if $one_event.background} style="padding: 1px 4px;"{/if}>
                                        {if $one_event.data.mount_date}{$one_event.data.mount_date}{/if}{$one_event.data.mount}
                                    </div>
                                    {if $config['display_calendar_events'] == '1'}
                                        <div class="hoverEventBlock">
                                            <div class="cal_event_header">
                                                <b class="one_event_date_block"></b>
                                            </div>
                                            <div class="event_hover--block">
                                                <div class="event_datefields"></div>
                                                <div class="event_fields"></div>
                                            </div>
                                            <div class="cal_event_footer">
                                                <a href="">Перейти к записи »</a>
                                            </div>
                                        </div>
                                        <script>hoverEvent({$one_event.event_id}, {$one_event.line_id}, event, {$one_event.date_field});</script>
                                    {/if}
                                </div>
                            {/foreach}
                        {/if}
                    {/foreach}
                    &nbsp;
                </td>
            {/foreach}
        </tr>
    {/foreach}
  </table>
  <style>
    .mini_calendar_layout__show {
      width: calc(100vw - 238px);
    }
    .unselectable{
      user-select: none; 
    }
  </style>
{/if}
