<?php

if (!defined('ABSPATH')) {
    exit;
}


// Floating button design related code goes here
add_action('wp_footer', 'sapmfly_render_sitewide_floating_button');

function sapmfly_render_sitewide_floating_button()
{
    if (get_option('sapmfly_sitewide_floating_button') !== 'yes') {
        return;
    }

    $sapmfly_floating_button_text = get_option('sapmfly_floating_btn_text');
    if ($sapmfly_floating_button_text == '') {
        $sapmfly_floating_button_text = 'Get Special Offer';
    }

    $sapmfly_floating_button_url  = get_option('sapmfly_floating_btn_url', '#');
    $sapmfly_floating_btn_style  = get_option('sapmfly_floating_btn_style');
    if ($sapmfly_floating_btn_style == '') {
        $sapmfly_floating_btn_style = 'rectangular';
    }

    $sapmfly_floating_btn_icon  = get_option('sapmfly_floating_btn_icon', '#');
    $sapmfly_floating_btn_cross  = get_option('sapmfly_floating_btn_close_option', '');
    $sapmfly_floating_btn_open_link  = get_option('sapmfly_floating_btn_open_link');
    $sapmfly_floating_btn_open = '_self';

    if ($sapmfly_floating_btn_open_link == 'new-tab') {
        $sapmfly_floating_btn_open = '_blank';
    }

?>
    <div class="sapmfly-floating-button-wrapper" id="sapmfly-floating-wrapper">

        <!-- Close button -->
        <?php if ($sapmfly_floating_btn_cross !== 'no-need'): ?>
            <span class="sapmfly-floating-close" id="sapmfly-floating-close">&times;</span>
        <?php endif; ?>

        <a href="<?php echo esc_url($sapmfly_floating_button_url); ?>" class="sapmfly-floating-button sapmfly-floating-button-<?php echo esc_html($sapmfly_floating_btn_style); ?>" target="<?php echo esc_attr($sapmfly_floating_btn_open); ?>" rel="noopener noreferrer">
            <?php
            if (! empty($sapmfly_floating_btn_icon)) : ?>
                <img src="<?php echo esc_url($sapmfly_floating_btn_icon); ?>" alt="" class="sapmfly-floating-button-icon" />
            <?php endif; ?>

            <span class="sapmfly-floating-button-text">
                <?php echo esc_html($sapmfly_floating_button_text); ?>
            </span>
        </a>
    </div>
<?php
}
