import { LS_TOKENS } from "@/lib/constants";
import { makeAutoObservable } from "mobx";

export class AccountStore {
	userId?: string;

	isMainMenuOpen: boolean;
	isSandboxOpen: boolean;

	constructor() {
		makeAutoObservable(this, {}, { autoBind: true });

		const savedState = localStorage.getItem(LS_TOKENS.isMainMenuOpen);
		this.isMainMenuOpen = savedState ? savedState === "true" : false;

		this.isSandboxOpen = false;

		const savedUserId = localStorage.getItem(LS_TOKENS.userId);
		this.userId = savedUserId ? savedUserId : undefined;
	}

	setIsMainMenuOpen(value: boolean) {
		this.isMainMenuOpen = value;
		localStorage.setItem(LS_TOKENS.isMainMenuOpen, String(this.isMainMenuOpen));
	}

	setIsSandboxOpen(value: boolean) {
		this.isSandboxOpen = value;
	}

	setUserId(value: string) {
		this.userId = value;
		localStorage.setItem(LS_TOKENS.userId, value);
	}
}
