"use strict";

require("core-js/modules/es.symbol.js");
require("core-js/modules/es.array.filter.js");
require("core-js/modules/es.array.for-each.js");
require("core-js/modules/es.array.iterator.js");
require("core-js/modules/es.array.push.js");
require("core-js/modules/es.object.define-properties.js");
require("core-js/modules/es.object.define-property.js");
require("core-js/modules/es.object.get-own-property-descriptor.js");
require("core-js/modules/es.object.get-own-property-descriptors.js");
require("core-js/modules/es.object.keys.js");
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/es.string.iterator.js");
require("core-js/modules/es.weak-map.js");
require("core-js/modules/esnext.iterator.constructor.js");
require("core-js/modules/esnext.iterator.filter.js");
require("core-js/modules/esnext.iterator.for-each.js");
require("core-js/modules/esnext.weak-map.delete-all.js");
require("core-js/modules/esnext.weak-map.emplace.js");
require("core-js/modules/web.dom-collections.for-each.js");
require("core-js/modules/web.dom-collections.iterator.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FcrInputPassword = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _classnames = _interopRequireDefault(require("classnames"));
var _react = _interopRequireWildcard(require("react"));
var _icon = require("../icon");
require("./index.css");
var _type = require("../icon/type");
var _tooltip = require("../tooltip");
var _i18n = require("../../i18n");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // import React, { useState } from 'react';
// const FcrPasswordInput = () => {
//   const [showPassword, setShowPassword] = useState(false);
//   return (
//     <div>
//       <input type={showPassword ? 'text' : 'password'} />
//       <button onClick={toggleShowPassword}>
//         {showPassword ? '隐藏密码' : '显示密码'}
//       </button>
//     </div>
//   );
// };
// export default FcrPasswordInput;
var FcrInputPassword = exports.FcrInputPassword = function FcrInputPassword(_ref) {
  var placeholder = _ref.placeholder,
    _ref$value = _ref.value,
    value = _ref$value === void 0 ? '' : _ref$value,
    disabled = _ref.disabled,
    iconPrefix = _ref.iconPrefix,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? 'medium' : _ref$size,
    label = _ref.label,
    _ref$onChange = _ref.onChange,
    onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
    _ref$onBlur = _ref.onBlur,
    onBlur = _ref$onBlur === void 0 ? function () {} : _ref$onBlur,
    _ref$onKeyDown = _ref.onKeyDown,
    onKeyDown = _ref$onKeyDown === void 0 ? function () {} : _ref$onKeyDown,
    _ref$onKeyUp = _ref.onKeyUp,
    onKeyUp = _ref$onKeyUp === void 0 ? function () {} : _ref$onKeyUp,
    _ref$allowShowPasswor = _ref.allowShowPassword,
    allowShowPassword = _ref$allowShowPasswor === void 0 ? true : _ref$allowShowPasswor,
    autoFocus = _ref.autoFocus,
    style = _ref.style,
    _ref$shape = _ref.shape,
    shape = _ref$shape === void 0 ? 'circle' : _ref$shape,
    maxLength = _ref.maxLength;
  var t = (0, _i18n.useI18n)();
  var _useState = (0, _react.useState)(false),
    _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
    showPassword = _useState2[0],
    setShowPassword = _useState2[1];
  var _useState3 = (0, _react.useState)(false),
    _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
    focused = _useState4[0],
    setFocused = _useState4[1];
  var inputRef = (0, _react.useRef)(null);
  var handleFocus = function handleFocus() {
    setFocused(true);
  };
  var handleBlur = function handleBlur() {
    setFocused(false);
    onBlur();
  };
  var handleChange = function handleChange(e) {
    onChange(e.target.value);
  };
  var handleClick = function handleClick() {
    if (inputRef.current) {
      inputRef.current.focus();
    }
  };
  var cls = (0, _classnames["default"])('fcr-input', "fcr-input-".concat(shape), {
    'fcr-input--focused': focused,
    'fcr-input-l': size === 'large',
    'fcr-input-m': size === 'medium',
    'fcr-input-s': size === 'small',
    'fcr-input-xs': size === 'mini',
    'fcr-input-allow-show-password': allowShowPassword,
    'fcr-input--disabled': disabled
  });
  var iconWrapCls = (0, _classnames["default"])('fcr-input-icon-wrap', 'input-password-hidden');
  var iconCls = (0, _classnames["default"])('fcr-input-icon', {});
  var labelCls = (0, _classnames["default"])('fcr-input-label', {});
  var toggleShowPassword = function toggleShowPassword() {
    setShowPassword(!showPassword);
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react["default"].Fragment, {
    children: [label && /*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
      className: labelCls,
      children: label
    }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: cls,
      style: style,
      onClick: handleClick,
      children: [iconPrefix && /*#__PURE__*/(0, _jsxRuntime.jsx)(_icon.FcrIcon, _objectSpread({
        style: {
          marginRight: 10
        },
        size: 18
      }, iconPrefix)), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
        type: showPassword ? 'text' : 'password',
        maxLength: maxLength,
        ref: inputRef,
        placeholder: placeholder,
        onFocus: handleFocus,
        onBlur: handleBlur,
        value: value,
        disabled: disabled,
        onChange: handleChange,
        onKeyDown: onKeyDown,
        onKeyUp: onKeyUp,
        autoFocus: autoFocus
      }), allowShowPassword && /*#__PURE__*/(0, _jsxRuntime.jsx)(_tooltip.FcrToolTip, {
        content: showPassword ? t('fmt_broadcast_livestream_button_show') : t('fmt_broadcast_livestream_button_hide'),
        mouseEnterDelay: 0,
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: iconWrapCls,
          onMouseDown: toggleShowPassword,
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icon.FcrIcon, {
            className: iconCls,
            colors: {
              iconPrimary: 'var(--fcr_ui_scene_icontext1)'
            },
            type: showPassword ? _type.FcrIconType.FCR_SHOWVIDEO : _type.FcrIconType.FCR_HIDEVIDEO,
            size: 24
          })
        })
      })]
    })]
  });
};