import { useSetting } from '../../state/hooks/settings';
import { settingsAtom, CallPanelDockPosition } from '../../state/settings';
import { useCall } from './useCall';
import { CallState } from './types';

/**
 * Hook to determine if the call panel should be rendered docked
 * Returns true if there's an active call AND the panel is set to docked mode
 */
export function useIsCallDocked(): boolean {
  const { activeCall } = useCall();
  const [isDocked] = useSetting(settingsAtom, 'isCallPanelDocked');
  
  const hasActiveCall = activeCall && 
    (activeCall.state === CallState.Connecting || activeCall.state === CallState.Connected);
  
  return Boolean(hasActiveCall && isDocked);
}

/**
 * Hook to determine if the call panel is docked to the right side
 */
export function useIsCallDockedRight(): boolean {
  const isCallDocked = useIsCallDocked();
  const [dockPosition] = useSetting(settingsAtom, 'callPanelDockPosition');
  
  return isCallDocked && dockPosition === 'right';
}

/**
 * Hook to determine if the call panel is docked in the sidebar
 */
export function useIsCallDockedSidebar(): boolean {
  const isCallDocked = useIsCallDocked();
  const [dockPosition] = useSetting(settingsAtom, 'callPanelDockPosition');
  
  return isCallDocked && dockPosition === 'sidebar';
}

/**
 * Hook to get the current dock position setting
 */
export function useCallDockPosition(): CallPanelDockPosition {
  const [dockPosition] = useSetting(settingsAtom, 'callPanelDockPosition');
  return dockPosition;
}
