{"version":3,"sources":["../ui/src/components/player-components/comments/singleComment.tsx"],"sourcesContent":["import { useEffect, useState } from \"react\";\r\nimport AddComment from \"./addComment\";\r\nimport Image from \"next/image\";\r\nimport LikeComment from \"./likeComment\";\r\nimport { useAppDispatch, useAppSelector } from \"redux-share/hooks\";\r\nimport { IComments, ConditionName, ISingleCommentProps } from \"interfaces\";\r\nimport { conditions, getRemainingTime } from \"helpers\";\r\nimport { setReplyToAuthor } from \"redux-share/slices/commentsSlice\";\r\nimport { handleGetReplies } from \"redux-share/actions/comment.action\";\r\nimport { shallowEqual } from 'react-redux'\r\nimport dynamic from \"next/dynamic\";\r\n\r\nconst EmptyProfileIcon = dynamic(() => import(\"../../icon-components/emptyProfile\"));\r\nconst SingleReply = dynamic(() => import(\"./singleReply\"));\r\n\r\nconst SingleComment = ({ comment, user, commentsLocalStorageIds }: ISingleCommentProps) => {\r\n\r\n    const dispatch = useAppDispatch();\r\n    const { realTimeReply } = useAppSelector(({ comments: { realTimeReply, canAddComment } }) => ({ realTimeReply, canAddComment }), shallowEqual);\r\n    const { avatar_url, name } = useAppSelector(({ user: { avatar_url, name } }) => ({ avatar_url, name }), shallowEqual);\r\n\r\n    const [showReplyBox, setShowReplyBox] = useState<boolean>(false);\r\n    const [repliesCount, setRepliesCount] = useState<number>(comment.replies_count);\r\n    const [replies, setReplies] = useState<IComments[]>([]);\r\n    const [usersRepliesProfiles, setUsersRepliesProfiles] = useState<any[]>([]);\r\n\r\n    useEffect(() => {\r\n        setRepliesCount(comment.replies_count);\r\n    }, [comment.replies_count])\r\n\r\n\r\n    useEffect(() => {\r\n        if (realTimeReply && comment.id === realTimeReply.reply_to) {\r\n            setReplies([realTimeReply, ...replies]);\r\n            setRepliesCount((prev: number) => prev + 1);\r\n            setUsersRepliesProfiles(prev => [...prev, { id: realTimeReply.author, profile: { avatar_url: avatar_url, name: name}}])\r\n        }\r\n    }, [realTimeReply])\r\n\r\n\r\n    const handleHideComments = () => {\r\n        setShowReplyBox(false);\r\n        setReplies([]);\r\n    }\r\n\r\n    const handleAnswer = () => {\r\n        dispatch(setReplyToAuthor({ author: user ? user.profile.name : \"کاربر ناشناس\", id: comment.id }));\r\n        if (!conditions(ConditionName.isTouchScreen)) setShowReplyBox(true);\r\n\r\n    }\r\n\r\n    return (\r\n        <div className=\"pl-flex pl-flex-col pl-items-start\">\r\n            <div className=\"pl-flex pl-justify-between pl-items-center pl-w-full\">\r\n                <div className={`pl-flex pl-items-center pl-gap-1 pl-font-normal ${conditions(ConditionName.isTouchScreen) ? \"pl-text-[11px]\" : \"pl-text-[14px]\"}`}>\r\n                    {user && Object.keys(user.profile).length > 0 && user.profile.avatar_url ? <Image src={user.profile.avatar_url} width={24} height={24} alt=\"user-profile\" className=\"pl-rounded-full\"/> : <EmptyProfileIcon />}\r\n                    <p className=\"pl-text-main-highLight\">{user && Object.keys(user.profile).length > 0 ? user.profile.name : \"کاربر ناشناس\"} .</p>\r\n                    <span className=\"pl-text-z-secondary-600 dark:pl-text-z-gray-400\">{getRemainingTime(comment.created_at)}</span>\r\n                </div>\r\n                <LikeComment commentId={comment.id} likesCount={comment.like} isIdInLocalStorage={!!commentsLocalStorageIds && commentsLocalStorageIds.includes(comment.id)}/>\r\n            </div>\r\n            <p className=\"pl-text-[13px] pl-font-normal pl-leading-[22px] pl-mt-3 pl-mb-1 pl-text-z-gray-700 dark:pl-text-secondary-50\">{comment.text}</p>\r\n            <button disabled={!conditions(ConditionName.canAddComment)} className={`pl-font-normal pl-text-z-secondary-600 dark:pl-text-z-gray-400 ${conditions(ConditionName.isTouchScreen) ? \"pl-text-[11px]\" : \"pl-text-[12px]\"}`} onClick={handleAnswer}>پاسخ</button>\r\n            {showReplyBox && <AddComment type=\"reply\" setShowReplyBox={setShowReplyBox} />}\r\n            {!!repliesCount && replies.length === 0 && (\r\n                <div className=\"pl-flex pl-items-center pl-gap-[5px] pl-mt-1\">\r\n                    <div className=\"pl-w-6 pl-h-[1px] pl-bg-z-secondary-600 pl-rounded-[4px]\" />\r\n                    <button className={`pl-text-z-secondary-600 dark:pl-text-z-gray-400 pl-font-normal ${conditions(ConditionName.isTouchScreen) ? \"pl-text-[11px]\" : \"pl-text-[12px]\"}`} onClick={() => handleGetReplies(comment.id, replies, setReplies, usersRepliesProfiles, setUsersRepliesProfiles, realTimeReply)}>مشاهده {repliesCount} پاسخ دیگر</button>\r\n                </div>\r\n            )}\r\n            {!!replies.length && (\r\n                <>\r\n                    {replies.map((reply: IComments) => <SingleReply key={reply.id} reply={reply} usersRepliesProfiles={usersRepliesProfiles} commentsLocalStorageIds={commentsLocalStorageIds}/>)}\r\n                    {repliesCount - replies.length <= 0 ? (\r\n                        <div className=\"pl-flex pl-items-center pl-gap-[5px] pl-mt-1 pl-mr-4\">\r\n                            <div className=\"pl-w-6 pl-h-[1px] pl-bg-z-secondary-600 pl-rounded-[4px]\" />\r\n                            <button className=\"pl-text-z-gray-400 pl-text-[11px] pl-font-normal\" onClick={handleHideComments}>پنهان کردن پاسخ ها</button>\r\n                        </div>\r\n                    ) : (\r\n                        <div className=\"pl-flex pl-items-center pl-gap-[5px] pl-mt-1 pl-mr-4\">\r\n                            <div className=\"pl-w-6 pl-h-[1px] pl-bg-z-secondary-600 pl-rounded-[4px]\" />\r\n                            <button className=\"pl-text-z-gray-400 pl-text-[11px] pl-font-normal\" onClick={() => handleGetReplies(comment.id, replies, setReplies, usersRepliesProfiles, setUsersRepliesProfiles)}>مشاهده {repliesCount - replies.length} پاسخ دیگر</button>\r\n                        </div>\r\n                    )}\r\n                </>\r\n            )}\r\n        </div>\r\n    )\r\n}\r\n\r\nexport default SingleComment;"],"mappings":"6QAAAA,IAAA,OAAS,aAAAC,EAAW,YAAAC,MAAgB,QAEpC,OAAOC,MAAW,aAOlB,OAAS,gBAAAC,MAAoB,cAC7B,OAAOC,MAAa,eA6C2E,OAgB/E,YAAAC,EAhB+E,OAAAC,EAC3E,QAAAC,MAD2E,oBA3C/F,IAAMC,EAAmBJ,EAAQ,IAAM,OAA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,GAAIe,EAASC,EAAYC,EAAsBC,EAAyBb,CAAa,EAAG,kDAAQQ,EAAa,sDAAU,GACzU,EAEH,CAAC,CAACE,EAAQ,QACPnB,EAAAF,EAAA,CACK,UAAAqB,EAAQ,IAAKe,GAAqBnC,EAACG,EAAA,CAA2B,MAAOgC,EAAO,qBAAsBb,EAAsB,wBAAyBf,GAA7F4B,EAAM,EAA+G,CAAE,EAC3KjB,EAAeE,EAAQ,QAAU,EAC9BnB,EAAC,OAAI,UAAU,uDACX,UAAAD,EAAC,OAAI,UAAU,2DAA2D,EAC1EA,EAAC,UAAO,UAAU,mDAAmD,QAAS0B,EAAoB,yGAAkB,GACxH,EAEAzB,EAAC,OAAI,UAAU,uDACX,UAAAD,EAAC,OAAI,UAAU,2DAA2D,EAC1EC,EAAC,UAAO,UAAU,mDAAmD,QAAS,IAAMiC,EAAiB7B,EAAQ,GAAIe,EAASC,EAAYC,EAAsBC,CAAuB,EAAG,kDAAQL,EAAeE,EAAQ,OAAO,sDAAU,GAC1O,GAER,GAER,CAER,EAEOgB,GAAQhC","names":["init_esm_shims","useEffect","useState","Image","shallowEqual","dynamic","Fragment","jsx","jsxs","EmptyProfileIcon","SingleReply","SingleComment","comment","user","commentsLocalStorageIds","dispatch","useAppDispatch","realTimeReply","useAppSelector","canAddComment","avatar_url","name","showReplyBox","setShowReplyBox","useState","repliesCount","setRepliesCount","replies","setReplies","usersRepliesProfiles","setUsersRepliesProfiles","useEffect","prev","handleHideComments","handleAnswer","setReplyToAuthor","conditions","Image","getRemainingTime","likeComment_default","addComment_default","handleGetReplies","reply","singleComment_default"]}