System.register(["src/external/focalStorage.js"], function (_export, _context) {
  "use strict";

  var focalStorage, Favorites, __SystemJSRewritingHack, MAIN_DIRECTORY, MATCH_MAIN_DIRECTORY, STORAGE_KEY;
  function toFullURL(url) {
    return new URL(url, MAIN_DIRECTORY).toString();
  }
  function removeMainDirectory(fullURL) {
    return fullURL.replace(MATCH_MAIN_DIRECTORY, '');
  }
  _export("default", void 0);
  return {
    setters: [function (_srcExternalFocalStorageJs) {
      focalStorage = _srcExternalFocalStorageJs.default;
    }],
    execute: function () {
      __SystemJSRewritingHack = {};
      _recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_favorites_js = _recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_favorites_js || {};
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_favorites_js, "removeMainDirectory", {
        get() {
          return removeMainDirectory;
        },
        set(thisIsVererySecretVariableName) {
          removeMainDirectory = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_favorites_js, "toFullURL", {
        get() {
          return toFullURL;
        },
        set(thisIsVererySecretVariableName) {
          toFullURL = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_favorites_js, "focalStorage", {
        get() {
          return focalStorage;
        },
        set(thisIsVererySecretVariableName) {
          focalStorage = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      MAIN_DIRECTORY = lively4url + '/';
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_favorites_js, "MAIN_DIRECTORY", {
        get() {
          return MAIN_DIRECTORY;
        },
        set(thisIsVererySecretVariableName) {
          MAIN_DIRECTORY = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      MATCH_MAIN_DIRECTORY = new RegExp('^' + MAIN_DIRECTORY, 'i');
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_favorites_js, "MATCH_MAIN_DIRECTORY", {
        get() {
          return MATCH_MAIN_DIRECTORY;
        },
        set(thisIsVererySecretVariableName) {
          MATCH_MAIN_DIRECTORY = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      STORAGE_KEY = 'favorite-files';
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_favorites_js, "STORAGE_KEY", {
        get() {
          return STORAGE_KEY;
        },
        set(thisIsVererySecretVariableName) {
          STORAGE_KEY = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      _export("default", Favorites = class Favorites {
        static async get() {
          const urls = (await focalStorage.getItem(STORAGE_KEY)) || [];
          const fullURLs = urls.map(toFullURL);
          return fullURLs;
        }
        static async set(fullURLs) {
          const relativeURLs = fullURLs.map(removeMainDirectory);
          return focalStorage.setItem(STORAGE_KEY, relativeURLs);
        }
        static async has(fullURL) {
          return (await this.get()).includes(fullURL);
        }
        static async add(newFullURL) {
          const fullURLs = new Set(await this.get());
          fullURLs.add(newFullURL);
          return this.set(Array.from(fullURLs));
        }
        static async remove(fullURL) {
          const fullURLs = new Set(await this.get());
          fullURLs.delete(fullURL);
          return this.set(Array.from(fullURLs));
        }
        static async toggle(fullURL) {
          if (await this.has(fullURL)) {
            await this.remove(fullURL);
          } else {
            await this.add(fullURL);
          }
        }
      });
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_client_favorites_js, "Favorites", {
        get() {
          return Favorites;
        },
        set(thisIsVererySecretVariableName) {
          _export("default", Favorites = thisIsVererySecretVariableName);
          return true;
        },
        enumerable: true,
        configurable: true
      });
    }
  };
});