import { createSelector as t } from "@reduxjs/toolkit"
import { CHAT_STATE_KEY as e } from "../chat.constant"
import { CHAT_SEARCH_STATE_KEY as a } from "./chat-search.constant"
import {
isChatSearching as h,
isChatSearchLoading as r,
isSearchTermsLimited as c,
} from "./chat-search.model"
export const getChatSearchState = (t) => t[e][a]
export const getChatSearchTerms = (t) => getChatSearchState(t).searchTerms
export const getChatSearchTermsEmpty = (t) => !getChatSearchState(t).searchTerms.length
export const getChatSearchTermsLimited = (t) => {
const e = getChatSearchTerms(t)
return e.length && c(e)
}
export const getChatSearchInputEmpty = (t) => {
const e = getChatSearchTerms(t)
return !e.length || c(e)
}
export const getChatSearchMode = (t) => getChatSearchState(t).mode
export const getChatSearchDataStatus = (t) => getChatSearchState(t).dataStatus
export const getChatSearchLive = (t) => h(getChatSearchMode(t))
export const getChatSearchLoading = (t) => r(getChatSearchDataStatus(t))
export const getChatSearchMessageIds = (t) => getChatSearchState(t).ids
export const getChatSearchActiveIndex = (t) => getChatSearchState(t).activeIndex
export const getChatSearchActiveId = t(
[getChatSearchActiveIndex, getChatSearchMessageIds],
(t, e) => e[t],
)
export const getChatSearchResultsEmpty = (t) =>
!getChatSearchInputEmpty(t) && !getChatSearchLoading(t) && !getChatSearchMessageIds(t).length
export const getChatSearchResultsCount = (t) => getChatSearchMessageIds(t).length
export const getChatSearchResultsEmptyCount = (t) => !getChatSearchMessageIds(t).length
export const getChatSearchMessageById = (t, e) => getChatSearchState(t).byId[e]
export const getChatSearchMessageAllById = (t) => getChatSearchState(t).byId
export const getChatSearchMessages = t(
[getChatSearchMessageIds, getChatSearchMessageAllById],
(t, e) => t.map((t) => e[t]),
)
export const getChatSearchSegmentsById = (t) => (e) => {
if (getChatSearchLive(e)) return getChatSearchState(e).byId[t]?.chat?.segments
}