import { MdOutlineWatchLater } from "react-icons/md"; import { FiSearch } from "react-icons/fi"; import { IoIosArrowDown, IoMdClose } from "react-icons/io"; import { MdOutlineMyLocation } from "react-icons/md"; import { AiOutlineClose } from "react-icons/ai"; import { useState, useEffect, useRef } from "react"; import { useNavigate } from "react-router-dom"; import { useDispatch, useSelector } from "react-redux"; import pozologo from "../../Images/PozoStore.svg"; import { HiLocationMarker } from "react-icons/hi"; import { PiShoppingCartLight, PiStorefrontLight, PiUserCircleLight, } from "react-icons/pi"; import { FaChevronDown } from "react-icons/fa6"; import { GoHeart } from "react-icons/go"; import { RxHamburgerMenu } from "react-icons/rx"; import "../../Styles/HomePage/PozoPublicNavbar.scss"; import PozoPublicSearch from "./PozoPublicSearch/PozoPublicSearch"; import { CiViewList } from "react-icons/ci"; import FullPageLoader from "../Loader/PozoPublicLoader"; import samplepic from "../../Images/Restaurant.png"; import { LuChevronDownCircle, LuChevronUpCircle } from "react-icons/lu"; import { breadCrumbSelector, changeBreadCrumb } from "../../Features/LandingPage/landingPage"; const subDirectory = import.meta.env.BASE_URL; const PozoPublicNavbar = () => { const dispatch = useDispatch(); const navigate = useNavigate(); const [Searchquery, setSearchquery] = useState(''); const breadCrumb = useSelector(breadCrumbSelector); const dropdownRef = useRef(null); const ref = useRef(null); const PageName = breadCrumb?.[breadCrumb.length - 1]?.name const [profile, setProfile] = useState(false); const [loading, setLoading] = useState(false); const [isCollapsed, setIsCollapsed] = useState(false); const [isCollapsedbook, setIsCollapsedbook] = useState(true); const [sidedrawer, setSidedrawer] = useState(true); const [locationDropdown, setLocationDropdown] = useState(false); const [dropdownClosing, setDropdownClosing] = useState(false); const [showLocationList, setShowLocationList] = useState(false); const [Locationdata, setLocationdata] = useState([]); const [currentLocation, setCurrentLocation] = useState( localStorage.getItem("currentLocation") || "Hosur,, PRPH+33F, Hamumanth..." ); const selectLocation = (locName) => { if (locName) { setCurrentLocation(locName); localStorage.setItem("currentLocation", locName); } toggleLocationDropdown(); }; const handleTrackCurrentLocation = () => { if (navigator.geolocation) { setCurrentLocation("Detecting location..."); navigator.geolocation.getCurrentPosition( async (position) => { const { latitude, longitude } = position.coords; try { const res = await fetch( `https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=json` ); const data = await res.json(); if (data && data.display_name) { const address = data.display_name; setCurrentLocation(address); localStorage.setItem("currentLocation", address); } else { const fallback = `${latitude.toFixed(4)}, ${longitude.toFixed(4)}`; setCurrentLocation(fallback); localStorage.setItem("currentLocation", fallback); } } catch (err) { console.error("Reverse geocoding error:", err); const fallback = `Lat: ${latitude.toFixed(2)}, Lon: ${longitude.toFixed(2)}`; setCurrentLocation(fallback); localStorage.setItem("currentLocation", fallback); } if (locationDropdown) { toggleLocationDropdown(); } }, (error) => { console.error("Geolocation error:", error); alert("Location permission denied. Please allow location access in your browser."); setCurrentLocation(localStorage.getItem("currentLocation") || "Hosur,, PRPH+33F, Hamumanth..."); } ); } else { alert("Geolocation is not supported by your browser."); } }; const GotoHomepage = () => { const items = [ { name: "Home", link: `${subDirectory}app-page`, }, ]; setLoading(true); setTimeout(() => { setLoading(false); navigate(`${subDirectory}app-page`); dispatch(changeBreadCrumb({ items: items })); }, 500); }; const toSignIn = () => { setLoading(true); setTimeout(() => { setLoading(false); navigate(`${subDirectory}app-page/signin`); }, 500); } const toMyProfile = () => { const items = [ { name: "Home", link: `${subDirectory}app-page`, }, { name: "My Profile", link: `${subDirectory}app-page/myprofile`, }, ]; setLoading(true); setTimeout(() => { setLoading(false); navigate(`${subDirectory}app-page/myprofile`); dispatch(changeBreadCrumb({ items: items })); }, 500); }; const toFavOrder = () => { const items = [ { name: "Home", link: `${subDirectory}app-page`, }, { name: "My Orders", link: `${subDirectory}app-page/order`, }, ]; setLoading(true); setTimeout(() => { setLoading(false); navigate(`${subDirectory}app-page/order`); dispatch(changeBreadCrumb({ items: items })); }, 500); }; const toFavShop = () => { const items = [ { name: "Home", link: `${subDirectory}app-page`, }, { name: "Fav Shop", link: `${subDirectory}app-page/favshop`, }, ]; setLoading(true); setTimeout(() => { setLoading(false); navigate(`${subDirectory}app-page/favshop`); dispatch(changeBreadCrumb({ items: items })); }, 500); }; const toFavList = () => { const items = [ { name: "Home", link: `${subDirectory}app-page`, }, { name: "Favourite List", link: `${subDirectory}app-page/favlist`, }, ]; setLoading(true); setTimeout(() => { setLoading(false); navigate(`${subDirectory}app-page/favlist`); dispatch(changeBreadCrumb({ items: items })); }, 500); }; const toStore = () => { const items = [ { name: "Home", link: `${subDirectory}app-page`, }, { name: "Stores", link: `${subDirectory}app-page/Stores`, }, ]; setLoading(true); setTimeout(() => { setLoading(false); navigate(`${subDirectory}app-page/Stores`); dispatch(changeBreadCrumb({ items: items })); }, 500); }; const navigatetoCart = () => { const items = [ { name: "Home", link: `${subDirectory}app-page`, }, { name: "Cart", link: `${subDirectory}app-page/cart`, }, ]; setLoading(true); setTimeout(() => { setLoading(false); navigate(`${subDirectory}app-page/cart`); dispatch(changeBreadCrumb({ items: items })); }, 500); }; useEffect(() => { if (Searchquery.length > 0) { setShowLocationList(true) } else if (Searchquery.length == 0) { setShowLocationList(false) } }, [Searchquery]) useEffect(() => { const handleClickOutside = (event) => { if (ref.current && !ref.current.contains(event.target)) { setProfile(false); } }; document.addEventListener("mousedown", handleClickOutside); return () => { document.removeEventListener("mousedown", handleClickOutside); }; }, []); const handleLoginClick = () => { setProfile(!profile); }; const toggleCollapse = () => { setIsCollapsed(!isCollapsed); }; const toggleCollapsebook = () => { setIsCollapsedbook(!isCollapsedbook); }; const toggleHamburger = () => { setSidedrawer(!sidedrawer); }; const handleInputClick = () => { setShowLocationList((prevShowLocationList) => !prevShowLocationList); }; const handleSubmitLocation = (e) => { e.preventDefault(); if (!Searchquery.trim()) return; let items = JSON.parse(localStorage.getItem('Locationdata')) || []; const isDuplicate = items.some(item => item.ShopLocation.toLowerCase() === Searchquery.trim().toLowerCase()); if (!isDuplicate) { items.push({ ShopLocation: Searchquery.trim() }); localStorage.setItem('Locationdata', JSON.stringify(items)); } setLocationdata(items); setSearchquery(''); setShowLocationList(false); }; useEffect(() => { let items = JSON.parse(localStorage.getItem('Locationdata')) || []; setLocationdata(items); }, []); const deleteRecentSearch = (locationToDelete) => { let items = JSON.parse(localStorage.getItem('Locationdata')) || []; const updatedItems = items.filter(item => item.ShopLocation !== locationToDelete); localStorage.setItem('Locationdata', JSON.stringify(updatedItems)); setLocationdata(updatedItems); }; const handleChange = (e) => { setSearchquery(e.target.value); }; const toggleLocationDropdown = () => { if (locationDropdown) { setDropdownClosing(true); setTimeout(() => { setLocationDropdown(false); setDropdownClosing(false); }, 300); } else { setLocationDropdown(true); } }; useEffect(() => { const handleClickOutside = (event) => { if (dropdownRef.current && !dropdownRef.current.contains(event.target)) { setDropdownClosing(true); setTimeout(() => { setLocationDropdown(false); setDropdownClosing(false); }, 300); } }; if (locationDropdown) { document.addEventListener("mousedown", handleClickOutside); } else { document.removeEventListener("mousedown", handleClickOutside); } return () => { document.removeEventListener("mousedown", handleClickOutside); }; }, [locationDropdown]); const handlerSearchFuntion = () => { if (!Searchquery.trim()) return; let items = JSON.parse(localStorage.getItem('Locationdata')) || []; const isDuplicate = items.some(item => item.ShopLocation.toLowerCase() === Searchquery.trim().toLowerCase()); if (!isDuplicate) { items.push({ ShopLocation: Searchquery.trim() }); localStorage.setItem('Locationdata', JSON.stringify(items)); } setLocationdata(items); setSearchquery(''); setShowLocationList(false); } const StoreLocation = [ { ShopLocationName: "Pochampalli" }, { ShopLocationName: "Hosur" }, { ShopLocationName: "Mathur" }, { ShopLocationName: "Dharmapuri" }, { ShopLocationName: "Coimbatore" }, { ShopLocationName: "Salem" }, { ShopLocationName: "Chennai" }, { ShopLocationName: "Namakkal" } ]; const ShopLocationLists = [ { location: "Hosur" }, { location: "Pochampalli" }, { location: "Mathur" }, { location: "Dharmapuri" }, { location: "Coimbatore" }, { location: "Salem" }, { location: "Chennai" }, { location: "Namakkal" } ]; const filteredData2 = Array.isArray(ShopLocationLists) ? ShopLocationLists?.filter((item) => item?.location?.toLowerCase()?.includes(Searchquery?.toLowerCase())) : []; return (
{cat}
{cat}
Select Delivery location
Location Not Found
}# Store Location
{e?.ShopLocation} { event.stopPropagation(); deleteRecentSearch(e?.ShopLocation); }}> ⨉