import React from 'react';
import Omit from 'omit.js';
import Switch from '../switch';
import './style';

/**
 * 评分组件
 *
 * @param
 */
import { Fragment as _Fragment } from "react/jsx-runtime";
import { jsx as _jsx } from "react/jsx-runtime";
const FieldSwitch = ({
  text,
  mode,
  render,
  renderFormItem,
  fieldProps
}, ref) => {
  if (mode === 'read') {
    const dom = text ? fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.checkedChildren : fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.unCheckedChildren;
    if (render) {
      return render(text, {
        mode,
        ...fieldProps
      }, /*#__PURE__*/_jsx(_Fragment, {
        children: dom
      }));
    }
    return dom || '-';
  }
  if (mode === 'edit' || mode === 'update') {
    const dom = /*#__PURE__*/_jsx(Switch, {
      ref: ref,
      ...Omit(fieldProps, ['value']),
      checked: (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.checked) || (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.value)
    });
    if (renderFormItem) {
      return renderFormItem(text, {
        mode,
        ...fieldProps
      }, dom);
    }
    return dom;
  }
  return null;
};
export default /*#__PURE__*/React.forwardRef(FieldSwitch);