| Total Complexity | 1 | 
| Complexity/F | 0 | 
| Lines of Code | 20 | 
| Function Count | 0 | 
| Duplicated Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
| 1 | import Cookies from "js-cookie";  | 
            ||
| 2 | import { get, writable } from "svelte/store"; | 
            ||
| 3 | import { Theme } from "src/constants"; | 
            ||
| 4 | |||
| 5 | const THEME_COOKIE = "permacoop_theme";  | 
            ||
| 6 | |||
| 7 | export const getThemeCookie = (  | 
            ||
| 8 |   cookieStore: { get: (v: string) => string | undefined } = Cookies | 
            ||
| 9 | ): Theme | null => { | 
            ||
| 10 | return (cookieStore.get(THEME_COOKIE) as Theme | undefined) || null;  | 
            ||
| 11 | };  | 
            ||
| 12 | |||
| 13 | export const theme = writable(getThemeCookie(Cookies));  | 
            ||
| 14 | |||
| 15 | export const toggleTheme = () => { | 
            ||
| 16 | const newTheme = get(theme) === Theme.DARK ? Theme.LIGHT : Theme.DARK;  | 
            ||
| 17 | Cookies.set(THEME_COOKIE, newTheme.toString());  | 
            ||
| 18 | theme.set(newTheme);  | 
            ||
| 19 | };  | 
            ||
| 20 |