"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _comp = require("../../ui/src/comp");
var _xeUtils = _interopRequireDefault(require("xe-utils"));
var _core = require("@vxe-ui/core");
var _util = require("./util");
var _image = _interopRequireDefault(require("./image"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var _default2 = exports.default = /* define-vxe-component start */(0, _comp.defineVxeComponent)({
  name: 'VxeImageGroup',
  mixins: [_core.globalMixins.sizeMixin],
  props: {
    urlList: [Array, String],
    showPreview: {
      type: Boolean,
      default: function _default() {
        return (0, _core.getConfig)().imageGroup.showPreview;
      }
    },
    imageStyle: Object,
    zIndex: Number,
    size: {
      type: String,
      default: function _default() {
        return (0, _core.getConfig)().imageGroup.size || (0, _core.getConfig)().size;
      }
    },
    toolbarConfig: Object,
    showPrintButton: {
      type: Boolean,
      default: function _default() {
        return (0, _core.getConfig)().imageGroup.showPrintButton;
      }
    },
    showDownloadButton: {
      type: Boolean,
      default: function _default() {
        return (0, _core.getConfig)().imageGroup.showDownloadButton;
      }
    },
    getThumbnailUrlMethod: Function
  },
  provide: function provide() {
    var $xeImageGroup = this;
    return {
      $xeImageGroup: $xeImageGroup
    };
  },
  data: function data() {
    var xID = _xeUtils.default.uniqueId();
    var reactData = {};
    return {
      xID: xID,
      reactData: reactData
    };
  },
  computed: Object.assign(Object.assign({}, {}), {
    computeImgList: function computeImgList() {
      var $xeImageGroup = this;
      var props = $xeImageGroup;
      var urlList = props.urlList;
      if (urlList) {
        return (_xeUtils.default.isArray(urlList) ? urlList : [urlList]).map(function (item) {
          if (_xeUtils.default.isString(item)) {
            return {
              url: item,
              alt: ''
            };
          }
          return {
            url: item.url,
            alt: item.alt
          };
        });
      }
      return [];
    },
    computeImgStyleOpts: function computeImgStyleOpts() {
      var $xeImageGroup = this;
      var props = $xeImageGroup;
      return Object.assign({}, (0, _core.getConfig)().imageGroup.imageStyle, props.imageStyle);
    },
    computeGetThumbnailUrlMethod: function computeGetThumbnailUrlMethod() {
      var $xeImageGroup = this;
      var props = $xeImageGroup;
      return props.getThumbnailUrlMethod || (0, _core.getConfig)().imageGroup.getThumbnailUrlMethod;
    }
  }),
  methods: {
    //
    // Method
    //
    dispatchEvent: function dispatchEvent(type, params, evnt) {
      var $xeImageGroup = this;
      $xeImageGroup.$emit(type, (0, _core.createEvent)(evnt, {
        $imageGroup: $xeImageGroup
      }, params));
    },
    handleClickImgEvent: function handleClickImgEvent(evnt, params) {
      var $xeImageGroup = this;
      var props = $xeImageGroup;
      var showPreview = props.showPreview,
        toolbarConfig = props.toolbarConfig,
        showPrintButton = props.showPrintButton,
        showDownloadButton = props.showDownloadButton,
        zIndex = props.zIndex;
      var url = params.url;
      var imgList = $xeImageGroup.computeImgList;
      if (showPreview && url) {
        (0, _util.openPreviewImage)({
          activeIndex: Math.max(0, _xeUtils.default.findIndexOf(imgList, function (item) {
            return item.url === url;
          })),
          urlList: imgList,
          toolbarConfig: toolbarConfig,
          showPrintButton: showPrintButton,
          showDownloadButton: showDownloadButton,
          zIndex: zIndex,
          events: {
            change: function change(eventParams) {
              $xeImageGroup.dispatchEvent('change', eventParams, eventParams.$event);
            },
            rotate: function rotate(eventParams) {
              $xeImageGroup.dispatchEvent('rotate', eventParams, eventParams.$event);
            }
          }
        });
      }
      $xeImageGroup.dispatchEvent('click', {
        url: url,
        urlList: imgList
      }, evnt);
    },
    //
    // Render
    //
    renderVN: function renderVN(h) {
      var $xeImageGroup = this;
      var imgList = $xeImageGroup.computeImgList;
      var vSize = $xeImageGroup.computeSize;
      var imgStyleOpts = $xeImageGroup.computeImgStyleOpts;
      var getThumbnailUrlMethod = $xeImageGroup.computeGetThumbnailUrlMethod;
      return h('div', {
        class: ['vxe-image-group', _defineProperty({}, "size--".concat(vSize), vSize)]
      }, imgList ? imgList.map(function (item, index) {
        return h(_image.default, {
          key: index,
          props: {
            src: item.url,
            alt: item.alt,
            width: imgStyleOpts.width,
            height: imgStyleOpts.height,
            getThumbnailUrlMethod: getThumbnailUrlMethod
          }
        });
      }) : []);
    }
  },
  render: function render(h) {
    return this.renderVN(h);
  }
});
/* define-vxe-component end */