import { memo } from 'react';
import type { FC } from 'react';
import { Badge } from 'antd';
import React from 'react';
import { useModel } from '../../utils/umiExport';
type Props = {
  badgeKey: string;
  value: number | string;
  replaceText?: string;
  isExternalText?: boolean;
};
const RBadge: FC<Props> = (props) => {
  const { initialState } = useModel('@@initialState');
  const dictionary = initialState?.dictionary;
  const item: any = dictionary[props.badgeKey]?.filter(
    (res: any) => res.value == props.value,
  )?.[0];
  const badge = (colData: any) => {
    if (colData && colData.status && colData.status !== 'none') {

      if (colData.status !== 'gary') {
        return <Badge color={colData.status} text={!props.isExternalText ? colData.text : null} />;
      } else {
        console.log(colData);
        return <Badge color={'#D9D9D9'} text={!props.isExternalText ? colData.text : null} />;
      }
    } else if (colData) {
      return colData.text;
    }
    return props.replaceText ? props.replaceText : props.value;
  };
  return (
    <>
      {badge(item)}
      {props?.isExternalText ? item.text : ''}
    </>
  );
};
export default memo(RBadge);
RBadge.defaultProps = {
  replaceText: '',
};
