/* See license.txt for terms of usage */

"use strict";

module.metadata = {
  "stability": "experimental"
};

const { Trace, TraceError } = require("../core/trace.js");
const { Domplate } = require("../core/domplate.js");
const { Rep } = require("./rep.js");
const { Reps } = require("./reps.js");

// Domplate
const { domplate } = Domplate;
const { OBJECTLINK } = Rep.tags;

/**
 * @rep
 */
var Event = domplate(Rep,
/** @lends Event */
{
  className: "event",

  tag:
    OBJECTLINK("$object|summarizeEvent"),

  summarizeEvent: function(grip) {
    var info = [grip.preview.type, " "];

    let eventFamily = grip.class;
    let props = grip.preview.properties;

    if (eventFamily == "MouseEvent")
      info.push("clientX=", props.clientX, ", clientY=", props.clientY);
    else if (eventFamily == "key")
      info.push("charCode=", props.charCode, ", keyCode=", props.keyCode);
    else if (event.type == "message")
      info.push("origin=", props.origin, ", data=", props.data);

    return info.join("");
  },

  supportsObject: function(grip, type) {
    return (grip.preview && grip.preview.kind == "DOMEvent");
  },

  getTitle: function(grip, context) {
    return "Event " + grip.type;
  }
});

// Registration
Reps.registerRep(Event);

// Exports from this module
exports.Event = Event;

@@ -799,19 +799,29 @@
 ily == %22
-k
+K
 ey
+boardEvent
 %22)%0A     
@@ -912,25 +912,31 @@
 vent
-.type
+Family
  == %22
-m
+M
 essage
+Event
 %22)%0A 

Fix event class name