import { createCookieSessionStorage } from 'remix' ; import { getRequiredServerEnvVar } from './misc' ; import { Theme , isTheme } from './theme-provider' ; const themeStorage = createCookieSessionStorage ( { cookie : { name : 'KCD_theme' , secure : true , secrets : [ getRequiredServerEnvVar ( 'SESSION_SECRET' ) ] , sameSite : 'lax' , path : '/' , expires : new Date ( '2088-10-18' ) , httpOnly : true , } , } ) ; async function getThemeSession ( request ) { const session = await themeStorage . getSession ( request . headers . get ( 'Cookie' ) ) ; return { getTheme : ( ) => { const themeValue = session . get ( 'theme' ) ; return isTheme ( themeValue ) ? themeValue : Theme . DARK ; } , setTheme : ( theme ) => session . set ( 'theme' , theme ) , commit : ( ) => themeStorage . commitSession ( session ) , } ; } export { getThemeSession } ;