"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = require("react");

var _indexModule = _interopRequireDefault(require("./index.module.less"));

var _classnames = _interopRequireDefault(require("classnames"));

var _configProvider = require("../config-provider");

var _sheet = require("../sheet");

var _getPlatform = _interopRequireDefault(require("../get-platform"));

var _getCurrentPage = _interopRequireDefault(require("../get-current-page"));

var _excluded = ["onChange", "onConfirm", "className", "placeholderStyle", "value", "disabled"];

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var _default = function _default(_ref) {
  var onChange = _ref.onChange,
      onConfirm = _ref.onConfirm,
      className = _ref.className,
      placeholderStyle = _ref.placeholderStyle,
      value = _ref.value,
      disabled = _ref.disabled,
      props = _objectWithoutProperties(_ref, _excluded);

  var inSheet = (0, _react.useContext)(_sheet.SheetContent);

  var _useConfig = (0, _configProvider.useConfig)(),
      isShowSheetPage = _useConfig.isShowSheetPage;

  var page = (0, _getCurrentPage.default)();

  var newProps = _objectSpread(_objectSpread({
    adjustPosition: true
  }, props), {}, {
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    disabled: disabled || page === isShowSheetPage && !inSheet,
    value: value,
    className: (0, _classnames.default)(_indexModule.default.input, className),
    placeholderStyle: _objectSpread({
      color: '#CCCCCC',
      wordBreak: 'breakWord'
    }, placeholderStyle),
    onInput: (0, _react.useCallback)(function (e) {
      var _e$detail, _e$target;

      var value = ((_e$detail = e.detail) === null || _e$detail === void 0 ? void 0 : _e$detail.value) || ((_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.value);
      onChange === null || onChange === void 0 ? void 0 : onChange(value);
      return {
        value: value || ''
      };
    }, [onChange]),
    onConfirm: (0, _react.useCallback)(function () {
      return onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(value);
    }, [onConfirm, value])
  });

  if (_getPlatform.default === 'web') {
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    delete newProps.adjustPosition;
    delete newProps.confirmType;
  }

  return newProps;
};

exports.default = _default;