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

$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'])) ? $ciws_floating_settings['layout']['button_heading'] : 'Need Help? Chat with us';
$notification_status = (!empty($ciws_floating_settings['layout']['notification_status'])) ? $ciws_floating_settings['layout']['notification_status'] : '';
$notification_number = (!empty($ciws_floating_settings['layout']['notification_number'])) ? $ciws_floating_settings['layout']['notification_number'] : '';
$greeting_header_text = (!empty($ciws_floating_settings['layout']['greeting_header_text'])) ? $ciws_floating_settings['layout']['greeting_header_text'] : '';
$greeting_message_text = (!empty($ciws_floating_settings['layout']['greeting_message_text'])) ? $ciws_floating_settings['layout']['greeting_message_text'] : '';
$greeting_footer_text = (!empty($ciws_floating_settings['layout']['greeting_footer_text'])) ? $ciws_floating_settings['layout']['greeting_footer_text'] : '';

$greeting_button_text = (!empty($ciws_floating_settings['layout']['greeting_button_text'])) ? $ciws_floating_settings['layout']['greeting_button_text'] : '';
$floating_position = (!empty($ciws_floating_settings['layout']['floating_position'])) ? esc_attr($ciws_floating_settings['layout']['floating_position']) : 'ciws-floating-right';
$customize = (!empty($ciws_floating_settings['layout']['customize_status'])) ? esc_attr($ciws_floating_settings['layout']['customize_status']) : '';

$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'] : '';

$profile_photo = !empty($account_details['account']['profile_photo']) ? $account_details['account']['profile_photo'] : '';
$box_status = (!empty($ciws_floating_settings['layout']['box_status'])) ? $ciws_floating_settings['layout']['box_status'] : 0;

