import { a as tickStep, s as bisector } from "./precisionRound-CnHPY_5v.js";
import { a as copy, i as continuous } from "./linear-2NnK4cxi.js";
import { A as durationSecond, C as timeMinute, D as durationHour, E as durationDay, M as durationYear, N as millisecond, O as durationMinute, S as utcHour, T as second, _ as utcSunday, c as timeMonth, j as durationWeek, k as durationMonth, l as utcMonth, o as timeYear, p as timeSunday, s as utcYear, t as timeFormat, v as timeDay, w as utcMinute, x as timeHour, y as unixDay } from "./defaultLocale-DoeErsX2.js";
import { n as initRange } from "./init-uv0kkh4g.js";
function max(e, g) {
  let _;
  if (g === void 0) for (let g2 of e) g2 != null && (_ < g2 || _ === void 0 && g2 >= g2) && (_ = g2);
  else {
    let v = -1;
    for (let y of e) (y = g(y, ++v, e)) != null && (_ < y || _ === void 0 && y >= y) && (_ = y);
  }
  return _;
}
function min(e, g) {
  let _;
  if (g === void 0) for (let g2 of e) g2 != null && (_ > g2 || _ === void 0 && g2 >= g2) && (_ = g2);
  else {
    let v = -1;
    for (let y of e) (y = g(y, ++v, e)) != null && (_ > y || _ === void 0 && y >= y) && (_ = y);
  }
  return _;
}
function ticker(_, v, b, E, O, k) {
  let M = [
    [
      second,
      1,
      durationSecond
    ],
    [
      second,
      5,
      5 * durationSecond
    ],
    [
      second,
      15,
      15 * durationSecond
    ],
    [
      second,
      30,
      30 * durationSecond
    ],
    [
      k,
      1,
      durationMinute
    ],
    [
      k,
      5,
      5 * durationMinute
    ],
    [
      k,
      15,
      15 * durationMinute
    ],
    [
      k,
      30,
      30 * durationMinute
    ],
    [
      O,
      1,
      durationHour
    ],
    [
      O,
      3,
      3 * durationHour
    ],
    [
      O,
      6,
      6 * durationHour
    ],
    [
      O,
      12,
      12 * durationHour
    ],
    [
      E,
      1,
      durationDay
    ],
    [
      E,
      2,
      2 * durationDay
    ],
    [
      b,
      1,
      durationWeek
    ],
    [
      v,
      1,
      durationMonth
    ],
    [
      v,
      3,
      3 * durationMonth
    ],
    [
      _,
      1,
      durationYear
    ]
  ];
  function N(e, g, _2) {
    let v2 = g < e;
    v2 && ([e, g] = [g, e]);
    let y = _2 && typeof _2.range == "function" ? _2 : P(e, g, _2), b2 = y ? y.range(e, +g + 1) : [];
    return v2 ? b2.reverse() : b2;
  }
  function P(v2, y, b2) {
    let x = Math.abs(y - v2) / b2, S = bisector(([, , e]) => e).right(M, x);
    if (S === M.length) return _.every(tickStep(v2 / durationYear, y / durationYear, b2));
    if (S === 0) return millisecond.every(Math.max(tickStep(v2, y, b2), 1));
    let [T, E2] = M[x / M[S - 1][2] < M[S][2] / x ? S - 1 : S];
    return T.every(E2);
  }
  return [N, P];
}
var [utcTicks, utcTickInterval] = ticker(utcYear, utcMonth, utcSunday, unixDay, utcHour, utcMinute), [timeTicks, timeTickInterval] = ticker(timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute);
function nice(e, g) {
  e = e.slice();
  var _ = 0, v = e.length - 1, y = e[_], b = e[v], x;
  return b < y && (x = _, _ = v, v = x, x = y, y = b, b = x), e[_] = g.floor(y), e[v] = g.ceil(b), e;
}
function date(e) {
  return new Date(e);
}
function number(e) {
  return e instanceof Date ? +e : +/* @__PURE__ */ new Date(+e);
}
function calendar(e, g, y, b, x, S, C, w, T, E) {
  var D = continuous(), O = D.invert, k = D.domain, A = E(".%L"), j = E(":%S"), M = E("%I:%M"), N = E("%I %p"), P = E("%a %d"), F = E("%b %d"), I = E("%B"), L = E("%Y");
  function R(e2) {
    return (T(e2) < e2 ? A : w(e2) < e2 ? j : C(e2) < e2 ? M : S(e2) < e2 ? N : b(e2) < e2 ? x(e2) < e2 ? P : F : y(e2) < e2 ? I : L)(e2);
  }
  return D.invert = function(e2) {
    return new Date(O(e2));
  }, D.domain = function(e2) {
    return arguments.length ? k(Array.from(e2, number)) : k().map(date);
  }, D.ticks = function(g2) {
    var _ = k();
    return e(_[0], _[_.length - 1], g2 ?? 10);
  }, D.tickFormat = function(e2, g2) {
    return g2 == null ? R : E(g2);
  }, D.nice = function(e2) {
    var _ = k();
    return (!e2 || typeof e2.range != "function") && (e2 = g(_[0], _[_.length - 1], e2 ?? 10)), e2 ? k(nice(_, e2)) : D;
  }, D.copy = function() {
    return copy(D, calendar(e, g, y, b, x, S, C, w, T, E));
  }, D;
}
function time() {
  return initRange.apply(calendar(timeTicks, timeTickInterval, timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute, second, timeFormat).domain([new Date(2e3, 0, 1), new Date(2e3, 0, 2)]), arguments);
}
export {
  utcTicks as a,
  utcTickInterval as i,
  time as n,
  min as o,
  nice as r,
  max as s,
  calendar as t
};
