{"version":3,"file":"D4PCPn2B.js","sources":["../../../../src/middleware/cars-filters.ts"],"sourcesContent":["import {useFilters} from \"~/composables/useFilters\";\n\nexport default defineNuxtRouteMiddleware(async (to, from) => {\n if (import.meta.server) return\n\n const {getAllCars} = useCar()\n const {parseQueryStructured} = useFilters()\n\n const page = to.params?.page ? Number(to.params.page) : 1\n const params = useState('carsParams', () => ({\n orderBy: {\n attribute: 'listings.created_at',\n direction: 'DESC',\n label: 'Más Recientes'\n }\n }))\n const filters = useState('carsFilter', () => [])\n filters.value = []\n\n if (to.query?.search) {\n const s = to.query?.search;\n filters.value = [\n ...filters.value,\n {\n type: \"or-text-match\",\n value: [\n {\n attribute: \"cars.make\",\n type: \"partial-text-search\",\n value: s,\n },\n {\n attribute: \"cars.model\",\n type: \"partial-text-search\",\n value: s,\n }\n ]\n }\n ]\n } else if (to.query && (to.query.make || to.query.model || to.query.max_price || to.query.mileage)) {\n const f: any = to.query;\n const filters_ = []\n\n if (f?.condition !== '') {\n filters_.push({\n type: 'complete-text-search',\n attribute: 'sub_category',\n value: f.condition\n })\n }\n if (f?.make !== 'Todas las marcas') {\n filters_.push({\n type: 'complete-text-search',\n value: f.make,\n attribute: 'cars.make'\n })\n }\n if (f?.model !== 'Todos los modelos') {\n filters_.push({\n type: 'complete-text-search',\n value: f.model,\n attribute: 'cars.model'\n })\n }\n if (f?.max_price !== 'Sin Precio Máximo') {\n if (f?.max_price < 175000) {\n filters_.push({\n type: 'minmax',\n value: {\n min: 0,\n max: f.max_price\n },\n attribute: 'price'\n })\n } else {\n filters_.push({\n type: 'minmax',\n value: {\n min: f.max_price,\n max: 0\n },\n attribute: 'price'\n })\n }\n\n }\n if (f?.mileage !== 'Sin Millaje máximo') {\n filters_.push({\n type: 'minmax',\n value: {\n min: 0,\n max: f.mileage\n },\n attribute: 'cars.millage'\n })\n }\n\n filters.value = [\n ...filters.value,\n ...filters_\n ]\n\n }\n if (to.params?.make) {\n const filters_ = []\n filters_.push({\n type: 'complete-text-search',\n value: to.params.make,\n attribute: 'cars.make'\n })\n\n filters.value = [\n ...filters.value,\n ...filters_\n ]\n\n }\n if (to.query) {\n const filters_ = parseQueryStructured(to.query)\n if (filters_.filters) {\n filters.value = [\n ...filters.value,\n ...filters_.filters\n ]\n }\n\n }\n\n\n const cars = useState('cars')\n const data = {\n ...(params.value ?? []),\n page,\n filters: filters.value\n }\n\n try {\n const response = await getAllCars(data)\n if (response.data) {\n cars.value = response.data\n }\n\n } catch (e) {\n console.log(\"Error\", e)\n }\n})"],"names":["carsFilters","defineNuxtRouteMiddleware","to","from","__temp","__restore","getAllCars","useCar","parseQueryStructured","page","_a","params","useState","filters","_b","s","_c","f","filters_","_d","cars","data","__executeAsync","response"],"mappings":"wLAGI,MAAAA,EAAwBC,EAAA,MAAAC,EAAAC,IAAA,aAAA,IAAAC,EAAAC,EAGlB,KAAA,CAAC,WAAAC,GAAoBC,IAErB,CAAA,qBAAAC,OACAC,GAAAC,EAAAR,EAAkB,SAAlB,MAAAQ,EAAkB,KAAA,OAAcR,EAAO,OAAA,IAAA,EAAA,EAChCS,EAAAC,EAAA,aAAA,KAAA,CAAA,QACM,CACX,UAAW,sBACX,UAAO,OACX,MAAA,eACF,CACF,EAAA,EACAC,EAAgBD,EAAC,aAAA,IAAA,CAAA,CAAA,EAGP,GADNC,QAAkB,IACZC,EAAAZ,EAAA,QAAA,MAAAY,SAAc,CACpB,MAAAC,GAAgBC,EAAAd,EAAA,QAAA,YAAAc,EAAA,OAAAH,EACD,MAAA,CACX,GAAAA,EAAA,MAAA,CAEI,KAAO,gBACH,MAAA,CAAA,CAEI,UAAM,YACN,KAAO,sBACX,MAAAE,CACA,EAAA,CAEI,UAAM,aACN,KAAO,sBACX,MAAAA,CACJ,CACJ,CACJ,CAAA,CAEA,WAAkB,QAAAb,EAAA,MAAA,MAAAA,EAAA,MAAA,OAAAA,EAAA,MAAA,WAAAA,EAAA,MAAA,SAAA,CAClB,MAAMe,UAEFC,MACAD,GAAA,YAAAA,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