"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
Object.defineProperty(exports, "ImagePreviewGroup", {
  enumerable: true,
  get: function () {
    return _PreviewGroup.default;
  }
});
exports.default = void 0;
Object.defineProperty(exports, "imageProps", {
  enumerable: true,
  get: function () {
    return _Image.imageProps;
  }
});
exports.mergeCover = mergeCover;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _vue = require("vue");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _vcImage = _interopRequireDefault(require("../vc-image"));
var _Image = require("../vc-image/src/Image");
var _useConfigInject = _interopRequireDefault(require("../config-provider/hooks/useConfigInject"));
var _PreviewGroup = _interopRequireWildcard(require("./PreviewGroup"));
var _transition = require("../_util/transition");
var _style = _interopRequireDefault(require("./style"));
var _classNames = _interopRequireDefault(require("../_util/classNames"));
require("vue/jsx-runtime");
var _usePlaceholderConfig = require("./hooks/usePlaceholderConfig");
var _Progress = _interopRequireDefault(require("./Progress"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (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 (const 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); }
const _imageProps = () => (0, _extends2.default)((0, _extends2.default)({}, (0, _Image.imageProps)()), {
  placeholder: {
    type: Object,
    default: undefined
  },
  style: Object
});
function mergeCover(cover, coverSlot) {
  if (cover === false) {
    return cover;
  }
  let placement = undefined;
  let coverNode = undefined;
  if (typeof cover === 'function') {
    placement = 'center';
    coverNode = cover;
  } else if (typeof cover === 'object') {
    placement = cover.placement;
    coverNode = cover.coverNode;
  } else {
    // case true
    placement = 'center';
  }
  return {
    placement,
    coverNode: coverNode || coverSlot
  };
}
const Image = (0, _vue.defineComponent)({
  name: 'AImage',
  inheritAttrs: false,
  props: _imageProps(),
  slots: Object,
  setup(props, {
    slots,
    attrs
  }) {
    const {
      prefixCls,
      rootPrefixCls
    } = (0, _useConfigInject.default)('image', props);
    // Style
    const [wrapSSR, hashId] = (0, _style.default)(prefixCls);
    const {
      placeholderConfig,
      showProgressOverlay,
      placeholderNode
    } = (0, _usePlaceholderConfig.usePlaceholderConfig)((0, _vue.toRef)(props, 'placeholder'));
    const mergedPreview = (0, _vue.computed)(() => {
      const {
        preview
      } = props;
      if (preview === false) {
        return preview;
      }
      const _preview = typeof preview === 'object' ? preview : {};
      return (0, _extends2.default)((0, _extends2.default)({
        icons: _PreviewGroup.icons
      }, _preview), {
        cover: mergeCover(_preview.cover, slots.cover),
        transitionName: (0, _transition.getTransitionName)(rootPrefixCls.value, 'zoom', _preview.transitionName),
        maskTransitionName: (0, _transition.getTransitionName)(rootPrefixCls.value, 'fade', _preview.maskTransitionName)
      });
    });
    return () => {
      var _a;
      const {
        width,
        height,
        style
      } = props;
      const shouldRenderPlaceholderOverlay = placeholderNode.value && !props.src;
      const {
        render: progressRender,
        percent
      } = ((_a = placeholderConfig.value) === null || _a === void 0 ? void 0 : _a.progressConfig) || {};
      const mergedProgressRender = shouldRenderPlaceholderOverlay ? () => placeholderNode.value : progressRender;
      if (showProgressOverlay.value || shouldRenderPlaceholderOverlay) {
        return (0, _vue.createVNode)(_Progress.default, {
          "prefixCls": prefixCls.value,
          "percent": percent,
          "render": mergedProgressRender,
          "width": width,
          "height": height,
          "classNames": {},
          "styles": {},
          "rootStyle": (0, _extends2.default)({}, style || {}),
          "rootClassName": (0, _classNames.default)(props.rootClassName, hashId.value)
        }, null);
      }
      return wrapSSR((0, _vue.createVNode)(_vcImage.default, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({}, attrs), props), {
        prefixCls: prefixCls.value
      })), {}, {
        "preview": mergedPreview.value,
        "rootClassName": (0, _classNames.default)(props.rootClassName, hashId.value)
      }), (0, _extends2.default)({}, slots)));
    };
  }
});
Image.PreviewGroup = _PreviewGroup.default;
Image.install = function (app) {
  app.component(Image.name, Image);
  app.component(Image.PreviewGroup.name, Image.PreviewGroup);
  return app;
};
var _default = exports.default = Image;