System.register(["src/client/poid.js", "src/external/focalStorage.js", "utils", "src/client/fileindex.js", "src/external/lodash/lodash.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;
    }, function (_srcExternalLodashLodashJs) {
      _ = _srcExternalLodashLodashJs.default;
    }],
    execute: function () {
      const __SystemJSRewritingHack = {};
      _recorder_._src_client_protocols_bibliography_scheme_js = _recorder_._src_client_protocols_bibliography_scheme_js || {};
      Object.defineProperty(_recorder_._src_client_protocols_bibliography_scheme_js, "Scheme", {
        get() {
          return Scheme;
        },

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

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

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

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

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

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

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

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

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

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

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

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

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

        enumerable: true,
        configurable: true
      });

      /*MD # Abstract Class for all Bibliograpgy Schemes MD*/

      class BibliographyScheme extends Scheme {

        get scheme() {
          throw new Error("subclass responsibility");
        }

        resolve() {
          return true;
        }

        generateArticlesSource(entries) {
          return "<h3>Articles</h3><ul>" + entries.map(ea => {
            return `<li><a href="bib://${ea.key}">[${ea.key}]</a> ${ea.authors.map(ea => `<a href="author://${ea}">${ea}</a>`).join(", ")}. ${ea.title}. ${ea.keywords.map(ea => `<a href="keyword://${ea}">${ea}</a>`).join(", ")}.</li>`;
          }).join("\n") + "</ul>";
        }

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

        async searchEntries(entries, query) {
          return entries;
        }

        async content(entries, query) {
          var content = `<h2>${this.scheme}: ${query}</h2>`;
          content += this.generateArticlesSource(entries);
          return content;
        }

        async GET(options) {
          var query = this.url.replace(new RegExp(this.scheme + "\:\/\/"), "");
          if (query.length < 2) return this.response("query to short");

          query = decodeURI(query);
          var entries = await FileIndex.current().db.bibliography.toArray();

          let filteredEntries = await this.searchEntries(entries, query

          // entries = _.uniqBy(entries, ea => ea.key)

          );var content = await this.content(filteredEntries, query);

          return this.response(content);
        }

        async OPTIONS(options) {
          var content = JSON.stringify({}, undefined, 2);
          return new Response(content, {
            headers: {
              "content-type": "application/json"
            },
            status: 200
          });
        }

      }

      _export("default", BibliographyScheme);

      Object.defineProperty(_recorder_._src_client_protocols_bibliography_scheme_js, "BibliographyScheme", {
        get() {
          return BibliographyScheme;
        },

        set(thisIsVererySecretVariableName) {
          _export("default", BibliographyScheme = thisIsVererySecretVariableName);

          return true;
        },

        enumerable: true,
        configurable: true
      });
    }
  };
});