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

$wpwab_settings = get_option('wpwab_settings');

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

$button_color_menu = isset($wpwab_settings['button_color_menu'])?sanitize_text_field($wpwab_settings['button_color_menu']): '';
$text_color_menu = isset($wpwab_settings['text_color_menu'])?sanitize_text_field($wpwab_settings['text_color_menu']): '';
$icon_background_color_menu = isset($wpwab_settings['icon_background_color_menu'])?sanitize_text_field($wpwab_settings['icon_background_color_menu']): '';
$icon_color_menu = isset($wpwab_settings['icon_color_menu'])?sanitize_text_field($wpwab_settings['icon_color_menu']): '';
$wpwab_screen_detector = new wpwab_Mobile_Detect();
$enable_desktop = (isset($atts['enable_desktop']) && $atts['enable_desktop'] =='show') ? 'show' : 'hide';
$enable_mobile = (isset($atts['enable_mobile']) && $atts['enable_mobile'] == 'show') ? 'show' : 'hide';
$enable_button_text_only = (isset($atts['button_text_only'])) ? $atts['button_text_only'] : '';
$button_template = (isset($atts['button_template'])) ? $atts['button_template'] : 'template-1';
$button_text_enable = (isset($atts['button_enable_text'])) ? $atts['button_enable_text'] : 'hide';
$button_text = (isset($atts['button_text'])) ? $atts['button_text'] : '';
$button_description = (isset($atts['button_description'])) ? $atts['button_description'] : '';
$user_name = (isset($atts['user_name'])) ? $atts['user_name'] : 'devteam2070';
$button_color = (isset($atts['button_color'])) ? $atts['button_color'] : '';
$icon_color = (isset($atts['icon_color'])) ? $atts['icon_color'] : '';
$button_position = (isset($atts['button_location'])) ? $atts['button_location'] : '';
$btn_class = explode('_', $button_position);
$btn_text_position = (isset($atts['button_text_position'])) ? $atts['button_text_position'] : '';
$tooltip_text = (isset($atts['tooltip_text'])) ? $atts['tooltip_text'] : '';
$button_animation = (isset($atts['button_animation'])) ? $atts['button_animation'] : '';
$button_animation_type = (isset($atts['animation_type'])) ? $atts['animation_type'] : 'on_hover';
$sliding_animation = (isset($atts['sliding_animation'])) ? $atts['sliding_animation'] : '';
$enable_tooltip = (isset($atts['enable_tooltip'])) ? $atts['enable_tooltip'] : 'enable_tooltip';
$enable_sticky = (isset($atts['enable_sticky'])) ? $atts['enable_sticky'] : 'enable_sticky';
$icon_backgroud_color = (isset($atts['icon_background_color'])) ? $atts['icon_background_color'] : '';
$text_color = (isset($atts['text_color'])) ? $atts['text_color'] : 'text_color';
$contact_number = (isset($atts['contact_number'])) ? $atts['contact_number'] : $wpwab_settings['contact_number'];
$whatsapp_format = isset($wpwab_settings['whatsapp_format']) && $wpwab_settings['whatsapp_format'] == 'app' ? 'app': 'web';
$random=rand(11111,99999);

if(!empty($btn_class[0])){
    $first = "wpwab-".$btn_class[0];
}
if(!empty($btn_class[1])){
    $last = "wpwab-".$btn_class[1];
}

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

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

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="<?php echo ($sliding_animation=='1')?"wpwab-slide":'' ?> wpwab-<?php echo $random;?> wpwab-button-wrap <?php echo (isset($button_animation_type) && $button_animation_type=='always')?"wpwab-animate":'' ?> wpwab-<?php echo esc_attr($button_animation);?> wpwab-button-<?php echo esc_attr($button_template);?> <?php echo esc_attr($new_class) ?> <?php if($enable_sticky =='show'){ echo 'wpwab-enable-sticky'; } ?> <?php if($enable_tooltip =='show'){ echo 'wpwab-tooltip-enable'; } ?>  <?php if($enable_tooltip =='hide'){ echo 'wpwab-tooltip-disable'; } ?>" > 
    
    <div class="<?php echo ($button_text_enable =='show' && $enable_button_text_only !='show')?'wpwab-text-icon-both':'';?>     <?php echo ($enable_button_text_only == 'show' && $button_text_enable == 'show') ? 'wpwab-text-only ' : ''; ?> <?php echo ($button_text_enable != 'show') ? 'wpwab-icon-only' :'';?> <?php echo ($btn_text_position == 'right')? 'wpwab-button-postion-right' :''; ?> <?php echo ($btn_text_position == 'left') ? 'wpwab-button-postion-left': ''; ?>      wpwab-text-inner-wrapper " >
        
        <div class = "wpwab-tooltip-enable-text">
            <?php echo esc_attr($tooltip_text); ?>
        </div>

        <?php
        if ( $wpwab_screen_detector->isMobile() && $enable_mobile =='show' ) { 
            include(wpwab_PLUGIN_PATH. 'inc/frontend/inner_html.php');
        } elseif( $enable_desktop =='show') {
            include(wpwab_PLUGIN_PATH. 'inc/frontend/inner_html.php');
        }

        ?>
    </div>
</div>

<?php 

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