import { isSeqInRange as t } from "../chat.model"
import { UNREAD_MESSAGES_COUNT_SCROLL_THRESHOLD as s } from "../chat.constant"
import {
ANCHOR_LOADED_RETRY_COUNT as e,
ANCHOR_POS as o,
ANCHOR_STATUS as r,
VIEW_MODE as a,
} from "./list-view.constant"
export const isAnchorInView = (s, e, o) => {
const r = e.lastMessage ? o - 1 : e.seq
return t(s, r)
}
export const createAnchorToMessage = ({
messageId: t,
seq: s,
highlight: a,
pos: n,
status: c,
startTime: i,
}) => ({
highlight: !!a,
lastMessage: !1,
messageId: t,
pos: n || o.MESSAGE_TOP,
seq: s,
startTime: i ?? Date.now(),
status: c || r.ASKED,
retryCountProcessed: c === r.LOADED ? e : 0,
})
export const createAnchorToBottom = ({ pos: t, status: s, messageId: a, startTime: n } = {}) => ({
highlight: !1,
lastMessage: !0,
messageId: a || "unknown",
pos: t || o.DEFAULT,
seq: -1,
startTime: n ?? Date.now(),
status: s || r.ASKED,
retryCountProcessed: s === r.LOADED ? e : 0,
})
export const isChatListLive = (t) => t === a.HISTORY || t === a.LATEST || t === a.ON_HOLD
export const isAnchorScrollProcessed = (t) => t === r.PROCESSED || t === r.RETRY
export const isAnchorScrolling = (t) => t === r.LOADED || t === r.PROCESSED || t === r.RETRY
export const hasMessagesInView = (t) => t.bottom >= t.top && t.top >= 0
export const shouldStartHistory = ({ count: t, startSeq: e }) =>
Number.isInteger(e) && e > -1 && t - e > s
export const calcStartLastSeen = ({ lastSeenSeq: t, count: s }) => (t > 0 && t + 1 < s ? t : -1)