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 (
Left
Right