'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
require('react');
var classnames = require('classnames');
var formik = require('formik');
var reactI18next = require('react-i18next');
var Button = require('../Button.js');
var index = require('../index-CNZKW5X0.js');
var formik_Button = require('./Button.js');
var jsxRuntime = require('react/jsx-runtime');
require('@babel/runtime/helpers/objectWithoutProperties');
require('react-router-dom');
require('../Spinner.js');
require('../Tooltip.js');
require('@babel/runtime/helpers/slicedToArray');
require('@tippyjs/react');
require('tippy.js');
require('@bigbinary/neeto-hotkeys');
require('../overlayManager.js');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
require('@bigbinary/neeto-cist');
require('qs');
require('ramda');
require('../index-BgzkP01c.js');
require('@babel/runtime/helpers/toConsumableArray');
require('dayjs');
require('dayjs/plugin/localeData');
require('dayjs/plugin/utc');
require('dayjs/plugin/weekday');
require('dayjs/plugin/weekOfYear');
require('i18next');
require('../usePrefersReducedMotion-D2Ck84HM.js');
require('../en-B1i-pQJm.js');

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

var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var POSITIONS = {
  left: "left",
  right: "right"
};
var ActionBlock = function ActionBlock(_ref) {
  var className = _ref.className,
    submitButtonProps = _ref.submitButtonProps,
    cancelButtonProps = _ref.cancelButtonProps,
    isFormSubmitting = _ref.isSubmitting,
    _ref$position = _ref.position,
    position = _ref$position === void 0 ? POSITIONS.left : _ref$position;
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t,
    i18n = _useTranslation.i18n;
  var _useFormikContext = formik.useFormikContext(),
    handleReset = _useFormikContext.handleReset,
    isFormikSubmitting = _useFormikContext.isSubmitting,
    dirty = _useFormikContext.dirty;
  var isSubmitting = isFormSubmitting !== null && isFormSubmitting !== void 0 ? isFormSubmitting : isFormikSubmitting;
  var isButtonPositionRight = position === POSITIONS.right;
  var cancelButton = /*#__PURE__*/jsxRuntime.jsx(Button, _objectSpread({
    "data-testid": "cancel-button",
    disabled: isSubmitting,
    label: index.getLocale(i18n, t, "neetoui.actionBlock.cancel"),
    style: "text",
    onClick: handleReset,
    onMouseDown: function onMouseDown(e) {
      return e.preventDefault();
    }
  }, cancelButtonProps));
  var submitButton = /*#__PURE__*/jsxRuntime.jsx(formik_Button, _objectSpread({
    "data-testid": "save-changes-button",
    disabled: isSubmitting || !dirty,
    label: index.getLocale(i18n, t, "neetoui.actionBlock.saveChanges"),
    loading: isSubmitting,
    style: "primary",
    type: "submit"
  }, submitButtonProps));
  return /*#__PURE__*/jsxRuntime.jsx("div", {
    className: classnames__default.default(["neeto-ui-action-block__wrapper", {
      "justify-end": isButtonPositionRight
    }, className]),
    children: isButtonPositionRight ? /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
      children: [cancelButton, submitButton]
    }) : /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
      children: [submitButton, cancelButton]
    })
  });
};

module.exports = ActionBlock;
//# sourceMappingURL=ActionBlock.js.map
