function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

import React from 'react';
import { omit } from 'lodash-es';
import { useBoolean } from 'ahooks';
import classNames from 'classnames';
import { useNamespace } from '@parallel-line/common/es/hooks';
import { DeleteOutlined, EyeFill } from '@parallel-line/icons';
import RcImage from 'antd/es/image';
var placeholderUrl = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNMTQuNSAyLjVoLTEzQS41LjUgMCAwIDAgMSAzdjEwYS41LjUgMCAwIDAgLjUuNWgxM2EuNS41IDAgMCAwIC41LS41VjNhLjUuNSAwIDAgMC0uNS0uNXpNNS4yODEgNC43NWExIDEgMCAwIDEgMCAyIDEgMSAwIDAgMSAwLTJ6bTguMDMgNi44M2EuMTI3LjEyNyAwIDAgMS0uMDgxLjAzSDIuNzY5YS4xMjUuMTI1IDAgMCAxLS4wOTYtLjIwN2wyLjY2MS0zLjE1NmEuMTI2LjEyNiAwIDAgMSAuMTc3LS4wMTZsLjAxNi4wMTZMNy4wOCAxMC4wOWwyLjQ3LTIuOTNhLjEyNi4xMjYgMCAwIDEgLjE3Ny0uMDE2bC4wMTUuMDE2IDMuNTg4IDQuMjQ0YS4xMjcuMTI3IDAgMCAxLS4wMi4xNzV6IiBmaWxsPSIjOEM4QzhDIiBmaWxsLXJ1bGU9Im5vbnplcm8iLz48L3N2Zz4=';
var fallbackUrl = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/PjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy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I5LjE1OTQyNC0yMS45MjU4ODggNTMuMjE3MjgtNTAuMjQ3NjggNTYuNTA2MzY4bC02LjY0MTY2NCAwLjM4Mjk3Nkg2MjYuMjMzMzQ0TDY4My4xMjI2ODggNjgzLjAwOCA1MTAuMzUwMzM2IDQyMy44MjIzMzZsNzIuODE4Njg4LTg3LjMyNDY3MmMyMS4wMjU3OTItMjUuMjczMzQ0IDU4LjU1NDM2OC0yNy4yMDY2NTYgODIuMDU4MjQtNS42MTI1NDRsNC44MTA3NTIgNC45ODY4OCAyNDAuNjQgMjgwLjc0NzAwOFYyMjcuODk3MzQ0SDQ5My41MTE2OGwxOC45NDQtNTYuODg5MzQ0aDM5OC4yMjMzNnpNMzEzLjM3MjY3MiAyODQuNzYzMTM2YzE1Ljg4MDE5MiAwIDMwLjc1MDcyIDQuMzQ0ODMyIDQzLjQ4OTI4IDExLjkwOTEybC0xNS4wNzMyOCA0NS4wMDI3NTIgNDYuMzY4NzY4IDY5LjUzMzY5NmMtMTQuNTI4NTEyIDI2LjM1NDY4OC00Mi41ODMwNCA0NC4yMjE0NC03NC43ODQ3NjggNDQuMjIxNDQtNDcuMTA0IDAtODUuMzMyOTkyLTM4LjIyODk5Mi04NS4zMzI5OTItODUuMzM0MDE2IDAtNDcuMTA0IDM4LjIyODk5Mi04NS4zMzI5OTIgODUuMzMyOTkyLTg1LjMzMjk5MnoiIHAtaWQ9IjM1NDgiIGZpbGw9IiM4QzhDOEMiPjwvcGF0aD48L3N2Zz4=";

var InternalImage = function InternalImage(props) {
  var prefixCls = props.prefixCls,
      className = props.className,
      width = props.width,
      height = props.height,
      style = props.style,
      disabled = props.disabled,
      _props$size = props.size,
      size = _props$size === void 0 ? 'default' : _props$size,
      _props$preview = props.preview,
      preview = _props$preview === void 0 ? true : _props$preview,
      _props$fallback = props.fallback,
      fallback = _props$fallback === void 0 ? fallbackUrl : _props$fallback,
      onDelete = props.onDelete;

  var _useBoolean = useBoolean(),
      _useBoolean2 = _slicedToArray(_useBoolean, 2),
      visible = _useBoolean2[0],
      setVisible = _useBoolean2[1].toggle;

  var _useBoolean3 = useBoolean(),
      _useBoolean4 = _slicedToArray(_useBoolean3, 2),
      hasError = _useBoolean4[0],
      toggle = _useBoolean4[1].toggle;

  var _useNamespace = useNamespace('image', prefixCls),
      _useNamespace2 = _slicedToArray(_useNamespace, 2),
      bem = _useNamespace2[1];

  var restProps = _objectSpread(_objectSpread({}, omit(props, ['prefixCls', 'className', 'preview', 'delete', 'onDelete', 'onClick'])), {}, {
    fallback: fallback
  });

  var placeholderProps = _objectSpread(_objectSpread({}, restProps), {}, {
    prefixCls: bem(),
    preview: false,
    src: placeholderUrl
  });

  var imageProps = _objectSpread(_objectSpread({}, restProps), {}, {
    prefixCls: bem(),
    placeholder: /*#__PURE__*/React.createElement(RcImage, Object.assign({}, placeholderProps)),
    onError: function onError() {
      toggle(true);
    },
    preview: preview ? {
      visible: visible,
      onVisibleChange: function onVisibleChange(flag) {
        setVisible(flag);
      }
    } : false
  });

  var previewClick = function previewClick(event) {
    event.stopPropagation();
    setVisible(true);
  };

  var deleteClick = function deleteClick(event) {
    event.stopPropagation();
    onDelete === null || onDelete === void 0 ? void 0 : onDelete();
  };

  var dominoRender = function dominoRender() {
    if (hasError) return null;
    return /*#__PURE__*/React.createElement(React.Fragment, null, preview && /*#__PURE__*/React.createElement("div", {
      className: bem('domino', [size]),
      onClick: previewClick
    }, /*#__PURE__*/React.createElement("div", {
      className: bem('domino-preview'),
      title: "\u9884\u89C8"
    }, /*#__PURE__*/React.createElement("span", {
      className: bem('domino-preview-icon')
    }, /*#__PURE__*/React.createElement(EyeFill, null)), /*#__PURE__*/React.createElement("span", null, "\u67E5\u770B\u5927\u56FE"))), !disabled && props.delete && /*#__PURE__*/React.createElement("div", {
      className: bem('delete'),
      title: "\u5220\u9664",
      onClick: deleteClick
    }, /*#__PURE__*/React.createElement(DeleteOutlined, null)));
  };

  return /*#__PURE__*/React.createElement("div", {
    className: classNames(bem('wrapper'), className),
    style: _objectSpread({
      width: width,
      height: height
    }, style)
  }, /*#__PURE__*/React.createElement(RcImage, Object.assign({}, imageProps)), dominoRender());
};

var Image = InternalImage;
Image.PLACEHOLDER = placeholderUrl;
Image.FALLBACK = fallbackUrl;
export { Image };
export default Image;