'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var elementPlus = require('element-plus');
var useVideo = require('./composables/useVideo.js');
var uuid = require('../../utils/uuid.js');
var index$1 = require('../../svg-icon/index.js');
var index = require('../../flex-box/index.js');
var index$2 = require('../../upload/index.js');
require('./upload-video-item.vue.js');
var uploadVideoItem_vue_vue_type_script_setup_true_lang = require('./upload-video-item.vue2.js');

"use strict";
const _hoisted_1 = { class: "me-upload-video" };
const _hoisted_2 = {
  key: 0,
  class: "video-wrapper-item"
};
const _hoisted_3 = ["index"];
const _hoisted_4 = { style: { "align-items": "center", "height": "24px" } };
const __default__ = vue.defineComponent({
  name: "me-upload-video"
});
var script = /* @__PURE__ */ vue.defineComponent({
  ...__default__,
  props: /* @__PURE__ */ vue.mergeModels({
    uploadRequest: { type: Function, required: false, default: () => Promise.resolve() },
    videoRequest: { type: Function, required: false, default: () => Promise.resolve() },
    url: { type: String, required: false, default: "" },
    title: { type: String, required: false, default: "\u4E0A\u4F20\u89C6\u9891" },
    width: { type: Number, required: false, default: 80 },
    height: { type: Number, required: false, default: 80 },
    videoWidth: { type: Number, required: false, default: 160 },
    videoHeight: { type: Number, required: false, default: 90 },
    maxCount: { type: Number, required: false, default: 1 },
    closeEvent: { type: Function, required: false, default: () => {
    } },
    uploadRules: { type: null, required: false, default: [{ name: "mp4", size: 1024 * 1024 * 50 }] },
    module: { type: String, required: false }
  }, {
    "modelValue": { type: String },
    "modelModifiers": {}
  }),
  emits: ["update:modelValue"],
  setup(__props, { expose: __expose }) {
    const props = __props;
    const inputVal = vue.useModel(__props, "modelValue");
    const videoStore = useVideo.useVideo(props);
    vue.watch(
      inputVal,
      (newValue) => {
        if (videoStore.allowWatch) {
          videoStore.importData(newValue || "");
        } else {
          setTimeout(() => {
            videoStore.allowWatch = true;
          }, 100);
        }
      },
      { immediate: true }
    );
    const uploadCompleteEventHandler = (uploadResultList) => {
      videoStore.fileList.value.push(uploadResultList[0]);
      videoStore.allowWatch = false;
      inputVal.value = videoStore.getValue();
    };
    const setFileList = (uploadResultList) => {
      uploadResultList.forEach((item) => {
        item.domuuid = uuid.uuid();
        videoStore.fileList.value.push(item);
      });
      videoStore.allowWatch = false;
      inputVal.value = videoStore.getValue();
    };
    __expose({
      setFileList,
      openUpload: videoStore.openUpload,
      closeUpload: videoStore.closeUpload
    });
    const removeItem = (index) => {
      console.log(index);
      videoStore.fileList.value.splice(index, 1);
      videoStore.allowWatch = false;
      inputVal.value = videoStore.getValue();
    };
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
        vue.withDirectives(vue.createVNode(vue.unref(elementPlus.ElInput), {
          modelValue: inputVal.value,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => inputVal.value = $event)
        }, null, 8, ["modelValue"]), [
          [vue.vShow, false]
        ]),
        vue.unref(videoStore).fileList.value.length > 0 ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_2, [
          (vue.openBlock(true), vue.createElementBlock(
            vue.Fragment,
            null,
            vue.renderList(vue.unref(videoStore).fileList.value, (item, index) => {
              return vue.openBlock(), vue.createElementBlock("div", {
                key: item.domuuid,
                index
              }, [
                vue.createVNode(uploadVideoItem_vue_vue_type_script_setup_true_lang.default, {
                  index,
                  url: item.url,
                  width: props.videoWidth,
                  height: props.videoHeight,
                  onCloseEvent: removeItem
                }, null, 8, ["index", "url", "width", "height"])
              ], 8, _hoisted_3);
            }),
            128
            /* KEYED_FRAGMENT */
          ))
        ])) : vue.createCommentVNode("v-if", true),
        vue.createCommentVNode(" \u6253\u5F00\u4E0A\u4F20\u5BF9\u8BDD\u6846 "),
        vue.unref(videoStore).fileList.value.length < props.maxCount ? (vue.openBlock(), vue.createElementBlock(
          "div",
          {
            key: 1,
            style: vue.normalizeStyle([{ "float": "left" }, { width: `${props.width}px`, height: `${props.height}px` }])
          },
          [
            vue.createVNode(vue.unref(index.MeFlexBox), {
              class: "video-container",
              onClick: vue.unref(videoStore).openUpload
            }, {
              default: vue.withCtx(() => [
                vue.createElementVNode("div", _hoisted_4, [
                  vue.createVNode(vue.unref(index$1.MeSvgIcon), {
                    name: "ri-video-upload-fill",
                    size: 24,
                    style: { "color": "#767676" }
                  })
                ])
              ]),
              _: 1
              /* STABLE */
            }, 8, ["onClick"])
          ],
          4
          /* STYLE */
        )) : vue.createCommentVNode("v-if", true),
        vue.createCommentVNode(" \u901A\u7528\u4E0A\u4F20\u7EC4\u4EF6 "),
        vue.createVNode(vue.unref(index$2.MeUpload), vue.mergeProps({
          modelValue: vue.unref(videoStore).uploadVisible.value,
          "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => vue.unref(videoStore).uploadVisible.value = $event),
          "upload-request": __props.uploadRequest,
          title: props.title,
          maxCount: 1,
          url: __props.url,
          rules: __props.uploadRules,
          uploadCompleteEvent: uploadCompleteEventHandler
        }, _ctx.$attrs), {
          footer: vue.withCtx(() => [
            vue.renderSlot(_ctx.$slots, "footer")
          ]),
          _: 3
          /* FORWARDED */
        }, 16, ["modelValue", "upload-request", "title", "url", "rules"])
      ]);
    };
  }
});

exports.default = script;
//# sourceMappingURL=upload-video.vue2.js.map
