"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useCopyToClipboardAction = void 0;
var _react = _interopRequireDefault(require("react"));
var _eui = require("@elastic/eui");
var _i18n = require("@kbn/i18n");
var _mlAggUtils = require("@kbn/ml-agg-utils");
var _table_action_button = require("./table_action_button");
var _get_table_item_as_kql = require("./get_table_item_as_kql");
/*
 * 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.
 */

const copyToClipboardButtonLabel = _i18n.i18n.translate('xpack.aiops.logRateAnalysis.resultsTable.linksMenu.copyToClipboardButtonLabel', {
  defaultMessage: 'Copy to clipboard'
});
const copyToClipboardSignificantTermMessage = _i18n.i18n.translate('xpack.aiops.logRateAnalysis.resultsTable.linksMenu.copyToClipboardSignificantTermMessage', {
  defaultMessage: 'Copy field/value pair as KQL syntax to clipboard'
});
const copyToClipboardGroupMessage = _i18n.i18n.translate('xpack.aiops.logRateAnalysis.resultsTable.linksMenu.copyToClipboardGroupMessage', {
  defaultMessage: 'Copy group items as KQL syntax to clipboard'
});
const useCopyToClipboardAction = () => ({
  render: tableItem => {
    const message = (0, _mlAggUtils.isSignificantTerm)(tableItem) ? copyToClipboardSignificantTermMessage : copyToClipboardGroupMessage;
    return /*#__PURE__*/_react.default.createElement(_eui.EuiToolTip, {
      content: message
    }, /*#__PURE__*/_react.default.createElement(_eui.EuiCopy, {
      textToCopy: (0, _get_table_item_as_kql.getTableItemAsKQL)(tableItem)
    }, copy => /*#__PURE__*/_react.default.createElement(_table_action_button.TableActionButton, {
      dataTestSubjPostfix: "CopyToClipboard",
      iconType: "copyClipboard",
      isDisabled: false,
      label: copyToClipboardButtonLabel,
      onClick: copy
    })));
  }
});
exports.useCopyToClipboardAction = useCopyToClipboardAction;