// Export the Planet object
var Planet;

(function() {

// Clean up the default table feed content
function cleanBug(feed) {
  // Remove the bug number from the title
  let [, num, summary] = feed.title.match(/\[Bug (\d+)\] (.*)/);
  feed.title = summary;

  // Convert the feed html content into the table
  let table = $(feed.content);

  // Grab the value for each field and store it in a hash
  let fields = "Product,Component,Assignee,Reporter,Status,Resolution,Priority,Severity,Target Milestone,Opened,Changed".split(",").
    reduce(function(fields, entry) {
      fields[entry.replace(/ /g, "")] = table.find("td:contains(" + entry + ")").next().text();
      return fields;
    }, {});

  let status = (fields.Status + " " + fields.Resolution).trim();
  let who = "Reporter: " + fields.Reporter;
  if (fields.Assignee.split(";")[0] != "Nobody")
    who = "Assignee: " + fields.Assignee;
  let severity = fields.Severity.substring(0, 3);

  // Replace the content with something less table-y
  feed.content = "(" + [status, num, severity, fields.Priority, fields.TargetMilestone].join(", ") + ") " + who;
}

// Ignore the content
function ignore(feed) {
  feed.content = "";
}

const ED = "http://ed.agadak.net/";
const AZA = "http://www.azarask.in/blog/post/";
const LAB = "http://labs.mozilla.com/";
const SEAN = "http://blog.seanmartell.com/";
const BUG = "https://bugzilla.mozilla.org/buglist.cgi?component=New+Tab&chfieldfrom=1w&order=bugs.delta_ts+desc";
const WP = "/feed/atom";

Planet = [[
  ["code", "about-tab commits", "http://hg.mozilla.org/users/dmills_mozilla.com/about-tab", "/atom-log", ignore],
  ["bugs", "Newly Created Bugs", BUG + "&chfield=[Bug+creation]&bug_status=NEW", "&ctype=atom", cleanBug],
  ["bugs", "Recently Resolved Bugs", BUG + "&chfield=bug_status&chfieldvalue=RESOLVED", "&ctype=atom", cleanBug],
  ["comments", "Firefox New Tab: Visual Update", AZA + "firefox-new-tab-visual-update", WP],
  ["comments", "Firefox New Tab: Now With More Pixels!", SEAN + "2009/04/13/firefox-new-tab-now-with-more-pixels", WP],
  ["comments", "Firefox New Tab: Visual Update", LAB + "2009/04/firefox-new-tab-visual-update", WP],
  ["comments", "Firefox New Tab: In-Line Search", AZA + "firefox-new-tab-in-line-search", WP],
  ["comments", "Firefox New Tab: Latest Iteration & Next Steps", LAB + "2009/03/firefox-new-tab-latest-iteration-next-steps", WP],
  ["comments", "Cognitive Shield for the Firefox New Tab", AZA + "cognitive-shield-for-the-firefox-new-tab", WP],
  ["comments", "Firefox New Tab Page: Cognitive Shield", LAB + "2009/03/firefox-new-tab-page-cognitive-shield", WP],
  ["comments", "New Tab Text View & Customizations", ED + "2009/03/new-tab-text-view-customizations", WP],
  ["comments", "Firefox New Tab: Next Iteration", LAB + "2009/03/firefox-new-tab-next-iteration", WP],
  ["comments", "New Tab for Firefox: Iterations", AZA + "new-tab-iterations", WP],
  ["comments", "About:Tab (New Tab Page From Mozilla Labs)", ED + "2009/03/abouttab-new-tab-page-from-mozilla-labs", WP],
  ["comments", "New Tab Page: Proposed design principles and prototype", LAB + "2009/03/new-tab-page-proposed-design-principles-and-prototype", WP],
  ["comments", "Firefox 3.1 New Tab Specification", AZA + "firefox-31-new-tab-spec", WP],
  ["comments", "New Tab Concepts", LAB + "2008/08/new-tab-concepts", WP],
],
"Planet New Tab", 3];

})();
