import { useCallback } from 'react';
import { useTimezone } from '@/contexts/TimezoneContext';
import { formatDate as fmtDate, formatDateTime as fmtDateTime, formatTime as fmtTime } from '@/lib/utils';

/**
 * Returns format functions pre-bound with the app-wide timezone.
 * Use this in components instead of importing formatDate/DateTime/Time directly.
 */
export function useFormattedDate() {
  const timezone = useTimezone();

  const formatDate = useCallback(
    (date: string | Date) => fmtDate(date, timezone),
    [timezone],
  );

  const formatDateTime = useCallback(
    (date: string | Date) => fmtDateTime(date, timezone),
    [timezone],
  );

  const formatTime = useCallback(
    (date: string | Date) => fmtTime(date, timezone),
    [timezone],
  );

  return { formatDate, formatDateTime, formatTime, timezone };
}
