'use strict';

var React = require('react');
var PropTypes = require('prop-types');
var react = require('@carbon/react');
var index = require('../../../Tooltip/index.js');
var Settings = require('../../../../constants/Settings.js');
var TablePropTypes = require('../../TablePropTypes.js');
var iconsReact = require('@carbon/icons-react');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);

var iotPrefix = Settings.settings.iotPrefix;
var propTypes = {
  /** I18N label for action failed */
  actionFailedText: PropTypes__default.default.string,
  /** I18N label for learn more */
  learnMoreText: PropTypes__default.default.string,
  /** I18N label for dismiss */
  dismissText: PropTypes__default.default.string,
  /** did an error occur */
  rowActionsError: TablePropTypes.RowActionErrorPropTypes,
  onClearError: PropTypes__default.default.func
};
var defaultProps = {
  actionFailedText: 'Action failed',
  learnMoreText: 'Learn more',
  dismissText: 'Dismiss',
  rowActionsError: null,
  onClearError: null
};
var RowActionsError = function RowActionsError(_ref) {
  var rowActionsError = _ref.rowActionsError,
    actionFailedText = _ref.actionFailedText,
    learnMoreText = _ref.learnMoreText,
    dismissText = _ref.dismissText,
    onClearError = _ref.onClearError;
  if (!rowActionsError) {
    return null;
  }
  var title = rowActionsError.title,
    message = rowActionsError.message,
    learnMoreURL = rowActionsError.learnMoreURL;
  return /*#__PURE__*/React__default.default.createElement(React.Fragment, null, /*#__PURE__*/React__default.default.createElement(index.Tooltip, {
    tabIndex: 0,
    triggerText: "",
    triggerId: "tooltip-error",
    tooltipId: "tooltip",
    renderIcon: /*#__PURE__*/React__default.default.forwardRef(function (props, ref) {
      return /*#__PURE__*/React__default.default.createElement(iconsReact.WarningAlt, {
        ref: ref
      });
    })
  }, /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(iotPrefix, "--row-actions-error--tooltip")
  }, /*#__PURE__*/React__default.default.createElement("p", {
    className: "".concat(iotPrefix, "--row-actions-error--title")
  }, title), message, /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(iotPrefix, "--row-actions-error--footer")
  }, learnMoreURL ? /*#__PURE__*/React__default.default.createElement("a", {
    href: learnMoreURL,
    target: "_blank",
    rel: "noopener noreferrer"
  }, learnMoreText) : /*#__PURE__*/React__default.default.createElement("div", null), onClearError ? /*#__PURE__*/React__default.default.createElement(react.Button, {
    onClick: function onClick(evt) {
      onClearError(evt);
      evt.stopPropagation();
    }
  }, dismissText) : null))), /*#__PURE__*/React__default.default.createElement("span", {
    className: "".concat(iotPrefix, "--row-actions-error--span")
  }, actionFailedText));
};
RowActionsError.propTypes = propTypes;
RowActionsError.defaultProps = defaultProps;
RowActionsError.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "RowActionsError",
  "props": {
    "actionFailedText": {
      "defaultValue": {
        "value": "'Action failed'",
        "computed": false
      },
      "description": "I18N label for action failed",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "learnMoreText": {
      "defaultValue": {
        "value": "'Learn more'",
        "computed": false
      },
      "description": "I18N label for learn more",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "dismissText": {
      "defaultValue": {
        "value": "'Dismiss'",
        "computed": false
      },
      "description": "I18N label for dismiss",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "rowActionsError": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "did an error occur",
      "type": {
        "name": "custom",
        "raw": "RowActionErrorPropTypes"
      },
      "required": false
    },
    "onClearError": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "func"
      },
      "required": false
    }
  }
};
var RowActionsError$1 = RowActionsError;

module.exports = RowActionsError$1;
