"use client"; import React, { useEffect, useState } from "react"; import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious } from "@/components/ui/carousel"; import Image from "next/image"; import { Skeleton } from "@/components/ui/skeleton"; import { formatDateToIndonesian, secondToTimes } from "@/utils/globals"; import { useParams, usePathname } from "next/navigation"; import { listData } from "@/service/landing/landing"; import { useRouter } from "@/i18n/routing"; import { Icon } from "@iconify/react/dist/iconify.js"; import { useTranslations } from "next-intl"; import { Reveal } from "../Reveal"; const LatestContentKaltara = (props: { group: string; type: string }) => { const [selectedTab, setSelectedTab] = useState("video"); const [isLoading, setIsLoading] = useState(true); const params = useParams(); const poldaName: any = params?.polda_name; const satkerName = params?.satker_name; const [content, setContent] = useState([]); const [isBannerLoading, setIsBannerLoading] = useState(true); const [centerPadding, setCenterPadding] = useState(); const router = useRouter(); const pathname = usePathname(); const t = useTranslations("LandingPage"); let prefixPath = poldaName ? `/polda/${poldaName}` : satkerName ? `/satker/${satkerName}` : "/"; useEffect(() => { // async function initState() { // const res = await listCarousel(); // setContent(res?.data?.data); // setCenterPadding(`${Math.trunc(Number(window.innerWidth) / 10 + 40)}px`); // } async function fetchData() { const res = await listData("1", "", "", 5, 0, "createdAt", "", "", poldaName); let data = res?.data?.data?.content; setContent(data); setCenterPadding(`${Math.trunc(Number(window.innerWidth) / 10 + 40)}px`); setIsBannerLoading(false); console.log("Done"); } fetchData(); }, [params?.page]); useEffect(() => { const timer = setTimeout(() => { setIsLoading(false); }, 3000); return () => clearTimeout(timer); }, []); const shimmer = (w: number, h: number) => ` `; const toBase64 = (str: string) => (typeof window === "undefined" ? Buffer.from(str).toString("base64") : window.btoa(str)); return ( <>
{/*
Berita {props.type == "popular" ? "Terpopuler" : props.type == "latest" ? t("new", { defaultValue: "New" }) : "Serupa"}
*/}

{pathname?.split("/")[1] == "in" ? ( <> {t("content", { defaultValue: "Content" })}  {props.type == "popular" ? "Terpopuler" : props.type == "latest" ? t("new", { defaultValue: "New" }) : "Serupa"} ) : ( <> {props.type == "popular" ? "Popular" : props.type == "latest" ? t("new", { defaultValue: "New" }) : "Serupa"}  {t("content", { defaultValue: "Content" })} )}

Audio Visual
|
Audio
|
Foto
|
Teks
{isLoading ? (
) : (
{selectedTab == "image" ? ( content?.length > 0 ? ( {content?.map((image: any) => (
router.push(prefixPath + `/image/detail/${image?.slug}`)} className="cursor-pointer relative group overflow-hidden shadow-md hover:shadow-lg"> {/* Gambar */} video {/* Overlay gelap */}

{image?.title}

{formatDateToIndonesian(new Date(image?.createdAt))} {image?.timezone ? image?.timezone : "WIB"} | {image.clickCount}{" "}

))}
) : (

empty

) ) : selectedTab == "audio" ? ( content?.length > 0 ? ( {content?.map((audio: any) => (
router.push(prefixPath + `/audio/detail/${audio?.slug}`)} className="cursor-pointer flex flex-col sm:flex-row items-center bg-white dark:bg-gray-800 shadow-md rounded-lg p-4 gap-4 w-full">
{formatDateToIndonesian(new Date(audio?.createdAt))} {audio?.timezone ? audio?.timezone : "WIB"} |    {audio?.clickCount}{" "}
{audio?.title}

{audio?.duration ? secondToTimes(Number(audio?.duration)) : "00:00:00"}

))}
) : (

empty

) ) : selectedTab == "video" ? ( content?.length > 0 ? ( {content?.map((video: any) => (
router.push(prefixPath + `/video/detail/${video?.slug}`)} className="cursor-pointer relative group overflow-hidden shadow-md hover:shadow-lg"> {/* Gambar */} video {/* Overlay Gelap */}

{video?.title}

{formatDateToIndonesian(new Date(video?.createdAt))} {video?.timezone ? video?.timezone : "WIB"} | {video.clickCount}{" "}

))}
) : (

empty

) ) : content.length > 0 ? ( {content?.map((text: any) => (
router.push(prefixPath + `/document/detail/${text?.slug}`)} className="flex flex-col bg-yellow-500 sm:flex-row items-center dark:bg-gray-800 cursor-pointer shadow-md rounded-lg p-4 gap-4">
{formatDateToIndonesian(new Date(text?.createdAt))} {text?.timezone ? text?.timezone : "WIB"}| {text?.clickCount}
{text?.title}
Download {t("document", { defaultValue: "Document" })}
))}
) : (

empty

)}
)}
router.push(prefixPath + `/${selectedTab}/filter?sortBy=${props.type}`)} className="cursor-pointer border text-[#bb3523] rounded-lg text-sm lg:text-md px-4 py-1 border-[#bb3523]"> {t("seeAll", { defaultValue: "See All" })}
); }; export default LatestContentKaltara;