import { useState } from 'react';

// Zoom-Levels Konstante
export const ZOOM_LEVELS = [0.15, 0.25, 0.5, 0.75, 1];

// Zoom-State Hook
export const useZoomState = () => {
  const [zoom, setZoom] = useState(() => {
    const z = parseFloat(localStorage.getItem('adsZoom') || '1');
    return ZOOM_LEVELS.includes(z) ? z : 1;
  });

  const handleZoom = (direction) => {
    setZoom(currentZoom => {
      const idx = ZOOM_LEVELS.indexOf(currentZoom);
      let nextZoom = currentZoom;
      if (direction === 'in') {
        nextZoom = ZOOM_LEVELS[Math.min(ZOOM_LEVELS.length - 1, idx + 1)];
      }
      if (direction === 'out') {
        nextZoom = ZOOM_LEVELS[Math.max(0, idx - 1)];
      }
      localStorage.setItem('adsZoom', nextZoom);
      return nextZoom;
    });
  };

  return { zoom, handleZoom, ZOOM_LEVELS };
};
