"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _react = _interopRequireDefault(require("react"));

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

var _upload = _interopRequireDefault(require("./upload"));

var _button = _interopRequireDefault(require("../button"));

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

/**
 * 业务型组件
 * 木偶组件，内部不能有自己的状态
 */
var Preset = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
  var fileUrl = props.fileUrl,
      className = props.className,
      customPrefixCls = props.prefixCls,
      onReset = props.onReset,
      onChange = props.onChange,
      tips = props.tips,
      actionTips = props.actionTips,
      showReset = props.showReset,
      resetProps = (0, _objectWithoutProperties2.default)(props, ["fileUrl", "className", "prefixCls", "onReset", "onChange", "tips", "actionTips", "showReset"]);

  var _React$useContext = _react.default.useContext(_context.ConfigContext),
      getPrefixClassName = _React$useContext.getPrefixClassName;

  var uploadPrefixCls = (0, _classnames.default)(getPrefixClassName('upload', customPrefixCls), className);
  var presetCls = "".concat(uploadPrefixCls, "-preset");

  var handleFileChange = function handleFileChange(info) {
    onChange === null || onChange === void 0 ? void 0 : onChange(info);
  };

  var handleReset = function handleReset() {
    onReset === null || onReset === void 0 ? void 0 : onReset();
  };

  var renderPresetDom = function renderPresetDom() {
    var endProps = (0, _objectSpread2.default)({
      ref: ref,
      prefixCls: "".concat(presetCls, "-change"),
      showUploadList: false,
      onChange: handleFileChange
    }, resetProps);
    return /*#__PURE__*/_react.default.createElement("div", {
      className: uploadPrefixCls
    }, /*#__PURE__*/_react.default.createElement("div", {
      className: presetCls
    }, fileUrl && /*#__PURE__*/_react.default.createElement("div", {
      className: "".concat(presetCls, "-img")
    }, /*#__PURE__*/_react.default.createElement("div", {
      style: {
        backgroundImage: "url(".concat(fileUrl, ")")
      },
      className: "".concat(presetCls, "-img-single")
    }), /*#__PURE__*/_react.default.createElement("div", {
      className: "".concat(presetCls, "-img-mask")
    }, /*#__PURE__*/_react.default.createElement(_upload.default, Object.assign({}, endProps), /*#__PURE__*/_react.default.createElement(_button.default, {
      size: "small"
    }, "\u66FF\u6362")), showReset && /*#__PURE__*/_react.default.createElement(_button.default, {
      className: "".concat(presetCls, "-img-reset"),
      size: "small",
      onClick: handleReset
    }, "\u91CD\u7F6E"))), actionTips && /*#__PURE__*/_react.default.createElement("div", {
      className: "".concat(presetCls, "-action")
    }, actionTips), tips && /*#__PURE__*/_react.default.createElement("div", {
      className: "".concat(presetCls, "-tips")
    }, tips)));
  };

  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, renderPresetDom());
});

Preset.defaultProps = {
  showReset: true
};
var _default = Preset;
exports.default = _default;