import { path } from "./deps.ts";
import initialCart from "./initialCart.json" assert { type: "json" };
import { Sheet } from "./sheet.ts";

let cart = initialCart as Array<Sheet>;

const virtualPathToRealPath = (virtualFname: string) => {
	const realPath = path.join(".", "carts", ...virtualFname.split("/"));
	return realPath;
}

export const saveCart = async (fname: string) => {
	await Deno.writeTextFile(virtualPathToRealPath(fname+".fx"), JSON.stringify(getCart()));
}

export const loadCart = async (fname: string) => {
	cart = JSON.parse(await Deno.readTextFile(virtualPathToRealPath(fname+".fx")));
}

export const getCart = () => {
	return cart;
}