import React, { useContext } from 'react';
import Alert from '../alert';
import Space from '../space';
import ConfigProvider from '../config-provider';
import { useIntl } from '../wau-provider';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
const defaultAlertOptionRender = props => {
  const {
    intl,
    onCleanSelected
  } = props;
  return [/*#__PURE__*/_jsx("a", {
    onClick: onCleanSelected,
    children: intl.getMessage('alert.clear', '清空')
  }, "0")];
};
function TableAlert({
  selectedRowKeys,
  onCleanSelected,
  selectedRows,
  alertInfoRender = ({
    intl
  }) => /*#__PURE__*/_jsxs(Space, {
    children: [intl.getMessage('alert.selected', '已选择'), selectedRowKeys.length, intl.getMessage('alert.item', '项'), "\xA0\xA0"]
  }),
  alertOptionRender = defaultAlertOptionRender
}) {
  const intl = useIntl();
  const option = alertOptionRender && alertOptionRender({
    onCleanSelected,
    selectedRowKeys,
    selectedRows,
    intl
  });
  const {
    getPrefixCls
  } = useContext(ConfigProvider.ConfigContext);
  const className = getPrefixCls('pro-table-alert');
  if (alertInfoRender === false) {
    return null;
  }
  const dom = alertInfoRender({
    intl,
    selectedRowKeys,
    selectedRows,
    onCleanSelected
  });
  if (dom === false || selectedRowKeys.length < 1) {
    return null;
  }
  return /*#__PURE__*/_jsx("div", {
    className: className,
    children: /*#__PURE__*/_jsx(Alert, {
      message: /*#__PURE__*/_jsxs("div", {
        className: `${className}-info`,
        children: [/*#__PURE__*/_jsx("div", {
          className: `${className}-info-content`,
          children: dom
        }), option ? /*#__PURE__*/_jsx("div", {
          className: `${className}-info-option`,
          children: option
        }) : null]
      }),
      type: "info"
    })
  });
}
export default TableAlert;