import React from 'react';
import PropTypes from 'prop-types';
import { Text } from '@buffetjs/core';
import { ModalConfirm } from '@strapi/helper-plugin';
import { useIntl } from 'react-intl';
import useDeleteLocale from '../../hooks/useDeleteLocale';
import { getTrad } from '../../utils';

const ModalDelete = ({ localeToDelete, onClose }) => {
  const { isDeleting, deleteLocale } = useDeleteLocale();
  const { formatMessage } = useIntl();
  const isOpened = Boolean(localeToDelete);

  const handleDelete = () => deleteLocale(localeToDelete.id).then(onClose);

  return (
    <ModalConfirm
      confirmButtonLabel={{
        id: getTrad('Settings.locales.modal.delete.confirm'),
      }}
      showButtonLoader={isDeleting}
      isOpen={isOpened}
      toggle={onClose}
      onClosed={onClose}
      onConfirm={handleDelete}
      type="warning"
      content={{
        id: getTrad(`Settings.locales.modal.delete.message`),
      }}
    >
      <Text fontWeight="bold">
        {formatMessage({ id: getTrad('Settings.locales.modal.delete.secondMessage') })}
      </Text>
    </ModalConfirm>
  );
};

ModalDelete.defaultProps = {
  localeToDelete: undefined,
};

ModalDelete.propTypes = {
  localeToDelete: PropTypes.shape({
    id: PropTypes.number.isRequired,
  }),
  onClose: PropTypes.func.isRequired,
};

export default ModalDelete;

@@ -69,59 +69,21 @@
 t %7B 
-Text %7D from '@buffetjs/core';%0Aimport %7B Modal
 Confirm
+Dialog
  %7D f
@@ -115,46 +115,8 @@
 n';%0A
-import %7B useIntl %7D from 'react-intl';%0A
 impo
@@ -173,47 +173,8 @@
 le';
-%0Aimport %7B getTrad %7D from '../../utils';
 %0A%0Aco
@@ -288,47 +288,8 @@
 ();%0A
-  const %7B formatMessage %7D = useIntl();%0A
   co
@@ -426,130 +426,37 @@
    %3C
-Modal
 Confirm
-%0A      confirmButtonLabel=%7B%7B%0A        id: getTrad('Settings.locales.modal.delete.confirm'),%0A      %7D%7D%0A      show
+Dialog%0A      isConfirm
 Butt
@@ -461,18 +461,19 @@
 ttonLoad
-er
+ing
 =%7BisDele
@@ -488,371 +488,93 @@
     
-isOpen=%7BisOpened%7D%0A      toggle=%7BonClose%7D%0A      onClosed=%7BonClose%7D%0A      onConfirm=%7BhandleDelete%7D%0A      type=%22warning%22%0A      content=%7B%7B%0A        id: getTrad(%60Settings.locales.modal.delete.message%60),%0A      %7D%7D%0A    %3E%0A      %3CText fontWeight=%22bold%22%3E%0A        %7BformatMessage(%7B id: getTrad('Settings.locales.modal.delete.secondMessage') %7D)
+onConfirm=%7BhandleDelete%7D%0A      onToggleDialog=%7BonClose%7D%0A      isOpen=%7BisOpened
 %7D%0A    
- 
- %3C/Text%3E%0A    %3C/ModalConfirm
+/
 %3E%0A  

Delete locale with parts