'use strict';

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

var vue = require('vue');
var uploadItem = require('./uploadItem.js');

var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{
    name: "GmUploadItem"
  },
  __name: "UploadItem",
  props: /* @__PURE__ */ vue.mergeModels(uploadItem.uploadItemProps, {
    "imageUrl": { required: true },
    "imageUrlModifiers": {}
  }),
  emits: ["update:imageUrl"],
  setup(__props) {
    const props = __props;
    const imageUrl = vue.useModel(__props, "imageUrl");
    const slots = vue.useSlots();
    const fileList = vue.ref([]);
    const uploadDisabled = vue.computed(() => Boolean(props.disabled) || fileList.value.length > 0);
    vue.watch(
      imageUrl,
      (newVal) => {
        if (newVal) {
          fileList.value = [{ url: newVal, name: newVal }];
        } else {
          fileList.value = [];
        }
      },
      { immediate: true }
    );
    const handleComplete = () => {
      imageUrl.value = fileList.value[0]?.response?.url ?? "";
      props.onAllComplete?.();
    };
    const handleRemove = (file, uploadFiles) => {
      imageUrl.value = "";
      props.onRemove?.(file, uploadFiles);
    };
    return (_ctx, _cache) => {
      const _component_gm_upload_pro = vue.resolveComponent("gm-upload-pro");
      return vue.openBlock(), vue.createBlock(_component_gm_upload_pro, vue.mergeProps(props, {
        fileList: fileList.value,
        "onUpdate:fileList": _cache[0] || (_cache[0] = ($event) => fileList.value = $event),
        limit: 1,
        disabled: uploadDisabled.value,
        "on-all-complete": handleComplete,
        "on-remove": handleRemove
      }), vue.createSlots({
        _: 2
        /* DYNAMIC */
      }, [
        vue.unref(slots).default ? {
          name: "default",
          fn: vue.withCtx(() => [
            vue.renderSlot(_ctx.$slots, "default")
          ]),
          key: "0"
        } : {
          name: "file",
          fn: vue.withCtx((slotValue) => [
            vue.renderSlot(_ctx.$slots, "file", vue.normalizeProps(vue.guardReactiveProps(slotValue)))
          ]),
          key: "1"
        },
        vue.unref(slots).trigger ? {
          name: "trigger",
          fn: vue.withCtx(() => [
            vue.renderSlot(_ctx.$slots, "trigger")
          ]),
          key: "2"
        } : void 0,
        vue.unref(slots).tip ? {
          name: "tip",
          fn: vue.withCtx(() => [
            vue.renderSlot(_ctx.$slots, "tip")
          ]),
          key: "3"
        } : void 0,
        vue.unref(slots).fileActions ? {
          name: "fileActions",
          fn: vue.withCtx((slotValue) => [
            vue.renderSlot(_ctx.$slots, "fileActions", vue.normalizeProps(vue.guardReactiveProps(slotValue)))
          ]),
          key: "4"
        } : void 0
      ]), 1040, ["fileList", "disabled"]);
    };
  }
});

exports.default = _sfc_main;
//# sourceMappingURL=UploadItem.vue2.js.map
