import { type PropsWithChildren } from 'react'

import { PopupModal } from '~/components/popup/modal'
import Banner from '~/components/ui/banner'
import { FormLogin } from '~/components/ui/form-login'
import { FormRegister } from '~/components/ui/form-register'
import { useNewsContext } from '~/contexts/news'

import { FooterLinks } from './footer-links'
import { FooterNewsletter } from './footer-newsletter'
import { HeaderMenu } from './header-menu'
import { HeaderTop } from './header-top'

export const NewsDefaultLayout = (properties: PropsWithChildren) => {
  const { children } = properties
  const { isLoginOpen, setIsLoginOpen, isRegisterOpen, setIsRegisterOpen } =
    useNewsContext()
  return (
    <main className="relative min-h-dvh bg-[#ECECEC]">
      <header>
        <HeaderTop />
        <HeaderMenu />
      </header>
      <div className="grid sm:mx-[50px] sm:my-[25px] sm:gap-y-[25px]">
        <Banner />
        {children}
      </div>

      <footer className="grid w-full grid-cols-1 gap-6 bg-[#2E2F7C] px-5 py-20 text-white sm:grid-cols-5 sm:gap-16 sm:px-16">
        <FooterNewsletter />
        <FooterLinks />
      </footer>

      <PopupModal
        isOpen={isLoginOpen}
        onClose={() => setIsLoginOpen(false)}
        description="Selamat Datang, silakan daftarkan akun Anda untuk melanjutkan!"
      >
        <FormLogin
          setIsRegisterOpen={setIsRegisterOpen}
          setIsLoginOpen={setIsLoginOpen}
        />
      </PopupModal>

      <PopupModal
        isOpen={isRegisterOpen}
        onClose={() => setIsRegisterOpen(false)}
        description="Selamat Datang, silakan daftarkan akun Anda untuk melanjutkan!"
      >
        <FormRegister />
      </PopupModal>
    </main>
  )
}
