import { useCallback } from 'react';
import { useSetAtom } from 'jotai';
import { settingsSheetAtom } from '../settingsSheet';
import { SettingsPages } from '../../features/settings/Settings';

export const useOpenSettingsSheet = (): ((page?: SettingsPages) => void) => {
  const setSheet = useSetAtom(settingsSheetAtom);
  return useCallback(
    (page) => {
      setSheet({ page });
    },
    [setSheet]
  );
};

export const useCloseSettingsSheet = (): (() => void) => {
  const setSheet = useSetAtom(settingsSheetAtom);
  return useCallback(() => {
    setSheet(undefined);
  }, [setSheet]);
};
