/**
 * This file/module will soon be removed. Prefer to use the new Modals API instead.
 * @deprecated
 */

import { getModule, modal } from '@vizality/webpack';
import { deprecate } from '@vizality/util/logger';
import React from 'react';

const { closeModal: closeNewModal, openModal: openNewModal } = getModule('openModal');

/**
 * Opens a new modal.
 * @deprecated
 * @param {React.Component|function(): React.ReactElement} Component Modal component to show
 */
export const open = Component => {
  deprecate({ labels: [ 'Modal', 'Open' ], message: 'This module will soon be removed. Prefer to use the new Modals API instead.' });
  modal.push(
    class VizalityModal extends React.Component {
      render () {
        return <Component />;
      }
    }
  );
};

/**
 * Closes the currently opened modal
 * @deprecated
 */
export const close = () => {
  deprecate({ labels: [ 'Modal', 'Close' ], message: 'This module will soon be removed. Prefer to use the new Modals API instead.' });
  modal.pop();
};

/**
 * Closes all modals
 * @deprecated
 */
export const closeAll = () => {
  deprecate({ labels: [ 'Modal', 'CloseAll' ], message: 'This module will soon be removed. Prefer to use the new Modals API instead.' });
  modal.popAll();
};


/**
 * Closes a new modal (for NewModal).
 * @param {React.Component|function(): React.ReactElement} Component Component to show
 */
export const closeModal = closeNewModal;

/**
 * Opens a new modal (for NewModal).
 * @param {React.Component|function(): React.ReactElement} Component Component to show
 */
export const openModal = openNewModal;
