function ModalHandler() {
  let _ref;
  let _modalRef;
  let _modalId;

  function setRef(ref) {
    _ref = ref;
    _modalRef = new bootstrap.Modal(ref);
  }

  function show() {
    _modalRef.show();
  }

  function hide() {
    _modalRef.hide();
  }

  function setModalId(modalId) {
    _modalId = modalId;
  }
  
  function onHidden(callback) {
    _ref.addEventListener('hidden.bs.modal', () => {
      callback();
    });
  }
  
  function onShow(callback) {
    _ref.addEventListener('show.bs.modal', () => {
      callback();
    });
  }

  return {
    setRef,
    show,
    hide,
    setModalId,
    onHidden,
    onShow,
  };
}

export default ModalHandler;
