Instead of showing the name of the file inside brackets, this bubble should show a thumbnail of the file icon followed by the full name of the file under the prompt text: # ui/chat_bubble.py
import os
import logging
from PyQt6.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QLabel
from PyQt6.QtGui import QFont, QColor #,QGraphicsDropShadowEffect
from PyQt6.QtCore import Qt

# Configure logging at the module level
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

class ChatBubble(QWidget):
    def __init__(self, text, is_user, metadata=None, file_indicator=None, custom_font=None):
        super().__init__()
        self.is_user = is_user
        self.text = text
        self.metadata = metadata  # Dictionary to hold metadata like latency
        self.file_indicator = file_indicator  # File name if any
        self.custom_font = custom_font or "Arial"
        self.init_ui()
        logging.debug("ChatBubble created. User: %s, Text: %s", self.is_user, self.text)

    def init_ui(self):
        layout = QHBoxLayout()
        if self.is_user:
            layout.addStretch()
            bubble_color = QColor(76, 175, 80)  # Green bubble
        else:
            bubble_color = QColor(66, 133, 244)  # Blue bubble

        # Create a vertical layout to include metadata
        bubble_layout = QVBoxLayout()

        bubble_text = self.text
        if self.file_indicator:
            bubble_text += f"\n[Attached File: {self.file_indicator}]"

        bubble = QLabel(bubble_text)
        bubble.setWordWrap(True)
        bubble.setFont(QFont(self.custom_font, 11))
        bubble.setContentsMargins(10, 10, 10, 10)
        bubble.setStyleSheet(f"""
            background-color: {bubble_color.name()};
            border-radius: 10px;
            color: white;
        """)
        bubble_layout.addWidget(bubble)

        if self.metadata:
            # Display metadata like response time and source file
            metadata_text = ""
            if "latency" in self.metadata:
                latency = self.metadata["latency"]
                metadata_text += f"Time Taken: {latency:.2f} sec"
            if "source_file" in self.metadata and self.metadata["source_file"]:
                source_file = self.metadata["source_file"]
                metadata_text += f"\nSource: {os.path.basename(source_file)}"
            metadata_label = QLabel(metadata_text)
            metadata_label.setFont(QFont(self.custom_font, 8))
            metadata_label.setStyleSheet("color: gray;")
            bubble_layout.addWidget(metadata_label)

        bubble_widget = QWidget()
        bubble_widget.setLayout(bubble_layout)
        bubble_widget.setStyleSheet("background-color: transparent;")

        # Add shadow effect to bubble_widget
        #shadow = QGraphicsDropShadowEffect()
        #shadow.setBlurRadius(5)
        #shadow.setOffset(0, 0)
        #bubble_widget.setGraphicsEffect(shadow)

        layout.addWidget(bubble_widget)
        if not self.is_user:
            layout.addStretch()
        self.setLayout(layout)

    def setText(self, text):
        logging.debug("Updating ChatBubble text from '%s' to '%s'.", self.text, text)
        self.text = text
        bubble_layout = self.layout().itemAt(0).widget().layout()
        bubble_label = bubble_layout.itemAt(0).widget()

        if isinstance(bubble_label, QLabel):
            bubble_label.setText(self.text)
        else:
            logging.warning("Expected QLabel, but got %s", type(bubble_label))

    def setMetadata(self, metadata):
        logging.debug("Updating ChatBubble metadata.")
        self.metadata = metadata
        # Update the metadata label
        bubble_layout = self.layout().itemAt(1).widget().layout()
        if self.metadata:
            metadata_text = ""
            if "latency" in self.metadata:
                latency = self.metadata["latency"]
                metadata_text += f"Time Taken: {latency:.2f} sec"
            if "source_file" in self.metadata and self.metadata["source_file"]:
                source_file = self.metadata["source_file"]
                metadata_text += f"\nSource: {os.path.basename(source_file)}"
            metadata_label = QLabel(metadata_text)
            metadata_label.setFont(QFont(self.custom_font, 8))
            metadata_label.setStyleSheet("color: gray;")
            if bubble_layout.count() >= 2:
                bubble_layout.itemAt(1).widget().deleteLater()
            bubble_layout.addWidget(metadata_label)