"use strict";

exports.__esModule = true;
exports.default = void 0;
var _noop2 = _interopRequireDefault(require("lodash/fp/noop"));
var _omit2 = _interopRequireDefault(require("lodash/fp/omit"));
var _snakeCase2 = _interopRequireDefault(require("lodash/fp/snakeCase"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _loader = _interopRequireDefault(require("../loader"));
var _buttonLink = _interopRequireDefault(require("../button-link"));
var _style = _interopRequireDefault(require("./style.css"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
const ConfirmationInput = ({
  onChange,
  placeholder = ''
}) => {
  const handleOnChange = (0, _react.useMemo)(() => e => {
    return onChange(e.target.value);
  }, [onChange]);
  return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("input", {
    "data-testid": "input",
    onInput: handleOnChange,
    placeholder: placeholder,
    className: _style.default.input,
    onChange: _noop2.default
  }));
};
ConfirmationInput.propTypes = process.env.NODE_ENV !== "production" ? {
  onChange: _propTypes.default.func,
  placeholder: _propTypes.default.string
} : {};
const ConfirmationForm = props => {
  const {
    confirmValue,
    confirmDisabled = false,
    onConfirm,
    cancelValue,
    onHandleClose,
    onChange,
    textValidation,
    placeholder,
    isPending = false
  } = props;
  const form = /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.confirmForm
  }, textValidation ? /*#__PURE__*/_react.default.createElement(ConfirmationInput, {
    onChange: onChange,
    placeholder: placeholder
  }) : /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.confirmEmptySpace
  }), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.confirmationCTAWrapper
  }, /*#__PURE__*/_react.default.createElement(_buttonLink.default, {
    label: cancelValue,
    "data-testid": "cancel-confirmation-button",
    onClick: onHandleClose
  }), /*#__PURE__*/_react.default.createElement(_buttonLink.default, {
    label: confirmValue,
    disabled: confirmDisabled,
    "data-testid": "confirm-delete-button",
    onClick: onConfirm,
    customStyle: {
      backgroundColor: 'orange',
      color: 'white'
    }
  })));
  return isPending ? /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.confirmForm
  }, /*#__PURE__*/_react.default.createElement(_loader.default, null)) : form;
};
ConfirmationForm.propTypes = process.env.NODE_ENV !== "production" ? {
  confirmValue: _propTypes.default.string.isRequired,
  confirmDisabled: _propTypes.default.bool,
  onConfirm: _propTypes.default.func.isRequired,
  cancelValue: _propTypes.default.string.isRequired,
  onHandleClose: _propTypes.default.func.isRequired,
  textValidation: _propTypes.default.bool,
  isPending: _propTypes.default.bool,
  ...ConfirmationInput.propTypes
} : {};
const Confirmation = props => {
  const {
    description
  } = props;
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.sectionConfirm
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.description
  }, description), /*#__PURE__*/_react.default.createElement(ConfirmationForm, props));
};
Confirmation.propTypes = process.env.NODE_ENV !== "production" ? {
  description: _propTypes.default.string
} : {};
const inputDoubleProps = process.env.NODE_ENV !== "production" ? (0, _omit2.default)(['onConfirm', 'onHandleClose'], {
  ...Confirmation.propTypes
}) : {};
class InputDoublestep extends _react.default.Component {
  constructor(props, context) {
    super(props);
    this.state = {
      open: false
    };
    this.handleToggle = this.handleToggle.bind(this);
    this.handleOnClick = this.handleOnClick.bind(this);
  }
  handleToggle() {
    this.setState(state => ({
      open: !state.open
    }));
    const {
      open
    } = this.state;
    const {
      onCloseConfirmation = _noop2.default,
      onOpenConfirmation = _noop2.default
    } = this.props;
    open ? onCloseConfirmation() : onOpenConfirmation();
  }
  handleOnClick(e) {
    e.preventDefault();
    this.setState({
      open: false
    });
    const {
      onClick = _noop2.default
    } = this.props;
    return onClick(e);
  }
  render() {
    const {
      toggleValue,
      disabled,
      icon
    } = this.props;
    const {
      open
    } = this.state;
    const formView = !open ? /*#__PURE__*/_react.default.createElement(_buttonLink.default, _extends({}, icon ? {
      icon: {
        position: 'left',
        faIcon: {
          name: icon,
          color: '#ffffff',
          size: 16
        }
      }
    } : {}, {
      type: "dangerous",
      label: toggleValue,
      disabled: disabled,
      "data-testid": "input-toggle-button",
      onClick: this.handleToggle
    })) : /*#__PURE__*/_react.default.createElement(Confirmation, _extends({}, this.props, {
      onHandleClose: this.handleToggle,
      onConfirm: this.handleOnClick
    }));
    return /*#__PURE__*/_react.default.createElement("div", {
      className: _style.default.wrapper
    }, /*#__PURE__*/_react.default.createElement("div", {
      "data-name": `input_doublestep_${(0, _snakeCase2.default)(toggleValue)}`,
      className: _style.default.value
    }, formView));
  }
}
InputDoublestep.propTypes = process.env.NODE_ENV !== "production" ? {
  toggleValue: _propTypes.default.string.isRequired,
  onClick: _propTypes.default.func.isRequired,
  onOpenConfirmation: _propTypes.default.func,
  onCloseConfirmation: _propTypes.default.func,
  icon: _propTypes.default.string,
  ...inputDoubleProps
} : {};
var _default = exports.default = InputDoublestep;
//# sourceMappingURL=index.js.map