All files / src/components/features/support/ChatbotWidget index.tsx

39.53% Statements 17/43
100% Branches 0/0
0% Functions 0/1
39.53% Lines 17/43

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                                      
'use client';
 
/**
 * ChatbotWidget - Main chatbot component with floating button and expandable window
 */
 
import React, { useState, useCallback } from 'react';
import ChatbotButton from './ChatbotButton';
import ChatbotWindow from './ChatbotWindow';
 
export interface ChatbotWidgetProps {
  /** Initial open state */
  defaultOpen?: boolean;
  /** Position of the widget */
  position?: 'bottom-right' | 'bottom-left';
}
 
export default function ChatbotWidget({
  defaultOpen = false,
  position = 'bottom-right'}: ChatbotWidgetProps) {
  const [isOpen, setIsOpen] = useState(defaultOpen);

  const handleToggle = useCallback(() => {
    setIsOpen((prev) => !prev);
  }, []);

  const handleClose = useCallback(() => {
    setIsOpen(false);
  }, []);

  const positionClasses =
    position === 'bottom-right' ? 'right-4 sm:right-6' : 'left-4 sm:left-6';

  return (
    <div className={`fixed bottom-4 sm:bottom-6 ${positionClasses} z-50`}>
      {/* Chat Window */}
      {isOpen && <ChatbotWindow onClose={handleClose} />}

      {/* Floating Button */}
      <ChatbotButton isOpen={isOpen} onClick={handleToggle} />
    </div>
  );
}