import { writable, derived } from 'svelte/store';

function createVersionStore() {
  const { subscribe, set, update } = writable({"auth":null});

  return {
    subscribe,

    set: (v) => {
      update((m) => Object.assign(m, v));
    },

    update,

    refresh: async () => {
      const version = await (await fetch('api/version', {headers: {'Accept': 'application/json'}})).json()
      update((m) => version);
      return version;
    },
  };

}

export const version = createVersionStore();

export const auth = derived(
  version,
  $version => $version.auth,
);
