import { persistentDbWritable } from "$lib/index";
import type { Writable } from "svelte/store";
import Dexie, { type Table } from "dexie";

interface MetaEntry {
  key: string;
  value: string;
}

class SettingsDB extends Dexie {
    meta!: Table<MetaEntry, string>;

    constructor() {
        super("settings");
        this.version(1).stores({
            meta: "&key"
        });
    }
}

const settingsDB = new SettingsDB();

export const shaderEnabled: Writable<boolean> = persistentDbWritable<boolean, SettingsDB>(
    "shaderEnabled",
    true,

    settingsDB
);