$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($floating_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">

        <?php if ($box_status == 'greeting') {

        ?>
            <div class="ciws-greeting-box-wrap">
                <div class="ciws-greeting-template-check ciws-customize-specific">

                    <div class="ciws-greeting-header-wrap" <?php echo ($customize == 1) ? 'style="background:' . esc_attr($floating_button_fill_color) . ';"' : ''; ?>>

                        <div class="ciws-greeting-header-img-wrap">
                            <div class="ciws-greeting-heading-img">
                                <?php
                                if (!empty($profile_photo)) { ?>
                                    <img class="ciws-box-header-logo-white" src="<?php echo esc_url($profile_photo); ?>" alt="">
                                <?php } else { ?>
                                    <img class="ciws-box-header-logo-white" src="<?php echo esc_url(CIWS_IMG_DIR . '/whats-app.png'); ?>" alt="">
                                <?php  } ?>

                            </div>
                        </div>

                        <div class="ciws-greeting-heading-desc">
                            <div class="ciws-greeting-heading" <?php echo ($customize == 1) ? 'style="color:' . esc_attr($floating_button_title_color) . ';"' : ''; ?>>
                                <?php

                                $allowed_html = wp_kses_allowed_html('post');
                                $allowed_html['span'] = array('style' => true);

                                $content = wp_kses($greeting_header_text, $allowed_html);


                                echo wp_kses_post(wpautop($content));

                                ?>

                            </div>
                        </div>
                        <div class="ciws-close-btn ciws-gretting-close"><img data-logo=""
                                src="<?php echo esc_url(CIWS_IMG_DIR . '/ciws-close.svg'); ?>" class="ciws-close-svg" />
                        </div>
                    </div> <!-- End of .ciws-greeting-header-wrap -->
                    <div class="ciws-body-form-wrap">
                        <div class="ciws-greeting-main-body-wrap">
                            <div class="ciws-greeting-main-content">
                                <div class="ciws-greeting-main-content-txt">
                                    <?php
                                    $allowed_html = wp_kses_allowed_html('post');
                                    $allowed_html['span'] = array('class' => true, 'style' => true, 'id' => true);

                                    $content1 = wp_kses($greeting_message_text, $allowed_html);
                                    ?>
                                    <?php

                                    $allowed_html = wp_kses_allowed_html('post');
                                    $allowed_html['span'] = array('style' => true);

                                    $msg_content = wp_kses($greeting_message_text, $allowed_html);
                                    ?>
                                    <span><?php echo wp_kses_post(wpautop($msg_content)); ?></span>
                                </div>
                            </div>
                        </div>


                    </div>


                    <div class="ciws-greeting-cta-wrap">
                        <div class="ciws-greeting-cta-btn">
                            <div class="ciws-button-wrapper">
                                <div class="ciws-button" <?php echo ($customize == 1) ? 'style="background:' . esc_attr($floating_button_fill_color) . ';"' : ''; ?>>
                                    <a href="<?php echo esc_url($wh_url); ?>" data-form="ciws-form" class="ciws-btn-content-wrap ciws-computer-url">
                                        <div class="ciws-icon-wrap">
                                           
                                            <img decoding="async" src="<?php echo $icon_url; ?>" alt="chat-in-website">
                                        </div>
                                        <div class="ciws-btn-info-wrap">
                                            <div class="ciws-btn-info">
                                                <div class="ciws-account-name"><?php echo esc_html($account_row->account_name); ?></div>
                                                <div class="ciws-status ciws-offline"><span></span></div>
                                            </div>
                                            <div class="ciws-btn-title" <?php echo ($customize == 1) ? 'style="color:' . esc_attr($floating_button_title_color) . ';"' : ''; ?>><?php echo esc_html($greeting_button_text); ?></div>
                                        </div>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>


                    <div class="ciws-greeting-footer-wrap">
                        <p><?php echo wp_kses_post(wpautop($greeting_footer_text)); ?></p>
                    </div>

                </div> <!-- End of .ciws-greeting-template-check -->
            </div> <!-- End of .ciws-greeting-box-wrap -->

            <a class="ciws-floating-btn-content-wrap ciws-floating-box">
                <div class="ciws-floating-icon-wrap ciws-floating-icon-attr ciws-btn-fill-color" <?php echo ($customize == 1) ? 'style="background-color:' . esc_attr($floating_button_fill_color) . ';"' : ''; ?>>
                    <img src="<?php echo $icon_url; ?>" alt="chat-in-website">
                </div>

                <div class="ciws-floating-btn-info-wrap ciws-floating-bg-attr ciws-btn-fill-color" <?php echo ($customize == 1) ? 'style="background-color:' . esc_attr($floating_button_fill_color) . ';"' : ''; ?>>
                    <div class="ciws-floating-btn-title ciws-floating-btn-info-attr" <?php echo ($customize == 1) ? 'style="color:' . esc_attr($floating_button_title_color) . ';"' : ''; ?>>
                        <?php echo esc_html($button_head); ?>
                    </div>
                </div>

            </a>

        <?php } else { ?>

            <a href="<?php echo esc_url($wh_url); ?>" target="<?php echo esc_attr(($url_open_tab == 1) ? '_blank' : ''); ?>" class="ciws-floating-btn-content-wrap ciws-floating-computer-url ciws-box-desktop">
                <div class="ciws-floating-icon-wrap ciws-floating-icon-attr ciws-btn-fill-color" style="background-color: <?php echo esc_attr($floating_button_fill_color); ?>">
                  <img src="<?php echo $icon_url; ?>" alt="chat-in-website">
                </div>
                <div class="ciws-floating-btn-info-wrap ciws-floating-bg-attr ciws-btn-fill-color" style="background-color: <?php echo esc_attr($floating_button_fill_color); ?>">
                    <div class="ciws-floating-btn-title ciws-floating-btn-info-attr" style="color:<?php echo esc_attr($button_text_color); ?>">
                        <?php echo esc_html($button_head); ?>
                    </div>
                </div>

            </a>

            <a href="<?php echo esc_url($mob_wh_url); ?>" target="<?php echo esc_attr(($url_open_tab == 1) ? '_blank' : ''); ?>" class="ciws-floating-btn-content-wrap ciws-floating-mobile-url ciws-box-mobile">
                <div class="ciws-floating-icon-wrap ciws-floating-icon-attr ciws-btn-fill-color" style="background-color: <?php echo esc_attr($floating_button_fill_color); ?>">
                  <img src="<?php echo $icon_url; ?>" alt="chat-in-website">
                </div>
                <div class="ciws-floating-btn-info-wrap ciws-floating-bg-attr ciws-btn-fill-color" style="background-color: <?php echo esc_attr($floating_button_fill_color); ?>">
                    <div class="ciws-floating-btn-title ciws-floating-btn-info-attr" style="color:<?php echo esc_attr($button_text_color); ?>">
                        <?php echo esc_html($button_head); ?>
                    </div>
                </div>

            </a>

        <?php } ?>

    </div> <!-- End of .ciws-floating-button -->

    <?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');
    ?>

</div> <!-- End of .ciws-floating-button-wrapper -->