<?php
    $query = new WP_Query([
        'post_type' => 'globalblocks',
        'posts_per_page' => 1,
    ]);
    $globalblocks = $query->posts;
    $post_id = $globalblocks[0]->ID;
?>

<?php  if ( $globalblocks ) : ?>
    <?php  if ( get_field( "show_block_2", $post_id ) ) : ?>
        <div class="wyn-for-short-component wyn-component">
            <div class="row">
                <div class="col-2">
                    <h3><?= get_field( "block_2", $post_id )['left_column']['headline'] ?></h3>
                    <p><?= get_field( "block_2", $post_id )['left_column']['short_description'] ?></p>
                    <?php  if ( get_field( "block_2", $post_id )['left_column']['use_button'] ) : ?>
                        <a href="<?= get_field( "block_2", $post_id )['left_column']['button_wrapper']['link'] ?>" class="button contact-button"> <?= get_field( "block_2", $post_id )['left_column']['button_wrapper']['label'] ?></a>
                    <?php endif; ?>
                </div>

                <div class="col-2 wyn-find-primary-contact">
                    <h3><?= get_field( "block_2", $post_id )['right_column']['headline'] ?> </h3>
                    <?php $locagtions =  get_field( "block_2", $post_id )['right_column']['location'] ?>
                    <?php //print_r( $locagtions)?>

                    <label class="wyn-select-component">
                        <select class="wyn-location-select">
                            <?php foreach ($locagtions as $key => $location):?>
                                <?php
                                    $thumb = $location['card_info']['avatar'];

                                    if ($thumb) {
                                        $thumb = $location['card_info']['avatar'];
                                    }else{
                                        $thumb = site_url('/wp-content/uploads/2022/05/Default-Avatar.jpg');
                                    }
                                ?>
                                <option
                                    value="<?= $location['title'] ?>"
                                    data-name="<?= $location['card_info']['name'] ?>"
                                    data-position="<?= $location['card_info']['position'] ?>"
                                    data-office-phone=""
                                    data-cell-phone="<?= $location['card_info']['cell_phone'] ?>"
                                    data-fax=""
                                    data-lat="32.3182314"
                                    data-long="-86.90229799999997"
                                    data-thumb="<?= $thumb ?>"
                                >
                                <?= $location['title'] ?>
                            </option>
                            <?php endforeach ?>
                        </select>
                    </label>

                    <div class="contacts">
                        <div class="contacts-left">
                            <div class="contact-img" title="" style=""></div>
                        </div>
                        <div class="contacts-right">
                            <span class="person"> <span class="name"></span> — <span class="position"></span> </span>
                            <ul>
                                <li data-copy="Office: " class="phone"></li>
                                <li data-copy="Cell: " class="cell"> </li>
                                <li data-copy="Fax: " class="fax"></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    <?php endif; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>