import "core-js/modules/es.array.iterator.js";
import "core-js/modules/web.dom-collections.iterator.js";
import React from 'react';
import { EyeOutlined, EyeInvisibleOutlined } from '@wii/icons';
import useMergedState from 'rc-util/es/hooks/useMergedState';
import Input from '../input';
import Space from '../space';
import { useIntl } from '../wau-provider';
import './style';

/**
 * 最基本的组件，就是个普通的 Input.Password
 *
 * @param
 */
import { Fragment as _Fragment } from "react/jsx-runtime";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
const FieldPassword = ({
  text,
  mode,
  render,
  renderFormItem,
  fieldProps,
  ...rest
}, ref) => {
  const intl = useIntl();
  const [visible, setVisible] = useMergedState(() => rest.visible || false, {
    value: rest.visible,
    onChange: rest.onVisible
  });
  if (mode === 'read') {
    let dom = /*#__PURE__*/_jsx(_Fragment, {
      children: "-"
    });
    if (text) {
      dom = /*#__PURE__*/_jsxs(Space, {
        children: [/*#__PURE__*/_jsx("span", {
          ref: ref,
          children: visible ? text : '＊ ＊ ＊ ＊ ＊'
        }), /*#__PURE__*/_jsx("a", {
          onClick: () => setVisible(!visible),
          children: visible ? /*#__PURE__*/_jsx(EyeOutlined, {}) : /*#__PURE__*/_jsx(EyeInvisibleOutlined, {})
        })]
      });
    }
    if (render) {
      return render(text, {
        mode,
        ...fieldProps
      }, dom);
    }
    return dom;
  }
  if (mode === 'edit' || mode === 'update') {
    const dom = /*#__PURE__*/_jsx(Input.Password, {
      placeholder: intl.getMessage('tableForm.inputPlaceholder', '请输入'),
      ref: ref,
      ...fieldProps
    });
    if (renderFormItem) {
      return renderFormItem(text, {
        mode,
        ...fieldProps
      }, dom);
    }
    return dom;
  }
  return null;
};
export default /*#__PURE__*/React.forwardRef(FieldPassword);