"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SpanLinksBadge = SpanLinksBadge;
var _eui = require("@elastic/eui");
var _i18n = require("@kbn/i18n");
var _react = _interopRequireDefault(require("react"));
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0; you may not use this file except in compliance with the Elastic License
 * 2.0.
 */

function SpanLinksBadge({
  linkedParents,
  linkedChildren,
  id,
  onClick
}) {
  if (!linkedParents && !linkedChildren) {
    return null;
  }
  const spanLinksFlyoutTab = 'span_links';
  const total = linkedParents + linkedChildren;
  return /*#__PURE__*/_react.default.createElement(_eui.EuiToolTip, {
    title: _i18n.i18n.translate('xpack.apm.waterfall.spanLinks.tooltip.title', {
      defaultMessage: '{total} {total, plural, one {Span link} other {Span links}} found',
      values: {
        total
      }
    }),
    content: /*#__PURE__*/_react.default.createElement(_eui.EuiFlexGroup, {
      direction: "column",
      gutterSize: "xs"
    }, /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, null, _i18n.i18n.translate('xpack.apm.waterfall.spanLinks.tooltip.linkedChildren', {
      defaultMessage: '{linkedChildren} incoming',
      values: {
        linkedChildren
      }
    })), /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, null, _i18n.i18n.translate('xpack.apm.waterfall.spanLinks.tooltip.linkedParents', {
      defaultMessage: '{linkedParents} outgoing',
      values: {
        linkedParents
      }
    })))
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiBadge, {
    "data-test-subj": `spanLinksBadge_${id}`,
    onClick: e => {
      e.stopPropagation();
      onClick(spanLinksFlyoutTab);
    },
    onClickAriaLabel: _i18n.i18n.translate('xpack.apm.waterfall.spanLinks.badgeAriaLabel', {
      defaultMessage: 'Open span links details'
    })
  }, _i18n.i18n.translate('xpack.apm.waterfall.spanLinks.badge', {
    defaultMessage: '{total} {total, plural, one {Span link} other {Span links}}',
    values: {
      total
    }
  })));
}