define(["exports", "core/pubsubhub", "core/l10n"], function (exports, _pubsubhub, _l10n) {
  "use strict";

  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.name = undefined;
  exports.run = run;

  var _templateObject = _taggedTemplateLiteral(["\n    <a href=\"", "\">\n      ", "\n    </a>\n  "], ["\n    <a href=\"", "\">\n      ", "\n    </a>\n  "]),
      _templateObject2 = _taggedTemplateLiteral(["\n        <summary>\n          tests: ", "\n        </summary>\n        <ul>", "</ul>\n      "], ["\n        <summary>\n          tests: ", "\n        </summary>\n        <ul>", "</ul>\n      "]);

  function _taggedTemplateLiteral(strings, raw) {
    return Object.freeze(Object.defineProperties(strings, {
      raw: {
        value: Object.freeze(raw)
      }
    }));
  }

  var l10n = {
    en: {
      missing_test_suite_uri: "Found tests in your spec, but missing '" + "[`testSuiteURI`](https://github.com/w3c/respec/wiki/testSuiteURI)' in your ReSpec config.",
      tests: "tests",
      test: "test"
    }
  };
  var name = exports.name = "core/data-tests";

  var lang = _l10n.lang in l10n ? _l10n.lang : "en";

  function toListItem(href) {
    return hyperHTML.bind(document.createElement("li"))(_templateObject, href, href.split("/").pop());
  }

  function run(conf, doc, cb) {
    var testables = doc.querySelectorAll("[data-tests]");
    if (!testables.length) {
      return cb();
    }
    if (!conf.testSuiteURI) {
      (0, _pubsubhub.pub)("error", l10n[lang].missing_test_suite_uri);
      return cb();
    }
    Array.from(testables).filter(function (elem) {
      return elem.dataset.tests;
    }
    // Render details + ul, returns HTMLDetailsElement
    ).map(function (elem) {
      var details = document.createElement("details");
      var renderer = hyperHTML.bind(details);
      var testURLs = elem.dataset.tests.split(/\s+/gm).map(function (url) {
        var href = "";
        try {
          href = new URL(url, conf.testSuiteURI).href;
        } catch (err) {
          (0, _pubsubhub.pub)("warn", l10n[lang].bad_uri + ": " + url);
        }
        return href;
      });
      details.classList.add("respec-tests-details", "removeOnSave");
      renderer(_templateObject2, testURLs.length, testURLs.map(toListItem));
      return { elem: elem, details: details };
    }).forEach(function (_ref) {
      var elem = _ref.elem,
          details = _ref.details;

      delete elem.dataset.tests;
      elem.insertAdjacentElement("beforeend", details);
    });
    cb();
  }
});
//# sourceMappingURL=data-tests.js.map