import * as dntShim from "./_dnt.shims.js";
import type { 
  StorageArea as IStorageArea, Options, AllowedKey, Key 
} from 'kv-storage-interface';
export type { Options, AllowedKey, Key }

import * as dn from '@worker-tools/deno-kv-storage';
import * as cf from '@worker-tools/cloudflare-kv-storage';
import * as br from '@worker-tools/kv-storage-polyfill';

type StorageAreaConstructor = new (name: string, opts?: Options) => IStorageArea;
type StorageAreaClass = StorageAreaConstructor & { prototype: IStorageArea };

export const StorageArea: StorageAreaClass =
  'Deno' in dntShim.dntGlobalThis
    ? dn.StorageArea
    : navigator.userAgent?.includes('Cloudflare-Workers')
      ? cf.StorageArea
      : br.StorageArea;
