"use strict";

exports.__esModule = true;
exports.default = void 0;

var _react = require("react");

var _reactSingletonHook = require("react-singleton-hook");

function useConfirmDialogImpl() {
  const [confirmTitle, setConfirmTitle] = (0, _react.useState)('Confirm');
  const [confirmContent, setConfirmContent] = (0, _react.useState)('Are you sure?');
  const [confirmOpen, setConfirmOpen] = (0, _react.useState)(false);
  const [applyConfirm, setApplyConfirm] = (0, _react.useState)(() => () => {}); // default no-op

  const [applyCancel, setApplyCancel] = (0, _react.useState)(() => () => {}); // default no-op

  const [button1Label, setButton1Label] = (0, _react.useState)('Yes');
  const [button2Label, setButton2Label] = (0, _react.useState)('Yes');
  const [autoApplyTimeout, setAutoApplyTimeout] = (0, _react.useState)(null); // passing in a funtion to return a function is from
  // https://medium.com/swlh/how-to-store-a-function-with-the-usestate-hook-in-react-8a88dd4eede1

  const confirmUserAction = (title, content, action, cancelAction, button1Label = 'Yes', button2Label = 'No', autoApplyTimeout = null) => {
    setConfirmTitle(title);
    setConfirmContent(content);
    setApplyConfirm(() => action);
    setApplyCancel(() => cancelAction);
    setButton1Label(button1Label);
    setButton2Label(button2Label);
    setConfirmOpen(true);
    setAutoApplyTimeout(autoApplyTimeout);
  };

  return {
    confirmTitle,
    confirmContent,
    confirmOpen,
    setConfirmOpen,
    applyConfirm,
    applyCancel,
    confirmUserAction,
    button1Label,
    button2Label,
    autoApplyTimeout
  };
}

const useConfirmDialog = (0, _reactSingletonHook.singletonHook)({}, useConfirmDialogImpl);
var _default = useConfirmDialog;
exports.default = _default;