import { defineComponent, openBlock, createBlock, unref, isRef, withCtx, createElementVNode, normalizeClass, normalizeStyle, withDirectives, vModelText, createElementBlock, createCommentVNode, vShow } from 'vue';
import '../../../hooks/index.mjs';
import { ElDialog } from '../../dialog/index.mjs';
import { cropperProps, croppersEmits, useCropper } from './upload-cropper2.mjs';
import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
import { useNamespace } from '../../../hooks/use-namespace/index.mjs';

const _hoisted_1 = ["src"];
const _hoisted_2 = ["src"];
const __default__ = defineComponent({
  name: "ElCropper"
});
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: cropperProps,
  emits: croppersEmits,
  setup(__props, { emit }) {
    const props = __props;
    const ns = useNamespace("cropper");
    const clippingNs = useNamespace("cropper-clipping");
    const previewNs = useNamespace("cropper-preview");
    const {
      createImgUrl,
      isShowDialog,
      previewImgStyle,
      shadeStyle,
      sourImgStyle,
      scalingRatio,
      canvasRef,
      startMoveImg,
      moveImg,
      zoomImg,
      data2blob,
      createImg,
      sourImgUrl
    } = useCropper(props);
    const handleClose = () => {
      emit("update:modelValue", false);
    };
    const confirm = () => {
      if (!sourImgUrl.value || !createImgUrl.value) {
        return;
      }
      const blob = data2blob(createImgUrl.value);
      if (blob) {
        emit("cropUploadSuccess", blob);
        handleClose();
      }
    };
    const preventDefault = (e) => {
      e.preventDefault();
      return false;
    };
    return (_ctx, _cache) => {
      return openBlock(), createBlock(unref(ElDialog), {
        modelValue: unref(isShowDialog),
        "onUpdate:modelValue": _cache[7] || (_cache[7] = ($event) => isRef(isShowDialog) ? isShowDialog.value = $event : null),
        title: "\u56FE\u7247\u526A\u5207",
        "before-close": handleClose,
        width: "580px",
        "submit-handle": confirm
      }, {
        default: withCtx(() => [
          createElementVNode("div", {
            class: normalizeClass(unref(ns).b())
          }, [
            createElementVNode("div", {
              class: normalizeClass(unref(clippingNs).b())
            }, [
              createElementVNode("div", {
                class: normalizeClass(unref(clippingNs).e("picture"))
              }, [
                createElementVNode("img", {
                  class: normalizeClass(unref(clippingNs).e("picture-img")),
                  src: unref(sourImgUrl),
                  style: normalizeStyle(unref(sourImgStyle)),
                  draggable: "false",
                  onDrag: preventDefault,
                  onDragstart: preventDefault,
                  onDragend: preventDefault,
                  onDragleave: preventDefault,
                  onDragover: preventDefault,
                  onDragenter: preventDefault,
                  onMousedown: _cache[0] || (_cache[0] = (...args) => unref(startMoveImg) && unref(startMoveImg)(...args)),
                  onMousemove: _cache[1] || (_cache[1] = (...args) => unref(moveImg) && unref(moveImg)(...args)),
                  onMouseup: _cache[2] || (_cache[2] = (...args) => unref(createImg) && unref(createImg)(...args)),
                  onMouseout: _cache[3] || (_cache[3] = (...args) => unref(createImg) && unref(createImg)(...args))
                }, null, 46, _hoisted_1),
                createElementVNode("div", {
                  class: normalizeClass([
                    unref(clippingNs).e("picture-shade"),
                    unref(clippingNs).em("picture-shade", "left")
                  ]),
                  style: normalizeStyle(unref(shadeStyle))
                }, null, 6),
                createElementVNode("div", {
                  class: normalizeClass([
                    unref(clippingNs).e("picture-shade"),
                    unref(clippingNs).em("picture-shade", "right")
                  ]),
                  style: normalizeStyle(unref(shadeStyle))
                }, null, 6)
              ], 2),
              createElementVNode("div", {
                class: normalizeClass(unref(clippingNs).e("range"))
              }, [
                withDirectives(createElementVNode("input", {
                  "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => isRef(scalingRatio) ? scalingRatio.value = $event : null),
                  type: "range",
                  step: 1,
                  min: 0,
                  max: 100,
                  class: normalizeClass(unref(clippingNs).e("range-input"))
                }, null, 2), [
                  [vModelText, unref(scalingRatio)]
                ]),
                createElementVNode("span", {
                  class: normalizeClass(unref(clippingNs).e("range-track"))
                }, null, 2),
                createElementVNode("i", {
                  class: normalizeClass([
                    unref(clippingNs).e("range-icon"),
                    unref(clippingNs).em("range-icon", "plus")
                  ]),
                  onClick: _cache[5] || (_cache[5] = ($event) => unref(zoomImg)(-1))
                }, null, 2),
                createElementVNode("i", {
                  class: normalizeClass([
                    unref(clippingNs).e("range-icon"),
                    unref(clippingNs).em("range-icon", "minus")
                  ]),
                  onClick: _cache[6] || (_cache[6] = ($event) => unref(zoomImg)(-2))
                }, null, 2)
              ], 2)
            ], 2),
            createElementVNode("div", {
              class: normalizeClass(unref(previewNs).b())
            }, [
              createElementVNode("div", {
                class: normalizeClass(unref(previewNs).e("title"))
              }, "\u56FE\u7247\u9884\u89C8\uFF1A", 2),
              unref(createImgUrl) !== "" ? (openBlock(), createElementBlock("img", {
                key: 0,
                src: unref(createImgUrl),
                style: normalizeStyle(unref(previewImgStyle))
              }, null, 12, _hoisted_2)) : createCommentVNode("v-if", true)
            ], 2)
          ], 2),
          withDirectives(createElementVNode("canvas", {
            ref_key: "canvasRef",
            ref: canvasRef
          }, null, 512), [
            [vShow, false]
          ])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
});
var UploadCropper = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "/Users/judai/code/d-element-plus/packages/components/upload/src/upload-cropper.vue"]]);

export { UploadCropper as default };
//# sourceMappingURL=upload-cropper.mjs.map
