"use strict";
const common_vendor = require("../../common/vendor.js");
const common_libraries_watermark = require("../../common/libraries/watermark.js");
const common_libraries_upload = require("../../common/libraries/upload.js");
require("../../gen/Apis.js");
require("../../common/libraries/request.js");
require("../../common/store/useWeAppAuthStore.js");
require("../../common/libraries/apiLoading.js");
require("../../common/store/useWatermarkStore.js");
require("../../common/store/useWorkStore.js");
if (!Array) {
  const _easycom_up_icon2 = common_vendor.resolveComponent("up-icon");
  const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  (_easycom_up_icon2 + _easycom_uni_icons2)();
}
const _easycom_up_icon = () => "../../node-modules/uview-plus/components/u-icon/u-icon.js";
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
if (!Math) {
  (_easycom_up_icon + _easycom_uni_icons)();
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "hs-upload",
  props: [
    "valueModel",
    "size",
    "display",
    "length",
    "borderTop",
    "mediaType",
    "labelTitle",
    "count",
    "styles",
    "hasCover",
    "iconName",
    "iconSize",
    "required",
    "title"
  ],
  emits: ["update:valueModel"],
  setup(__props, { emit }) {
    const props = __props;
    const list = common_vendor.ref([]);
    const handleUpload = async () => {
      const res = await common_libraries_upload.upload(props.count || 1, props == null ? void 0 : props.size, (props == null ? void 0 : props.mediaType) || ["image"]);
      console.log(res, "res");
      list.value = [...list.value, ...res];
      emit("update:valueModel", list.value);
    };
    const onDelete = (idx) => {
      if (props == null ? void 0 : props.display) {
        return false;
      }
      list.value.splice(idx, 1);
    };
    common_vendor.watch(
      () => props == null ? void 0 : props.valueModel,
      () => {
        if (props.valueModel) {
          list.value = props.valueModel || [];
        }
      }
    );
    const onPreviewMedia = (url) => {
      console.log(url, "url1");
      if (url) {
        common_vendor.index.showLoading({
          title: "获取图片中...",
          mask: true
        });
        console.log(url, "url2");
        common_vendor.index.downloadFile({
          url,
          success: (res) => {
            const imagePath = res.tempFilePath;
            console.log(imagePath, "imagePath");
            common_libraries_watermark.watermark.addWatermark(imagePath, "仅用于内部查看，请勿外传");
          },
          fail: (err) => {
            common_vendor.index.showToast({
              title: "获取失败",
              duration: 1e3
            });
            console.error("下载图片失败:", err);
          }
        });
      }
    };
    common_vendor.onMounted(() => {
      if (props.valueModel) {
        list.value = props.valueModel || [];
      }
    });
    return (_ctx, _cache) => {
      var _a, _b, _c, _d;
      return common_vendor.e({
        a: common_vendor.t((props == null ? void 0 : props.title) || "上传"),
        b: props == null ? void 0 : props.required
      }, (props == null ? void 0 : props.required) ? {} : {}, {
        c: common_vendor.t((props == null ? void 0 : props.count) || 1),
        d: common_vendor.f(list.value, (i, index, i0) => {
          var _a2, _b2;
          return common_vendor.e({
            a: (_a2 = i == null ? void 0 : i.type) == null ? void 0 : _a2.includes("video")
          }, ((_b2 = i == null ? void 0 : i.type) == null ? void 0 : _b2.includes("video")) ? {
            b: "eb3a1d92-0-" + i0,
            c: common_vendor.p({
              name: "play-circle-fill",
              size: "30"
            })
          } : {
            d: i == null ? void 0 : i.url,
            e: common_vendor.o(($event) => onPreviewMedia(i == null ? void 0 : i.url), index)
          }, {
            f: "eb3a1d92-1-" + i0,
            g: common_vendor.o(($event) => onDelete(index), index),
            h: index === 0 && (props == null ? void 0 : props.hasCover)
          }, index === 0 && (props == null ? void 0 : props.hasCover) ? {
            i: common_vendor.o(($event) => onDelete(index), index)
          } : {}, {
            j: index
          });
        }),
        e: common_vendor.p({
          type: "clear",
          color: "#f00",
          size: "25"
        }),
        f: common_vendor.s(props == null ? void 0 : props.styles),
        g: !(props == null ? void 0 : props.display) && ((_a = list.value) == null ? void 0 : _a.length) < ((props == null ? void 0 : props.count) || 1)
      }, !(props == null ? void 0 : props.display) && ((_b = list.value) == null ? void 0 : _b.length) < ((props == null ? void 0 : props.count) || 1) ? common_vendor.e({
        h: props == null ? void 0 : props.iconName
      }, (props == null ? void 0 : props.iconName) ? {
        i: common_vendor.p({
          name: props == null ? void 0 : props.iconName,
          label: props.labelTitle || "",
          color: "#333",
          size: (props == null ? void 0 : props.iconSize) || 50
        })
      } : {
        j: common_vendor.p({
          name: (props == null ? void 0 : props.iconName) || "plus",
          label: props.labelTitle || "",
          labelPos: "bottom",
          labelSize: "20rpx",
          lableColor: "#666",
          color: "#333",
          size: "20",
          space: "6px"
        })
      }, {
        k: common_vendor.o(handleUpload),
        l: common_vendor.s(props == null ? void 0 : props.styles)
      }) : {}, {
        m: (props == null ? void 0 : props.display) && !((_c = list.value) == null ? void 0 : _c.length)
      }, (props == null ? void 0 : props.display) && !((_d = list.value) == null ? void 0 : _d.length) ? {} : {}, {
        n: props.borderTop ? "1rpx solid #eee" : ""
      });
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-eb3a1d92"], ["__file", "/Users/zsq/Sources/github/2025property-pay/pay-employee/src/components/hs-upload/hs-upload.vue"]]);
wx.createComponent(Component);
