import React, { useContext } from 'react';
import Space from '../space';
import ConfigProvider from '../config-provider';
import './style';
import { jsx as _jsx } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
const addArrayKeys = doms => doms.map((dom, index) => {
  if (! /*#__PURE__*/React.isValidElement(dom)) {
    // eslint-disable-next-line react/no-array-index-key
    return /*#__PURE__*/_jsx(React.Fragment, {
      children: dom
    }, index);
  }
  return /*#__PURE__*/React.cloneElement(dom, {
    // eslint-disable-next-line react/no-array-index-key
    key: index,
    ...(dom === null || dom === void 0 ? void 0 : dom.props)
  });
});

/**
 * 一般用于放多个按钮
 *
 * @param
 */
const FieldOptions = ({
  text,
  mode: type,
  render,
  fieldProps
}) => {
  const {
    getPrefixCls
  } = useContext(ConfigProvider.ConfigContext);
  const className = getPrefixCls('pro-field-option');
  if (render) {
    const doms = render(text, {
      mode: type,
      ...fieldProps
    }, /*#__PURE__*/_jsx(_Fragment, {}));
    if (!doms || (doms === null || doms === void 0 ? void 0 : doms.length) < 1 || !Array.isArray(doms)) {
      return null;
    }
    return /*#__PURE__*/_jsx(Space, {
      size: 16,
      className: className,
      children: addArrayKeys(doms)
    });
  }
  if (!text || !Array.isArray(text)) {
    if (! /*#__PURE__*/React.isValidElement(text)) {
      return null;
    }
    return text;
  }
  return /*#__PURE__*/_jsx(Space, {
    size: 16,
    className: className,
    children: addArrayKeys(text)
  });
};
export default FieldOptions;