/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, computed, watch } from '@vue/composition-api';
import { ImageErrorIcon } from '@ldesign/icons-vue';
import { useDrag } from '../hooks.js';
import { setTransform } from '../../utils/helper.js';
import '../../hooks/useConfig.js';
import { useConfig } from '../../config-provider/useConfig.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';
import '../../config-provider/context.js';
import 'lodash/merge';
import 'lodash/mergeWith';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../../_chunks/dep-be599ec8.js';
import 'dayjs';
import '../../_chunks/dep-67ff4010.js';
import '../../config-provider/type.js';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var TImageItem = defineComponent({
  name: "TImageItem",
  props: {
    rotate: Number,
    scale: Number,
    mirror: Number,
    src: String,
    placementSrc: String
  },
  setup: function setup(props) {
    var _useConfig = useConfig("imageViewer"),
      classPrefix = _useConfig.classPrefix,
      globalConfig = _useConfig.global;
    var error = ref(false);
    var loaded = ref(false);
    var _useDrag = useDrag({
        translateX: 0,
        translateY: 0
      }),
      transform = _useDrag.transform,
      mouseDownHandler = _useDrag.mouseDownHandler;
    var imgStyle = computed(function () {
      return _objectSpread(_objectSpread({}, setTransform("rotate(".concat(props.rotate, "deg) scale(").concat(props.scale, ")"))), {}, {
        display: !props.placementSrc || loaded.value ? "block" : "none"
      });
    });
    var placementImgStyle = computed(function () {
      return _objectSpread(_objectSpread({}, setTransform("rotate(".concat(props.rotate, "deg) scale(").concat(props.scale, ")"))), {}, {
        display: !loaded.value ? "block" : "none"
      });
    });
    var boxStyle = computed(function () {
      var _transform$value = transform.value,
        translateX = _transform$value.translateX,
        translateY = _transform$value.translateY;
      return setTransform("translate(".concat(translateX, "px, ").concat(translateY, "px) scale(").concat(props.mirror, ", 1)"));
    });
    var resetStatus = function resetStatus() {
      error.value = false;
      loaded.value = false;
    };
    watch(function () {
      return props.src;
    }, function () {
      resetStatus();
    });
    return {
      globalConfig: globalConfig,
      classPrefix: classPrefix,
      boxStyle: boxStyle,
      loaded: loaded,
      error: error,
      mouseDownHandler: mouseDownHandler,
      placementImgStyle: placementImgStyle,
      imgStyle: imgStyle
    };
  },
  render: function render() {
    var _this = this;
    var h = arguments[0];
    return h("div", {
      "class": "".concat(this.classPrefix, "-image-viewer__modal-pic")
    }, [h("div", {
      "class": "".concat(this.classPrefix, "-image-viewer__modal-box"),
      "style": this.boxStyle
    }, [this.error && h("div", {
      "class": "".concat(this.classPrefix, "-image-viewer__img-error")
    }, [h("div", {
      "class": "".concat(this.classPrefix, "-image-viewer__img-error-content")
    }, [h(ImageErrorIcon, {
      "attrs": {
        "size": "4em"
      }
    }), h("div", {
      "class": "".concat(this.classPrefix, "-image-viewer__img-error-text")
    }, [this.globalConfig.errorText])])]), !this.error && !!this.placementSrc && h("img", {
      "class": "".concat(this.classPrefix, "-image-viewer__modal-image"),
      "on": {
        "mousedown": function mousedown(event) {
          event.stopPropagation();
          _this.mouseDownHandler(event);
        }
      },
      "attrs": {
        "src": this.placementSrc,
        "alt": "image",
        "draggable": "false"
      },
      "style": this.placementImgStyle
    }), !this.error && h("img", {
      "class": "".concat(this.classPrefix, "-image-viewer__modal-image"),
      "on": {
        "mousedown": function mousedown(event) {
          event.stopPropagation();
          _this.mouseDownHandler(event);
        },
        "load": function load() {
          return _this.loaded = true;
        },
        "error": function error() {
          return _this.error = true;
        }
      },
      "attrs": {
        "src": this.src,
        "alt": "image",
        "draggable": "false"
      },
      "style": this.imgStyle
    })])]);
  }
});

export { TImageItem as default };
//# sourceMappingURL=ImageItem.js.map
