import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";

/**
 * 业务型组件
 * 木偶组件，内部不能有自己的状态
 */
import React from 'react';
import classNames from 'classnames';
import Upload from './upload';
import Button from '../button';
import { ConfigContext } from '../config-provider/context';
var Preset = /*#__PURE__*/React.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 = _objectWithoutProperties(props, ["fileUrl", "className", "prefixCls", "onReset", "onChange", "tips", "actionTips", "showReset"]);

  var _React$useContext = React.useContext(ConfigContext),
      getPrefixClassName = _React$useContext.getPrefixClassName;

  var uploadPrefixCls = classNames(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 = _objectSpread({
      ref: ref,
      prefixCls: "".concat(presetCls, "-change"),
      showUploadList: false,
      onChange: handleFileChange
    }, resetProps);

    return /*#__PURE__*/React.createElement("div", {
      className: uploadPrefixCls
    }, /*#__PURE__*/React.createElement("div", {
      className: presetCls
    }, fileUrl && /*#__PURE__*/React.createElement("div", {
      className: "".concat(presetCls, "-img")
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        backgroundImage: "url(".concat(fileUrl, ")")
      },
      className: "".concat(presetCls, "-img-single")
    }), /*#__PURE__*/React.createElement("div", {
      className: "".concat(presetCls, "-img-mask")
    }, /*#__PURE__*/React.createElement(Upload, Object.assign({}, endProps), /*#__PURE__*/React.createElement(Button, {
      size: "small"
    }, "\u66FF\u6362")), showReset && /*#__PURE__*/React.createElement(Button, {
      className: "".concat(presetCls, "-img-reset"),
      size: "small",
      onClick: handleReset
    }, "\u91CD\u7F6E"))), actionTips && /*#__PURE__*/React.createElement("div", {
      className: "".concat(presetCls, "-action")
    }, actionTips), tips && /*#__PURE__*/React.createElement("div", {
      className: "".concat(presetCls, "-tips")
    }, tips)));
  };

  return /*#__PURE__*/React.createElement(React.Fragment, null, renderPresetDom());
});
Preset.defaultProps = {
  showReset: true
};
export default Preset;