/*
 * @Author: 赵伟
 * @Date: 2024-05-11 15:40:58
 * @Description: 自定义菜单项
 */

import KFIcon from '@/components/KFIcon';
import { MenuDataItem } from '@ant-design/pro-components';
import { Link } from '@umijs/max';

export const menuItemRender = (isSubMenu: boolean) => {
  return (item: MenuDataItem) => {
    const defaultIcon: string = item.icon as string;
    const activeIcon = defaultIcon + '-active';
    const hasParent = item.pro_layout_parentKeys?.length > 0;
    const childen = (
      <>
        {!hasParent && defaultIcon && (
          <>
            <KFIcon type={defaultIcon} font={17} className="kf-menu-item__default-icon" />
            <KFIcon type={activeIcon} font={17} className="kf-menu-item__active-icon" />
          </>
        )}
        <span className="kf-menu-item__name">{item.name}</span>
      </>
    );

    if (isSubMenu) {
      return <div className="kf-menu-item">{childen}</div>;
    } else if (item.isUrl) {
      return (
        <a href={item.path || ''} target="_blank" className="kf-menu-item" rel="noreferrer">
          {childen}
        </a>
      );
    } else {
      return (
        <Link to={item.path || ''} className="kf-menu-item">
          {childen}
        </Link>
      );
    }
  };
};
