import { Modal, Typography } from 'antd';
import Link from 'antd/lib/typography/Link';
import { useState } from 'react';
import { request, useIntl } from 'umi';

export interface RenewalModelProps {
  packageRow: any;
  refresh?: () => void;
}

const RenewalModel = (props: RenewalModelProps) => {
  const { packageRow, refresh } = props;

  const { packageInfo } = packageRow ?? {};
  const { multiAuditId } = packageInfo ?? {};

  const { formatMessage } = useIntl();
  const [open, setOpen] = useState(false);

  const requestRenewal = async () => {
    await request('/goapi/audit/multi/renew', {
      method: 'POST',
      data: { multiAuditId },
    });
    setOpen(false);
    refresh?.();
  };

  return (
    <>
      <Link onClick={() => setOpen(true)}>{formatMessage({ id: 'base.renewal' })}</Link>

      <Modal
        title={formatMessage({ id: 'pages.permission.package.renewal' })}
        open={open}
        destroyOnClose={true}
        onCancel={() => setOpen(false)}
        onOk={requestRenewal}
      >
        <Typography.Text>{formatMessage({ id: 'base.renewal.package.tips' })}</Typography.Text>
      </Modal>
    </>
  );
};
export default RenewalModel;
