import { Button, Card, CardBody, CardFooter, Image, Spinner, Tab, Tabs, } from "@heroui/react"; import React, { useEffect, useState } from "react"; import { Swiper, SwiperSlide } from "swiper/react"; import "swiper/css"; import "swiper/css/navigation"; import "swiper/css/pagination"; import { Navigation, Pagination } from "swiper/modules"; import { topNewsMediahub } from "@/services/medol-news-update"; import Link from "next/link"; import { getImageInp, inpLogin, topNewsInp, topNewsTbn, } from "@/services/third-party-service"; import { convertDateFormatNoTime, textEllipsis } from "@/utils/global"; import PolriTvWidget from "../ui/social-media/polri-tv"; import { useTranslations } from "next-intl"; export default function MedolUpdate() { const [selectedTab, setSelectedTab] = useState("mediahub"); const [mediahubUpdate, setMediahubUpdate] = useState([]); const [tbnUpdate, setTbnUpdate] = useState([]); const [inpUpdate, setInpUpdate] = useState([]); // const t = useTranslations("Landing"); useEffect(() => { if (selectedTab === "mediahub" && mediahubUpdate?.length < 1) { getMedihubUpdate(); } if (selectedTab === "tbnews" && tbnUpdate?.length < 1) { getTbnUpdate(); } if (selectedTab === "inp" && inpUpdate?.length < 1) { // getInpUpdate(); getTbnUpdate(); } }, [selectedTab]); async function getMedihubUpdate() { const res = await topNewsMediahub(); setMediahubUpdate(res?.data?.data?.content); } async function getTbnUpdate() { const res = await topNewsTbn(); console.log("tbn data", res?.data?.data); const tempTbn: any = []; const tempINP: any = []; for (const element of res?.data?.data) { if ( element.website.name.includes("Tribratanews") || element.website.name.includes("Tribrata News") ) { if (tempTbn.length <= 10) { tempTbn.push(element); } } if (element.website.name.includes("INP")) { if (tempINP.length <= 10) { tempINP.push(element); } } } setTbnUpdate(tempTbn); setInpUpdate(tempINP); } async function getInpUpdate() { const headers = { "content-type": "application/json", }; const resLog = await inpLogin(headers); const res = await topNewsInp(resLog?.data?.access_token); // setInpUpdate(res?.data); setInpUpdate(res?.data?.data); // getDataImage(res?.data); } async function getDataImage(data: any) { let temp = data; for (let i = 0; i < data?.length; i++) { const res = await getImageInp(temp[i].id); const data = res?.data[0]?.guid?.rendered; temp[i].image = data; } setInpUpdate(temp); } const formatDate = (dateString: string): string => { const date = new Date(dateString); let timeZone = "Asia/Jakarta"; let timeZoneAbbr = "WIB"; if (dateString.includes("+09:00")) { timeZone = "Asia/Jayapura"; timeZoneAbbr = "WIT"; } else if (dateString.includes("+08:00")) { timeZone = "Asia/Makassar"; timeZoneAbbr = "WITA"; } const options: Intl.DateTimeFormatOptions = { day: "2-digit", month: "2-digit", year: "numeric", hour: "2-digit", minute: "2-digit", hour12: false, timeZone, }; // Format tanggal const formattedDate = new Intl.DateTimeFormat("id-ID", options) .format(date) .replace(/\//g, "-"); // Ubah '/' menjadi '-' return `${formattedDate} ${timeZoneAbbr}`; }; return (

Media Update

{mediahubUpdate?.length > 1 ? ( <> { swiper.navigation.nextEl?.classList.add( "bg-white", "!text-black", "rounded-full", "!w-[40px]", "!h-[40px]", "!border-2" ); swiper.navigation.prevEl?.classList.add( "bg-white", "!text-black", "rounded-full", "!w-[40px]", "!h-[40px]", "!border-2" ); }} > {mediahubUpdate?.map((newsItem: any) => ( thumbnail

{formatDate(newsItem?.createdAt)}

{textEllipsis(newsItem?.title, 120)}
))}
) : (
)}
{tbnUpdate?.length > 1 ? ( <> {" "} { swiper.navigation.nextEl?.classList.add( "bg-white/70", "!text-black", "rounded-full", "!w-[40px]", "!h-[40px]" ); swiper.navigation.prevEl?.classList.add( "bg-white/70", "!text-black", "rounded-full", "!w-[40px]", "!h-[40px]" ); }} > {tbnUpdate?.map((newsItem: any) => ( thumbnail {/* {convertDateFormatNoTime(newsItem?.date)} */}

{formatDate(newsItem?.date)}

{textEllipsis(newsItem?.title, 120)}
))}
) : (
)}
{inpUpdate?.length > 1 ? ( <> { swiper.navigation.nextEl?.classList.add( "bg-white/70", "!text-black", "rounded-full", "!w-[40px]", "!h-[40px]" ); swiper.navigation.prevEl?.classList.add( "bg-white/70", "!text-black", "rounded-full", "!w-[40px]", "!h-[40px]" ); }} > {inpUpdate?.map((newsItem: any) => ( thumnail {/* {newsItem?.created_at} */}

{" "} {formatDate(newsItem?.date)}

{textEllipsis(newsItem?.title, 120)}
))}
) : (
)}
); }