import extend from "../utils/extend.js";
import { createUTC } from "./utc.js";
import getParsingFlags from "./parsing-flags.js";
import some from "../utils/some.js";
export function isValid(m) {
  if (m._isValid == null) {
    var flags = getParsingFlags(m),
        parsedParts = some.call(flags.parsedDateParts, function (i) {
      return i != null;
    }),
        isNowValid = !isNaN(m._d.getTime()) && flags.overflow < 0 && !flags.empty && !flags.invalidEra && !flags.invalidMonth && !flags.invalidWeekday && !flags.weekdayMismatch && !flags.nullInput && !flags.invalidFormat && !flags.userInvalidated && (!flags.meridiem || flags.meridiem && parsedParts);

    if (m._strict) {
      isNowValid = isNowValid && flags.charsLeftOver === 0 && flags.unusedTokens.length === 0 && flags.bigHour === undefined;
    }

    if (Object.isFrozen == null || !Object.isFrozen(m)) {
      m._isValid = isNowValid;
    } else {
      return isNowValid;
    }
  }

  return m._isValid;
}
export function createInvalid(flags) {
  var m = createUTC(NaN);

  if (flags != null) {
    extend(getParsingFlags(m), flags);
  } else {
    getParsingFlags(m).userInvalidated = true;
  }

  return m;
}