<?php
if (!defined('ABSPATH')) {
    exit;
}
?>

<script>
    document.addEventListener('DOMContentLoaded', function () {
        const floatingButton = new window.WFloatingButton({
            token: "<?php echo esc_attr(get_option('token')); ?>",
            element: document.querySelector("<?php echo esc_attr(get_option('wizartFloatingElementSelector')); ?>"),
        });

        <?php
        $wizart_parameters = array(
            'context' => get_option('context'),
            'locale' => get_option('locale'),
            'room_uuid' => get_option('roomUuid'),
            'open_first_room' => get_option('openFirstRoom'),
            'deactivate_custom_photo' => get_option('deactivateCustomPhoto'),
        );
        $wizart_parameters = array_filter($wizart_parameters, fn($value) => !empty($value));
        ?>

        const wizart_parameters = <?php echo wp_json_encode($wizart_parameters); ?>;

        floatingButton.render({
            fontSize: "<?php echo esc_attr(get_option('wizartFloatingFontSize')); ?>",
            title: "<?php echo esc_attr(get_option('wizartFloatingTitle')); ?>",
            tooltipTitle: "<?php echo esc_attr(get_option('wizartFloatingTooltipTitle')); ?>",
            tooltipPosition: "<?php echo esc_attr(get_option('wizartFloatingTooltipPosition')); ?>",
            tooltipDisable: <?php echo get_option('wizartFloatingTooltipDisable') ? 'true' : 'false'; ?>,
            glitterDisable: <?php echo get_option('wizartFloatingGlitterDisable') ? 'true' : 'false'; ?>,
            className: "<?php echo esc_attr(get_option('wizartFloatingClassName')); ?>",
            borderRadius: "<?php echo esc_attr(get_option('wizartFloatingBorderRadius')); ?>",
            parameters: wizart_parameters,
            background: "<?php echo esc_attr(get_option('wizartFloatingBackground')); ?>",
            color: "<?php echo esc_attr(get_option('wizartFloatingColor')); ?>",
            width: "<?php echo esc_attr(get_option('wizartFloatingWidth')); ?>",
            height: "<?php echo esc_attr(get_option('wizartFloatingHeight')); ?>",
            border: "<?php echo esc_attr(get_option('wizartFloatingBorder')); ?>",
            image: "<?php echo esc_attr(get_option('wizartFloatingImage')); ?>",
            onloadCallback: <?php echo get_option('wizartFloatingOnloadCallback')
                ? '"' . esc_attr(get_option('wizartFloatingOnloadCallback')) . '"'
                : 'null'; ?>,
            onCloseCallback: <?php echo get_option('wizartFloatingOnCloseCallback')
                ? '"' . esc_attr(get_option('wizartFloatingOnCloseCallback')) . '"'
                : 'null'; ?>,
            onButtonClick: <?php echo get_option('wizartFloatingOnButtonClick')
                ? '"' . esc_attr(get_option('wizartFloatingOnButtonClick')) . '"'
                : 'null'; ?>,
            iframeElementSelector: "<?php echo esc_attr(get_option('wizartFloatingIframeElementSelector')); ?>",
            insertIframeElementPosition: "<?php echo esc_attr(get_option('wizartFloatingInsertIframeElementPosition')); ?>",
            onAddShoppigCartItem: <?php echo get_option('wizartFloatingOnAddShoppigCartItem')
                ? '"' . esc_attr(get_option('wizartFloatingOnAddShoppigCartItem')) . '"'
                : 'null'; ?>,
            onRemoveShoppingCartItem: <?php echo get_option('wizartFloatingOnRemoveShoppingCartItem')
                ? '"' . esc_attr(get_option('wizartFloatingOnRemoveShoppingCartItem')) . '"'
                : 'null'; ?>,
        });
    });
</script>