import clsx from 'clsx'; import React, { useState } from 'react'; import { FaCheckCircle } from 'react-icons/fa'; import { HighlightColor, HighlightStyle } from '@/types/book'; import { useEnv } from '@/context/EnvContext'; import { useThemeStore } from '@/store/themeStore'; import { useSettingsStore } from '@/store/settingsStore'; import { useResponsiveSize } from '@/hooks/useResponsiveSize'; import { saveSysSettings } from '@/helpers/settings'; const styles = ['highlight', 'underline', 'squiggly'] as HighlightStyle[]; const colors = ['red', 'violet', 'blue', 'green', 'yellow'] as HighlightColor[]; interface HighlightOptionsProps { isVertical: boolean; popupWidth: number; popupHeight: number; triangleDir: 'up' | 'down' | 'left' | 'right'; selectedStyle: HighlightStyle; selectedColor: HighlightColor; onHandleHighlight: (update: boolean) => void; } const OPTIONS_HEIGHT_PIX = 28; const OPTIONS_PADDING_PIX = 16; const HighlightOptions: React.FC = ({ isVertical, popupWidth, popupHeight, triangleDir, selectedStyle: _selectedStyle, selectedColor: _selectedColor, onHandleHighlight, }) => { const { envConfig } = useEnv(); const { settings } = useSettingsStore(); const { isDarkMode } = useThemeStore(); const globalReadSettings = settings.globalReadSettings; const isEink = settings.globalViewSettings.isEink; const einkBgColor = isDarkMode ? '#000000' : '#ffffff'; const einkFgColor = isDarkMode ? '#ffffff' : '#000000'; const customColors = globalReadSettings.customHighlightColors; const [selectedStyle, setSelectedStyle] = useState(_selectedStyle); const [selectedColor, setSelectedColor] = useState(_selectedColor); const size16 = useResponsiveSize(16); const size28 = useResponsiveSize(28); const highlightOptionsHeightPx = useResponsiveSize(OPTIONS_HEIGHT_PIX); const highlightOptionsPaddingPx = useResponsiveSize(OPTIONS_PADDING_PIX); const handleSelectStyle = (style: HighlightStyle) => { const newGlobalReadSettings = { ...globalReadSettings, highlightStyle: style }; saveSysSettings(envConfig, 'globalReadSettings', newGlobalReadSettings); setSelectedStyle(style); setSelectedColor(globalReadSettings.highlightStyles[style]); onHandleHighlight(true); }; const handleSelectColor = (color: HighlightColor) => { const newGlobalReadSettings = { ...globalReadSettings, highlightStyle: selectedStyle, highlightStyles: { ...globalReadSettings.highlightStyles, [selectedStyle]: color }, }; saveSysSettings(envConfig, 'globalReadSettings', newGlobalReadSettings); setSelectedColor(color); onHandleHighlight(true); }; return (
{styles.map((style) => ( ))}
{colors .filter((c) => (isEink ? selectedColor === c : true)) .map((color) => ( ))}
); }; export default HighlightOptions;