<?php
/*===============================
Shortocde tz-skill-item
===============================*/

function tzinteriart_contact_info($atts)
{
    $tz_type_icon = $tz_image = $tz_icon = $tz_title = $tz_color_title = $tz_color_info = $tz_info = $tz_css_animation = '';
    $tz_type_contact = $tz_phone_number = $tz_email = $css = $tz_color_phone_number = $tz_color_email = '';
    $tz_left_box = $tz_padding_top_phone_number = $tz_padding_bottom_phone_number = $tz_padding_top_email = $tz_padding_bottom_email = $tz_padding_email = $tz_bgcolor = '';
    extract(shortcode_atts(array(
        'tz_type_contact' => '1',
        'tz_type_icon' => 'icon',
        'tz_image' => '',
        'tz_icon' => '',
        'tz_title' => '',
        'tz_color_title' => '',
        'tz_phone_number' => '',
        'tz_color_phone_number' => '',
        'tz_phone_padding' => '87',
        'tz_email' => '',
        'tz_color_email' => '',
        'tz_email_padding' => '',
        'tz_left_box' => '',
        'tz_padding_top_phone_number' => '87',
        'tz_padding_bottom_phone_number' => '210',
        'tz_padding_top_email' => '87',
        'tz_padding_bottom_email' => '210',
        'tz_info' => '',
        'tz_color_info' => '',
        'tz_bgcolor' => '',
        'tz_css_animation' => '',
        'css' => '',
    ), $atts));
    ob_start();

    $contact_classes = '';
    if (isset($css) && $css != ''):
        $contact_classes .= ' ' . vc_shortcode_custom_css_class($css);
    endif;

    $tz_contact_type = '';
    if ($tz_type_contact == '3') :
        $tz_contact_type = 'tz_contact_type3';
    endif;

    $tz_top = null;
    if(is_numeric($tz_padding_top_phone_number) && is_numeric($tz_padding_bottom_phone_number) && is_numeric($tz_padding_top_email) && is_numeric($tz_padding_bottom_phone_number)) :
        $tz_top = ($tz_padding_top_phone_number + $tz_padding_bottom_phone_number + $tz_padding_top_email + $tz_padding_bottom_phone_number)/2;
    endif;
    $tz_class_contact_info = '';
    if ($tz_css_animation != '') {
        wp_enqueue_script('waypoints');
        $tz_class_contact_info .= ' wpb_animate_when_almost_visible wpb_' . $tz_css_animation;
    }

    ?>
    <?php if ($tz_type_contact == '1') : ?>
    <div class="tzElement_Contact <?php echo esc_attr($tz_class_contact_info); ?> <?php echo esc_attr($contact_classes); ?>">
        <?php
        if ($tz_type_icon == 'icon'):
            ?>
            <div class="contact-icon">
                <i class="<?php echo esc_attr($tz_icon); ?>"></i>
            </div>
        <?php else: ?>
            <div class="contact-image">
                <?php
                $tz_image_url = wp_get_attachment_url($tz_image);
                $tz_width_img = '';
                $tz_height_img = '';
                $tz_images_info = wp_get_attachment_image_src($tz_image, $size = 'full');
                if (isset($tz_images_info) && !empty($tz_images_info)) {
                    $tz_width_img = $tz_images_info[1];
                    $tz_height_img = $tz_images_info[2];
                }

                echo '<img width ="' . esc_attr($tz_width_img) . '" height ="' . esc_attr($tz_height_img) . '" src="' . esc_url($tz_image_url) . '" alt="' . esc_attr($tz_info) . '" />';

                ?>
            </div>
        <?php endif; ?>
        <?php if ($tz_title != ''): ?>
            <div class="contact-title" <?php
            if ($tz_color_title != '') {
                echo 'style="color:' . esc_attr($tz_color_title) . '"';
            }
            ?>>
                <?php echo esc_html($tz_title); ?>
            </div>
        <?php endif; ?>
        <?php if ($tz_info != ''): ?>
            <div class="contact-info" <?php
            if ($tz_color_info != '') {
                echo 'style="color:' . esc_attr($tz_color_info) . '"';
            }
            ?>>
                <?php echo esc_html($tz_info); ?>
            </div>
        <?php endif; ?>
    </div>
<?php elseif ($tz_type_contact == '2'): ?>
    <div class="tz_contact_us <?php echo esc_attr($tz_contact_type); ?> <?php echo esc_attr($contact_classes); ?>">
        <div class="tz_contact_box" style="background: <?php echo esc_attr($tz_bgcolor); ?>;">
            <?php
            if ($tz_title != '') {
                ?>
                <h6 class="tz_contact_title">
                    <?php
                    echo balanceTags($tz_title);
                    ?>
                </h6>
                <?php
            }
            ?>
            <?php
            if ($tz_phone_number) {
                ?>

                <a href="tel:<?php echo balanceTags($tz_phone_number); ?>"
                   style="color: <?php echo esc_attr($tz_color_phone_number); ?> !important;"
                   class="tz_contact_phone"><?php if ($tz_type_contact == '3') : ?><i
                            class="fas fa-phone"></i><?php endif; ?>
                    <?php
                    echo balanceTags($tz_phone_number);
                    ?>
                </a>
                <?php
            }
            ?>
            <?php
            if ($tz_email) {
                ?>
                <a href="mailto:<?php echo balanceTags($tz_email); ?>"
                   style="color: <?php echo esc_attr($tz_color_email); ?> !important;"
                   class="tz_contact_mail"><?php if ($tz_type_contact == '3') : ?><i
                            class="fas fa-envelope-open"></i><?php endif; ?>
                    <?php
                    echo balanceTags($tz_email);
                    ?>
                </a>
                <?php
            }
            ?>
        </div>
    </div>
<?php elseif ($tz_type_contact == '3'): ?>
    <div class="tz_contact_us <?php echo esc_attr($tz_contact_type); ?> <?php echo esc_attr($contact_classes); ?>"
         style="left: <?php echo esc_attr($tz_left_box); ?>; top: <?php echo esc_attr($tz_top); ?>px;">
        <div class="tz_contact_box" style="background: <?php echo esc_attr($tz_bgcolor); ?>;">
            <?php
            if ($tz_title != '') {
                ?>
                <h6 class="tz_contact_title">
                    <?php
                    echo balanceTags($tz_title);
                    ?>
                </h6>
                <?php
            }
            ?>
            <?php
            if ($tz_phone_number) {
                ?>

                <a href="tel:<?php echo balanceTags($tz_phone_number); ?>"
                   style="color: <?php echo esc_attr($tz_color_phone_number); ?> !important; padding-left: <?php echo esc_attr($tz_padding_bottom_phone_number); ?>px; padding-right: <?php echo esc_attr($tz_padding_top_phone_number); ?>px;"
                   class="tz_contact_phone"><?php if ($tz_type_contact == '3') : ?><i
                            class="fas fa-phone"></i><?php endif; ?>
                    <?php
                    echo balanceTags($tz_phone_number);
                    ?>
                </a>
                <?php
            }
            ?>
            <?php
            if ($tz_email) {
                ?>
                <a href="mailto:<?php echo balanceTags($tz_email); ?>"
                   style="color: <?php echo esc_attr($tz_color_email); ?> !important;  padding-left: <?php echo esc_attr($tz_padding_bottom_email); ?>px; padding-right:  <?php echo esc_attr($tz_padding_top_email); ?>px;"
                   class="tz_contact_mail"><?php if ($tz_type_contact == '3') : ?><i
                            class="fas fa-envelope-open"></i><?php endif; ?>
                    <?php
                    echo balanceTags($tz_email);
                    ?>
                </a>
                <?php
            }
            ?>
        </div>
    </div>
<?php endif; ?>
    <?php

    return ob_get_clean();
}

add_shortcode('tz-contact-info', 'tzinteriart_contact_info');
?>
