import cookie from "cookie-cutter"; import useTranslation from "next-translate/useTranslation"; import { useRouter } from "next/router"; import { useState } from "react"; import { formatDates } from "../utils"; export default function CaseNoticeBanner(props) { let { t, lang } = useTranslation(); const { messagesObj } = props; const router = useRouter(); const noticeContent = messagesObj.value[0].description; const noticeTitle = messagesObj.value[0].subject.split("Banner ")[1]; const bannerOpenCookie = typeof cookie.get("pedwNotice") == "undefined"; let messagesObjArr = messagesObj.value; let todaysDate = new Date(); return ( <> {messagesObjArr.map((message, index) => ( <> {todaysDate.toISOString() >= message.scheduledstart && todaysDate.toISOString() <= message.scheduledend && (
{t("case:notice-label")}

{( message.subject.match( new RegExp(">>>", "g") ) || [] ).length > 0 ? router.locale == "cy" ? message.subject .split("Banner ")[1] .split(">>>")[1] : message.subject .split("Banner ")[1] .split(">>>")[0] : ( message.subject.match( new RegExp(";", "g") ) || [] ).length > 0 ? router.locale == "cy" ? message.subject .split("Banner ")[1] .split(";")[1] : message.subject .split("Banner ")[1] .split(";")[0] : message.subject.split( "Banner " )[1]}

{( message.description.match( new RegExp(">>>", "g") ) || [] ).length > 0 ? router.locale == "cy" ? message.description.split( ">>>" )[1] : message.description.split( ">>>" )[0] : ( message.description.match( new RegExp(";", "g") ) || [] ).length > 0 ? router.locale == "cy" ? message.description.split( ";" )[1] : message.description.split( ";" )[0] : message.description}
{t("case:date-raised")}:{" "} {formatDates(message.createdon)}
)} ))} ); }