"use strict";

exports.__esModule = true;
exports.toValidDate = exports.setNativeInputValue = exports.isValidDate = void 0;
const isValidDate = d => d instanceof Date && !isNaN(d.getTime());
exports.isValidDate = isValidDate;
const toValidDate = value => {
  if (value == null) {
    return null;
  }
  const date = value instanceof Date ? value : new Date(value);
  return isValidDate(date) ? date : null;
};

/**
 * Bypass React's synthetic event system to set a controlled <input>'s value
 * AND fire an `input` event that React's listener picks up. Used for the
 * type-to-edit gesture: forward the keystroke that triggered edit into the
 * underlying WDS input without re-implementing its parsing.
 */
exports.toValidDate = toValidDate;
const setNativeInputValue = (el, value) => {
  var _Object$getOwnPropert;
  const setter = (_Object$getOwnPropert = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')) == null ? void 0 : _Object$getOwnPropert.set;
  if (!setter) {
    return;
  }
  setter.call(el, value);
  el.dispatchEvent(new Event('input', {
    bubbles: true
  }));
};
exports.setNativeInputValue = setNativeInputValue;
//# sourceMappingURL=helpers.js.map