import { _ as _defineProperty } from '../defineProperty-Dcer7TUY.js';
import { _ as _toConsumableArray } from '../toConsumableArray-B7CFjjkW.js';
import { _ as _createClass, a as _classCallCheck } from '../createClass-CuM_Q_Jb.js';
import pureDayjs from 'dayjs';
import '../toPropertyKey-BAXkSB3z.js';
import '../typeof-D-UKOauR.js';
import '../unsupportedIterableToArray-Dqz8Y8_I.js';

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var LRUCache = /*#__PURE__*/function () {
  function LRUCache(limit) {
    _classCallCheck(this, LRUCache);
    this.limit = limit;
    this.cache = new Map();
  }
  return _createClass(LRUCache, [{
    key: "get",
    value: function get(key) {
      var value = this.cache.get(key);
      this.cache["delete"](key);
      this.cache.set(key, value);
      return value;
    }
  }, {
    key: "set",
    value: function set(key, value) {
      if (this.cache.size >= this.limit) {
        var oldestKey = this.cache.keys().next().value;
        this.cache["delete"](oldestKey);
      }
      this.cache.set(key, value);
    }
  }, {
    key: "has",
    value: function has(key) {
      return this.cache.has(key);
    }
  }, {
    key: "clear",
    value: function clear() {
      this.cache.clear();
    }
  }]);
}();
var hasTimezone = function hasTimezone(dateString) {
  var timezoneRegex = /Z|[+-]\d{2}:\d{2}$|[+-]\d{4}$|GMT([+-]\d{4})?$/;
  return timezoneRegex.test(dateString);
};
var cache = new LRUCache(1000);
var dayjs = function dayjs() {
  var _input$$x, _args$;
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
    args[_key] = arguments[_key];
  }
  var input = args[0];
  var isDayjsInput = (input === null || input === void 0 ? void 0 : input.$d) instanceof Date;
  var inputTimezone = isDayjsInput ? (_input$$x = input.$x) === null || _input$$x === void 0 ? void 0 : _input$$x.$timezone : undefined;
  var cacheKey = isDayjsInput ? "".concat(JSON.stringify(args), "|").concat(input.$offset, "|").concat(inputTimezone || "") : JSON.stringify(args);
  if (cache.has(cacheKey) && input !== undefined) return cache.get(cacheKey);
  var userTimezone = pureDayjs.tz().$x.$timezone;
  var browserTimezone = pureDayjs.tz.guess();
  var timezone = userTimezone || browserTimezone || "UTC";
  if (userTimezone === browserTimezone || userTimezone === undefined || inputTimezone) {
    var _result = pureDayjs.apply(void 0, args);
    if (input !== undefined) cache.set(cacheKey, _result);
    return _result;
  }
  if (args.length > 0 && (typeof args[0] === "string" || args[0] === null) || args.length > 2) {
    if (hasTimezone(args[0])) {
      args[0] = pureDayjs.apply(void 0, args);
    } else {
      args[0] = pureDayjs.apply(void 0, args).format("YYYY-MM-DD HH:mm:ss");
      args[1] = "YYYY-MM-DD HH:mm:ss";
    }
  }
  if (((_args$ = args[0]) === null || _args$ === void 0 ? void 0 : _args$.toString()) === "Invalid Date") {
    var _result2 = pureDayjs.apply(void 0, args);
    if (args[0] !== undefined) cache.set(cacheKey, _result2);
    return _result2;
  }
  var result = args.length < 2 ? pureDayjs.tz.apply(pureDayjs, args) : pureDayjs.tz.apply(pureDayjs, _toConsumableArray(args.slice(0, 2)).concat([timezone]));
  if (args[0] !== undefined) cache.set(cacheKey, result);
  return result;
};
Object.assign(dayjs, _objectSpread({}, pureDayjs));
var setDefaultPatched = false;
Object.defineProperty(dayjs, "tz", {
  get: function get() {
    var _pureDayjs$tz;
    if (setDefaultPatched || !((_pureDayjs$tz = pureDayjs.tz) !== null && _pureDayjs$tz !== void 0 && _pureDayjs$tz.setDefault)) return pureDayjs.tz;
    setDefaultPatched = true;
    var originalSetDefault = pureDayjs.tz.setDefault;
    pureDayjs.tz.setDefault = function (timezone) {
      cache.clear();
      originalSetDefault.call(this, timezone);
    };
    return pureDayjs.tz;
  },
  configurable: true
});

export { dayjs as default };
//# sourceMappingURL=dayjs.js.map
