diff --git a/src/components/Expenses/PreviewDocument.jsx b/src/components/Expenses/PreviewDocument.jsx index c9000059..dd756893 100644 --- a/src/components/Expenses/PreviewDocument.jsx +++ b/src/components/Expenses/PreviewDocument.jsx @@ -1,54 +1,128 @@ -import { useState } from "react"; +import { useState, useRef } from "react"; const PreviewDocument = ({ imageUrl }) => { const [loading, setLoading] = useState(true); const [rotation, setRotation] = useState(0); + const [zoom, setZoom] = useState(1); + const [position, setPosition] = useState({ x: 0, y: 0 }); + const [isDragging, setIsDragging] = useState(false); + const [startPos, setStartPos] = useState({ x: 0, y: 0 }); + const containerRef = useRef(null); + + // Zoom handlers + const handleZoomIn = () => setZoom((prev) => Math.min(prev + 0.2, 3)); + const handleZoomOut = () => setZoom((prev) => Math.max(prev - 0.2, 0.5)); + + // Mouse wheel zoom + const handleWheel = (e) => { + e.preventDefault(); + const delta = e.deltaY > 0 ? -0.1 : 0.1; + setZoom((prev) => Math.min(Math.max(prev + delta, 0.5), 3)); + }; + + const handleMouseDown = (e) => { + if (zoom <= 1) return; + setIsDragging(true); + setStartPos({ + x: e.clientX - position.x, + y: e.clientY - position.y, + }); + }; + + const handleMouseMove = (e) => { + if (!isDragging) return; + setPosition({ + x: e.clientX - startPos.x, + y: e.clientY - startPos.y, + }); + }; + + const handleMouseUp = () => setIsDragging(false); + const handleMouseLeave = () => setIsDragging(false); + + const handleReset = () => { + setRotation(0); + setZoom(1); + setPosition({ x: 0, y: 0 }); + }; return ( - <> -