<?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 {
    $linkAttributes = (!empty(get_field('table_cta_link_attributes'))) ? 'rel="' . get_field('table_cta_link_attributes') . '"' : '';
    $header_1       = (!empty(get_field('table_cta_header1')))? get_field('table_cta_header1') : acf_get_field('table_cta_header1')['default_value'];
    $header_2       = (!empty(get_field('table_cta_header2')))? get_field('table_cta_header2') : acf_get_field('table_cta_header2')['default_value'];
    $header_3       = (!empty(get_field('table_cta_header3')))? get_field('table_cta_header3') : acf_get_field('table_cta_header3')['default_value'];
?>
    <table id="ftm_table_cta">
        <tbody>
            <tr>
                <th><?php echo $header_1 ;?></th>
                <th><?php echo $header_2 ;?></th>
                <th><?php echo $header_3 ;?></th>
            </tr>
            <?php
            if (have_rows('table_cta_sites')) :
                while (have_rows('table_cta_sites')) : the_row();
                    $siteName       = get_sub_field('table_cta_site_name');
                    $siteLogo       = get_sub_field('table_cta_site_logo');
                    $siteFacts      = get_sub_field('table_cta_facts');
                    $linkText       = get_sub_field('table_cta_link_text');
                    $linkTarget     = get_sub_field('table_cta_link_target');                    
            ?>
                    <tr>
                        <td>
                            <img src="<?php echo $siteLogo["url"]; ?>" class="aligncenter" alt="<?php echo $siteLogo["alt"]; ?>" width="200" height="80">
                            <strong><?php echo $siteName; ?></strong>
                        </td>
                        <td>
                            <?php
                            echo $siteFacts;
                            ?>
                        </td>
                        <td>
                            <a href="<?php echo $linkTarget; ?>" <?php echo $linkAttributes; ?> target="_blank"><?php echo $linkText; ?></a>
                        </td>
                    </tr>
            <?php
                endwhile;
            else :
            // no rows found
            endif;
            ?>
        </tbody>
    </table>
<?php
}
?>