"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/DateField/validation.ts
var validation_exports = {};
__export(validation_exports, {
  convertToDateFormat: () => convertToDateFormat,
  isValidDate: () => isValidDate
});
module.exports = __toCommonJS(validation_exports);
var convertToDateFormat = (date, format) => {
  const dateParts = date.split(/[-/]/);
  const formatParts = format ? format.split(/[-/]/) : ["yyyy", "mm", "dd"];
  const dateObj = {};
  const formattedDate = [];
  for (let i = 0; i < formatParts.length; i++) {
    dateObj[formatParts[i]] = dateParts[i] ? parseInt(dateParts[i], 10) : 0;
  }
  formattedDate.push(dateObj["yyyy"]?.toString() || "0000");
  formattedDate.push(
    (dateObj["mm"] < 10 ? "0" : "") + (dateObj["mm"]?.toString() || "00")
  );
  formattedDate.push(
    (dateObj["dd"] < 10 ? "0" : "") + (dateObj["dd"]?.toString() || "00")
  );
  return formattedDate.join("-");
};
var isValidDate = (date, format = "yyyy-mm-dd") => {
  if (!date) return true;
  const standardDate = convertToDateFormat(date, format);
  const [yearStr, monthStr, dayStr] = standardDate.split("-");
  const year = parseInt(yearStr, 10);
  const month = parseInt(monthStr, 10);
  const day = parseInt(dayStr, 10);
  if (month < 1 || month > 12) {
    return false;
  }
  const daysInMonth = new Date(year, month, 0).getDate();
  return day > 0 && day <= daysInMonth;
};
//# sourceMappingURL=validation.js.map
