import { Fragment } from "react"; import { Checkbox } from "../ui/checkbox"; import { Label } from "../ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "../ui/select"; import { t } from "@/utils"; import { Button } from "../ui/button"; const ExtraDetailsFilter = ({ customFields, extraDetails, setExtraDetails, newSearchParams, }) => { const isApplyDisabled = () => { return !Object.values(extraDetails).some( (val) => (Array.isArray(val) && val.length > 0) || (!!val && val !== "") ); }; const handleCheckboxChange = (id, value, checked) => { setExtraDetails((prev) => { const existing = prev[id] || []; const updated = checked ? [...existing, value] : existing.filter((v) => v !== value); return { ...prev, [id]: updated.length ? updated : "" }; }); }; const handleInputChange = (fieldId, value) => { setExtraDetails((prev) => ({ ...prev, [fieldId]: value, })); }; const handleApply = () => { Object.entries(extraDetails).forEach(([key, val]) => { if (Array.isArray(val) && val.length) { newSearchParams.set(key, val.join(",")); } else if (val) { newSearchParams.set(key, val); } else { newSearchParams.delete(key); } }); window.history.pushState(null, '', `/ads?${newSearchParams.toString()}`); }; return (
{customFields.map((field) => ( {/* Checkbox */} {field.type === "checkbox" && (
{field.values.map((option, index) => (
handleCheckboxChange(field.id, option, checked) } />
))}
)} {/* Radio */} {field.type === "radio" && (
{field.values.map((option, index) => ( ))}
)} {/* Dropdown */} {field.type === "dropdown" && (
)}
))}
); }; export default ExtraDetailsFilter;