{"version":3,"file":"FilterLayout.module-f559ddbd.js","sources":["../src/components/SelectorsForm/index.jsx"],"sourcesContent":["import React, { useState, useEffect, useRef } from 'react';\nimport PropTypes from 'prop-types';\nimport styles from '@styles/SelectorsForm.module.css';\nimport styles_input from '@styles/InputContainer.module.css';\nimport { MdOutlineLocationOn, MdSearch } from 'react-icons/md';\nimport Floated from '@components/Floated';\nimport { SelectorCityOptions } from '@utils/constants';\nimport { useSearchParams } from 'react-router-dom';\nimport { useDebounce } from '../../hooks/useDebounce';\n\nfunction SelectorsForm({\n placeholderSearch = '关键字搜索',\n placeholderTag = '选择地点',\n options = [],\n tagOptions = [],\n handleSubmit,\n replace = true,\n}) {\n const [searchParams, setSearchParams] = useSearchParams();\n const setDebounceSearchParams = useDebounce(setSearchParams, 500);\n const [pickerActive, setPickerActive] = useState(false);\n const [selectorOptions, setSelectorOptions] = useState([...SelectorCityOptions]);\n const [selectorName, setSelectorName] = useState('');\n const textRef = useRef();\n\n useEffect(() => {\n if (options.length > 0) {\n setSelectorOptions(options);\n }\n }, [options]);\n\n // Update display text and selector name\n useEffect(() => {\n const params = new URLSearchParams(searchParams);\n const selector = params.get('selector');\n let name;\n if (selector) {\n if (!!selector) {\n const item = selectorOptions.find((item) => item.value == selector);\n if (item) {\n name = item.name;\n }\n }\n }\n setSelectorName(name);\n const text = params.get('text');\n if (text) {\n textRef.current.value = text;\n }\n }, [searchParams]);\n\n const handleOnSelect = (e) => {\n const selector = e.target.attributes.value.nodeValue;\n const params = new URLSearchParams(searchParams);\n params.set('selector', selector || '');\n setSearchParams(params, { replace: replace });\n setPickerActive(false);\n };\n\n const handleOnTagClick = (name, selector) => {\n const params = new URLSearchParams(searchParams);\n const sel = params.get('selector');\n if (selector == sel) {\n selector = '';\n params.delete('selector');\n } else {\n params.set('selector', selector);\n }\n setSearchParams(params, { replace: replace });\n };\n\n const handleOoTextChange = (e) => {\n const text = textRef.current.value;\n const params = new URLSearchParams(searchParams);\n if (!!text) {\n params.set('text', text || '');\n } else {\n params.delete('text');\n }\n setDebounceSearchParams(params, { replace: replace });\n };\n\n return (\n