import { a$ as X, r as S, l as q, y as Q, v as P, aN as J, aM as K, j as h, c as b, aI as Y, aJ as Z, b0 as ee, aK as te, ap as _, aR as R, E as O, _ as T, w as re, m as ie, b1 as se, X as oe, ao as ae, b2 as $, b3 as ne, aS as le, aQ as de, ai as ce, aC as ue } from "./index-6wLGsgHc.js";
import { t as V } from "./UploadFileInfo-B5SttewO-Cfj4jyqp.js";
import { d as he } from "./FormClearHelper-Dgu5Halt-DyRdP6JG.js";
import { q as pe, U as fe } from "./ProgressBar-bzD0ionS-BU2taYKp.js";
var L = /* @__PURE__ */ S.forwardRef(function(r, l) {
  var e = {
    fill: "currentColor",
    xmlns: "http://www.w3.org/2000/svg"
  };
  return /* @__PURE__ */ S.createElement(O, T({
    iconAttrs: e,
    iconVerticalAlign: "middle",
    iconViewBox: "0 0 24 24"
  }, r, {
    ref: l
  }), /* @__PURE__ */ S.createElement("rect", {
    width: 24,
    height: 24,
    fill: "none"
  }), /* @__PURE__ */ S.createElement("path", {
    d: "M20 5h-3.17l-1.24-1.35A1.99 1.99 0 0014.12 3H9.88c-.56 0-1.1.24-1.48.65L7.17 5H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm-1.35 8.35l-2.79 2.79c-.32.32-.86.1-.86-.35v-1.75H9v1.75c0 .45-.54.67-.85.35l-2.79-2.79c-.2-.2-.2-.51 0-.71l2.79-2.79a.5.5 0 01.85.36v1.83h6v-1.83c0-.45.54-.67.85-.35l2.79 2.79c.2.19.2.51.01.7z"
  }));
});
L.displayName = "SwitchCamera";
var D = /* @__PURE__ */ S.forwardRef(function(r, l) {
  var e = {
    fill: "currentColor",
    xmlns: "http://www.w3.org/2000/svg"
  };
  return /* @__PURE__ */ S.createElement(O, T({
    iconAttrs: e,
    iconVerticalAlign: "middle",
    iconViewBox: "0 0 8 8"
  }, r, {
    ref: l
  }), /* @__PURE__ */ S.createElement("path", {
    d: "M.5 1c-.28 0-.5.23-.5.5v4c0 .28.23.5.5.5h5c.28 0 .5-.22.5-.5V4l1 1h1V2H7L6 3V1.5c0-.28-.22-.5-.5-.5h-5z"
  }));
});
D.displayName = "Video";
var A = /* @__PURE__ */ S.forwardRef(function(r, l) {
  var e = {
    fill: "currentColor",
    xmlns: "http://www.w3.org/2000/svg"
  };
  return /* @__PURE__ */ S.createElement(O, T({
    iconAttrs: e,
    iconVerticalAlign: "middle",
    iconViewBox: "0 0 8 8"
  }, r, {
    ref: l
  }), /* @__PURE__ */ S.createElement("path", {
    d: "M1.41 0L0 1.41l.72.72L2.5 3.94.72 5.72 0 6.41l1.41 1.44.72-.72 1.81-1.81 1.78 1.81.69.72 1.44-1.44-.72-.69-1.81-1.78 1.81-1.81.72-.72L6.41 0l-.69.72L3.94 2.5 2.13.72 1.41 0z"
  }));
});
A.displayName = "X";
function ge(r, l) {
  switch (r) {
    case "xsmall":
      return {
        padding: `${l.spacing.twoXS} ${l.spacing.sm}`,
        fontSize: l.fontSizes.sm
      };
    case "small":
      return {
        padding: `${l.spacing.twoXS} ${l.spacing.md}`
      };
    case "large":
      return {
        padding: `${l.spacing.md} ${l.spacing.md}`
      };
    default:
      return {
        padding: `${l.spacing.xs} ${l.spacing.md}`
      };
  }
}
const H = /* @__PURE__ */ b("div", {
  target: "etz5kuj9"
})({
  name: "b6gpc",
  styles: "position:relative;overflow:hidden;width:100%;object-fit:contain"
}), k = /* @__PURE__ */ b("div", {
  target: "etz5kuj8"
})(({
  theme: r,
  width: l
}) => ({
  backgroundColor: r.colors.secondaryBg,
  borderRadius: `${r.radii.default} ${r.radii.default} 0 0`,
  width: "100%",
  height: l * 9 / 16,
  display: "flex",
  flexDirection: "column",
  justifyContent: "center",
  alignItems: "center"
}), ""), me = /* @__PURE__ */ b("p", {
  target: "etz5kuj7"
})(({
  theme: r
}) => ({
  marginTop: r.spacing.sm,
  textAlign: "center"
}), ""), ve = /* @__PURE__ */ b("img", {
  target: "etz5kuj6"
})(({
  theme: r,
  opacity: l
}) => ({
  borderRadius: `${r.radii.default} ${r.radii.default} 0 0`,
  objectFit: "contain",
  opacity: l
}), ""), Se = /* @__PURE__ */ b("a", {
  target: "etz5kuj5"
})(({
  theme: r
}) => ({
  color: r.colors.link,
  textDecoration: r.linkUnderline ? "underline" : "none",
  display: "block"
}), ""), ye = /* @__PURE__ */ b("span", {
  target: "etz5kuj4"
})({
  name: "s5xdrg",
  styles: "display:flex;align-items:center"
}), we = /* @__PURE__ */ b("div", {
  target: "etz5kuj3"
})(({
  theme: r
}) => ({
  position: "absolute",
  top: r.spacing.lg,
  right: r.spacing.lg,
  zIndex: r.zIndices.priority,
  color: r.colors.fadedText40,
  mixBlendMode: "difference",
  opacity: 0.6
}), ""), Me = /* @__PURE__ */ b("div", {
  target: "etz5kuj1"
})({
  name: "1yoks5w",
  styles: "height:fit-content;width:100%;position:absolute;bottom:0"
}), Ue = /* @__PURE__ */ b("button", {
  target: "etz5kuj0"
})(({
  theme: r
}) => ({
  position: "relative",
  display: "inline-flex",
  flexDirection: "column",
  alignItems: "center",
  justifyContent: "center",
  backgroundColor: r.colors.lightenedBg05,
  border: `${r.sizes.borderWidth} solid ${r.colors.borderColor}`,
  borderRadius: `0 0 ${r.radii.default} ${r.radii.default}`,
  "&:hover": {
    borderColor: r.colors.primary,
    color: r.colors.primary
  },
  "&:active": {
    color: r.colors.white,
    borderColor: r.colors.primary,
    backgroundColor: r.colors.primary
  },
  "&:focus:not(:active)": {
    borderColor: r.colors.primary,
    color: r.colors.primary
  },
  "&:disabled, &:disabled:hover, &:disabled:active": {
    color: r.colors.fadedText40,
    borderColor: r.colors.borderColor,
    backgroundColor: r.colors.lightenedBg05,
    cursor: "not-allowed"
  },
  fontWeight: r.fontWeights.normal,
  padding: `${r.spacing.xs} ${r.spacing.md}`,
  margin: r.spacing.none,
  lineHeight: r.lineHeights.base,
  color: "inherit",
  width: "100%",
  userSelect: "none",
  "&:focus": {
    outline: "none"
  },
  "&:focus-visible": {
    boxShadow: `0 0 0 0.2rem ${ae(r.colors.primary, 0.5)}`
  },
  ...ge("medium", r)
}), "");
function Ce({
  disabled: r,
  onClick: l,
  children: e,
  progress: s
}) {
  return /* @__PURE__ */ h.jsxs(Ue, {
    disabled: r || !1,
    onClick: l || (() => {
    }),
    progress: s || null,
    "data-testid": "stCameraInputButton",
    children: [e, s ? /* @__PURE__ */ h.jsx(Me, {
      children: /* @__PURE__ */ h.jsx(pe, {
        value: s,
        size: fe.EXTRASMALL,
        overrides: {
          Bar: {
            style: {
              borderTopLeftRadius: 0,
              borderTopRightRadius: 0
            }
          },
          BarProgress: {
            style: {
              borderTopLeftRadius: 0,
              borderTopRightRadius: 0
            }
          },
          BarContainer: {
            style: {
              borderTopLeftRadius: 0,
              borderTopRightRadius: 0
            }
          }
        }
      })
    }) : null]
  });
}
const N = S.memo(Ce);
var E = /* @__PURE__ */ ((r) => (r.USER = "user", r.ENVIRONMENT = "environment", r))(E || {});
const xe = ({
  switchFacingMode: r
}) => /* @__PURE__ */ h.jsx(we, {
  "data-testid": "stCameraInputSwitchButton",
  children: /* @__PURE__ */ h.jsx(le, {
    content: "Switch camera",
    placement: _.TOP_RIGHT,
    children: /* @__PURE__ */ h.jsx(de, {
      kind: ce.MINIMAL,
      onClick: r,
      children: /* @__PURE__ */ h.jsx(R, {
        content: L,
        size: "twoXL",
        color: $.white
      })
    })
  })
}), be = S.memo(xe);
var F = {
  exports: {}
}, Ie = F.exports, z;
function je() {
  return z || (z = 1, (function(r, l) {
    (function(e, s) {
      r.exports = s(ue);
    })(Ie, function(e) {
      return (
        /******/
        (function(s) {
          var o = {};
          function a(n) {
            if (o[n]) return o[n].exports;
            var p = o[n] = {
              /******/
              i: n,
              /******/
              l: !1,
              /******/
              exports: {}
              /******/
            };
            return s[n].call(p.exports, p, p.exports, a), p.l = !0, p.exports;
          }
          return a.m = s, a.c = o, a.d = function(n, p, y) {
            a.o(n, p) || Object.defineProperty(n, p, {
              enumerable: !0,
              get: y
            });
          }, a.r = function(n) {
            typeof Symbol < "u" && Symbol.toStringTag && Object.defineProperty(n, Symbol.toStringTag, {
              value: "Module"
            }), Object.defineProperty(n, "__esModule", {
              value: !0
            });
          }, a.t = function(n, p) {
            if (p & 1 && (n = a(n)), p & 8 || p & 4 && typeof n == "object" && n && n.__esModule) return n;
            var y = /* @__PURE__ */ Object.create(null);
            if (a.r(y), Object.defineProperty(y, "default", {
              enumerable: !0,
              value: n
            }), p & 2 && typeof n != "string") for (var x in n) a.d(y, x, (function(C) {
              return n[C];
            }).bind(null, x));
            return y;
          }, a.n = function(n) {
            var p = n && n.__esModule ? (
              /******/
              (function() {
                return n.default;
              })
            ) : (
              /******/
              (function() {
                return n;
              })
            );
            return a.d(p, "a", p), p;
          }, a.o = function(n, p) {
            return Object.prototype.hasOwnProperty.call(n, p);
          }, a.p = "", a(a.s = "./src/react-webcam.tsx");
        })({
          /***/
          "./src/react-webcam.tsx": (
            /*!******************************!*\
              !*** ./src/react-webcam.tsx ***!
              \******************************/
            /*! exports provided: default */
            /***/
            (function(s, o, a) {
              a.r(o);
              var n = a(
                /*! react */
                "react"
              ), p = /* @__PURE__ */ (function() {
                var f = function(u, i) {
                  return f = Object.setPrototypeOf || {
                    __proto__: []
                  } instanceof Array && function(t, c) {
                    t.__proto__ = c;
                  } || function(t, c) {
                    for (var d in c) c.hasOwnProperty(d) && (t[d] = c[d]);
                  }, f(u, i);
                };
                return function(u, i) {
                  f(u, i);
                  function t() {
                    this.constructor = u;
                  }
                  u.prototype = i === null ? Object.create(i) : (t.prototype = i.prototype, new t());
                };
              })(), y = function() {
                return y = Object.assign || function(f) {
                  for (var u, i = 1, t = arguments.length; i < t; i++) {
                    u = arguments[i];
                    for (var c in u) Object.prototype.hasOwnProperty.call(u, c) && (f[c] = u[c]);
                  }
                  return f;
                }, y.apply(this, arguments);
              }, x = function(f, u) {
                var i = {};
                for (var t in f) Object.prototype.hasOwnProperty.call(f, t) && u.indexOf(t) < 0 && (i[t] = f[t]);
                if (f != null && typeof Object.getOwnPropertySymbols == "function") for (var c = 0, t = Object.getOwnPropertySymbols(f); c < t.length; c++) u.indexOf(t[c]) < 0 && Object.prototype.propertyIsEnumerable.call(f, t[c]) && (i[t[c]] = f[t[c]]);
                return i;
              };
              (function() {
                typeof window > "u" || (navigator.mediaDevices === void 0 && (navigator.mediaDevices = {}), navigator.mediaDevices.getUserMedia === void 0 && (navigator.mediaDevices.getUserMedia = function(f) {
                  var u = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
                  return u ? new Promise(function(i, t) {
                    u.call(navigator, f, i, t);
                  }) : Promise.reject(new Error("getUserMedia is not implemented in this browser"));
                }));
              })();
              function C() {
                return !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia);
              }
              var I = (
                /** @class */
                (function(f) {
                  p(u, f);
                  function u(i) {
                    var t = f.call(this, i) || this;
                    return t.canvas = null, t.ctx = null, t.requestUserMediaId = 0, t.unmounted = !1, t.state = {
                      hasUserMedia: !1
                    }, t;
                  }
                  return u.prototype.componentDidMount = function() {
                    var i = this, t = i.state, c = i.props;
                    if (this.unmounted = !1, !C()) {
                      c.onUserMediaError("getUserMedia not supported");
                      return;
                    }
                    t.hasUserMedia || this.requestUserMedia(), c.children && typeof c.children != "function" && console.warn("children must be a function");
                  }, u.prototype.componentDidUpdate = function(i) {
                    var t = this.props;
                    if (!C()) {
                      t.onUserMediaError("getUserMedia not supported");
                      return;
                    }
                    var c = JSON.stringify(i.audioConstraints) !== JSON.stringify(t.audioConstraints), d = JSON.stringify(i.videoConstraints) !== JSON.stringify(t.videoConstraints), M = i.minScreenshotWidth !== t.minScreenshotWidth, v = i.minScreenshotHeight !== t.minScreenshotHeight;
                    (d || M || v) && (this.canvas = null, this.ctx = null), (c || d) && (this.stopAndCleanup(), this.requestUserMedia());
                  }, u.prototype.componentWillUnmount = function() {
                    this.unmounted = !0, this.stopAndCleanup();
                  }, u.stopMediaStream = function(i) {
                    i && (i.getVideoTracks && i.getAudioTracks ? (i.getVideoTracks().map(function(t) {
                      i.removeTrack(t), t.stop();
                    }), i.getAudioTracks().map(function(t) {
                      i.removeTrack(t), t.stop();
                    })) : i.stop());
                  }, u.prototype.stopAndCleanup = function() {
                    var i = this.state;
                    i.hasUserMedia && (u.stopMediaStream(this.stream), i.src && window.URL.revokeObjectURL(i.src));
                  }, u.prototype.getScreenshot = function(i) {
                    var t = this, c = t.state, d = t.props;
                    if (!c.hasUserMedia) return null;
                    var M = this.getCanvas(i);
                    return M && M.toDataURL(d.screenshotFormat, d.screenshotQuality);
                  }, u.prototype.getCanvas = function(i) {
                    var t = this, c = t.state, d = t.props;
                    if (!this.video || !c.hasUserMedia || !this.video.videoHeight) return null;
                    if (!this.ctx) {
                      var M = this.video.videoWidth, v = this.video.videoHeight;
                      if (!this.props.forceScreenshotSourceSize) {
                        var m = M / v;
                        M = d.minScreenshotWidth || this.video.clientWidth, v = M / m, d.minScreenshotHeight && v < d.minScreenshotHeight && (v = d.minScreenshotHeight, M = v * m);
                      }
                      this.canvas = document.createElement("canvas"), this.canvas.width = i?.width || M, this.canvas.height = i?.height || v, this.ctx = this.canvas.getContext("2d");
                    }
                    var U = this, w = U.ctx, g = U.canvas;
                    return w && g && (g.width = i?.width || g.width, g.height = i?.height || g.height, d.mirrored && (w.translate(g.width, 0), w.scale(-1, 1)), w.imageSmoothingEnabled = d.imageSmoothing, w.drawImage(this.video, 0, 0, i?.width || g.width, i?.height || g.height), d.mirrored && (w.scale(-1, 1), w.translate(-g.width, 0))), g;
                  }, u.prototype.requestUserMedia = function() {
                    var i = this, t = this.props, c = function(v, m) {
                      var U = {
                        video: typeof m < "u" ? m : !0
                      };
                      t.audio && (U.audio = typeof v < "u" ? v : !0), i.requestUserMediaId++;
                      var w = i.requestUserMediaId;
                      navigator.mediaDevices.getUserMedia(U).then(function(g) {
                        i.unmounted || w !== i.requestUserMediaId ? u.stopMediaStream(g) : i.handleUserMedia(null, g);
                      }).catch(function(g) {
                        i.handleUserMedia(g);
                      });
                    };
                    if ("mediaDevices" in navigator) c(t.audioConstraints, t.videoConstraints);
                    else {
                      var d = function(v) {
                        return {
                          optional: [{
                            sourceId: v
                          }]
                        };
                      }, M = function(v) {
                        var m = v.deviceId;
                        return typeof m == "string" ? m : Array.isArray(m) && m.length > 0 ? m[0] : typeof m == "object" && m.ideal ? m.ideal : null;
                      };
                      MediaStreamTrack.getSources(function(v) {
                        var m = null, U = null;
                        v.forEach(function(j) {
                          j.kind === "audio" ? m = j.id : j.kind === "video" && (U = j.id);
                        });
                        var w = M(t.audioConstraints);
                        w && (m = w);
                        var g = M(t.videoConstraints);
                        g && (U = g), c(d(m), d(U));
                      });
                    }
                  }, u.prototype.handleUserMedia = function(i, t) {
                    var c = this.props;
                    if (i || !t) {
                      this.setState({
                        hasUserMedia: !1
                      }), c.onUserMediaError(i);
                      return;
                    }
                    this.stream = t;
                    try {
                      this.video && (this.video.srcObject = t), this.setState({
                        hasUserMedia: !0
                      });
                    } catch {
                      this.setState({
                        hasUserMedia: !0,
                        src: window.URL.createObjectURL(t)
                      });
                    }
                    c.onUserMedia(t);
                  }, u.prototype.render = function() {
                    var i = this, t = this, c = t.state, d = t.props, M = d.audio;
                    d.forceScreenshotSourceSize;
                    var v = d.disablePictureInPicture;
                    d.onUserMedia, d.onUserMediaError, d.screenshotFormat, d.screenshotQuality, d.minScreenshotWidth, d.minScreenshotHeight, d.audioConstraints, d.videoConstraints, d.imageSmoothing;
                    var m = d.mirrored, U = d.style, w = U === void 0 ? {} : U, g = d.children, j = x(d, ["audio", "forceScreenshotSourceSize", "disablePictureInPicture", "onUserMedia", "onUserMediaError", "screenshotFormat", "screenshotQuality", "minScreenshotWidth", "minScreenshotHeight", "audioConstraints", "videoConstraints", "imageSmoothing", "mirrored", "style", "children"]), W = m ? y(y({}, w), {
                      transform: (w.transform || "") + " scaleX(-1)"
                    }) : w, B = {
                      getScreenshot: this.getScreenshot.bind(this)
                    };
                    return n.createElement(n.Fragment, null, n.createElement("video", y({
                      autoPlay: !0,
                      disablePictureInPicture: v,
                      src: c.src,
                      muted: !M,
                      playsInline: !0,
                      ref: function(G) {
                        i.video = G;
                      },
                      style: W
                    }, j)), g && g(B));
                  }, u.defaultProps = {
                    audio: !1,
                    disablePictureInPicture: !1,
                    forceScreenshotSourceSize: !1,
                    imageSmoothing: !0,
                    mirrored: !1,
                    onUserMedia: function() {
                    },
                    onUserMediaError: function() {
                    },
                    screenshotFormat: "image/webp",
                    screenshotQuality: 0.92
                  }, u;
                })(n.Component)
              );
              o.default = I;
            })
          ),
          /***/
          react: (
            /*!**************************************************************************************!*\
              !*** external {"root":"React","commonjs2":"react","commonjs":"react","amd":"react"} ***!
              \**************************************************************************************/
            /*! no static exports found */
            /***/
            (function(s, o) {
              s.exports = e;
            })
          )
          /******/
        }).default
      );
    });
  })(F)), F.exports;
}
var Pe = je();
const Ee = /* @__PURE__ */ oe(Pe), Fe = ({
  width: r
}) => /* @__PURE__ */ h.jsxs(k, {
  width: r,
  children: [/* @__PURE__ */ h.jsx(R, {
    size: "threeXL",
    color: $.gray60,
    content: D
  }), /* @__PURE__ */ h.jsxs(me, {
    children: ["This app would like to use your camera.", /* @__PURE__ */ h.jsx(Se, {
      href: ne,
      rel: "noopener noreferrer",
      target: "_blank",
      children: "Learn how to allow access."
    })]
  })]
}), Re = ({
  handleCapture: r,
  width: l,
  disabled: e,
  clearPhotoInProgress: s,
  setClearPhotoInProgress: o,
  facingMode: a,
  setFacingMode: n,
  testOverride: p
}) => {
  const [y, x] = S.useState(
    p || "pending"
    /* PENDING */
  ), C = S.useRef(null), [I, f] = S.useState(l), u = S.useCallback(re(1e3, f), []);
  S.useEffect(() => {
    u(l);
  }, [l, u]);
  function i() {
    if (C.current !== null) {
      const c = C.current.getScreenshot();
      r(c);
    }
  }
  const t = ie();
  return /* @__PURE__ */ h.jsxs(H, {
    "data-testid": "stCameraInputWebcamComponent",
    children: [y !== "success" && !e && !s ? /* @__PURE__ */ h.jsx(Fe, {
      width: I
    }) : se() && /* @__PURE__ */ h.jsx(be, {
      switchFacingMode: n
    }), /* @__PURE__ */ h.jsx(k, {
      "data-testid": "stCameraInputWebcamStyledBox",
      hidden: y !== "success" && !e && !s,
      width: I,
      children: !e && /* @__PURE__ */ h.jsx(Ee, {
        audio: !1,
        ref: C,
        screenshotFormat: "image/jpeg",
        screenshotQuality: 1,
        width: I,
        height: I * 9 / 16,
        style: {
          borderRadius: `${t.radii.default} ${t.radii.default} 0 0`
        },
        onUserMediaError: () => {
          x(
            "error"
            /* ERROR */
          );
        },
        onUserMedia: () => {
          x(
            "success"
            /* SUCCESS */
          ), o(!1);
        },
        videoConstraints: {
          width: {
            ideal: I
          },
          facingMode: a
        }
      })
    }), /* @__PURE__ */ h.jsx(N, {
      onClick: i,
      disabled: y !== "success" || e || s,
      children: "Take Photo"
    })]
  });
}, Oe = S.memo(Re), Te = 150, ke = q.getLogger("CameraInput");
class Ve extends S.PureComponent {
  constructor(l) {
    super(l), this.localFileIdCounter = 1, this.RESTORED_FROM_WIDGET_STRING = "RESTORED_FROM_WIDGET", this.formClearHelper = new he(), this.getProgress = () => {
      if (this.state.files.length > 0 && this.state.files[this.state.files.length - 1].status.type === "uploading") return this.state.files[this.state.files.length - 1].status.progress;
    }, this.setClearPhotoInProgress = (e) => {
      this.setState({
        clearPhotoInProgress: e
      });
    }, this.setFacingMode = () => {
      this.setState((e) => ({
        facingMode: e.facingMode === E.USER ? E.ENVIRONMENT : E.USER
      }));
    }, this.handleCapture = (e) => {
      if (e === null) return Promise.resolve();
      this.setState({
        imgSrc: e,
        shutter: !0,
        minShutterEffectPassed: !1
      });
      const s = (o) => new Promise((a) => setTimeout(a, o));
      return ze(e, `camera-input-${(/* @__PURE__ */ new Date()).toISOString().replace(/:/g, "_")}.jpg`).then((o) => this.props.uploadClient.fetchFileURLs([o]).then((a) => ({
        file: o,
        fileUrls: a[0]
      }))).then(({
        file: o,
        fileUrls: a
      }) => this.uploadFile(a, o)).then(() => s(Te)).then(() => {
        this.setState((o, a) => ({
          imgSrc: e,
          shutter: o.shutter,
          minShutterEffectPassed: !0
        }));
      }).catch((o) => {
        ke.error(o);
      });
    }, this.removeCapture = () => {
      this.state.files.length !== 0 && (this.state.files.forEach((e) => this.deleteFile(e.id)), this.setState({
        imgSrc: null,
        clearPhotoInProgress: !0
      }));
    }, this.componentDidUpdate = () => {
      if (this.status !== "ready") return;
      const e = this.createWidgetValue(), {
        element: s,
        widgetMgr: o,
        fragmentId: a
      } = this.props, n = o.getFileUploaderStateValue(s);
      Q(e, n) || o.setFileUploaderStateValue(s, e, {
        fromUi: !0
      }, a);
    }, this.onFormCleared = () => {
      this.setState({
        files: []
      }, () => {
        const e = this.createWidgetValue();
        if (P(e)) return;
        this.setState({
          imgSrc: null
        });
        const {
          widgetMgr: s,
          element: o,
          fragmentId: a
        } = this.props;
        s.setFileUploaderStateValue(o, e, {
          fromUi: !0
        }, a);
      });
    }, this.deleteFile = (e) => {
      const s = this.getFile(e);
      P(s) || (s.status.type === "uploading" && s.status.abortController.abort(), s.status.type === "uploaded" && s.status.fileUrls.deleteUrl && this.props.uploadClient.deleteFile(s.status.fileUrls.deleteUrl), this.removeFile(e));
    }, this.addFile = (e) => {
      this.setState((s) => ({
        files: [...s.files, e]
      }));
    }, this.removeFile = (e) => {
      this.setState((s) => ({
        files: s.files.filter((o) => o.id !== e)
      }));
    }, this.getFile = (e) => this.state.files.find((s) => s.id === e), this.updateFile = (e, s) => {
      this.setState((o) => ({
        files: o.files.map((a) => a.id === e ? s : a)
      }));
    }, this.onUploadComplete = (e, s) => {
      this.setState(() => ({
        shutter: !1
      }));
      const o = this.getFile(e);
      P(o) || o.status.type !== "uploading" || this.updateFile(o.id, o.setStatus({
        type: "uploaded",
        fileId: s.fileId,
        fileUrls: s
      }));
    }, this.onUploadProgress = (e, s) => {
      const o = this.getFile(s);
      if (P(o) || o.status.type !== "uploading") return;
      const a = Math.round(e.loaded * 100 / e.total);
      o.status.progress !== a && this.updateFile(s, o.setStatus({
        type: "uploading",
        abortController: o.status.abortController,
        progress: a
      }));
    }, this.reset = () => {
      this.setState({
        files: [],
        imgSrc: null
      });
    }, this.uploadFile = (e, s) => {
      const o = new AbortController(), a = new V(s.name, s.size, this.nextLocalFileId(), {
        type: "uploading",
        abortController: o,
        progress: 1
      });
      this.addFile(a), this.props.uploadClient.uploadFile(this.props.element, e.uploadUrl, s, (n) => this.onUploadProgress(n, a.id), o.signal).then(() => this.onUploadComplete(a.id, e)).catch((n) => {
        n instanceof DOMException && n.name === "AbortError" || this.updateFile(a.id, a.setStatus({
          type: "error",
          errorMessage: n ? n.toString() : "Unknown error"
        }));
      });
    }, this.state = this.initialValue;
  }
  get initialValue() {
    const l = {
      files: [],
      imgSrc: null,
      shutter: !1,
      minShutterEffectPassed: !0,
      clearPhotoInProgress: !1,
      facingMode: E.USER
    }, {
      widgetMgr: e,
      element: s
    } = this.props, o = e.getFileUploaderStateValue(s);
    if (P(o)) return l;
    const {
      uploadedFileInfo: a
    } = o;
    return P(a) || a.length === 0 ? l : {
      files: a.map((n) => {
        const p = n.name, y = n.size, x = n.fileId, C = n.fileUrls;
        return new V(p, y, this.nextLocalFileId(), {
          type: "uploaded",
          fileId: x,
          fileUrls: C
        });
      }),
      imgSrc: a.length === 0 ? "" : this.RESTORED_FROM_WIDGET_STRING,
      shutter: !1,
      minShutterEffectPassed: !1,
      clearPhotoInProgress: !1,
      facingMode: E.USER
    };
  }
  componentWillUnmount() {
    this.formClearHelper.disconnect();
  }
  /**
   * Return the FileUploader's current status, which is derived from
   * its state.
   */
  get status() {
    const l = (e) => e.status.type === "uploading";
    return this.state.files.some(l) ? "updating" : "ready";
  }
  componentDidMount() {
    const l = this.createWidgetValue(), {
      element: e,
      widgetMgr: s,
      fragmentId: o
    } = this.props;
    s.getFileUploaderStateValue(e) === void 0 && s.setFileUploaderStateValue(e, l, {
      fromUi: !1
    }, o);
  }
  createWidgetValue() {
    const l = this.state.files.filter((e) => e.status.type === "uploaded").map((e) => {
      const {
        name: s,
        size: o,
        status: a
      } = e;
      return new J({
        fileId: a.fileId,
        fileUrls: a.fileUrls,
        name: s,
        size: o
      });
    });
    return new K({
      uploadedFileInfo: l
    });
  }
  render() {
    const {
      element: l,
      widgetMgr: e,
      disabled: s,
      width: o
    } = this.props;
    return this.formClearHelper.manageFormClearListener(e, l.formId, this.onFormCleared), /* @__PURE__ */ h.jsxs(H, {
      className: "stCameraInput",
      "data-testid": "stCameraInput",
      children: [/* @__PURE__ */ h.jsx(Y, {
        label: l.label,
        disabled: s,
        labelVisibility: Z(l.labelVisibility?.value),
        children: l.help && /* @__PURE__ */ h.jsx(ee, {
          children: /* @__PURE__ */ h.jsx(te, {
            content: l.help,
            placement: _.TOP_RIGHT
          })
        })
      }), this.state.imgSrc ? /* @__PURE__ */ h.jsxs(h.Fragment, {
        children: [/* @__PURE__ */ h.jsx(k, {
          width: o,
          children: this.state.imgSrc !== this.RESTORED_FROM_WIDGET_STRING && /* @__PURE__ */ h.jsx(ve, {
            src: this.state.imgSrc,
            alt: "Snapshot",
            opacity: this.state.shutter || !this.state.minShutterEffectPassed ? "50%" : "100%",
            width: o,
            height: o * 9 / 16
          })
        }), /* @__PURE__ */ h.jsx(N, {
          onClick: this.removeCapture,
          progress: this.getProgress(),
          disabled: !!this.getProgress() || s,
          children: this.getProgress() ? "Uploading..." : /* @__PURE__ */ h.jsxs(ye, {
            children: [/* @__PURE__ */ h.jsx(R, {
              content: A,
              margin: "0 xs 0 0",
              size: "sm"
            }), " Clear photo"]
          })
        })]
      }) : /* @__PURE__ */ h.jsx(Oe, {
        handleCapture: this.handleCapture,
        width: o,
        disabled: s,
        clearPhotoInProgress: this.state.clearPhotoInProgress,
        setClearPhotoInProgress: this.setClearPhotoInProgress,
        facingMode: this.state.facingMode,
        setFacingMode: this.setFacingMode,
        testOverride: this.props.testOverride
      })]
    });
  }
  nextLocalFileId() {
    return this.localFileIdCounter++;
  }
}
function ze(r, l) {
  return fetch(r).then((e) => e.arrayBuffer()).then((e) => new File([e], l, {
    type: "image/jpeg"
  }));
}
const Ae = X(Ve);
export {
  Ae as default
};
//# sourceMappingURL=index-X1p_3J78-X2qBtr8x.js.map
