import { useEffect } from 'react';
import { useSettingsStore } from '@/stores/settings.store';

/** Update the browser tab title. Appends org name as suffix. */
export function useDocumentTitle(title: string | null | undefined) {
  const { settings } = useSettingsStore();
  const orgName = settings?.organizationName || 'Changemaker Lite';

  useEffect(() => {
    if (title) {
      document.title = `${title} | ${orgName}`;
    }
  }, [title, orgName]);
}
