<?php

defined( 'ABSPATH' ) or die( 'No script kiddies please!' );

$wpwab_settings = get_option('wpwab_settings');

// echo"<pre>";
// print_r($wpwab_settings);
// echo"</pre>";

$btn_text_position = isset($wpwab_settings['multi']['button_text_position']) && $wpwab_settings['multi']['button_text_position'] == 'left' ? 'left' : 'right';
$button_text = isset($wpwab_settings['multi']['button_text']) && $wpwab_settings['multi']['button_text'] != '' ? $wpwab_settings['multi']['button_text'] : 'Whats App Me!';
$button_description = isset($wpwab_settings['multi']['button_description']) && $wpwab_settings['multi']['button_description'] != '' ? $wpwab_settings['multi']['button_description'] : 'Connect To Us';
$button_position = (isset($wpwab_settings['multi']['button_location'])) ? $wpwab_settings['multi']['button_location'] : 'bottom_right';
$btn_class = explode('_', $button_position);

$first = ( !empty($btn_class[0]) ) ? "wpwab-" . $btn_class[0] : '' ;
$last = ( !empty($btn_class[1]) ) ? "wpwab-" . $btn_class[1] : '' ;

(!empty($last)? $last: $last = "");

$new_class = $first." ".$last;

$enable_tooltip = (isset($wpwab_settings['multi']['enable_tooltip']) && $wpwab_settings['multi']['enable_tooltip']=='show') ? 'wpwab-tooltip-enable' : '' ;
$tooltip_text = (isset($wpwab_settings['multi']['tooltip_text'])) ? $wpwab_settings['multi']['tooltip_text'] : 'Connect To Us';
$enable_sticky = (isset($wpwab_settings['multi']['enable_sticky']) && $wpwab_settings['multi']['enable_sticky']=='show') ? 'wpwab-enable-sticky' : 'wpwab-disable-sticky';

$whatsapp_format = (isset($wpwab_settings['multi']['whatsapp_format']) && $wpwab_settings['multi']['whatsapp_format'] === "app")? 'app':'web';

$greeting_text = (isset($wpwab_settings['multi']['greeting_text'])) ? $wpwab_settings['multi']['greeting_text'] : 'Start A Conversation';

$greeting_sub_text = (isset($wpwab_settings['multi']['greeting_sub_text'])) ? $wpwab_settings['multi']['greeting_sub_text'] : 'Connect with any one of our support members';

$wpwab_screen_detector = new wpwab_Mobile_Detect();

if(isset($wpwab_settings['multiple']) && !empty($wpwab_settings['multiple'])){
    ?>
   <div class="wpwab-multi-outer-wrapper <?php echo esc_attr($new_class) ?> <?php echo esc_attr($enable_sticky) ?>">
    <div class="wpwab-multi-contacts-wrap" >
        <div class="wpwab-chat-head">
            <i class = "socicon-whatsapp"></i>
            <div class="wpwab-chat-desc">
                <p><?php echo $greeting_text; ?> </p>
                <small><?php echo $greeting_sub_text; ?></small>
            </div>
        </div>
        <div class="wpwab-chat-below-wrapper">
            <?php

            foreach ($wpwab_settings['multiple'] as $key => $value) { 

                $contact_number= (isset($value['contact_number']) && $value['contact_number'] != '') ? $value['contact_number'] : '' ;
                $btn_text_position = isset($value['button_text_position']) && $value['button_text_position'] == 'left' ? 'left' : 'right';
                $button_text = isset($value['button_text']) && $value['button_text'] != '' ? $value['button_text'] : 'Whats App Me!';
                $button_description = isset($value['button_description']) && $value['button_description'] != '' ? $value['button_description'] : 'Connect To Us';

                $icon = isset($value['icon']) && $value['icon'] == 'custom'? 'custom' :'default';
                $custom_icon = isset($value['custom_icon']) && $value['custom_icon'] != ''? $value['custom_icon'] :'';

                if($wpwab_screen_detector->isMobile()) {
                    $href_link = "whatsapp://send?phone=$contact_number&text=";
                } else {
                    if ($whatsapp_format == "web") {
                        $href_link = "https://web.whatsapp.com/send?l=en&phone=$contact_number";
                    } else {
                        $href_link = "https://api.whatsapp.com/send?phone=$contact_number&text=";
                    }
                }
                ?>   
                <div class="wpwab-button-wrap wpwab-button-template-15"  > 
                    <div class="wpwab-text-inner-wrapper wpwab-text-icon-both <?php echo ($btn_text_position == 'right')? 'wpwab-button-postion-right' :''; ?> <?php echo ($btn_text_position == 'left') ? 'wpwab-button-postion-left': ''; ?>" > 

                        <a href="<?php echo $href_link; ?>">
                            <div class="wpwab-text-wrapper">
                                <p> <?php echo esc_attr($button_text);?> </p>
                                <p class="wpwab-mbd"> <?php echo esc_attr($button_description);?> </p>
                                </div><?php 
                                if($icon=='custom' && $custom_icon != ''){ ?>
                                    <div class="wpwab-custom-image">
                                        <img src="<?php echo $custom_icon ?>" >
                                    </div>
                                    <?php 
                                }else{ ?>
                                    <i class="socicon-whatsapp"></i><?php 
                                } ?>
                            </a>
                        </div>
                    </div>
                <?php 
            } ?>
        </div>
    </div>

    <a href="javascript:void(0);"  class = "wpwab-multi-contacts-open ">
        <div class = "wpwab-slide-wrap">
            <i class = "socicon-whatsapp wpwab-slide-item 1"></i>
            <i class = "fa fa-comment wpwab-slide-item 2"></i>
            <i class = "fa fa-comments wpwab-slide-item 3"></i>
            <i class = "fa fa-phone wpwab-slide-item 4"></i>
        </div>
    </a>
    <a href="javascript:void(0);" class = "wpwab-multi-contacts-close " style="display:none;">
        <i class = "fa fa-times"></i>
    </a>

</div> 
<?php
}
?>


<?php 

include(wpwab_PLUGIN_PATH. 'inc/frontend/customize_css.php');