"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _omit = _interopRequireDefault(require("omit.js"));
var _switch = _interopRequireDefault(require("../switch"));
require("./style");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * 评分组件
 *
 * @param
 */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__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
        children: dom
      }));
    }
    return dom || '-';
  }
  if (mode === 'edit' || mode === 'update') {
    const dom = /*#__PURE__*/(0, _jsxRuntime.jsx)(_switch.default, {
      ref: ref,
      ...(0, _omit.default)(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;
};
var _default = /*#__PURE__*/_react.default.forwardRef(FieldSwitch);
exports.default = _default;