<?php
if (isset($block['data']['preview_image_help'])) {    /* rendering in inserter preview  */
    echo '<img src="' . $block['data']['preview_image_help'] . '" style="width:100%; height:auto;">';
} else {
    $columns            = get_field('ftm_list_icon_columns');
    $iconColor          = (!empty(get_field('ftm_list_icon_icon_color'))) ? get_field('ftm_list_icon_icon_color') : '';
    $iconType           = get_field('ftm_list_icon_type');
    $textColor          = (!empty(get_field('ftm_list_icon_text_color'))) ? get_field('ftm_list_icon_text_color') : '';
    $textSize           = (!empty(get_field('ftm_list_icon_text_size'))) ? get_field('ftm_list_icon_text_size') : '';

    $style              = 'style="';
    if (!empty($textColor)) {

        $style     .= 'color:' . $textColor . ';';
    }

    if (!empty($textSize)) {

        $style     .= 'font-size:' . $textSize . 'px;';
    }

    $style .= '"';


?>
    <ul id="ftm-list-icon" <?php echo $style; ?> class="columns-<?php echo $columns; ?>">
        <?php
        if (have_rows('ftm_list_icon_items')) :
            while (have_rows('ftm_list_icon_items')) : the_row();
                $listItem = get_sub_field('ftm_list_icon_item');
                $listLink = get_sub_field('ftm_list_icon_link_target');
                $content  = trim($listItem);
                if (!empty($listLink)) {
                    $content = '<a href="' . $listLink . '">' . $listItem . '</a>';
                }
        ?>
                <li><i class="icon-<?php echo $iconType; ?>" style="color:<?php echo $iconColor; ?>"></i><?php echo $content; ?></li>
        <?php
            endwhile;
        else :
        // no rows found
        endif;
        ?>
    </ul>
    <?php
    if (!empty($iconColor)) {
    ?>
        <style>
            .icon-<?php echo $iconType; ?>:before {
                content: attr(style);
            }
        </style>
<?php
    }
}
?>