import w from "../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import * as d from "react";
import { getValue as c, updateValues as m } from "../utils/miscUtil.mjs";
import { getClosingViewDate as p, isSameMonth as _, isSameYear as q, isSameDecade as A } from "../utils/dateUtil.mjs";
function E(a, u, l, r) {
  var e = p(a, l, r, 1);
  function n(t) {
    return t(a, u) ? "same" : t(e, u) ? "closing" : "far";
  }
  switch (l) {
    case "year":
      return n(function(t, s) {
        return A(r, t, s);
      });
    case "quarter":
    case "month":
      return n(function(t, s) {
        return q(r, t, s);
      });
    default:
      return n(function(t, s) {
        return _(r, t, s);
      });
  }
}
function M(a, u, l, r) {
  var e = c(a, 0), n = c(a, 1);
  if (u === 0)
    return e;
  if (e && n) {
    var t = E(e, n, l, r);
    switch (t) {
      case "same":
        return e;
      case "closing":
        return e;
      default:
        return p(n, l, r, -1);
    }
  }
  return e;
}
function j(a) {
  var u = a.values, l = a.picker, r = a.defaultDates, e = a.generateConfig, n = d.useState(function() {
    return [c(r, 0), c(r, 1)];
  }), t = w(n, 2), s = t[0], $ = t[1], h = d.useState(null), D = w(h, 2), v = D[0], S = D[1], g = c(u, 0), V = c(u, 1);
  function y(i) {
    return s[i] ? s[i] : c(v, i) || M(u, i, l, e) || g || V || e.getNow();
  }
  function N(i, f) {
    if (i) {
      var o = m(v, i, f);
      $(
        // Should always be an array
        m(s, null, f) || [null, null]
      );
      var R = (f + 1) % 2;
      c(u, R) || (o = m(o, i, R)), S(o);
    } else
      (g || V) && S(null);
  }
  return [y, N];
}
export {
  j as default
};
