'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var React = require('react');
var formik = require('formik');
var jsxRuntime = require('react/jsx-runtime');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var neetoAtoms = require('@bigbinary/neeto-atoms');
var ramda = require('ramda');

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

var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties);
var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray);

var _excluded$2 = ["formikProps", "formProps", "children"];
function ownKeys$2(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$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var FormikForm = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
  var formikProps = _ref.formikProps,
    formProps = _ref.formProps,
    _children = _ref.children,
    rest = _objectWithoutProperties__default.default(_ref, _excluded$2);
  return /*#__PURE__*/jsxRuntime.jsx(formik.Formik, _objectSpread$2(_objectSpread$2({}, formikProps), {}, {
    children: function children(formikBag) {
      return /*#__PURE__*/jsxRuntime.jsx(formik.Form, _objectSpread$2(_objectSpread$2({}, _objectSpread$2(_objectSpread$2({
        ref: ref
      }, formProps), rest)), {}, {
        children: typeof _children === "function" ? _children(formikBag) : _children
      }));
    }
  }));
});
FormikForm.displayName = "FormikForm";

var _excluded$1 = ["name", "label", "required", "stacked", "className", "onChange", "children"];
function ownKeys$1(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$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var FormikRadioGroup = function FormikRadioGroup(_ref) {
  var name = _ref.name,
    label = _ref.label,
    required = _ref.required,
    stacked = _ref.stacked,
    className = _ref.className,
    onChangeProp = _ref.onChange,
    children = _ref.children,
    rest = _objectWithoutProperties__default.default(_ref, _excluded$1);
  var _useField = formik.useField(name),
    _useField2 = _slicedToArray__default.default(_useField, 3),
    field = _useField2[0],
    meta = _useField2[1],
    helpers = _useField2[2];
  var hasError = meta.touched && meta.error;
  return /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.RadioGroup, _objectSpread$1(_objectSpread$1({
    className: className,
    label: label,
    required: required,
    error: hasError ? meta.error : "",
    orientation: stacked ? "vertical" : "horizontal",
    value: field.value,
    onValueChange: function onValueChange(val) {
      helpers.setValue(val);
      onChangeProp === null || onChangeProp === void 0 || onChangeProp({
        target: {
          value: val
        }
      });
    }
  }, rest), {}, {
    children: children
  }));
};
FormikRadioGroup.Item = neetoAtoms.RadioGroup.Item;

var _excluded = ["name", "onOpenChange", "onChange"];
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 FormikSelect = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var name = props.name,
    _onOpenChange = props.onOpenChange,
    _onChange = props.onChange,
    otherProps = _objectWithoutProperties__default.default(props, _excluded);
  var _useField = formik.useField(name),
    _useField2 = _slicedToArray__default.default(_useField, 3),
    field = _useField2[0],
    meta = _useField2[1],
    _useField2$ = _useField2[2],
    setValue = _useField2$.setValue,
    setTouched = _useField2$.setTouched;
  var _useFormikContext = formik.useFormikContext(),
    _useFormikContext$sta = _useFormikContext.status,
    status = _useFormikContext$sta === void 0 ? {} : _useFormikContext$sta,
    setStatus = _useFormikContext.setStatus;
  var fieldStatus = formik.getIn(status, name);
  var selectProps = _objectSpread(_objectSpread({}, otherProps), {}, {
    ref: ref,
    error: meta.touched ? meta.error || fieldStatus : "",
    name: field.name,
    value: field.value,
    onOpenChange: function onOpenChange(open) {
      if (!open) setTouched(true);
      _onOpenChange === null || _onOpenChange === void 0 || _onOpenChange(open);
    },
    onChange: function onChange(value) {
      setStatus(ramda.dissoc(name, status));
      setValue(value);
      _onChange === null || _onChange === void 0 || _onChange(value);
    }
  });
  return /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Select, _objectSpread({}, selectProps));
});
FormikSelect.displayName = "FormikSelect";

exports.FormikForm = FormikForm;
exports.FormikRadioGroup = FormikRadioGroup;
exports.FormikSelect = FormikSelect;
//# sourceMappingURL=Select-CshPoN2b.js.map
