'use client'; import { useToolStore } from '@/store'; import { useShapeStore } from '@/store/shape-store'; import { useSelectionStore } from '@/store/selection-store'; import { useTextStore } from '@/store/text-store'; import { WEB_SAFE_FONTS, GOOGLE_FONTS } from '@/lib/text-utils'; import { googleFontsLoader } from '@/lib/google-fonts-loader'; import { useCallback } from 'react'; export function ToolOptions() { const { activeTool, settings, setSize, setOpacity, setHardness, setColor, setFlow, setSecondaryColor, setGradientType } = useToolStore(); const { settings: shapeSettings, setShapeType } = useShapeStore(); const { selectionType, setSelectionType } = useSelectionStore(); const { settings: textSettings, setFontFamily, setFontSize, setFontStyle, setFontWeight, setAlign, setLineHeight, setLetterSpacing, setColor: setTextColor, } = useTextStore(); // Handle font change with Google Fonts loading const handleFontChange = useCallback( async (fontFamily: string) => { // Check if it's a Google Font if (GOOGLE_FONTS.includes(fontFamily as any)) { try { await googleFontsLoader.loadFont(fontFamily); } catch (error) { console.error('Failed to load Google Font:', error); } } setFontFamily(fontFamily); }, [setFontFamily] ); // Drawing tools: brush, pencil, eraser const isDrawingTool = ['brush', 'eraser', 'pencil'].includes(activeTool); const showHardness = ['brush'].includes(activeTool); const showColor = ['brush', 'pencil'].includes(activeTool); const showFlow = ['brush'].includes(activeTool); // Fill tool const isFillTool = activeTool === 'fill'; // Gradient tool const isGradientTool = activeTool === 'gradient'; // Crop tool const isCropTool = activeTool === 'crop'; // Shape tool const isShapeTool = activeTool === 'shape'; // Selection tool const isSelectionTool = activeTool === 'select'; // Text tool const isTextTool = activeTool === 'text'; // Don't show options bar if no options available if (!isDrawingTool && !isFillTool && !isGradientTool && !isCropTool && !isShapeTool && !isSelectionTool && !isTextTool) { return null; } return (
{/* Drawing Tools Options */} {isDrawingTool && ( <> {showColor && (
setColor(e.target.value)} className="h-8 w-16 rounded border border-border cursor-pointer" /> setColor(e.target.value)} className="w-24 px-2 py-1 text-xs rounded border border-border bg-background text-foreground" />
)}
setSize(Number(e.target.value))} className="w-32" /> {settings.size}px
setOpacity(Number(e.target.value) / 100)} className="w-32" /> {Math.round(settings.opacity * 100)}%
{showHardness && (
setHardness(Number(e.target.value) / 100)} className="w-32" /> {Math.round(settings.hardness * 100)}%
)} {showFlow && (
setFlow(Number(e.target.value) / 100)} className="w-32" /> {Math.round(settings.flow * 100)}%
)} )} {/* Fill Tool Options */} {isFillTool && ( <>
setColor(e.target.value)} className="h-8 w-16 rounded border border-border cursor-pointer" /> setColor(e.target.value)} className="w-24 px-2 py-1 text-xs rounded border border-border bg-background text-foreground" />
setOpacity(Number(e.target.value) / 100)} className="w-32" /> {Math.round(settings.opacity * 100)}%
)} {/* Crop Tool Options */} {isCropTool && ( <>
Drag to define crop area. Click and drag handles to resize.
)} {/* Gradient Tool Options */} {isGradientTool && ( <>
setColor(e.target.value)} className="h-8 w-16 rounded border border-border cursor-pointer" /> setColor(e.target.value)} className="w-24 px-2 py-1 text-xs rounded border border-border bg-background text-foreground" />
setSecondaryColor(e.target.value)} className="h-8 w-16 rounded border border-border cursor-pointer" /> setSecondaryColor(e.target.value)} className="w-24 px-2 py-1 text-xs rounded border border-border bg-background text-foreground" />
setOpacity(Number(e.target.value) / 100)} className="w-32" /> {Math.round(settings.opacity * 100)}%
)} {/* Shape Tool Options */} {isShapeTool && (
)} {/* Selection Tool Options */} {isSelectionTool && (
)} {/* Text Tool Options */} {isTextTool && ( <>
setFontSize(Number(e.target.value))} className="w-20 px-2 py-1 text-sm rounded border border-border bg-background text-foreground" /> px
{/* Font Style: Bold/Italic */}
{/* Text Alignment */}
setTextColor(e.target.value)} className="h-8 w-16 rounded border border-border cursor-pointer" /> setTextColor(e.target.value)} className="w-24 px-2 py-1 text-xs rounded border border-border bg-background text-foreground" />
setLineHeight(Number(e.target.value))} className="w-24" /> {textSettings.lineHeight.toFixed(1)}
setLetterSpacing(Number(e.target.value))} className="w-24" /> {textSettings.letterSpacing}px
)}
); }