import { Dispatch, SetStateAction, useState } from 'react';

type ValueType = boolean;
type UseBooleanStateReturnType = {
  value: ValueType;
  setValue: Dispatch<SetStateAction<ValueType>>;
  setTrue: () => void;
  setFalse: () => void;
  toggle: () => void;
};

export function useBooleanState(defaultValue: ValueType): UseBooleanStateReturnType {
  const [value, setValue] = useState<ValueType>(defaultValue);

  const setTrue = () => setValue(true);
  const setFalse = () => setValue(false);
  const toggle = () => setValue(value => !value);

  return { value, setValue, setTrue, setFalse, toggle };
}
