const TheadsContainer = styled.div` width: 100%; padding-left: 0.5rem; padding-right: 0.5rem; background-color: #0e0e10; padding-left: 1.125rem; padding-right: 1.125rem; pading-top: 2rem; padding-bottom: 1rem; border: 1px solid #777583; border-radius: 0.375rem; color: #fff; `; const CloseButton = styled.div` color: #fff; :hover { color: #5765f2; } z-index: 40; relative: absolute; margin-top: 10px; top: 10px; right: 1rem; cursor: pointer; `; const ReplyMessageContainer = styled.div` padding-top: 1rem; font-size: 18px; font-weight: 700; padding-bottom: 1rem; border-bottom: 1px solid #777583; `; const SenderInfoContainer = styled.div` width: 100%; display: flex; align-items: center; column-gap: 0.5rem; display: flex; justify-content: flex-start; `; const ProfileIconContainerMsg = styled.div` display: flex; justify-content: center; align-items: center; width: 32px; height: 32px; border-radius: 50%; ${({ id }) => id && `background-color: #111;`} text-align: center; /* Body/Small */ font-family: Helvetica Neue; font-size: 14px; font-style: normal; font-weight: 400; line-height: 150%; /* 21px */ margin-left: -8px; `; const NameContainerSender = styled.div` display: flex; justify-content: start; align-items: center; width: 100%; color: #6c757d; `; const TimeText = styled.p` color: #adb5bd; font-family: Helvetica Neue; font-size: 14px; font-style: normal; font-weight: 400; line-height: 100%; padding-top: 1rem; `; const formatTimeAgo = (seconds) => { const minutes = Math.floor(seconds / 60); const hours = Math.floor(minutes / 60); const days = Math.floor(hours / 24); const weeks = Math.floor(days / 7); const months = Math.floor(weeks / 4); if (months > 0) { return `${months} month${months > 1 ? "s" : ""} ago`; } else if (weeks > 0) { return `${weeks} week${weeks > 1 ? "s" : ""} ago`; } else if (days > 0) { return `${days} day${days > 1 ? "s" : ""} ago`; } else if (hours > 0) { return `${hours} hour${hours > 1 ? "s" : ""} ago`; } else if (minutes > 0) { return `${minutes} minute${minutes > 1 ? "s" : ""} ago`; } else { return `just now`; } }; const ImageContainer = styled.img` border-radius: 4px; `; const ReplyTextContainer = styled.div` max-width: 400px; position: relative; word-wrap: break-word; display: flex; flex-direction: column; row-gap: 20px; font-size: 16px; font-style: normal; font-weight: 400; line-height: 100%; `; const Header = styled.div` display: flex; justify-content: space-between; `; console.log("THREAD message", props.message); const text = props.message.text; return ( <TheadsContainer> <ReplyMessageContainer> <Header> <div>Thread</div> <CloseButton onClick={() => props.setOpenThreadId(undefined)}> <i class="bi bi-x-lg"></i> </CloseButton> </Header> <SenderInfoContainer ownMessage={props.message.sender === context.accountId} > <div> <ProfileIconContainerMsg> <Widget src={`${props.componentOwnerId}/widget/Calimero.Curb.ProfileIcon.UserProfileIcon`} props={{ accountId: props.message.sender, showStatus: false, componentOwnerId: props.componentOwnerId, }} /> </ProfileIconContainerMsg> </div> <div> <NameContainerSender>{props.message.sender}</NameContainerSender> </div> <TimeText> {formatTimeAgo((Date.now() - props.message.timestamp) / 1000)} </TimeText> </SenderInfoContainer> <ReplyTextContainer> {text.split("$?$")[0]} {text.split("$?$").length > 1 && ( <ImageContainer src={text.split("$?$")[1]} alt="uploaded" style={{ maxHeight: "400px", maxWidth: "400px" }} onClick={() => { if (text.split("$?$").length > 1) { showFullImage(); } }} /> )} </ReplyTextContainer> </ReplyMessageContainer> {props.message.thread.length > 0 && props.message.thread.map((message) => ( <Widget src={`${props.componentOwnerId}/widget/Calimero.Curb.Chat.UserMessage`} props={{ componentOwnerId: props.componentOwnerId, message, addMessageReaction: props.addMessageReaction, isThread: true, setImage: (src) => props.setImage(src), }} key={message.id} /> ))} </TheadsContainer> );