<?php
  $wrapper_width = get_sub_field('wrapper_width');
?>

<div class="layout-right-left <?php if($wrapper_width === 'full') echo 'full-width';?>" id="flex-section-<?php echo get_row_index();?>">
  <?php if($wrapper_width != 'full') echo "<div class='container {$wrapper_width}'>"; ?>
    <?php if( have_rows('right_left_blocks') ): $c = 0;?>

    	<div class="block-list">

    	<?php while( have_rows('right_left_blocks') ): the_row();

    		// vars
    		$image = get_sub_field('image');
        $title = get_sub_field('title');
    		$content = get_sub_field('content');
    		$link = get_sub_field('link');
    		?>

    		<div class="block <?php if($c % 2 == 0){echo 'right-img';}else{echo 'left-img';}?>">
          <?php if($c % 2 != 0):?>
            <?php if($image) echo '<figure class="block-image desktop"><img src="'.$image['sizes']['full_hd'].'" alt="'.$title.'" title="'.$title.'" longdesc="'.$title.'" /></figure>';?>
            <div class="text-container">
              <?php if($title) echo "<h3 class='block-title'>{$title}</h3>"; ?>
      		    <?php echo '<div class="block-content">'.$content.'</div>'; ?>
              <?php if( $link ): ?>
                <a class="btn btn-primary boxed" target="<?php echo $link['target'];?>" href="<?php echo $link['url']; ?>"><span><?php echo $link['title'];?></span></a>
              <?php endif; ?>
            </div>
            <?php if($image) echo '<figure class="block-image phablet"><img src="'.$image['sizes']['full_hd'].'" alt="'.$title.'" title="'.$title.'" longdesc="'.$title.'" /></figure>';?>
          <?php else:?>
            <div class="text-container">
              <?php if($title) echo "<h3 class='block-title'>{$title}</h3>"; ?>
      		    <?php echo '<div class="block-content">'.$content.'</div>'; ?>
              <?php if( $link ): ?>
                <a class="btn btn-primary boxed" target="<?php echo $link['target'];?>" href="<?php echo $link['url']; ?>"><span><?php echo $link['title'];?></span></a>
              <?php endif; ?>
            </div>
            <?php if($image) echo '<figure class="block-image"><img src="'.$image['sizes']['full_hd'].'" alt="'.$title.'" title="'.$title.'" longdesc="'.$title.'" /></figure>';?>
          <?php endif;?>
    		</div>
    	<?php $c++; endwhile; ?>
    </div>

    <?php endif; ?>
  <?php if($wrapper_width != 'full') echo "</div>"; ?>
</div>
