/**
 * 重发配置
 */
import { useState } from 'react';
import PropTypes from 'prop-types';
import { Box, Typography, FormControl, FormLabel, FormGroup, FormControlLabel, Checkbox, Button } from '@mui/material';
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
import Spinner from '@mui/material/CircularProgress';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const defaultChannels = [{
  label: 'Wallet',
  value: 'app',
  checked: true
}, {
  label: 'Email',
  value: 'email',
  checked: true
}, {
  label: 'Push Kit',
  value: 'push',
  checked: true
}, {
  label: 'Webhook',
  value: 'webhook',
  checked: true
}];
ResendConfig.propTypes = {
  loading: PropTypes.bool,
  onCancel: PropTypes.func,
  onConfirm: PropTypes.func
};
export default function ResendConfig({
  loading = false,
  onCancel = () => {},
  onConfirm = () => {}
}) {
  const {
    t
  } = useLocaleContext();
  const [channels, setChannels] = useState(defaultChannels);
  const [isResendFailedOnly, setIsResendFailedOnly] = useState(true);
  const handleChange = (ev, channel) => {
    channel.checked = ev.target.checked;
    const newChannels = channels.map(c => ({
      ...c,
      checked: c.value === channel.value ? channel.checked : c.checked
    }));
    setChannels(newChannels);
  };
  const handleConfirm = e => {
    e.stopPropagation();
    onConfirm({
      channels: channels.filter(c => c.checked).map(c => c.value),
      isResendFailedOnly
    });
  };
  return /*#__PURE__*/_jsxs(Box, {
    className: "resend-config",
    sx: {
      padding: '16px 24px'
    },
    children: [/*#__PURE__*/_jsx(Typography, {
      variant: "body1",
      component: "div",
      className: "check-title",
      sx: {
        fontWeight: 700,
        mb: 1
      },
      children: t('notification.config')
    }), /*#__PURE__*/_jsx(Box, {
      className: "choose-channel",
      children: /*#__PURE__*/_jsxs(FormControl, {
        component: "fieldset",
        variant: "standard",
        children: [/*#__PURE__*/_jsx(FormLabel, {
          component: "legend",
          children: t('notification.selectChannels')
        }), /*#__PURE__*/_jsx(FormGroup, {
          sx: {
            display: 'flex',
            flexDirection: 'row',
            flexWrap: 'wrap',
            gap: 1
          },
          children: channels.map(channel => /*#__PURE__*/_jsx(FormControlLabel, {
            control: /*#__PURE__*/_jsx(Checkbox, {
              checked: channel.checked,
              onChange: ev => handleChange(ev, channel),
              name: channel.value
            }),
            label: channel.label
          }, channel.value))
        })]
      })
    }), /*#__PURE__*/_jsx(Box, {
      className: "resend-config-footer",
      children: /*#__PURE__*/_jsx(FormGroup, {
        children: /*#__PURE__*/_jsx(FormControlLabel, {
          control: /*#__PURE__*/_jsx(Checkbox, {
            checked: isResendFailedOnly,
            onChange: ev => setIsResendFailedOnly(ev.target.checked)
          }),
          label: t('notification.resendFailedOnly')
        })
      })
    }), /*#__PURE__*/_jsxs(Box, {
      className: "resend-config-footer-tip",
      sx: {
        display: 'flex',
        justifyContent: 'flex-end',
        gap: 1
      },
      children: [/*#__PURE__*/_jsx(Button, {
        onClick: e => {
          e.stopPropagation();
          onCancel();
        },
        color: "inherit",
        children: t('common.cancel')
      }), /*#__PURE__*/_jsxs(Button, {
        onClick: handleConfirm,
        color: "primary",
        disabled: loading,
        variant: "contained",
        autoFocus: true,
        style: {
          marginLeft: 8
        },
        children: [loading && /*#__PURE__*/_jsx(Spinner, {
          size: 16
        }), t('common.confirm')]
      })]
    })]
  });
}