// import {  useEffect} from "react";
// import { useDispatch } from "react-redux";
// import { clearSession } from "../Services/Others";
// import { changeSelectedBranchId } from "../Features/BrachLogin/BranchLogin";
// import { closeCustomerDisplayWindow } from '../Features/customerDisplayWindow/customerDisplayWindow';

// const Logout = () =>{
//     const dispatch = useDispatch();
//     const commonUrl = import.meta.env.ENV_COMMON_BASE_URL
//     useEffect(() =>{
//         closeCustomerDisplayWindow()
//         clearSession()
//         dispatch(changeSelectedBranchId())
//         window.location.replace(commonUrl);
//     },[])
// }
// export default Logout

//mohan

import { useEffect } from 'react';
import { useDispatch } from 'react-redux';
import { clearSession, getSession, sessionStore } from '../Services/Others';
import {
  changeSelectedBranchId,
  GenerateLogout,
} from '../Features/BrachLogin/BranchLogin';

const Logout = () => {
  const dispatch = useDispatch();
  const commonUrl = import.meta.env.ENV_COMMON_BASE_URL;
  const logoutFunc = async () => {
    await sessionStore('Mode', 'Logout');
    const UserId = getSession('UserId');
    const status = 'N'; // replace with your actual status
    const res = await dispatch(GenerateLogout({ UserId, status })).unwrap();
    if (res?.data?.statusCode === 1) {
      clearSession();
      dispatch(changeSelectedBranchId());
      window.location.replace(commonUrl);
    }
  };
  useEffect(() => {
    logoutFunc();
  }, []);
};
export default Logout;
