import { get, set } from 'idb-keyval';
import { getContext, setContext } from 'svelte';
const key = Symbol('dashboard-context');
const defaults = () => ({
    isLoaded: false,
    cameraMode: 'perspective',
    transforming: false,
    snapping: false,
    transformMode: 'translate',
    grid: true,
    gridCellSize: 0.5,
    gridSectionSize: 10,
    gridFadeDistance: 25,
    pointSize: 0.01,
    pointColor: '#333333',
    lineWidth: 0.005,
    lineDotSize: 0.01,
    interactionMode: 'navigate',
    enableMeasureAxisX: true,
    enableMeasureAxisY: true,
    enableMeasureAxisZ: true,
    enableLabels: false,
    enableKeybindings: true,
    enableQueryDevtools: false,
    enableXR: false,
    enableArmPositionsWidget: false,
    openCameraWidgets: {},
    renderStats: false,
    renderArmModels: 'colliders+model',
    renderSubEntityHoverDetail: false,
    xrController: {
        left: {
            scaleFactor: 1,
            rotationEnabled: true,
        },
        right: {
            scaleFactor: 1,
            rotationEnabled: true,
        },
    },
});
export const provideSettings = () => {
    let settings = $state(defaults());
    let settingsLoaded = $state(false);
    get('motion-tools-settings').then((response) => {
        if (response) {
            settings = { ...settings, ...response };
        }
        settingsLoaded = true;
        settings.isLoaded = true;
    });
    $effect(() => {
        if (settingsLoaded) {
            set('motion-tools-settings', $state.snapshot(settings));
        }
    });
    const context = {
        get current() {
            return settings;
        },
        set current(value) {
            settings = value;
        },
    };
    setContext(key, context);
    return context;
};
export const useSettings = () => {
    return getContext(key);
};
