"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
require("core-js/modules/es.array.iterator.js");
require("core-js/modules/web.dom-collections.iterator.js");
var _react = _interopRequireDefault(require("react"));
var _icons = require("@wii/icons");
var _useMergedState = _interopRequireDefault(require("rc-util/es/hooks/useMergedState"));
var _input = _interopRequireDefault(require("../input"));
var _space = _interopRequireDefault(require("../space"));
var _wauProvider = require("../wau-provider");
require("./style");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * 最基本的组件，就是个普通的 Input.Password
 *
 * @param
 */const FieldPassword = ({
  text,
  mode,
  render,
  renderFormItem,
  fieldProps,
  ...rest
}, ref) => {
  const intl = (0, _wauProvider.useIntl)();
  const [visible, setVisible] = (0, _useMergedState.default)(() => rest.visible || false, {
    value: rest.visible,
    onChange: rest.onVisible
  });
  if (mode === 'read') {
    let dom = /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
      children: "-"
    });
    if (text) {
      dom = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_space.default, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
          ref: ref,
          children: visible ? text : '＊ ＊ ＊ ＊ ＊'
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
          onClick: () => setVisible(!visible),
          children: visible ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.EyeOutlined, {}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.EyeInvisibleOutlined, {})
        })]
      });
    }
    if (render) {
      return render(text, {
        mode,
        ...fieldProps
      }, dom);
    }
    return dom;
  }
  if (mode === 'edit' || mode === 'update') {
    const dom = /*#__PURE__*/(0, _jsxRuntime.jsx)(_input.default.Password, {
      placeholder: intl.getMessage('tableForm.inputPlaceholder', '请输入'),
      ref: ref,
      ...fieldProps
    });
    if (renderFormItem) {
      return renderFormItem(text, {
        mode,
        ...fieldProps
      }, dom);
    }
    return dom;
  }
  return null;
};
var _default = /*#__PURE__*/_react.default.forwardRef(FieldPassword);
exports.default = _default;