'use strict';

var icons = require('@ant-design/icons');
var React = require('react');
var index = require('../../Input/index.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
const InputPassword = (props) => {
  const [showPassword, setShowPassword] = React.useState(false);
  React.useEffect(() => {
    if (props.visible !== void 0) {
      setShowPassword(props.visible);
    }
  }, [props.visible]);
  const toggleShowPassword = () => {
    var _a;
    setShowPassword(!showPassword);
    (_a = props == null ? void 0 : props.onVisibleChange) == null ? void 0 : _a.call(props, !showPassword);
  };
  const inputType = showPassword ? "text" : "password";
  return /* @__PURE__ */ React__default.default.createElement(
    index,
    __spreadProps(__spreadValues({}, props), {
      type: inputType,
      suffix: showPassword ? /* @__PURE__ */ React__default.default.createElement(
        icons.EyeOutlined,
        {
          className: "ant-input-password-icon",
          onClick: toggleShowPassword
        }
      ) : /* @__PURE__ */ React__default.default.createElement(
        icons.EyeInvisibleOutlined,
        {
          className: "ant-input-password-icon",
          onClick: toggleShowPassword
        }
      )
    })
  );
};
const CustomInput = (props) => {
  if (props.type === "password") {
    return /* @__PURE__ */ React__default.default.createElement(InputPassword, __spreadValues({}, props));
  }
  return /* @__PURE__ */ React__default.default.createElement(index, __spreadValues({}, props));
};
const InputColumnHeaderCell = ({ disabled, column, onChange, onBlur, onVisibleChange }) => {
  const _onChange = (e) => {
    const newValue = e.target.value;
    onChange(newValue);
  };
  return /* @__PURE__ */ React__default.default.createElement(
    CustomInput,
    {
      style: { marginTop: "4px" },
      type: column.type,
      placeholder: column.placeholder,
      disabled,
      size: "small",
      onChange: _onChange,
      onBlur,
      onVisibleChange
    }
  );
};
const InputColumnBodyCell = ({
  data,
  latestData,
  column,
  index,
  disabled,
  onChange,
  onBlur,
  visible,
  error
}) => {
  const placeHolderValue = column.type === "password" ? "" : latestData[index][column.key];
  const _onChange = (e) => {
    const newValue = e.target.value;
    onChange(newValue);
  };
  return /* @__PURE__ */ React__default.default.createElement(
    CustomInput,
    {
      size: "small",
      value: data[index][column.key],
      type: column.type,
      defaultValue: column.defaultValue,
      disabled,
      placeholder: placeHolderValue || column.placeholder,
      onChange: _onChange,
      onBlur,
      visible,
      error
    }
  );
};

exports.InputColumnBodyCell = InputColumnBodyCell;
exports.InputColumnHeaderCell = InputColumnHeaderCell;
