import { ad as r, I as x, H as i, a4 as t, cD as K, a as P, cJ as Q, V as N, bX as Y, a9 as Z, a5 as O, cK as ee, aG as te, cL as ae, w as G, P as R, a3 as k, cM as ie, cN as oe, X as ne, aa as le, ci as re, U as se, ae as V, af as M, co as ce, am as I, c0 as de, ag as fe, ct as ue, cO as U, cP as h, ah as me, aj as D, cQ as pe, c1 as he, ak as ge, aC as be, aD as xe, aE as ye, cR as B, cS as we, c5 as F, cT as _, cU as L, c8 as T, cV as Ce, _ as H, cW as Se, cX as ve, cY as W, ao as Ve, as as Me } from "./56c67d3b.js";
import Te, { useContext as $, useState as y, useEffect as J, useRef as ke, useCallback as Ie, Suspense as Fe } from "react";
import "react-dom";
const A = Ce((e) => {
  var l;
  if (typeof e == "number")
    return e;
  if (typeof e == "string") {
    const n = e.trim();
    if (n === "")
      return 0;
    const d = Number(n);
    if (!H.isNaN(d))
      return d;
    const f = ["bytes", "kb", "mb", "gb", "tb"];
    if (new RegExp("^\\d+\\s*[kmgt]b$", "i").test(n)) {
      const g = parseInt(((l = n.match("^\\d+")) == null ? void 0 : l[0]) ?? "", 10), u = f.findIndex((b) => n.search(new RegExp(b, "i")) !== -1);
      return g * Math.pow(1024, u);
    }
  }
  throw new TypeError(t("file.typeErrorMsg", {
    value: typeof e
  }));
}), q = /* @__PURE__ */ r(x, {
  children: [/* @__PURE__ */ i("div", {
    children: t("file.parsedValueTooltip1")
  }), /* @__PURE__ */ i("div", {
    children: t("file.parsedValueTooltip2")
  })]
}), $e = [K, {
  label: t("event.parse"),
  value: "parse",
  description: t("event.parseDesc")
}], Ee = {
  minSize: A,
  maxSize: A,
  maxFiles: ge
}, ze = {
  value: P([]),
  files: P([]),
  fileType: Q,
  showUploadList: N.DEFAULT_TRUE,
  disabled: Y,
  onEvent: Z($e),
  style: O(ee, "style"),
  animationStyle: O(te, "animationStyle"),
  parseFiles: ae,
  parsedValue: P([]),
  prefixIcon: G(R, "/icon:solid/arrow-up-from-bracket"),
  suffixIcon: R,
  forceCapture: N,
  ...Ee
}, Pe = (e) => [e.minSize.propertyView({
  label: t("file.minSize"),
  placeholder: "1kb",
  tooltip: t("file.minSizeTooltip")
}), e.maxSize.propertyView({
  label: t("file.maxSize"),
  placeholder: "10kb",
  tooltip: t("file.maxSizeTooltip")
})], De = (e) => ({
  accept: e.fileType.toString(),
  multiple: e.uploadType === "multiple",
  directory: e.uploadType === "directory",
  showUploadList: e.showUploadList,
  customRequest: (l) => l.onSuccess && l.onSuccess({})
  // Override the default upload logic and do not upload to the specified server
}), Ue = (e) => be`
    .ant-btn {
      border-radius: ${e.radius};
      rotate: ${e.rotation};
      margin: ${e.margin};	
      padding: ${e.padding};	
      width: ${xe(e.margin)};	
      height: ${ye(e.margin)};
      font-family:${e.fontFamily};
      font-size:${e.textSize};
      font-weight:${e.textWeight};
      font-style:${e.fontStyle};
      border-width:${e.borderWidth};
      border-style:${e.borderStyle};
      text-decoration:${e.textDecoration};
      text-transform:${e.textTransform};
      text-transform:${e.textTransform};
    }

    .ant-btn:not(:disabled) {
      border-color: ${e.border};
      background: ${e.background};
      color: ${e.text};

      &:hover,
      &:focus {
        border-color: ${e.accent};
        color: ${e.accent};
      }

      &:active {
        border-color: ${B(e.accent, 0.1)};
        color: ${B(e.accent, 0.1)};
      }
    }
  `, Le = k(L)`
  .ant-upload,
  .ant-btn {
    ${(e) => e.$animationStyle}
    width: 100%;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 6px;

    > span {
      overflow: hidden;
      display: inline-flex;
      justify-content: flex-start;
      align-items: center;
      gap: 6px;
      min-height: 1px;
    }
  }
  ${(e) => e.$style && Ue(e.$style)}
`, X = k.span`
  display: flex;
`, je = k(Se)`
  top: 10vh;
  .react-draggable {
    max-width: 100%;
    width: 500px;

    video {
      width: 100%;
    }
  }
`, Ne = k.div`
  color: #f5222d;
  height: 100px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
`, Oe = k.div`
  img,
  video,
  .ant-skeleton {
    width: 100%;
    height: 400px;
    max-height: 70vh;
    position: relative;
    object-fit: cover;
    background-color: #000;
  }
  .ant-skeleton {
    h3,
    li {
      background-color: transparent;
    }
  }
`;
function Re(e) {
  return Promise.all(e.map((l) => {
    var n;
    return ((n = l.originFileObj) == null ? void 0 : n.arrayBuffer().then((d) => ie.Buffer.from(d).toString("base64")).catch(() => null)) ?? null;
  }));
}
function Be(e) {
  return Promise.all(e.map(async (l) => {
    var d;
    const n = await import("./2112abba.js");
    return ((d = l.originFileObj) == null ? void 0 : d.arrayBuffer().then((f) => {
      var u;
      const p = oe.getExtension(((u = l.originFileObj) == null ? void 0 : u.type) ?? "");
      if (p === "xlsx" || p === "csv") {
        const b = n.read(f, {
          raw: !0,
          codepage: 65001
        });
        return n.utils.sheet_to_json(b.Sheets[b.SheetNames[0]], {
          raw: !1
        });
      }
      const g = new TextDecoder("utf-8").decode(f);
      return g ? JSON.parse(g) : null;
    }).catch(() => null)) ?? null;
  }));
}
const _e = Te.lazy(() => import("./4e6d74df.js").then((e) => e.r)), We = (e) => {
  const [l, n] = y(""), [d, f] = y({
    facingMode: "environment"
  }), [p, g] = y([]), [u, b] = y(!1), [w, C] = y(), o = ke(null);
  J(() => {
    e.showModal && (C(""), n(""));
  }, [e.showModal]);
  const E = (a) => {
    typeof a == "string" ? n(a) : a.message === "getUserMedia is not implemented in this browser" ? n(t("scanner.errTip")) : n(a.message);
  }, m = Ie(() => {
    var c, S;
    const a = (S = (c = o.current) == null ? void 0 : c.getScreenshot) == null ? void 0 : S.call(c);
    C(a);
  }, [o]), s = () => {
    navigator.mediaDevices.enumerateDevices().then((a) => {
      const S = a.filter((v) => v.kind === "videoinput").map((v, z) => ({
        label: v.label || t("scanner.camera", {
          index: z + 1
        }),
        key: v.deviceId
      }));
      g(S);
    });
  };
  return /* @__PURE__ */ i(je, {
    showOkButton: !1,
    showCancelButton: !1,
    open: e.showModal,
    maskClosable: !0,
    destroyOnClose: !0,
    onCancel: e.onModalClose,
    children: l ? /* @__PURE__ */ i(Ne, {
      children: l
    }) : e.showModal && /* @__PURE__ */ r(Oe, {
      children: [w ? /* @__PURE__ */ i("img", {
        src: w,
        alt: "webcam"
      }) : /* @__PURE__ */ i(Fe, {
        fallback: /* @__PURE__ */ i(ve, {}),
        children: /* @__PURE__ */ i(_e, {
          ref: o,
          onUserMediaError: E,
          screenshotFormat: "image/jpeg"
        })
      }), w ? /* @__PURE__ */ r(W, {
        justify: "center",
        gap: 10,
        children: [/* @__PURE__ */ i(T, {
          type: "primary",
          style: {
            float: "right",
            marginTop: "10px"
          },
          onClick: (a) => {
            a.stopPropagation(), e.onImageCapture(w);
          },
          children: t("file.usePhoto")
        }), /* @__PURE__ */ i(T, {
          style: {
            float: "right",
            marginTop: "10px"
          },
          onClick: (a) => {
            a.stopPropagation(), C("");
          },
          children: t("file.retakePhoto")
        })]
      }) : /* @__PURE__ */ r(W, {
        justify: "center",
        gap: 10,
        children: [/* @__PURE__ */ i(T, {
          type: "primary",
          style: {
            float: "right",
            marginTop: "10px"
          },
          onClick: (a) => {
            a.stopPropagation(), m();
          },
          children: t("file.capture")
        }), /* @__PURE__ */ i(Ve, {
          placement: "bottomRight",
          trigger: ["click"],
          open: u,
          onOpenChange: (a) => b(a),
          dropdownRender: () => /* @__PURE__ */ i(Me, {
            items: p,
            onClick: (a) => f({
              ...d,
              deviceId: a.key
            })
          }),
          children: /* @__PURE__ */ i(T, {
            style: {
              float: "right",
              marginTop: "10px"
            },
            onClick: (a) => {
              a.stopPropagation(), s();
            },
            children: t("scanner.changeCamera")
          })
        })]
      })]
    })
  });
}, Ae = (e) => {
  const {
    dispatch: l,
    files: n,
    style: d
  } = e, [f, p] = y(n.map((o) => ({
    ...o,
    status: "done"
  }))), [g, u] = y(!1), b = we(window.innerWidth);
  J(() => {
    n.length === 0 && f.length !== 0 && p([]);
  }, [n]);
  const w = F(e.prefixIcon) || !!e.text || F(e.suffixIcon), C = (o) => {
    if (o.fileList.filter((a) => a.status === "uploading").length !== 0) {
      p(o.fileList);
      return;
    }
    let m = e.maxFiles;
    e.uploadType === "single" ? m = 1 : e.maxFiles <= 0 && (m = 100);
    const s = o.fileList.filter((a) => a.status === "done");
    if (o.file.status === "removed") {
      const a = e.files.findIndex((c) => c.uid === o.file.uid);
      l(U({
        value: h([...e.value.slice(0, a), ...e.value.slice(a + 1)], !1),
        files: h([...e.files.slice(0, a), ...e.files.slice(a + 1)], !1),
        parsedValue: h([...e.parsedValue.slice(0, a), ...e.parsedValue.slice(a + 1)], !1)
      })), e.onEvent("change");
    } else {
      const a = Math.min(e.value.length, s.length), c = Math.min(e.parsedValue.length, s.length);
      Promise.all([Re(s.slice(a)), Be(s.slice(c))]).then(([S, v]) => {
        l(U({
          value: h([...e.value, ...S].slice(-m), !1),
          files: h(s.map((z) => H.pick(z, ["uid", "name", "type", "size", "lastModified"])).slice(-m), !1),
          ...e.parseFiles ? {
            parsedValue: h([...e.parsedValue, ...v].slice(-m), !1)
          } : {}
        })), e.onEvent("change"), e.onEvent("parse");
      });
    }
    p(s.slice(-m));
  };
  return /* @__PURE__ */ r(x, {
    children: [/* @__PURE__ */ i(Le, {
      capture: e.forceCapture,
      $animationStyle: e.animationStyle,
      ...De(e),
      $style: d,
      fileList: f,
      beforeUpload: (o) => !o.size || o.size <= 0 ? (_.error(`${o.name} ` + t("file.fileEmptyErrorMsg")), L.LIST_IGNORE) : e.minSize && o.size < e.minSize || e.maxSize && o.size > e.maxSize ? (_.error(`${o.name} ` + t("file.fileSizeExceedErrorMsg")), L.LIST_IGNORE) : !0,
      onChange: C,
      children: /* @__PURE__ */ i(T, {
        disabled: e.disabled,
        onClick: (o) => {
          e.forceCapture && !b && (o.preventDefault(), o.stopPropagation(), u(!0));
        },
        children: w && /* @__PURE__ */ r("span", {
          children: [F(e.prefixIcon) && /* @__PURE__ */ i(X, {
            children: e.prefixIcon
          }), !!e.text && e.text, F(e.suffixIcon) && /* @__PURE__ */ i(X, {
            children: e.suffixIcon
          })]
        })
      })
    }), /* @__PURE__ */ i(We, {
      showModal: g,
      onModalClose: () => u(!1),
      onImageCapture: async (o) => {
        u(!1);
        const m = await (await fetch(o)).blob(), s = new File([m], "image.jpg", {
          type: "image/jpeg"
        }), c = {
          uid: uuid.v4(),
          name: s.name,
          type: s.type,
          size: s.size,
          lastModified: s.lastModified,
          lastModifiedDate: s.lastModifiedDate,
          status: "done",
          originFileObj: s
        };
        C({
          file: c,
          fileList: [...f, c]
        });
      }
    })]
  });
}, Xe = [{
  label: t("file.single"),
  value: "single"
}, {
  label: t("file.multiple"),
  value: "multiple"
}, {
  label: t("file.directory"),
  value: "directory"
}], Ge = {
  text: G(ne, t("file.upload")),
  uploadType: le(Xe, "single"),
  ...ze,
  ...re
};
let j = new se(Ge, (e, l) => /* @__PURE__ */ i(Ae, {
  ...e,
  dispatch: l
})).setPropertyViewFn((e) => /* @__PURE__ */ r(x, {
  children: [/* @__PURE__ */ r(V, {
    name: M.basic,
    children: [e.text.propertyView({
      label: t("text")
    }), e.uploadType.propertyView({
      label: t("file.uploadType")
    })]
  }), /* @__PURE__ */ i(ce, {
    ...e
  }), ($(I).editorModeStatus === "logic" || $(I).editorModeStatus === "both") && /* @__PURE__ */ r(x, {
    children: [/* @__PURE__ */ r(V, {
      name: M.validation,
      children: [e.uploadType.getView() !== "single" && e.maxFiles.propertyView({
        label: t("file.maxFiles")
      }), Pe(e)]
    }), /* @__PURE__ */ r(V, {
      name: M.interaction,
      children: [e.onEvent.getPropertyView(), de(e), fe(e)]
    }), /* @__PURE__ */ r(V, {
      name: M.advanced,
      children: [e.fileType.propertyView({
        label: t("file.fileType"),
        placeholder: '[".png"]',
        tooltip: /* @__PURE__ */ r(x, {
          children: [t("file.reference"), " ", /* @__PURE__ */ i("a", {
            href: t("file.fileTypeTooltipUrl"),
            target: "_blank",
            rel: "noreferrer",
            children: t("file.fileTypeTooltip")
          })]
        })
      }), e.prefixIcon.propertyView({
        label: t("button.prefixIcon")
      }), e.suffixIcon.propertyView({
        label: t("button.suffixIcon")
      }), e.forceCapture.propertyView({
        label: t("file.forceCapture"),
        tooltip: t("file.forceCaptureTooltip")
      }), e.showUploadList.propertyView({
        label: t("file.showUploadList")
      }), e.parseFiles.propertyView({
        label: t("file.parseFiles"),
        tooltip: q,
        placement: "right"
      })]
    })]
  }), ($(I).editorModeStatus === "layout" || $(I).editorModeStatus === "both") && /* @__PURE__ */ r(x, {
    children: [/* @__PURE__ */ i(V, {
      name: M.style,
      children: e.style.getPropertyView()
    }), /* @__PURE__ */ i(V, {
      name: M.animationStyle,
      hasTooltip: !0,
      children: e.animationStyle.getPropertyView()
    })]
  })]
})).build();
j = ue(j, [{
  method: {
    name: "clearValue",
    description: t("file.clearValueDesc"),
    params: []
  },
  execute: (e) => e.dispatch(U({
    value: h([], !1),
    files: h([], !1),
    parsedValue: h([], !1)
  }))
}]);
const Ke = me(j, [new D("value", t("file.filesValueDesc")), new D("files", /* @__PURE__ */ r(x, {
  children: [t("file.filesDesc"), (() => {
    const e = pe("file");
    if (e)
      return /* @__PURE__ */ r(x, {
        children: [" ", /* @__PURE__ */ i("a", {
          href: e,
          target: "_blank",
          rel: "noreferrer",
          children: t("uiComp.fileUploadCompName")
        })]
      });
  })()]
})), new D("parsedValue", q), ...he]);
export {
  Ke as FileComp,
  Be as resolveParsedValue,
  Re as resolveValue
};
