2025-10-12 17:42:17 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
import Image from "next/image";
|
|
|
|
|
import { useMediaQuery } from "usehooks-ts";
|
|
|
|
|
import { useSliderBanner } from "@/hooks/use-slider";
|
|
|
|
|
import Loader from "../ui/Loader";
|
2026-02-11 20:45:37 +00:00
|
|
|
import { useLocale } from "next-intl";
|
2025-10-12 17:42:17 +00:00
|
|
|
|
|
|
|
|
export const SliderClient = () => {
|
|
|
|
|
const isTab = useMediaQuery("(min-width: 1024px)");
|
|
|
|
|
const isMd = useMediaQuery("(min-width: 700px)");
|
|
|
|
|
|
|
|
|
|
const [data, setData] = useState<any>(null);
|
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
const bannerType = useSliderBanner(isTab, isMd);
|
2026-02-11 20:45:37 +00:00
|
|
|
const locale = useLocale();
|
2025-10-12 17:42:17 +00:00
|
|
|
|
|
|
|
|
const fetchData = async () => {
|
|
|
|
|
try {
|
|
|
|
|
setLoading(true);
|
|
|
|
|
const res = await fetch(`/api/banners?bannerType=${bannerType}`, {
|
|
|
|
|
headers: {
|
2026-02-11 20:45:37 +00:00
|
|
|
"Accept-Language": locale,
|
2025-10-12 17:42:17 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
const json = await res.json();
|
|
|
|
|
setData(json);
|
|
|
|
|
setLoading(false);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchData();
|
2026-02-11 20:45:37 +00:00
|
|
|
}, [bannerType, locale]);
|
2025-10-12 17:42:17 +00:00
|
|
|
|
|
|
|
|
if (loading) return <Loader className="h-[600px] min-h-[320px]" />;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Image
|
|
|
|
|
src={data.data.banner_items?.[0]?.image || ""}
|
|
|
|
|
alt="Баннер"
|
|
|
|
|
width={1920}
|
|
|
|
|
height={600}
|
|
|
|
|
className="object-cover max-h-[600px] min-h-[320px] size-full object-center"
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|