import { SPECIAL_TRUST_SCORE_FILTER_ID } from '@/constants'
import { getDefaultRelayUrls, getSearchRelayUrls } from '@/lib/relay'
import { TSearchParams } from '@/types'
import NormalFeed from '../NormalFeed'
import Profile from '../Profile'
import { ProfileListBySearch } from '../ProfileListBySearch'
import Relay from '../Relay'
import TrendingNotes from '../TrendingNotes'

export default function SearchResult({ searchParams }: { searchParams: TSearchParams | null }) {
  if (!searchParams) {
    return <TrendingNotes />
  }
  if (searchParams.type === 'profile') {
    return <Profile id={searchParams.search} />
  }
  if (searchParams.type === 'profiles') {
    return <ProfileListBySearch search={searchParams.search} />
  }
  if (searchParams.type === 'notes') {
    return (
      <NormalFeed
        trustScoreFilterId={SPECIAL_TRUST_SCORE_FILTER_ID.SEARCH}
        subRequests={[{ urls: getSearchRelayUrls(), filter: { search: searchParams.search } }]}
        showRelayCloseReason
      />
    )
  }
  if (searchParams.type === 'hashtag') {
    return (
      <NormalFeed
        trustScoreFilterId={SPECIAL_TRUST_SCORE_FILTER_ID.HASHTAG}
        subRequests={[{ urls: getDefaultRelayUrls(), filter: { '#t': [searchParams.search] } }]}
        showRelayCloseReason
      />
    )
  }
  if (searchParams.type === 'nak') {
    return (
      <NormalFeed
        trustScoreFilterId={SPECIAL_TRUST_SCORE_FILTER_ID.NAK}
        subRequests={[searchParams.request]}
        showRelayCloseReason
      />
    )
  }
  return <Relay url={searchParams.search} />
}
