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

  var Scheme, PolymorphicIdentifier, focalStorage, parseQuery, getDeepProperty, FileIndex;
  return {
    setters: [function (_srcClientPoidJs) {
      Scheme = _srcClientPoidJs.Scheme;
      PolymorphicIdentifier = _srcClientPoidJs.default;
    }, function (_srcExternalFocalStorageJs) {
      focalStorage = _srcExternalFocalStorageJs.default;
    }, function (_utils) {
      parseQuery = _utils.parseQuery;
      getDeepProperty = _utils.getDeepProperty;
    }, function (_srcClientFileindexJs) {
      FileIndex = _srcClientFileindexJs.default;
    }],
    execute: function () {
      const __SystemJSRewritingHack = {};
      _recorder_._src_client_protocols_bib_js = _recorder_._src_client_protocols_bib_js || {};
      Object.defineProperty(_recorder_._src_client_protocols_bib_js, "Scheme", {
        get() {
          return Scheme;
        },

        set(thisIsVererySecretVariableName) {
          Scheme = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_client_protocols_bib_js, "PolymorphicIdentifier", {
        get() {
          return PolymorphicIdentifier;
        },

        set(thisIsVererySecretVariableName) {
          PolymorphicIdentifier = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_client_protocols_bib_js, "focalStorage", {
        get() {
          return focalStorage;
        },

        set(thisIsVererySecretVariableName) {
          focalStorage = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_client_protocols_bib_js, "getDeepProperty", {
        get() {
          return getDeepProperty;
        },

        set(thisIsVererySecretVariableName) {
          getDeepProperty = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_client_protocols_bib_js, "parseQuery", {
        get() {
          return parseQuery;
        },

        set(thisIsVererySecretVariableName) {
          parseQuery = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._src_client_protocols_bib_js, "FileIndex", {
        get() {
          return FileIndex;
        },

        set(thisIsVererySecretVariableName) {
          FileIndex = thisIsVererySecretVariableName;
          return true;
        },

        enumerable: true,
        configurable: true
      });
      class BibScheme extends Scheme {

        get scheme() {
          return "bib";
        }

        resolve() {
          return true;
        }

        async GET(options) {
          var key = this.url.replace(/bib\:\/\//, "");

          var entries = await FileIndex.current().db.bibliography.where("key").equals(key).toArray();
          var entry = entries[0] || {};

          var content = `<h2>[${key}]<br/>${entry.authors ? entry.authors + "." : ""}  ${entry.year || ""}<br/><i> ${entry.title || ""} </i></h2>`;

          if (entry.source) {
            content += "<pre>" + entry.source + "</pre>";
          }

          var files = await FileIndex.current().db.files.where("bibkey").equals(key).toArray();

          content += "<h3>Documents</h3><ul>" + files.map(ea => {
            return `<li><a href="${ea.url}">${ea.name}</a></li>`;
          }).join("\n") + "</ul>";

          content += "<h3>Bibliographies</h3><ul>" + entries.map(ea => {
            return `<li><a href="${ea.url}">${ea.url}</a></li>`;
          }).join("\n") + "</ul>";

          return new Response(content, {
            headers: {
              "content-type": "text/html"
            },
            status: 200
          });
        }

        async OPTIONS(options) {

          var content = JSON.stringify({}, undefined, 2);

          return new Response(content, {
            headers: {
              "content-type": "application/json"
            },
            status: 200
          });
        }

      }

      _export("BibScheme", BibScheme);

      Object.defineProperty(_recorder_._src_client_protocols_bib_js, "BibScheme", {
        get() {
          return BibScheme;
        },

        set(thisIsVererySecretVariableName) {
          _export("BibScheme", BibScheme = thisIsVererySecretVariableName);

          return true;
        },

        enumerable: true,
        configurable: true
      });
      PolymorphicIdentifier.register(BibScheme);
    }
  };
});