import { browser } from '$app/environment';
import { writable } from 'svelte/store';

const defaultValue = true;
const initialValue = browser
	? window.localStorage.getItem('plausible_ignore') === 'true'
	: defaultValue;

const plausible = writable<boolean>(initialValue);

plausible.subscribe((value) => {
	if (browser) {
		window.localStorage.setItem('plausible_ignore', value ? 'true' : 'false');
	}
});

export default plausible;
