'use strict';

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

/**
 *+------------------------------------------------------------------------+
 *| Licensed Materials - Property of IBM
 *| IBM Cognos Products: Dashboard
 *| (C) Copyright IBM Corp. 2019
 *|
 *| US Government Users Restricted Rights - Use, duplication or disclosure
 *| restricted by GSA ADP Schedule Contract with IBM Corp.
 *+------------------------------------------------------------------------+
 */
define(['jquery', '../common/NonVIPREventTarget'], function ($, NonVIPREventTarget) {

	var BASE_SLOT_ID = 'actual';
	var TARGET_SLOT_ID = 'goal';

	var KpiEventTarget = function (_NonVIPREventTarget) {
		_inherits(KpiEventTarget, _NonVIPREventTarget);

		function KpiEventTarget() {
			var _ret;

			_classCallCheck(this, KpiEventTarget);

			for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
				args[_key] = arguments[_key];
			}

			var _this = _possibleConstructorReturn(this, _NonVIPREventTarget.call.apply(_NonVIPREventTarget, [this].concat(args)));

			var options = args[0] || {};
			_this.visControl = options.visControl;
			_this.view = options.view;
			_this.visualization = options.visualization;
			return _ret = _this.getAPI(), _possibleConstructorReturn(_this, _ret);
		}

		/**
   * Get the array of event targets based on the event.
   * Event target represents a data point object that corresponds to the event.
   *
   * @param event	Event object
   */


		KpiEventTarget.prototype.getEventTargets = function getEventTargets(event) {
			var node = this._getTargetNode(event);

			if (!node || event.type === 'click') {
				return [];
			}

			var $node = $(node);
			//ignore the general widget
			if (!this.mouseWithinBoundCheck(event) || $node.hasClass('kpi-widget-content')) {
				return [];
			}
			return this._getTargets(event, $node);
		};

		KpiEventTarget.prototype.remove = function remove() {
			this.visControl = null;
			this.view = null;
			_NonVIPREventTarget.prototype.remove.call(this);
		};

		KpiEventTarget.prototype._getTargets = function _getTargets(event, $node) {
			var targets = [];
			var kpiNode$ = $($node.closest('.kpi-widget-value')[0]);

			// Possible the user clicked on the sparkline.  If so ignore it.
			if (!kpiNode$.length) {
				return targets;
			}

			var selectionContext = this._getTargetSelectionContext(kpiNode$);
			if (selectionContext) {
				targets.push({
					key: $node.parent().attr('class'),
					type: 'datapoint',
					selectionContext: selectionContext,
					slotAPIs: selectionContext.slots,
					source: $node,
					isEdgeSelect: true,
					values: this._getTargetValues(kpiNode$),
					area: 'visualization'
				});
			}

			return targets;
		};

		KpiEventTarget.prototype._getTargetSelectionContext = function _getTargetSelectionContext($node) {
			var slot = void 0;
			var slots = this.visualization.getSlots();
			if ($node.hasClass('kpi-widget-base-value')) {
				slot = slots.getSlot(BASE_SLOT_ID);
			} else if ($node.hasClass('kpi-widget-target-value')) {
				slot = slots.getSlot(TARGET_SLOT_ID);
				//fix to disable event target for property set target value
				if (slot.getDataItemList().length === 0) {
					return null;
				}
			}
			return {
				mapIndex: 0,
				slots: [slot]
			};
		};

		KpiEventTarget.prototype._getTargetValues = function _getTargetValues($node) {
			var slots = [];
			var value = void 0;
			if ($node.hasClass('kpi-widget-base-value')) {
				value = this.view.getBaseValue();
			} else if ($node.hasClass('kpi-widget-target-value')) {
				value = this.view.getTargetValue();
			}
			if ($.isNumeric(value)) {
				slots.push([value]);
			}
			return slots;
		};

		return KpiEventTarget;
	}(NonVIPREventTarget);

	return KpiEventTarget;
});
//# sourceMappingURL=KpiEventTarget.js.map