import { useEffect, useState } from "react"; import useSphere from "../../store/useSphere"; import { IAppartmentComplex, ISphere } from "../../types/apartmentSphere"; import Button from "../Button"; import BookingIcon from "../icons/BookingIcon"; import ChevronDownIcon from "../icons/ChevronDownIcon"; import HeartIcon from "../icons/Heart"; import MapVectorIcon from "../icons/MapVectorIcon"; import useCompass from "../../store/useCompass"; import LeftArrowIcon from "../icons/LeftArrowIcon"; import InfoIcon from "../icons/InfoIcon"; import { useNavigate } from "react-router-dom"; import useModal from "../../store/useModal"; import { SendEnquiryModal } from "../modals/SendEnquryModal"; import { IAparmentRes } from "../../types/apartmentsRes"; import useFavorites from "../../store/useFavorites"; interface VirtualTourSidebarProps { appartmentSphere: null | IAppartmentComplex; apartment: null | IAparmentRes; } const VirtualTourSidebar = ({ appartmentSphere, apartment, }: VirtualTourSidebarProps) => { const { currentCompassRotate } = useCompass(); const [isActive, setIsActive] = useState(false); const { setSelectedSphere, selectedSphere } = useSphere(); const { setModal } = useModal(); const navigate = useNavigate(); const wing = apartment?.Unit_No.split("-")[0] === "W" ? "West Wing" : "East Wing"; const [isFavorite, setIsFavorite] = useState(false); const { setFavorites } = useFavorites(); const handleOnShowClick = () => { setIsActive((prev) => !prev); }; const handleOnLabelClick = (sphere: ISphere) => { setSelectedSphere(sphere); }; const handleOnBackClick = () => { navigate(-1); }; const handleAboutComplexClick = () => { if (!apartment) return; navigate(`../search/${apartment?.id}`); }; const handleOnSendEnquiryClick = () => { setModal(); }; const handleOnFavoriteClick = ( e: React.MouseEvent ) => { e.stopPropagation(); console.log("apartment", apartment); if (!apartment) return; const favorites = localStorage.getItem("Favorites"); if (!favorites) { setIsFavorite(true); const updatedFavorites = JSON.stringify([apartment]); localStorage.setItem("Favorites", updatedFavorites); } else { const _favorites = JSON.parse(favorites) as IAparmentRes[]; if (_favorites.some((apart) => apart.id === apartment.id)) { setIsFavorite(false); const updatedFavorites = [..._favorites].filter( (apart) => apart.id !== apartment.id ); const convertedFavorites = JSON.stringify(updatedFavorites); setFavorites(updatedFavorites); localStorage.setItem("Favorites", convertedFavorites); } else { setIsFavorite(true); const updatedFavorites = [..._favorites, apartment]; setFavorites(updatedFavorites); const convertedFavorites = JSON.stringify(updatedFavorites); localStorage.setItem("Favorites", convertedFavorites); } } }; useEffect(() => { if (!apartment) return; const favorites = localStorage.getItem("Favorites"); if (favorites) { const _isFavorite = (JSON.parse(favorites) as IAparmentRes[]).some( (apart) => apart.id === apartment.id ); setIsFavorite(_isFavorite); } }, [apartment, apartment?.id]); return (

{apartment?.Project_Name || "Rove Home Marasi Drive"}

{wing}

Floor {apartment?.Floor || 11}

№ {apartment?.Unit_No || 213}

Size

{apartment?.Total_Area_Sqft || 609} Sqft

Status

{apartment?.Property_Status || "Available"}

Unvailiable

{appartmentSphere && appartmentSphere.spheres.map((sphere) => { return (
handleOnLabelClick(sphere)} className={`font-semibold text-caption-s py-0.5 px-2 w-fit rounded-full cursor-pointer pointer-events-auto select-none text-white ${ selectedSphere?.id === sphere.id ? "bg-[#00BED7]" : "bg-[#0D192266]" }`} key={sphere.id} > {sphere.roomType}
); })}
Show
Hide
); }; export default VirtualTourSidebar;