System.register(["src/client/poid.js", "./bibliography-scheme.js", "src/client/fileindex.js", "src/client/literature.js"], function (_export, _context) {
  "use strict";

  var PolymorphicIdentifier, BibliographyScheme, FileIndex, Literature;
  return {
    setters: [function (_srcClientPoidJs) {
      PolymorphicIdentifier = _srcClientPoidJs.default;
    }, function (_bibliographySchemeJs) {
      BibliographyScheme = _bibliographySchemeJs.default;
    }, function (_srcClientFileindexJs) {
      FileIndex = _srcClientFileindexJs.default;
    }, function (_srcClientLiteratureJs) {
      Literature = _srcClientLiteratureJs.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, "PolymorphicIdentifier", {
        get() {
          return PolymorphicIdentifier;
        },

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

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

        set(thisIsVererySecretVariableName) {
          BibliographyScheme = 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
      });
      Object.defineProperty(_recorder_._src_client_protocols_bib_js, "Literature", {
        get() {
          return Literature;
        },

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

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

        get scheme() {
          return "bib";
        }

        async searchEntries(entries, query) {
          var key = query;
          return entries.filter(entry => entry.key == key);
        }

        async content(entries, query) {
          var entry = entries[0] || { authors: undefined, keywords: undefined, title: "" };
          var key = query;
          var files = await FileIndex.current().db.files.where("bibkey").equals(key).toArray();
          var literatureNotes = await FileIndex.current().db.files.filter(ea => ea.name.match(key + ".md")).toArray();

          var papers = await Literature.db.papers.where("key").equals(key).toArray();

          var content = `<h2>[${key}]<br/>${entry.authors ? entry.authors.map(ea => `<a href="author://${ea}">${ea}</a>`).join(", ") + "." : ""}  ${entry.year || ""}<br/><i> ${entry.title || ""} </i></h2>`;

          if (papers.length > 0) {
            content += "<div>" + papers.map(ea => {
              return `<academic-paper mode="short" microsoftid="${ea.microsoftid}"></academic-paper>`;
            }).join(" ") + "</div><br>";
          } else if (entry.year) {
            content += "<div>" + `<a href="academic://${entry.authors.join(",") + "." + entry.year}">[search academic]</a>` + "</div><br>";
          }

          if (entry.keywords) {
            content += `<div><b>Keywords:</b> ${entry.keywords.map(ea => `<a href="keyword://${ea}">${ea}</a>`).join(", ")} </div>`;
          }
          if (entry.source) {
            content += "<pre>" + entry.source + "</pre>";
          }
          content += "<h3>Documents</h3><ul>" + files.concat(literatureNotes).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 content;
        }
      }

      _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);
    }
  };
});