import { useEffect, useState } from "react"; import { projects } from "../data/projects"; import UnitTypeImageWithMarkers from "./UnitTypeImageWithMarkers"; import Button from "./ui/Button"; import { AnimatePresence, motion } from "framer-motion"; import ChevronLeftIcon from "./icons/ChevronLeftIcon"; import ChevronRightIcon from "./icons/ChevronRightIcon"; import { useSwipeable } from "react-swipeable"; import clsx from "clsx"; import { Unit } from "../types/IUnit"; import OnFloorMask from "./OnFloorMask"; interface UnitSliderProps { unitTypeVariant: string; complexName: string; unit?: Unit; } // костыль: в Мараси 2 bedroom b ЕДИНСТВЕННАЯ НЕ ЗЕРКАЛЬНАЯ ХАТА среди всех function UnitSlider({ unitTypeVariant, complexName, unit }: UnitSliderProps) { const [hasSide, setHasSide] = useState(false); const [selectedSide, setSelectedSide] = useState<"left" | "right">(); const [isLoft, setIsLoft] = useState(false); const [currentSlide, setCurrentSlide] = useState(0); useEffect( () => setSelectedSide( hasSide || unitTypeVariant === "2-bedroom-b" ? "left" : "left" ), [hasSide, unitTypeVariant] ); useEffect(() => { setIsLoft(unitTypeVariant.includes("loft")); setHasSide( unitTypeVariant.endsWith("-left") || unitTypeVariant.endsWith("-right") ); }, [unitTypeVariant]); const handlers = useSwipeable({ onSwipedLeft: () => setCurrentSlide( Math.min( currentSlide + 1, (unit && !unit.unitNo.endsWith("-C") ? 2 : 1) + (isLoft ? 1 : 0) ) ), onSwipedRight: () => setCurrentSlide(Math.max(currentSlide - 1, 0)), preventScrollOnSwipe: true, touchEventOptions: { passive: false, }, trackMouse: true, }); return (
{isLoft ? ( <> project.slug === complexName) ?.types.find( (type) => type.slug === (hasSide ? unitTypeVariant .split("-") .slice(0, isLoft ? -2 : -1) .join("-") : unitTypeVariant) )?.legend || [] } /> project.slug === complexName) ?.types.find( (type) => type.slug === (hasSide ? unitTypeVariant .split("-") .slice(0, isLoft ? -2 : -1) .join("-") : unitTypeVariant) )?.legend || [] } /> ) : ( project.slug === complexName) ?.types.find( (type) => type.slug === (hasSide ? unitTypeVariant.split("-").slice(0, -1).join("-") : unitTypeVariant) )?.legend || [] } /> )}
{unit && !unit.unitNo.endsWith("-C") && (
)}
{!hasSide && unitTypeVariant !== "2-bedroom-b" && currentSlide !== (isLoft ? 2 : 1) && (

Left

setSelectedSide(selectedSide === "left" ? "right" : "left") } >

Right

)}
{isLoft ? ( <> ) : ( )} {unit && !unit.unitNo.endsWith("-C") && ( )} {Array.from({ length: (unit && !unit.unitNo.endsWith("-C") ? 3 : 2) + (isLoft ? 1 : 0), }).map((_, index) => (
))}
); } export default UnitSlider;