// Rent filter sheet — dual-handle range slider, max ¥1,000,000 const { useState: useStateRent, useRef: useRefRent, useEffect: useEffectRent } = React; const MIN_RENT = 0; const MAX_RENT = 1000000; function RentSheet({ open, onClose, value, onChange }) { // value: {min, max} const [local, setLocal] = useStateRent(value); const trackRef = useRefRent(null); const dragging = useRefRent(null); useEffectRent(() => { if (open) setLocal(value); }, [open]); const pct = (v) => ((v - MIN_RENT) / (MAX_RENT - MIN_RENT)) * 100; const handlePointer = (e, handle) => { dragging.current = handle; e.preventDefault(); }; const onMove = (e) => { if (!dragging.current || !trackRef.current) return; const rect = trackRef.current.getBoundingClientRect(); const x = (e.touches ? e.touches[0].clientX : e.clientX) - rect.left; const ratio = Math.max(0, Math.min(1, x / rect.width)); let raw = MIN_RENT + ratio * (MAX_RENT - MIN_RENT); // Snap to 10,000 raw = Math.round(raw / 10000) * 10000; setLocal(prev => { if (dragging.current === 'min') { return { ...prev, min: Math.min(raw, prev.max - 10000) }; } return { ...prev, max: Math.max(raw, prev.min + 10000) }; }); }; const onUp = () => { dragging.current = null; }; useEffectRent(() => { if (!open) return; const moveHandler = (e) => onMove(e); const upHandler = () => onUp(); window.addEventListener('mousemove', moveHandler); window.addEventListener('mouseup', upHandler); window.addEventListener('touchmove', moveHandler, { passive: false }); window.addEventListener('touchend', upHandler); return () => { window.removeEventListener('mousemove', moveHandler); window.removeEventListener('mouseup', upHandler); window.removeEventListener('touchmove', moveHandler); window.removeEventListener('touchend', upHandler); }; }, [open]); if (!open) return null; // Quick presets const presets = [ { label: '〜¥8万', min: 0, max: 80000 }, { label: '¥8〜15万', min: 80000, max: 150000 }, { label: '¥15〜25万', min: 150000, max: 250000 }, { label: '¥25〜50万', min: 250000, max: 500000 }, { label: 'すべて', min: 0, max: 1000000 }, ]; const sheetContent = (