import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import {
Button, Icon, IconButton, OverlayTrigger, Tooltip,
} from '@openedx/paragon';
import {
StarFilled, StarOutline, ThumbUpFilled, ThumbUpOutline,
} from '@openedx/paragon/icons';
import classNames from 'classnames';
import { useIntl } from '@edx/frontend-platform/i18n';
import { ThreadType } from '../../data/constants';
import { useHasLikePermission, useUserPostingEnabled } from '../data/hooks';
import PostCommentsContext from '../post-comments/postCommentsContext';
import messages from '../posts/post/messages';
import ActionsDropdown from './ActionsDropdown';
import DiscussionContext from './context';
const HoverCard = ({
id,
contentType,
actionHandlers,
handleResponseCommentButton,
addResponseCommentButtonMessage,
onLike,
onFollow,
voted,
following,
endorseIcons,
}) => {
const intl = useIntl();
const { enableInContextSidebar } = useContext(DiscussionContext);
const { isClosed } = useContext(PostCommentsContext);
const isUserPrivilegedInPostingRestriction = useUserPostingEnabled();
const userHasLikePermission = useHasLikePermission(contentType, id);
return (
{isUserPrivilegedInPostingRestriction && (
)}
{endorseIcons && (
{intl.formatMessage(endorseIcons.label)}
)}
trigger={['hover', 'focus']}
>
{
const actionFunction = actionHandlers[endorseIcons.action];
actionFunction();
}}
className={['endorse', 'unendorse'].includes(endorseIcons.id) ? 'text-dark-500' : 'text-success-500'}
size="sm"
alt="Endorse"
/>
)}
{intl.formatMessage(voted ? messages.removeLike : messages.like)}
)}
>
{
e.preventDefault();
onLike();
}}
/>
{following !== undefined && (
{intl.formatMessage(following ? messages.unFollow : messages.follow)}
)}
>
{
e.preventDefault();
onFollow();
}}
/>
)}
);
};
HoverCard.propTypes = {
id: PropTypes.string.isRequired,
contentType: PropTypes.string.isRequired,
actionHandlers: PropTypes.objectOf(PropTypes.func).isRequired,
handleResponseCommentButton: PropTypes.func.isRequired,
addResponseCommentButtonMessage: PropTypes.string.isRequired,
onLike: PropTypes.func.isRequired,
voted: PropTypes.bool.isRequired,
endorseIcons: PropTypes.objectOf(PropTypes.shape(
{
id: PropTypes.string,
action: PropTypes.string,
icon: PropTypes.element,
label: {
id: PropTypes.string,
defaultMessage: PropTypes.string,
description: PropTypes.string,
},
conditions: {
endorsed: PropTypes.bool,
postType: ThreadType,
},
},
)),
onFollow: PropTypes.func,
following: PropTypes.bool,
};
HoverCard.defaultProps = {
onFollow: () => null,
endorseIcons: null,
following: undefined,
};
export default React.memo(HoverCard);