import { createContext, useState, useContext, type PropsWithChildren, type Dispatch, type SetStateAction, } from 'react' import type { ModalProperties } from '~/components/popup/success-modal' type NewsContextProperties = { isLoginOpen: boolean setIsLoginOpen: Dispatch> isRegisterOpen: boolean setIsRegisterOpen: Dispatch> isForgetOpen: boolean setIsForgetOpen: Dispatch> isSuccessOpen: ModalProperties['isOpen'] setIsSuccessOpen: Dispatch< SetStateAction > isSubscribeOpen: boolean setIsSubscribeOpen: Dispatch> } const NewsContext = createContext(undefined) export const NewsProvider = ({ children }: PropsWithChildren) => { const [isLoginOpen, setIsLoginOpen] = useState(false) const [isRegisterOpen, setIsRegisterOpen] = useState(false) const [isForgetOpen, setIsForgetOpen] = useState(false) const [isSuccessOpen, setIsSuccessOpen] = useState() const [isSubscribeOpen, setIsSubscribeOpen] = useState(false) return ( {children} ) } export const useNewsContext = (): NewsContextProperties => { const context = useContext(NewsContext) if (!context) { throw new Error('useNewsContext must be used within a NewsProvider') } return context }