/* eslint-disable max-lines-per-function -- 列表卡包含筛选态、行菜单与骨架,集中在一处便于对齐状态 */
import { Button, Dropdown, Skeleton } from '@douyinfe/semi-ui-19';
import type { RoleListItem } from '@lingxi/shared';
import { ErrorState, PageEmpty } from '@lingxi/ui';
import {
IconCopy,
IconDelete,
IconEdit,
IconMore,
IconPause,
IconPlay,
IconShield,
IconView,
} from '@lingxi/ui/icons';
import type { ReactNode } from 'react';
import { useState } from 'react';
import { scopeLabelOf } from './role-display';
import { RoleStatusTag } from './RoleStatusTag';
export type RoleRowAction = 'view' | 'rename' | 'edit' | 'copy' | 'disable' | 'enable' | 'delete';
export interface RoleListPanelProps {
roles: readonly RoleListItem[];
/** 未筛选的角色总数,用于区分「没有匹配」与「还没有自定义角色」 */
totalCount: number;
loading: boolean;
error: Error | null;
selectedRoleId: string | null;
/** 卡头右侧说明:内置 / 自定义计数或「当前:角色名」 */
note: string;
footerNote?: string;
canManage: boolean;
showRowMenu: boolean;
isFiltered: boolean;
onSelect: (roleId: string) => void;
onRowAction: (action: RoleRowAction, role: RoleListItem) => void;
onCreate: () => void;
onResetFilters: () => void;
onRetry: () => void;
}
function rolePermissionText(role: RoleListItem): ReactNode {
return (
<>
{role.permissionCount} 普通
{role.specialPermissionCount > 0 ? (
· ★{role.specialPermissionCount}
) : null}
>
);
}
function RowMenu({
role,
canManage,
onRowAction,
}: {
role: RoleListItem;
canManage: boolean;
onRowAction: (action: RoleRowAction, role: RoleListItem) => void;
}): ReactNode {
const [visible, setVisible] = useState(false);
if (!canManage) {
return null;
}
const trigger = (action: RoleRowAction): void => {
setVisible(false);
onRowAction(action, role);
};
const menuItems: ReactNode[] = role.isSystem
? [