import { useState, useCallback } from 'react';
import { loadPipSize, savePipSize } from '../utilities/pipUtils';

/**
 * Hook to manage PiP window size with localStorage persistence
 * 
 * Note: OS window manager handles resize operations.
 * This hook only manages initial size and persistence.
 * 
 * @returns {Object} { size, setSize }
 */
const usePipResize = () => {
  // Load initial size from localStorage
  const [size, setSizeState] = useState(() => loadPipSize());

  /**
   * Update size and save to localStorage
   * 
   * @param {{w: number, h: number}} newSize - New window size
   */
  const setSize = useCallback((newSize) => {
    setSizeState(newSize);
    savePipSize(newSize);
  }, []);

  return {
    size,
    setSize,
  };
};

export default usePipResize;
