import { useState } from "react"; import { BiMapPin } from "react-icons/bi"; import { FaLocationCrosshairs } from "react-icons/fa6"; import { IoLocationOutline } from "react-icons/io5"; import ManualAddress from "../AdsListing/ManualAddress"; import { t } from "@/utils"; import { getIsPaidApi } from "@/redux/reducer/settingSlice"; import { useSelector } from "react-redux"; import dynamic from "next/dynamic"; import { CurrentLanguageData } from "@/redux/reducer/languageSlice"; import LandingAdEditSearchAutocomplete from "@/components/Location/LandingAdEditSearchAutocomplete"; import { getIsBrowserSupported } from "@/redux/reducer/locationSlice"; import { Loader2 } from "lucide-react"; import useGetLocation from "@/components/Layout/useGetLocation"; const MapComponent = dynamic(() => import("@/components/Common/MapComponent"), { ssr: false, loading: () =>
, }); const EditComponentFour = ({ location, setLocation, handleFullSubmission, isAdPlaced, handleGoBack, }) => { const isBrowserSupported = useSelector(getIsBrowserSupported); const CurrentLanguage = useSelector(CurrentLanguageData); const [showManualAddress, setShowManualAddress] = useState(); const [IsGettingCurrentLocation, setIsGettingCurrentLocation] = useState(false); const IsPaidApi = useSelector(getIsPaidApi); const { fetchLocationData } = useGetLocation(); const getCurrentLocation = async () => { if (navigator.geolocation) { setIsGettingCurrentLocation(true); navigator.geolocation.getCurrentPosition( async (position) => { try { const { latitude, longitude } = position.coords; const data = await fetchLocationData({ lat: latitude, lng: longitude, }); setLocation(data); } catch (error) { console.error("Error fetching location data:", error); toast.error(t("errorOccurred")); } finally { setIsGettingCurrentLocation(false); } }, (error) => { toast.error(t("locationNotGranted")); setIsGettingCurrentLocation(false); } ); } else { toast.error(t("geoLocationNotSupported")); } }; const getLocationWithMap = async (pos) => { try { const data = await fetchLocationData(pos); setLocation(data); } catch (error) { console.error("Error fetching location data:", error); toast.error(t("errorOccurred")); } }; return ( <>
{t("addLocation")}
{isBrowserSupported && ( )}
{t("address")}
{location?.address_translated || location?.formattedAddress ? (

{location?.address_translated || location?.formattedAddress}

) : ( t("addYourAddress") )}
{!IsPaidApi && ( <>
{t("or")}

{t("whatLocAdYouSelling")}

)}
); }; export default EditComponentFour;