// Import necessary modules and hooks
import { useEffect, useState } from "react";
import { useGetStatesList } from "./useGetStatesList";

// Custom hook for managing town information in admin panel
export const useAdminTownInfo = (updateTown: ()=>void) => {
  const [isEnglish, setIsEnglish] = useState(false);
  const [isLoading, setIsLoading] = useState(true);
  const [renderCount, setRenderCount] = useState(0);
  const {getStates, statesList} = useGetStatesList();

  // Function to force re-render the list
  const forceRenderList = () =>{
    updateTown();
    setRenderCount(prevCount => prevCount + 1);
  }

  // Fetch states on component mount
  useEffect(()=> {
    getStates();
  // eslint-disable-next-line react-hooks/exhaustive-deps
  },[]);

  return {
    isEnglish,
    isLoading,
    setIsEnglish,
    setIsLoading,
    forceRenderList,
    renderCount,
    statesList,
  }
}