'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _react = require('react');

var React = _interopRequireWildcard(_react);

var _rcFieldForm = require('rc-field-form');

var _devWarning = require('./devWarning');

var _devWarning2 = _interopRequireDefault(_devWarning);

var _context = require('antd/lib/config-provider/context');

var _context2 = require('./context');

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var __rest = undefined && undefined.__rest || function (s, e) {
    var t = {};
    for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
    }if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
        if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
    }
    return t;
};

var FormList = function FormList(_a) {
    var customizePrefixCls = _a.prefixCls,
        children = _a.children,
        props = __rest(_a, ["prefixCls", "children"]);

    (0, _devWarning2['default'])(!!props.name, 'Form.List', 'Miss `name` prop.');
    // @ts-ignore

    var _React$useContext = React.useContext(_context.ConfigContext),
        getPrefixCls = _React$useContext.getPrefixCls;

    var prefixCls = getPrefixCls('form', customizePrefixCls);
    return React.createElement(
        _rcFieldForm.List,
        props,
        function (fields, operation, meta) {
            return React.createElement(
                _context2.FormItemPrefixContext.Provider,
                { value: { prefixCls: prefixCls, status: 'error' } },
                children(fields.map(function (field) {
                    return (0, _extends3['default'])((0, _extends3['default'])({}, field), { fieldKey: field.key });
                }), operation, {
                    errors: meta.errors
                })
            );
        }
    );
};
exports['default'] = FormList;
module.exports = exports['default'];