import { createSelector as e } from "@reduxjs/toolkit"
import { getChatReactionsById as t } from "../reaction"
import { CHAT_STATE_KEY as n } from "../chat.constant"
import { PIN_MESSAGE_STATE_KEY as s } from "./pin-message.constant"
export const getPinMessageState = (e) => e[n][s]
export const getPinnedChatMessages = (e) => getPinMessageState(e).pinnedMessages
export const getPinnedChatMessagesCount = (e) => getPinMessageState(e).pinnedMessages.length
export const getHasPinnedChatMessages = (e) => getPinnedChatMessagesCount(e) > 0
export const getLastPinnedChatMessage = (e) => {
const t = getPinnedChatMessages(e)
return t.length ? t[0] : null
}
export const makeGetPinnedChatMessageById = (e) => (t) =>
getPinnedChatMessages(t).find((t) => t.id === e)
export const getIsMessagePinned = (e, t) => !!getPinMessageState(e).isMessagePinnedMap[t]
export const getPinnedMessageCoreIdById = (e, t) =>
getPinnedChatMessages(e).find((e) => e.id === t)?.coreId
export const getIsPinnedTabOpen = (e) => getPinMessageState(e).isPinnedTabOpen
export const getIsPinnedLimitMessageShown = (e) => getPinMessageState(e).isPinnedLimitShown
export const getPinnedMessageReactionCount = (e) => (t) =>
makeGetPinnedChatMessageById(e)(t)?.reactionCount || 0
export const getHasReactionsForPinnedMessage = (n) =>
e(
[(e) => t(n)(e), (e) => getPinnedMessageReactionCount(n)(e)],
(e, t) => !!(e.reactions?.length > 0 || t),
)