<? /**
  * @var $block array
  * @var $this  SprintEditorBlocksComponent
  */ ?>
<?
$unicalBlockId = uniqid();
$blockTitle = '';
?>
<section class="tabs-block light-blue" id="types_<?= $this->includedBlocks; ?>">
    <div class="tabs-block__content container tabs-container">
        <div class="row">
            <div class="col-12">
                <? foreach ($block['blocks'] as $key => $blockElem): ?>
                    <? switch ($blockElem['name']) {
                        case 'htag': ?>
                            <h2 class="tabs-block__title block__title"><?= $blockElem['value']; ?></h2>
                            <? $blockTitle = $blockElem['value']; ?>
                            <? break;

                        default:
                            // code...
                            break;
                    } ?>
                <? endforeach; ?>
            </div>
            <div class="col-12">
                <div class="tabs-block__tabs tabs">
                    <? foreach ($block['items'] as $itemKey => $item): ?>
                        <button class="btn btn_hollow tabs-block__tab tab"
                            data-tab-val="<?= $block['name'] . '_' . $unicalBlockId . '_' . $itemKey ?>"><?= $item['title'] ?></button>
                    <? endforeach; ?>
                </div>
            </div>
        </div>
        <div class="tab-contents">

            <? foreach ($block['items'] as $itemKey => $itemblock): ?>
                <?

                $textBlocks = [];
                $imagesBlocks = [];
                $firstText = true;
                if ($itemblock['blocks'][0]['name'] == 'image')
                    $firstText = false;
                foreach ($itemblock['blocks'] as $blockInfo) {
                    switch ($blockInfo['name']) {
                        case 'text':
                            $textBlocks[] = $blockInfo['value'];
                            break;

                        case 'image':
                            if (!$blockInfo['file']['ID'])
                                continue;
                            $tempImage = CFile::GetFileArray($blockInfo['file']['ID']);
                            $tempImage['ALT'] = $tempImage['TITLE'] = ($blockInfo['desc'] ?: $blockTitle);
                            $imagesBlocks[] = $tempImage;
                            break;

                        default:
                            break;
                    }
                }
                ?>
                <div class="row tab-content" data-tab-name="<?= $block['name'] . '_' . $unicalBlockId . '_' . $itemKey ?>">
                    <? if ($firstText): ?>
                        <div class="<?= ($imagesBlocks ? 'col-lg-6' : 'col-lg-12'); ?> col-12">
                            <div class="tabs-block__text-container wrap-container">
                                <h3 class="tabs-block__text-title"><?= $itemblock['title']; ?></h3>
                                <div class="tabs-block__text wrap-block" data-wrap-height="150">
                                    <? foreach ($textBlocks as $text): ?>
                                        <?= $text; ?>
                                    <? endforeach; ?>
                                </div>
                                <button class="wrap-btn"></button>
                            </div>
                        </div>
                    <? endif; ?>
                    <div class="col-lg-6 col-12">
                        <div class="tabs-block__pic-container">
                            <? foreach ($imagesBlocks as $image): ?>
                                <div class="tabs-block__pic pic-wrapper">
                                    <picture>
                                        <img src="<?= makeWebp(CFile::GetPath($image['ID'])); ?>"
                                            alt="" loading="lazy">
                                    </picture>
                                </div>
                                <? if ($image['ALT']): ?>
                                    <div class="tabs-block__pic-sticker sticker-skew"><span><?= $image['ALT']; ?></span></div>
                                <? endif; ?>
                            <? endforeach; ?>
                        </div>
                    </div>
                    <? if (!$firstText): ?>
                        <div class="<?= ($imagesBlocks ? 'col-lg-6' : 'col-lg-12'); ?> col-12">
                            <div class="tabs-block__text-container wrap-container">
                                <h3 class="tabs-block__text-title"><?= $itemblock['title']; ?></h3>
                                <div class="tabs-block__text wrap-block" data-wrap-height="150">
                                    <? foreach ($textBlocks as $text): ?>
                                        <?= $text; ?>
                                    <? endforeach; ?>
                                </div>
                                <button class="wrap-btn"></button>
                            </div>
                        </div>
                    <? endif; ?>
                </div>
            <? endforeach; ?>
        </div>
    </div>
</section>