"use strict";
const React = require("react");
const is = require("../is.js");
var __read = globalThis && globalThis.__read || function(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m)
    return o;
  var i = m.call(o), r, ar = [], e;
  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
      ar.push(r.value);
  } catch (error) {
    e = { error };
  } finally {
    try {
      if (r && !r.done && (m = i["return"]))
        m.call(i);
    } finally {
      if (e)
        throw e.error;
    }
  }
  return ar;
};
function useMergeValue(defaultStateValue, props) {
  var _a = props || {}, defaultValue = _a.defaultValue, value = _a.value;
  var firstRenderRef = React.useRef(true);
  var _b = __read(React.useState(!is.isUndefined(value) ? value : !is.isUndefined(defaultValue) ? defaultValue : defaultStateValue), 2), stateValue = _b[0], setStateValue = _b[1];
  React.useEffect(function() {
    if (firstRenderRef.current) {
      firstRenderRef.current = false;
      return;
    }
    if (value === void 0) {
      setStateValue(value);
    }
  }, [value]);
  var mergedValue = is.isUndefined(value) ? stateValue : value;
  return [mergedValue, setStateValue, stateValue];
}
module.exports = useMergeValue;
//# sourceMappingURL=useMergeValue.js.map
