"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);

// packages/components/src/date-time/utils.ts
var utils_exports = {};
__export(utils_exports, {
  buildPadInputStateReducer: () => buildPadInputStateReducer,
  from12hTo24h: () => from12hTo24h,
  from24hTo12h: () => from24hTo12h,
  inputToDate: () => inputToDate,
  validateInputElementTarget: () => validateInputElementTarget
});
module.exports = __toCommonJS(utils_exports);
var import_date_fns = require("date-fns");
var import_actions = require("../input-control/reducer/actions");
function inputToDate(input) {
  if (typeof input === "string") {
    return new Date(input);
  }
  return (0, import_date_fns.toDate)(input);
}
function from12hTo24h(hours, isPm) {
  return isPm ? (hours % 12 + 12) % 24 : hours % 12;
}
function from24hTo12h(hours) {
  return hours % 12 || 12;
}
function buildPadInputStateReducer(pad) {
  return (state, action) => {
    const nextState = {
      ...state
    };
    if (action.type === import_actions.COMMIT || action.type === import_actions.PRESS_UP || action.type === import_actions.PRESS_DOWN) {
      if (nextState.value !== void 0) {
        nextState.value = nextState.value.toString().padStart(pad, "0");
      }
    }
    return nextState;
  };
}
function validateInputElementTarget(event) {
  var _ownerDocument$defaul;
  const HTMLInputElementInstance = (_ownerDocument$defaul = event.target?.ownerDocument.defaultView?.HTMLInputElement) !== null && _ownerDocument$defaul !== void 0 ? _ownerDocument$defaul : HTMLInputElement;
  if (!(event.target instanceof HTMLInputElementInstance)) {
    return false;
  }
  return event.target.validity.valid;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildPadInputStateReducer,
  from12hTo24h,
  from24hTo12h,
  inputToDate,
  validateInputElementTarget
});
//# sourceMappingURL=utils.js.map
