"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = require("react");
/**
 * @example
 * const [value, toggle, toggleOn, toggleOff]  = useToggle(false);
 *
 * @param {Boolean} initialValue
 */
var _default = exports["default"] = function _default(initialValue, _temp) {
  var _ref = _temp === void 0 ? {} : _temp,
    on = _ref.on,
    off = _ref.off,
    onToggle = _ref.toggle;
  var _useState = (0, _react.useState)(!!initialValue),
    value = _useState[0],
    setToggle = _useState[1];
  var toggle = (0, _react.useCallback)(function (val) {
    return setToggle(function (oldValue) {
      var nextValue = typeof val === "boolean" ? val : !oldValue;
      if (onToggle) onToggle(nextValue);
      if (on && nextValue) on();
      if (off && !nextValue) off();
      return nextValue;
    });
  }, [onToggle, on, off]);
  var toggleOn = (0, _react.useCallback)(function () {
    setToggle(true);
    if (on) on();
  }, [on]);
  var toggleOff = (0, _react.useCallback)(function () {
    setToggle(false);
    if (off) off();
  }, [off]);
  return [value, toggle, toggleOn, toggleOff];
};