import React, { useState } from "react"; import { useSearchParams } from "@remix-run/react"; import { X } from "lucide-react"; import { DrawerHeader, DrawerTitle, DrawerContent, Drawer } from "./ui/drawer"; import { RadioGroup, RadioGroupItem } from "./ui/radio-group"; import { Slider } from "./ui/slider"; import { Button } from "./ui/button"; import { useRootData } from "~/hooks/use-root-data"; import filterIcon from "~/assets/icons/filter.png"; import filterIconDark from "~/assets/icons/filter-dark.png"; interface FilterDrawerProps { minimumPrice: number; maximumPrice: number; } const FilterDrawer: React.FC = ({ minimumPrice, maximumPrice, }) => { const { theme } = useRootData(); const [isOpen, setIsOpen] = useState(false); const [searchParams, setSearchParams] = useSearchParams(); const [order, setOrder] = useState(searchParams.get("order") || "all"); // Get initial values from URL params or use defaults const initialMinPrice = searchParams.get("priceMin") ? parseInt(searchParams.get("priceMin") || "", 10) : minimumPrice; const initialMaxPrice = searchParams.get("priceMax") ? parseInt(searchParams.get("priceMax") || "", 10) : maximumPrice; // Check if any filters are different from defaults const isFiltersChanged = order !== "all" || initialMinPrice !== minimumPrice || initialMaxPrice !== maximumPrice; const [priceRange, setPriceRange] = useState<[number, number]>([ initialMinPrice, initialMaxPrice, ]); // Check if current values are different from URL values const hasChanges = order !== (searchParams.get("order") || "all") || priceRange[0] !== initialMinPrice || priceRange[1] !== initialMaxPrice; return ( <>
setIsOpen(true)} onKeyDown={(e) => { if (e.key === "Enter" || e.key === " ") { setIsOpen(true); } }} role="button" tabIndex={0} aria-label="Open filters" > filter
setIsOpen(false)} /> فیلتر نتایج
setOrder(value)} value={order} > setOrder(value)} value={order} > setOrder(value)} value={order} > setOrder(value)} value={order} >

محدوده قیمت :

setPriceRange(value as [number, number]) } className="w-full" />

کمترین قیمت

{ const value = parseInt( e.target.value.replace(/,/g, ""), 10 ); if (!isNaN(value)) { setPriceRange([value, priceRange[1]]); } }} className="w-full text-GRAY focus:text-BLACK px-4 h-full flex items-center justify-start bg-transparent outline-none" />
تومان

بیشترین قیمت

{ const value = parseInt( e.target.value.replace(/,/g, ""), 10 ); if (!isNaN(value)) { setPriceRange([priceRange[0], value]); } }} className="w-full text-GRAY focus:text-BLACK px-4 h-full flex items-center justify-start bg-transparent outline-none" />
تومان
); }; export default FilterDrawer;