import { useCallback } from 'react';
import { useRecoilState } from 'recoil';
import { sideDrawerState } from "../../atoms/ui/index.js";
import { useTrackStandardEvent } from "../tracking/index.js";
const useSideDrawerState = function useSideDrawerState(trackingOpts) {
  const [state, setState] = useRecoilState(sideDrawerState);
  const track = useTrackStandardEvent({
    component: 'SideDrawer',
    ...trackingOpts
  });
  const toggle = useCallback(cbTrackingOpts => {
    setState(old => {
      const next = old === 'open' ? 'closed' : 'open';
      track({
        event: 'Toggle',
        detail: next,
        ...cbTrackingOpts
      });
      return next;
    });
  }, [track]);
  const close = useCallback(() => {
    setState('closed');
  }, []);
  const open = useCallback(() => {
    setState('open');
  }, []);
  return {
    state,
    toggle,
    close,
    open
  };
};
export default useSideDrawerState;