import { g as ie } from "./dateFns-2367ee5b.mjs";
import se from "react";
var q = {};
(function(C) {
  Object.defineProperty(C, "__esModule", { value: !0 }), C.default = void 0;
  var I = U(se), K = ["placeholder", "separator", "isLastChild", "inputStyle", "focus", "isDisabled", "hasErrored", "errorStyle", "focusStyle", "disabledStyle", "shouldAutoFocus", "isInputNum", "index", "value", "className", "isInputSecure"];
  function R(t) {
    if (typeof WeakMap != "function")
      return null;
    var a = /* @__PURE__ */ new WeakMap(), u = /* @__PURE__ */ new WeakMap();
    return (R = function(n) {
      return n ? u : a;
    })(t);
  }
  function U(t, a) {
    if (!a && t && t.__esModule)
      return t;
    if (t === null || O(t) !== "object" && typeof t != "function")
      return { default: t };
    var u = R(a);
    if (u && u.has(t))
      return u.get(t);
    var e = {}, n = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for (var i in t)
      if (i !== "default" && Object.prototype.hasOwnProperty.call(t, i)) {
        var s = n ? Object.getOwnPropertyDescriptor(t, i) : null;
        s && (s.get || s.set) ? Object.defineProperty(e, i, s) : e[i] = t[i];
      }
    return e.default = t, u && u.set(t, e), e;
  }
  function D() {
    return D = Object.assign || function(t) {
      for (var a = 1; a < arguments.length; a++) {
        var u = arguments[a];
        for (var e in u)
          Object.prototype.hasOwnProperty.call(u, e) && (t[e] = u[e]);
      }
      return t;
    }, D.apply(this, arguments);
  }
  function z(t, a) {
    if (t == null)
      return {};
    var u = G(t, a), e, n;
    if (Object.getOwnPropertySymbols) {
      var i = Object.getOwnPropertySymbols(t);
      for (n = 0; n < i.length; n++)
        e = i[n], !(a.indexOf(e) >= 0) && Object.prototype.propertyIsEnumerable.call(t, e) && (u[e] = t[e]);
    }
    return u;
  }
  function G(t, a) {
    if (t == null)
      return {};
    var u = {}, e = Object.keys(t), n, i;
    for (i = 0; i < e.length; i++)
      n = e[i], !(a.indexOf(n) >= 0) && (u[n] = t[n]);
    return u;
  }
  function x(t, a) {
    if (!(t instanceof a))
      throw new TypeError("Cannot call a class as a function");
  }
  function F(t, a) {
    for (var u = 0; u < a.length; u++) {
      var e = a[u];
      e.enumerable = e.enumerable || !1, e.configurable = !0, "value" in e && (e.writable = !0), Object.defineProperty(t, e.key, e);
    }
  }
  function V(t, a, u) {
    return a && F(t.prototype, a), u && F(t, u), t;
  }
  function j(t, a) {
    if (typeof a != "function" && a !== null)
      throw new TypeError("Super expression must either be null or a function");
    t.prototype = Object.create(a && a.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), a && w(t, a);
  }
  function w(t, a) {
    return w = Object.setPrototypeOf || function(e, n) {
      return e.__proto__ = n, e;
    }, w(t, a);
  }
  function k(t) {
    var a = J();
    return function() {
      var e = b(t), n;
      if (a) {
        var i = b(this).constructor;
        n = Reflect.construct(e, arguments, i);
      } else
        n = e.apply(this, arguments);
      return H(this, n);
    };
  }
  function H(t, a) {
    return a && (O(a) === "object" || typeof a == "function") ? a : l(t);
  }
  function l(t) {
    if (t === void 0)
      throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
    return t;
  }
  function J() {
    if (typeof Reflect > "u" || !Reflect.construct || Reflect.construct.sham)
      return !1;
    if (typeof Proxy == "function")
      return !0;
    try {
      return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
      })), !0;
    } catch {
      return !1;
    }
  }
  function b(t) {
    return b = Object.setPrototypeOf ? Object.getPrototypeOf : function(u) {
      return u.__proto__ || Object.getPrototypeOf(u);
    }, b(t);
  }
  function c(t, a, u) {
    return a in t ? Object.defineProperty(t, a, { value: u, enumerable: !0, configurable: !0, writable: !0 }) : t[a] = u, t;
  }
  function O(t) {
    return typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? O = function(u) {
      return typeof u;
    } : O = function(u) {
      return u && typeof Symbol == "function" && u.constructor === Symbol && u !== Symbol.prototype ? "symbol" : typeof u;
    }, O(t);
  }
  var Q = 8, X = 37, Y = 39, Z = 46, ee = 32, m = function(a) {
    return O(a) === "object";
  }, te = function(t) {
    j(u, t);
    var a = k(u);
    function u(e) {
      var n;
      return x(this, u), n = a.call(this, e), c(l(n), "getClasses", function() {
        for (var i = arguments.length, s = new Array(i), r = 0; r < i; r++)
          s[r] = arguments[r];
        return s.filter(function(o) {
          return !m(o) && o !== !1;
        }).join(" ");
      }), c(l(n), "getType", function() {
        var i = n.props, s = i.isInputSecure, r = i.isInputNum;
        return s ? "password" : r ? "tel" : "text";
      }), n.input = I.default.createRef(), n;
    }
    return V(u, [{ key: "componentDidMount", value: function() {
      var n = this.props, i = n.focus, s = n.shouldAutoFocus, r = this.input.current;
      r && i && s && r.focus();
    } }, { key: "componentDidUpdate", value: function(n) {
      var i = this.props.focus, s = this.input.current;
      n.focus !== i && s && i && (s.focus(), s.select());
    } }, { key: "render", value: function() {
      var n = this.props, i = n.placeholder, s = n.separator, r = n.isLastChild, o = n.inputStyle, p = n.focus, h = n.isDisabled, S = n.hasErrored, v = n.errorStyle, f = n.focusStyle, y = n.disabledStyle;
      n.shouldAutoFocus;
      var g = n.isInputNum, _ = n.index, P = n.value, N = n.className;
      n.isInputSecure;
      var A = z(n, K);
      return I.default.createElement("div", { className: N, style: { display: "flex", alignItems: "center" } }, I.default.createElement("input", D({ "aria-label": "".concat(_ === 0 ? "Please enter verification code. " : "").concat(g ? "Digit" : "Character", " ").concat(_ + 1), autoComplete: "off", style: Object.assign({ width: "1em", textAlign: "center" }, m(o) && o, p && m(f) && f, h && m(y) && y, S && m(v) && v), placeholder: i, className: this.getClasses(o, p && f, h && y, S && v), type: this.getType(), maxLength: "1", ref: this.input, disabled: h, value: P || "" }, A)), !r && s);
    } }]), u;
  }(I.PureComponent), T = function(t) {
    j(u, t);
    var a = k(u);
    function u() {
      var e;
      x(this, u);
      for (var n = arguments.length, i = new Array(n), s = 0; s < n; s++)
        i[s] = arguments[s];
      return e = a.call.apply(a, [this].concat(i)), c(l(e), "state", { activeInput: 0 }), c(l(e), "getOtpValue", function() {
        return e.props.value ? e.props.value.toString().split("") : [];
      }), c(l(e), "getPlaceholderValue", function() {
        var r = e.props, o = r.placeholder, p = r.numInputs;
        if (typeof o == "string") {
          if (o.length === p)
            return o;
          o.length > 0 && console.error("Length of the placeholder should be equal to the number of inputs.");
        }
      }), c(l(e), "handleOtpChange", function(r) {
        var o = e.props.onChange, p = r.join("");
        o(p);
      }), c(l(e), "isInputValueValid", function(r) {
        var o = e.props.isInputNum ? !isNaN(parseInt(r, 10)) : typeof r == "string";
        return o && r.trim().length === 1;
      }), c(l(e), "focusInput", function(r) {
        var o = e.props.numInputs, p = Math.max(Math.min(o - 1, r), 0);
        e.setState({ activeInput: p });
      }), c(l(e), "focusNextInput", function() {
        var r = e.state.activeInput;
        e.focusInput(r + 1);
      }), c(l(e), "focusPrevInput", function() {
        var r = e.state.activeInput;
        e.focusInput(r - 1);
      }), c(l(e), "changeCodeAtFocus", function(r) {
        var o = e.state.activeInput, p = e.getOtpValue();
        p[o] = r[0], e.handleOtpChange(p);
      }), c(l(e), "handleOnPaste", function(r) {
        r.preventDefault();
        var o = e.state.activeInput, p = e.props, h = p.numInputs, S = p.isDisabled;
        if (!S) {
          for (var v = e.getOtpValue(), f = o, y = r.clipboardData.getData("text/plain").slice(0, h - o).split(""), g = 0; g < h; ++g)
            g >= o && y.length > 0 && (v[g] = y.shift(), f++);
          e.setState({ activeInput: f }, function() {
            e.focusInput(f), e.handleOtpChange(v);
          });
        }
      }), c(l(e), "handleOnChange", function(r) {
        var o = r.target.value;
        e.isInputValueValid(o) && e.changeCodeAtFocus(o);
      }), c(l(e), "handleOnKeyDown", function(r) {
        r.keyCode === Q || r.key === "Backspace" ? (r.preventDefault(), e.changeCodeAtFocus(""), e.focusPrevInput()) : r.keyCode === Z || r.key === "Delete" ? (r.preventDefault(), e.changeCodeAtFocus("")) : r.keyCode === X || r.key === "ArrowLeft" ? (r.preventDefault(), e.focusPrevInput()) : r.keyCode === Y || r.key === "ArrowRight" ? (r.preventDefault(), e.focusNextInput()) : (r.keyCode === ee || r.key === " " || r.key === "Spacebar" || r.key === "Space") && r.preventDefault();
      }), c(l(e), "handleOnInput", function(r) {
        if (e.isInputValueValid(r.target.value))
          e.focusNextInput();
        else if (!e.props.isInputNum) {
          var o = r.nativeEvent;
          o.data === null && o.inputType === "deleteContentBackward" && (r.preventDefault(), e.changeCodeAtFocus(""), e.focusPrevInput());
        }
      }), c(l(e), "renderInputs", function() {
        for (var r = e.state.activeInput, o = e.props, p = o.numInputs, h = o.inputStyle, S = o.focusStyle, v = o.separator, f = o.isDisabled, y = o.disabledStyle, g = o.hasErrored, _ = o.errorStyle, P = o.shouldAutoFocus, N = o.isInputNum, A = o.isInputSecure, re = o.className, L = [], W = e.getOtpValue(), B = e.getPlaceholderValue(), M = e.props["data-cy"], $ = e.props["data-testid"], ae = function(d) {
          L.push(I.default.createElement(te, { placeholder: B && B[d], key: d, index: d, focus: r === d, value: W && W[d], onChange: e.handleOnChange, onKeyDown: e.handleOnKeyDown, onInput: e.handleOnInput, onPaste: e.handleOnPaste, onFocus: function(oe) {
            e.setState({ activeInput: d }), oe.target.select();
          }, onBlur: function() {
            return e.setState({ activeInput: -1 });
          }, separator: v, inputStyle: h, focusStyle: S, isLastChild: d === p - 1, isDisabled: f, disabledStyle: y, hasErrored: g, errorStyle: _, shouldAutoFocus: P, isInputNum: N, isInputSecure: A, className: re, "data-cy": M && "".concat(M, "-").concat(d), "data-testid": $ && "".concat($, "-").concat(d) }));
        }, E = 0; E < p; E++)
          ae(E);
        return L;
      }), e;
    }
    return V(u, [{ key: "render", value: function() {
      var n = this.props.containerStyle;
      return I.default.createElement("div", { style: Object.assign({ display: "flex" }, m(n) && n), className: m(n) ? "" : n }, this.renderInputs());
    } }]), u;
  }(I.Component);
  c(T, "defaultProps", { numInputs: 4, onChange: function(a) {
    return console.log(a);
  }, isDisabled: !1, shouldAutoFocus: !1, value: "", isInputSecure: !1 });
  var ne = T;
  C.default = ne;
})(q);
const fe = /* @__PURE__ */ ie(q);
export {
  fe as O
};
