import React, { useState } from 'react';
import { Button, Flex, Divider } from 'antd';
import '@/themes/truncateText.css';
import { useDispatch } from 'react-redux';
import { setAction } from '@/states/view/functionAreaSlice';
import { switchToMeasurementPanel, switchToMorePanel, switchToAdvancedProcessingPanel, switchToRectCropPanel, switchToMarkPanel } from '@/states/panelSwitchSliceForView';
import Icon from '@/components/Icon';
import { showNotImplemented } from '@/utils/notificationHelper';
import { useAppSelector } from '@/states/store';
import { useButtonAvailability } from '@/utils/useButtonAvailability';
import { theme } from 'antd';
const { useToken } = theme;
// 有状态按钮列表 - 这些按钮代表持续的状态,不应在执行后清理action
const STATEFUL_BUTTON_ACTIONS = new Set([
'Adjust Brightness and Contrast',
'Magnifier',
]);
const FunctionButton = ({
title,
action,
iconName,
}: {
title: string;
action: string;
iconName: string;
}) => {
const dispatch = useDispatch();
const themeType = useAppSelector((state) => state.theme.themeType);
const activeTools = useAppSelector((state) => state.functionArea.activeTools);
const { disabled } = useButtonAvailability(action);
// 对于有状态按钮,基于工具激活状态;对于无状态按钮,基于action
const isActive = STATEFUL_BUTTON_ACTIONS.has(action)
? activeTools[action] || false
: false; // 无状态按钮不显示激活状态
const [isHovered, setIsHovered] = useState(false);
const colorPrimary = useToken().token.colorPrimary;
// 根据状态计算Icon的样式
const getIconStyle = () => {
const baseStyle = {
/*控制svg图标的大小,暂时使用这种fontSize方式 */
fontSize: '48px',
};
if (disabled) {
return { ...baseStyle, opacity: 0.4, filter: 'grayscale(1)' };
}
if (isActive) {
return { ...baseStyle, color: colorPrimary };
}
if (isHovered) {
return { ...baseStyle };
}
return { ...baseStyle }; // 默认颜色
};
const handleButtonClick = () => {
if (disabled) {
return;
}
if (action === 'Delete Digital Mask' ||
action === 'Crop Selected Area' ||
['Image Comparison', 'Zoom Image', 'Reset Cursor', 'Pan', 'Snapshot',
].includes(action)
) {
showNotImplemented('');
return;
}
if (action === 'Image Measurement') {
// 切换到测量面板
dispatch(switchToMeasurementPanel());
} else if (action === 'Rectangle Crop') {
// 切换到矩形裁剪面板
dispatch(switchToRectCropPanel());
} else if (action === 'More') {
// 切换到更多功能面板
dispatch(switchToMorePanel());
} else if (action === 'Advanced Processing') {
// 切换到高级图像处理面板
dispatch(switchToAdvancedProcessingPanel());
} else if (action === 'AddMark') {
// 切换到标记面板
dispatch(switchToMarkPanel());
} else {
// 其他功能按钮保持原有逻辑
dispatch(setAction(action));
}
};
return (
);
};
const FunctionArea = () => {
return (
);
};
export default FunctionArea;