|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useSearchParams } from "next/navigation"; |
| 4 | +import { useTranslations } from "next-intl"; |
| 5 | +import React from "react"; |
| 6 | + |
| 7 | +import cn from "@/utils/core/cn"; |
| 8 | + |
| 9 | +import { useTournamentsSection } from "./tournaments_provider"; |
| 10 | +import { TOURNAMENTS_SEARCH } from "../constants/query_params"; |
| 11 | + |
| 12 | +type Props = { |
| 13 | + children: React.ReactNode; |
| 14 | + className?: string; |
| 15 | +}; |
| 16 | + |
| 17 | +const TournamentsResults: React.FC<Props> = ({ children, className }) => { |
| 18 | + const t = useTranslations(); |
| 19 | + const { count } = useTournamentsSection(); |
| 20 | + const params = useSearchParams(); |
| 21 | + |
| 22 | + const q = (params.get(TOURNAMENTS_SEARCH) ?? "").trim(); |
| 23 | + const isSearching = q.length > 0; |
| 24 | + |
| 25 | + type PlainKey = Parameters<typeof t>[0]; |
| 26 | + |
| 27 | + if (count > 0) { |
| 28 | + return <div className={className}>{children}</div>; |
| 29 | + } |
| 30 | + |
| 31 | + const titleKey = ( |
| 32 | + isSearching ? "tournamentsEmptySearchTitle" : "tournamentsEmptyDefaultTitle" |
| 33 | + ) as PlainKey; |
| 34 | + |
| 35 | + const bodyKey = ( |
| 36 | + isSearching ? "tournamentsEmptySearchBody" : "tournamentsEmptyDefaultBody" |
| 37 | + ) as PlainKey; |
| 38 | + |
| 39 | + return ( |
| 40 | + <div |
| 41 | + className={cn( |
| 42 | + "flex items-center justify-center", |
| 43 | + "min-h-[260px] lg:min-h-[360px]", |
| 44 | + className |
| 45 | + )} |
| 46 | + > |
| 47 | + <div className="text-center"> |
| 48 | + <p className="my-0 text-[18px] font-medium text-blue-800/70 dark:text-blue-800-dark/70"> |
| 49 | + {t(titleKey, { count })} |
| 50 | + </p> |
| 51 | + |
| 52 | + <p className="mt-2 text-sm text-blue-700/60 dark:text-blue-700-dark/60"> |
| 53 | + {t(bodyKey)} |
| 54 | + </p> |
| 55 | + </div> |
| 56 | + </div> |
| 57 | + ); |
| 58 | +}; |
| 59 | + |
| 60 | +export default TournamentsResults; |
0 commit comments