import { useCallback, useMemo, useRef, useState, type ChangeEvent, type MouseEvent } from "react"; import type { RdsBadgeProps } from "../../raaghu-elements/rds-badge/rds-badge"; import RdsBadge from "../../raaghu-elements/rds-badge/rds-badge"; import RdsModal from "../../raaghu-elements/rds-modal/rds-modal"; import "./rds-comp-ai-attachment.scss"; import RdsInput from "../../raaghu-elements/rds-input/rds-input"; import RdsCompAiFabMenu from "../rds-comp-ai-fab-menu/rds-comp-ai-fab-menu"; import AttachmentIcon from "@mui/icons-material/Attachment"; import { registerMaterialIcons } from "../../raaghu-components/rds-comp-ai-icon/rds-comp-ai-icon"; export interface RdsCompAiAttachmentProps { menuIcon?: string; modalTitle?: string; hintText?: string; inputPlaceholder?: string; showBadge?: boolean; badgeLabel?: string; badgeColor?: RdsBadgeProps["colorVariant"]; uploadText?: string; importText?: string; modalText?: string; image?: string; userData?: UserData[]; onFileSelect?: (file: File) => void; onFigmaSubmit?: (value: string) => void; handleAddComment?: (comment: Comment) => void; menuAlignment?: "left" | "right"; } /** @deprecated Use `RdsCompAiAttachmentProps` */ export type RdsCompAiAttachementProps = RdsCompAiAttachmentProps; export interface UserData { firstName: string; lastName: string; activeDotButton: boolean; status: string; size: string; colorVariant: string; time: string; profilePic: string; messageStatus: string; comments: Comment[]; } export interface Comment { firstName: string; lastName: string; comment: string; image?: string; } registerMaterialIcons({ attachment_icon: AttachmentIcon }); const RdsCompAiAttachment = ({ menuIcon, modalTitle, hintText, inputPlaceholder, showBadge, badgeLabel, badgeColor, uploadText, importText, modalText, userData, onFigmaSubmit, handleAddComment, menuAlignment = "left", }: RdsCompAiAttachmentProps) => { const [showModal, setShowModal] = useState(false); const [figmaUrl, setFigmaUrl] = useState(""); const fileInputRef = useRef(null); const [, setCommentList] = useState(userData?.[0]?.comments || []); const handleFileUpload = useCallback( (event: ChangeEvent) => { const file = event.target.files?.[0]; if (!file?.type.startsWith("image/")) return; const reader = new FileReader(); reader.onloadend = () => { const base64String = reader.result as string; const newComment: Comment = { firstName: userData?.[0]?.firstName || "", lastName: userData?.[0]?.lastName || "", comment: "", image: base64String, }; setCommentList((prev) => [...prev, newComment]); handleAddComment?.(newComment); if (fileInputRef.current) { fileInputRef.current.value = ""; } }; reader.readAsDataURL(file); }, [handleAddComment, userData] ); const openModal = useCallback((event: MouseEvent) => { event.stopPropagation(); setShowModal(true); const fabMenu = document.querySelector(".fab-dropdown"); if (fabMenu?.classList.contains("show")) { fabMenu.classList.remove("show"); } }, []); const closeModal = useCallback(() => { setShowModal(false); setFigmaUrl(""); }, []); const handleImportClick = useCallback(() => { fileInputRef.current?.click(); }, []); const handleFigmaInputChange = useCallback( (e: ChangeEvent) => { setFigmaUrl(e.target.value); onFigmaSubmit?.(e.target.value); }, [onFigmaSubmit] ); const listItems = useMemo( () => [ { key: "new", value: ( ), }, { key: "refresh", value: ( ), }, ], [ openModal, uploadText, showBadge, badgeColor, badgeLabel, handleImportClick, importText, ] ); return ( <>
{showModal && (

{modalText}

)} ); }; RdsCompAiAttachment.displayName = "RdsCompAiAttachment"; export default RdsCompAiAttachment;