import { __exports as p } from "../../../../../../_virtual/feeds.js";
import { __require as B } from "./stringify.js";
import { __require as w } from "./legacy.js";
var b;
function C() {
  if (b) return p;
  b = 1, Object.defineProperty(p, "__esModule", { value: !0 }), p.getFeed = _;
  var D = /* @__PURE__ */ B(), m = /* @__PURE__ */ w();
  function _(r) {
    var t = v(x, r);
    return t ? t.name === "feed" ? k(t) : E(t) : null;
  }
  function k(r) {
    var t, e = r.children, i = {
      type: "atom",
      items: (0, m.getElementsByTagName)("entry", e).map(function(s) {
        var d, a = s.children, o = { media: c(a) };
        l(o, "id", "id", a), l(o, "title", "title", a);
        var g = (d = v("link", a)) === null || d === void 0 ? void 0 : d.attribs.href;
        g && (o.link = g);
        var h = f("summary", a) || f("content", a);
        h && (o.description = h);
        var y = f("updated", a);
        return y && (o.pubDate = new Date(y)), o;
      })
    };
    l(i, "id", "id", e), l(i, "title", "title", e);
    var n = (t = v("link", e)) === null || t === void 0 ? void 0 : t.attribs.href;
    n && (i.link = n), l(i, "description", "subtitle", e);
    var u = f("updated", e);
    return u && (i.updated = new Date(u)), l(i, "author", "email", e, !0), i;
  }
  function E(r) {
    var t, e, i = (e = (t = v("channel", r.children)) === null || t === void 0 ? void 0 : t.children) !== null && e !== void 0 ? e : [], n = {
      type: r.name.substr(0, 3),
      id: "",
      items: (0, m.getElementsByTagName)("item", r.children).map(function(s) {
        var d = s.children, a = { media: c(d) };
        l(a, "id", "guid", d), l(a, "title", "title", d), l(a, "link", "link", d), l(a, "description", "description", d);
        var o = f("pubDate", d) || f("dc:date", d);
        return o && (a.pubDate = new Date(o)), a;
      })
    };
    l(n, "title", "title", i), l(n, "link", "link", i), l(n, "description", "description", i);
    var u = f("lastBuildDate", i);
    return u && (n.updated = new Date(u)), l(n, "author", "managingEditor", i, !0), n;
  }
  var F = ["url", "type", "lang"], q = [
    "fileSize",
    "bitrate",
    "framerate",
    "samplingrate",
    "channels",
    "duration",
    "height",
    "width"
  ];
  function c(r) {
    return (0, m.getElementsByTagName)("media:content", r).map(function(t) {
      for (var e = t.attribs, i = {
        medium: e.medium,
        isDefault: !!e.isDefault
      }, n = 0, u = F; n < u.length; n++) {
        var s = u[n];
        e[s] && (i[s] = e[s]);
      }
      for (var d = 0, a = q; d < a.length; d++) {
        var s = a[d];
        e[s] && (i[s] = parseInt(e[s], 10));
      }
      return e.expression && (i.expression = e.expression), i;
    });
  }
  function v(r, t) {
    return (0, m.getElementsByTagName)(r, t, !0, 1)[0];
  }
  function f(r, t, e) {
    return e === void 0 && (e = !1), (0, D.textContent)((0, m.getElementsByTagName)(r, t, e, 1)).trim();
  }
  function l(r, t, e, i, n) {
    n === void 0 && (n = !1);
    var u = f(e, i, n);
    u && (r[t] = u);
  }
  function x(r) {
    return r === "rss" || r === "feed" || r === "rdf:RDF";
  }
  return p;
}
export {
  C as __require
};
//# sourceMappingURL=feeds.js.map
