import { useTranslation } from "react-i18next"; import styles from "./styles.module.css"; import { getCategoryIdByZodiacSign, getZodiacSignByDate, } from "@/services/zodiac-sign"; import { useEffect, useState } from "react"; import { useApi } from "@/api"; import { getRandomArbitrary } from "@/services/random-value"; interface ThermalProps { data: Thermal; onClick: () => void; } export interface Thermal { name: string; birthDate: string; } function ThermalSlider({ data, onClick }: ThermalProps): JSX.Element { const api = useApi(); const { i18n } = useTranslation(); const locale = i18n.language; const zodiacSign = getZodiacSignByDate(data.birthDate); const [backgroundUrl, setBackgroundUrl] = useState(""); useEffect(() => { (async () => { try { const { asset_categories } = await api.getAssetCategories({ locale }); const categoryId = getCategoryIdByZodiacSign( zodiacSign, asset_categories ); const assets = ( await api.getAssets({ category: String(categoryId || "1") }) ).assets; const randomAsset = assets[getRandomArbitrary(0, assets.length - 1)]; setBackgroundUrl(randomAsset.url); } catch (error) { console.error("Error: ", error); } })(); }, [api, locale, zodiacSign]); return (
background image

with {data.name}

Today
); } export default ThermalSlider;