"use client";
import { useState, useCallback, useEffect } from "react";
const DOCK_STATE_KEY = "om:ai-chat:dock-state";
const DEFAULT_DOCK_STATE = {
  position: "floating",
  floatingPosition: "bottom-right",
  width: 550,
  height: 700,
  isMinimized: false
};
const MIN_WIDTH = 400;
const MAX_WIDTH = 900;
const MIN_HEIGHT = 500;
const MAX_HEIGHT = 900;
function useDockPosition() {
  const [dockState, setDockState] = useState(DEFAULT_DOCK_STATE);
  const [isHydrated, setIsHydrated] = useState(false);
  useEffect(() => {
    try {
      const stored = localStorage.getItem(DOCK_STATE_KEY);
      if (stored) {
        const parsed = JSON.parse(stored);
        const rawPosition = parsed.position;
        const migratedPosition = rawPosition === "modal" ? "floating" : rawPosition;
        setDockState({
          position: migratedPosition || DEFAULT_DOCK_STATE.position,
          floatingPosition: parsed.floatingPosition || DEFAULT_DOCK_STATE.floatingPosition,
          width: Math.min(Math.max(parsed.width || DEFAULT_DOCK_STATE.width, MIN_WIDTH), MAX_WIDTH),
          height: Math.min(Math.max(parsed.height || DEFAULT_DOCK_STATE.height, MIN_HEIGHT), MAX_HEIGHT),
          isMinimized: parsed.isMinimized || false
        });
      }
    } catch {
    }
    setIsHydrated(true);
  }, []);
  useEffect(() => {
    if (!isHydrated) return;
    try {
      localStorage.setItem(DOCK_STATE_KEY, JSON.stringify(dockState));
    } catch {
    }
  }, [dockState, isHydrated]);
  const setPosition = useCallback((position) => {
    setDockState((prev) => ({ ...prev, position }));
  }, []);
  const setFloatingPosition = useCallback((floatingPosition) => {
    setDockState((prev) => ({ ...prev, floatingPosition }));
  }, []);
  const setWidth = useCallback((width) => {
    setDockState((prev) => ({
      ...prev,
      width: Math.min(Math.max(width, MIN_WIDTH), MAX_WIDTH)
    }));
  }, []);
  const setHeight = useCallback((height) => {
    setDockState((prev) => ({
      ...prev,
      height: Math.min(Math.max(height, MIN_HEIGHT), MAX_HEIGHT)
    }));
  }, []);
  const toggleMinimized = useCallback(() => {
    setDockState((prev) => ({ ...prev, isMinimized: !prev.isMinimized }));
  }, []);
  const setMinimized = useCallback((isMinimized) => {
    setDockState((prev) => ({ ...prev, isMinimized }));
  }, []);
  const cyclePosition = useCallback(() => {
    setDockState((prev) => {
      const positions = ["floating", "right", "left", "bottom"];
      const currentIndex = positions.indexOf(prev.position);
      const nextIndex = (currentIndex + 1) % positions.length;
      return { ...prev, position: positions[nextIndex] };
    });
  }, []);
  const cycleFloatingPosition = useCallback(() => {
    setDockState((prev) => {
      const positions = ["bottom-right", "bottom-left", "top-left", "top-right"];
      const currentIndex = positions.indexOf(prev.floatingPosition);
      const nextIndex = (currentIndex + 1) % positions.length;
      return { ...prev, floatingPosition: positions[nextIndex] };
    });
  }, []);
  return {
    dockState,
    setPosition,
    setFloatingPosition,
    setWidth,
    setHeight,
    toggleMinimized,
    setMinimized,
    cyclePosition,
    cycleFloatingPosition,
    isFloating: dockState.position === "floating",
    isDocked: dockState.position !== "floating",
    isHydrated
  };
}
export {
  useDockPosition
};
//# sourceMappingURL=useDockPosition.js.map
