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

$ciws_main_settings = get_option('ciws_main_settings');

$selected_floating_templates = (!empty($ciws_floating_settings['layout']['floating_template'])) ? esc_attr($ciws_floating_settings['layout']['floating_template']) : 'ciws-floating-template-1';
$button_head = (!empty($ciws_floating_settings['layout']['button_heading'])) ? esc_attr($ciws_floating_settings['layout']['button_heading']) : 'Need Help? Chat with us';
$floaing_position = (!empty($ciws_floating_settings['layout']['floating_position'])) ? esc_attr($ciws_floating_settings['layout']['floating_position']) : 'ciws-floating-right';

$floating_button_fill_color = (!empty($ciws_floating_settings['layout']['button_fill_color'])) ? esc_attr($ciws_floating_settings['layout']['button_fill_color']) : '';
$floating_button_title_color = (!empty($ciws_floating_settings['layout']['button_title_color'])) ? esc_attr($ciws_floating_settings['layout']['button_title_color']) : 'ciws-floating-right';

$hide_desktop = (!empty($ciws_main_settings['display']['desktop'])) ? esc_attr('ciws-desktop-hide') : '';
$hide_mobile = (!empty($ciws_main_settings['display']['mobile'])) ? esc_attr('ciws-mob-hide') : '';
$url_open_tab = (!empty($ciws_main_settings['url']['open_in_new_tab'])) ? 1 : 0;
$url_for_desktop = (!empty($ciws_main_settings['url']['url_for_desktop'])) ? $ciws_main_settings['url']['url_for_desktop'] : 'web';
$url_for_mobile = (!empty($ciws_main_settings['url']['url_for_mobile'])) ? $ciws_main_settings['url']['url_for_mobile'] : 'api';
$default_text = (!empty($account_details['account']['default_msg'])) ? $account_details['account']['default_msg'] : '';
$account_number = !empty($account_details['account']['account_number']) ? $account_details['account']['account_number'] : '';
$icon_slug = !empty($ciws_floating_settings['layout']['icon_img']) 
    ? esc_attr($ciws_floating_settings['layout']['icon_img']) 
    : 'ciws-whatsapp';

// Construct the image URL
$icon_url = esc_url(CIWS_IMG_DIR . '/' . $icon_slug . '.svg');
    

include('ciws-url-link.php');

?>
<div
    class="ciws-floating-button-wrapper <?php echo esc_attr($floaing_position); ?> <?php echo esc_attr($selected_floating_templates); ?> <?php echo esc_attr($hide_desktop); ?> <?php echo esc_attr($hide_mobile); ?>">
    <div class="ciws-floating-button">
        <a href="<?php echo esc_attr($wh_url); ?>" target="<?php echo esc_attr(($url_open_tab == 1) ? '_blank' : ''); ?>"
            class="ciws-floating-btn-content-wrap ciws-floating-computer-url">
            <div class="ciws-floating-icon-wrap">
                <img src="<?php echo $icon_url; ?>" alt="chat-in-website">
            </div>
            <div class="ciws-floating-btn-info-wrap">
                <div class="ciws-floating-btn-title"><?php echo esc_html($button_head); ?> </div>
            </div>
        </a>
        <a href="<?php echo esc_attr($mob_wh_url); ?>" target="<?php echo esc_attr(($url_open_tab == 1) ? '_blank' : ''); ?>"
            class="ciws-floating-btn-content-wrap ciws-floating-mobile-url">
            <div class="ciws-floating-icon-wrap">
                <img src="<?php echo $icon_url; ?>" alt="chat-in-website">
            </div>
            <div class="ciws-floating-btn-info-wrap">
                <div class="ciws-floating-btn-title"><?php echo esc_html($button_head); ?> </div>
            </div>
        </a>
    </div>
</div>
<?php
if (!empty($floating_button_fill_color)) {
    wp_register_style('ciws-frontend-custom', false);
    wp_enqueue_style('ciws-frontend-custom');
}
include(CIWS_PATH . '/includes/cores/ciws-customize.php');
