import { useState, useCallback } from '@tarojs/taro';
import { ITouchEvent } from '@tarojs/components/types/common';

type PasswordInput = {
  pwd: string;
  setPwd: (e: string) => void;
  showPwd: boolean;
  setShowPwd: (e: ITouchEvent) => void;
};
const usePasswordInput = (): PasswordInput => {
  const [pwd, setPwd] = useState('');
  const [showPwd, setShowPwd] = useState(false);

  const setShowPwdHandle = useCallback(() => {
    setShowPwd(showPwd ? false : true);
  }, [showPwd]);

  return { pwd, setPwd, showPwd, setShowPwd: setShowPwdHandle };
};

export default usePasswordInput;
