import React, { useState } from "react"; import { View, TouchableOpacity, StyleSheet } from "react-native"; import { Copy, Check } from "lucide-react-native"; import Clipboard from "@react-native-clipboard/clipboard"; import type { OperoChatStyles } from "../types"; import { mergeStyles } from "../utils/helpers"; export interface CopyableSectionProps { children: React.ReactNode; content: string; label?: string; backgroundColor?: string; customStyles?: OperoChatStyles; } /** * A wrapper component that adds a copy button overlay to any content section. * Used for code blocks, tables, and markdown sections with headings. */ export const CopyableSection: React.FC = ({ children, content, label = "Copy", backgroundColor, customStyles, }) => { const [copied, setCopied] = useState(false); const styles = createStyles(mergeStyles(customStyles)); const handleCopy = () => { Clipboard.setString(content); setCopied(true); setTimeout(() => setCopied(false), 2000); }; return ( {children} {copied ? ( ) : ( )} ); }; const createStyles = (theme: OperoChatStyles) => StyleSheet.create({ container: { position: "relative", marginVertical: 4, }, contentWrapper: { borderRadius: 4, }, copyButton: { position: "absolute", top: 4, right: 4, backgroundColor: "rgba(255, 255, 255, 0.9)", borderRadius: 6, padding: 6, borderWidth: 1, borderColor: theme.sourceItemBackgroundColor || "#e5e7eb", minWidth: 28, minHeight: 28, alignItems: "center", justifyContent: "center", shadowColor: "#000", shadowOffset: { width: 0, height: 1 }, shadowOpacity: 0.1, shadowRadius: 2, elevation: 2, }, checkIcon: { color: "#16a34a", // Green for success }, copyIcon: { color: theme.textColor || "#6b7280", }, });