@garagem-ai/site-sdk 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -3
- package/dist/index.d.mts +27 -361
- package/dist/index.d.ts +27 -361
- package/dist/index.js +530 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +493 -46
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +163 -0
- package/dist/react.d.ts +163 -0
- package/dist/react.js +2124 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +2083 -0
- package/dist/react.mjs.map +1 -0
- package/dist/search-engine-D4EZkNrQ.d.mts +468 -0
- package/dist/search-engine-D4EZkNrQ.d.ts +468 -0
- package/package.json +42 -4
- package/src/fetchers.ts +27 -18
- package/src/index.ts +44 -0
- package/src/internal/url.ts +14 -0
- package/src/listing-card-model.ts +90 -0
- package/src/presentation.ts +79 -0
- package/src/react/cn.ts +3 -0
- package/src/react/filter-panel.tsx +248 -0
- package/src/react/icons.tsx +46 -0
- package/src/react/index.ts +26 -0
- package/src/react/listing-card.tsx +86 -0
- package/src/react/search-chrome.tsx +73 -0
- package/src/react/search-page.tsx +465 -0
- package/src/react/search-pagination.tsx +120 -0
- package/src/react/search-query-form.tsx +81 -0
- package/src/react/search.css +717 -0
- package/src/react/styles/index.ts +1 -0
- package/src/react/styles/search-chrome-css.generated.ts +5 -0
- package/src/react/styles/search-chrome-styles.tsx +12 -0
- package/src/react/types.ts +106 -0
- package/src/react/use-public-search.ts +304 -0
- package/src/search-engine.ts +483 -0
package/dist/react.js
ADDED
|
@@ -0,0 +1,2124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/react/index.ts
|
|
32
|
+
var react_exports = {};
|
|
33
|
+
__export(react_exports, {
|
|
34
|
+
FilterPanel: () => FilterPanel,
|
|
35
|
+
ListingCard: () => ListingCard,
|
|
36
|
+
ResultsSkeleton: () => ResultsSkeleton,
|
|
37
|
+
SearchChromeStyles: () => SearchChromeStyles,
|
|
38
|
+
SearchPage: () => SearchPage,
|
|
39
|
+
SearchPageFallback: () => SearchPageFallback,
|
|
40
|
+
SearchPagination: () => SearchPagination,
|
|
41
|
+
SearchQueryForm: () => SearchQueryForm,
|
|
42
|
+
SearchSortSelect: () => SearchSortSelect,
|
|
43
|
+
rangeDraftFromPath: () => rangeDraftFromPath,
|
|
44
|
+
usePublicSearch: () => usePublicSearch
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(react_exports);
|
|
47
|
+
|
|
48
|
+
// src/react/listing-card.tsx
|
|
49
|
+
var import_link = __toESM(require("next/link"));
|
|
50
|
+
|
|
51
|
+
// src/presentation.ts
|
|
52
|
+
var SEARCH_CSS_VARS = {
|
|
53
|
+
cardRadius: "--garagem-listing-card-radius",
|
|
54
|
+
cardGap: "--garagem-listing-card-gap",
|
|
55
|
+
priceSize: "--garagem-listing-price-size",
|
|
56
|
+
mediaRatio: "--garagem-listing-media-ratio",
|
|
57
|
+
controlHeight: "--garagem-search-control-height",
|
|
58
|
+
iconSize: "--garagem-search-icon-size",
|
|
59
|
+
skeleton: "--garagem-skeleton"
|
|
60
|
+
};
|
|
61
|
+
var SEARCH_CSS_RECIPE = `:root {
|
|
62
|
+
${SEARCH_CSS_VARS.cardRadius}: 0.75rem;
|
|
63
|
+
${SEARCH_CSS_VARS.cardGap}: 1.5rem;
|
|
64
|
+
${SEARCH_CSS_VARS.priceSize}: 1.125rem;
|
|
65
|
+
${SEARCH_CSS_VARS.mediaRatio}: 4 / 3;
|
|
66
|
+
${SEARCH_CSS_VARS.controlHeight}: 2.75rem;
|
|
67
|
+
${SEARCH_CSS_VARS.iconSize}: 1.25rem;
|
|
68
|
+
${SEARCH_CSS_VARS.skeleton}: var(--muted, #e7e5e4);
|
|
69
|
+
}
|
|
70
|
+
`;
|
|
71
|
+
function formatListingPrice(amount, locale = "pt-BR", currency = "BRL") {
|
|
72
|
+
if (amount == null) return "Sob consulta";
|
|
73
|
+
try {
|
|
74
|
+
return new Intl.NumberFormat(locale, {
|
|
75
|
+
style: "currency",
|
|
76
|
+
currency,
|
|
77
|
+
minimumFractionDigits: 0,
|
|
78
|
+
maximumFractionDigits: 0
|
|
79
|
+
}).format(amount);
|
|
80
|
+
} catch {
|
|
81
|
+
return `${currency} ${amount}`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function formatGroupedInteger(value, locale = "pt-BR") {
|
|
85
|
+
const digits = String(value ?? "").replace(/\D/g, "");
|
|
86
|
+
if (!digits) return "";
|
|
87
|
+
const amount = Number.parseInt(digits, 10);
|
|
88
|
+
if (!Number.isFinite(amount)) return "";
|
|
89
|
+
return new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(
|
|
90
|
+
amount
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
function parseGroupedInteger(value) {
|
|
94
|
+
if (typeof value === "number") {
|
|
95
|
+
return Number.isFinite(value) ? Math.trunc(value) : void 0;
|
|
96
|
+
}
|
|
97
|
+
const digits = String(value ?? "").replace(/\D/g, "");
|
|
98
|
+
if (!digits) return void 0;
|
|
99
|
+
const amount = Number.parseInt(digits, 10);
|
|
100
|
+
return Number.isFinite(amount) ? amount : void 0;
|
|
101
|
+
}
|
|
102
|
+
function formatAreaM2(area) {
|
|
103
|
+
if (area == null || !Number.isFinite(area)) return null;
|
|
104
|
+
return `${area} m\xB2`;
|
|
105
|
+
}
|
|
106
|
+
function listingBusinessLabel(businessType) {
|
|
107
|
+
return businessType === "rental" ? "Aluguel" : "Venda";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/listing-path.ts
|
|
111
|
+
function listingPublicPath(listing) {
|
|
112
|
+
const composed = listing.path?.trim() ?? "";
|
|
113
|
+
if (composed.startsWith("/") && !composed.startsWith("//")) return composed;
|
|
114
|
+
const identity = listing.listingCode?.trim() || listing.id?.trim() || "";
|
|
115
|
+
if (!identity || identity === "undefined" || identity === "null") {
|
|
116
|
+
throw new TypeError("listingPublicPath: listing has no listingCode or id");
|
|
117
|
+
}
|
|
118
|
+
return `/imoveis/id-${identity}`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/listing-card-model.ts
|
|
122
|
+
function listingLocationLabel(location) {
|
|
123
|
+
return [location.neighborhood, location.city, location.state].map((part) => part ? String(part).trim() : "").filter(Boolean).join(", ");
|
|
124
|
+
}
|
|
125
|
+
function toListingCardModel(listing) {
|
|
126
|
+
const isPrivate = listing.priceVisibility === "private";
|
|
127
|
+
const area = listing.property?.usableArea ?? listing.property?.totalArea;
|
|
128
|
+
return {
|
|
129
|
+
href: listingPublicPath(listing),
|
|
130
|
+
title: listing.title,
|
|
131
|
+
businessType: listing.businessType,
|
|
132
|
+
businessLabel: listingBusinessLabel(listing.businessType),
|
|
133
|
+
priceVisibility: listing.priceVisibility,
|
|
134
|
+
price: listing.price,
|
|
135
|
+
priceLabel: isPrivate ? "Sob consulta" : formatListingPrice(listing.price),
|
|
136
|
+
pricePeriod: listing.businessType === "rental" && !isPrivate && listing.price != null ? "/m\xEAs" : null,
|
|
137
|
+
locationLabel: listingLocationLabel(listing.location || {}),
|
|
138
|
+
propertyType: listing.property?.type ?? null,
|
|
139
|
+
coverSrc: listing.coverImage?.src ?? null,
|
|
140
|
+
coverAlt: listing.coverImage?.alt ?? listing.title,
|
|
141
|
+
bedrooms: listing.property?.bedrooms ?? null,
|
|
142
|
+
bathrooms: listing.property?.bathrooms ?? null,
|
|
143
|
+
parkingSpaces: listing.property?.parkingSpaces ?? null,
|
|
144
|
+
areaM2: area ?? null
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/react/cn.ts
|
|
149
|
+
function cn(...parts) {
|
|
150
|
+
return parts.filter(Boolean).join(" ");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/react/listing-card.tsx
|
|
154
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
155
|
+
function isListing(value) {
|
|
156
|
+
return "priceVisibility" in value && "businessType" in value && "title" in value;
|
|
157
|
+
}
|
|
158
|
+
function ListingCard({
|
|
159
|
+
listing,
|
|
160
|
+
href,
|
|
161
|
+
className,
|
|
162
|
+
classNames,
|
|
163
|
+
slots,
|
|
164
|
+
style
|
|
165
|
+
}) {
|
|
166
|
+
const model = isListing(listing) ? toListingCardModel(listing) : listing;
|
|
167
|
+
const target = href ?? model.href;
|
|
168
|
+
const areaLabel = formatAreaM2(model.areaM2);
|
|
169
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
170
|
+
"article",
|
|
171
|
+
{
|
|
172
|
+
"data-slot": "listing-card",
|
|
173
|
+
className: cn(className, classNames?.root),
|
|
174
|
+
style,
|
|
175
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_link.default, { href: target, "data-slot": "listing-card-link", children: [
|
|
176
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { "data-slot": "listing-card-media", className: classNames?.media, children: [
|
|
177
|
+
slots?.media ?? (model.coverSrc ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: model.coverSrc, alt: model.coverAlt }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { "data-slot": "listing-card-empty", children: "Sem foto" })),
|
|
178
|
+
slots?.badge ?? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "data-slot": "listing-card-badge", className: classNames?.badge, children: model.businessLabel })
|
|
179
|
+
] }),
|
|
180
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { "data-slot": "listing-card-body", className: classNames?.body, children: [
|
|
181
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { "data-slot": "listing-card-price-row", children: [
|
|
182
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { "data-slot": "listing-card-price", className: classNames?.price, children: model.priceLabel }),
|
|
183
|
+
model.pricePeriod ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "data-slot": "listing-card-period", children: model.pricePeriod }) : null
|
|
184
|
+
] }),
|
|
185
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { "data-slot": "listing-card-title", className: classNames?.title, children: model.title }),
|
|
186
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { "data-slot": "listing-card-location", className: classNames?.location, children: model.locationLabel || model.propertyType || "" }),
|
|
187
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
188
|
+
"ul",
|
|
189
|
+
{
|
|
190
|
+
"data-slot": "listing-card-features",
|
|
191
|
+
className: classNames?.features,
|
|
192
|
+
children: [
|
|
193
|
+
model.bedrooms != null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [
|
|
194
|
+
model.bedrooms,
|
|
195
|
+
" quartos"
|
|
196
|
+
] }) : null,
|
|
197
|
+
model.bathrooms != null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [
|
|
198
|
+
model.bathrooms,
|
|
199
|
+
" banheiros"
|
|
200
|
+
] }) : null,
|
|
201
|
+
model.parkingSpaces != null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [
|
|
202
|
+
model.parkingSpaces,
|
|
203
|
+
" vagas"
|
|
204
|
+
] }) : null,
|
|
205
|
+
areaLabel ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: areaLabel }) : null
|
|
206
|
+
]
|
|
207
|
+
}
|
|
208
|
+
),
|
|
209
|
+
slots?.cta ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { "data-slot": "listing-card-cta", className: classNames?.cta, children: slots.cta }) : null
|
|
210
|
+
] })
|
|
211
|
+
] })
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/react/search-page.tsx
|
|
217
|
+
var import_react2 = require("react");
|
|
218
|
+
|
|
219
|
+
// ../search-url/types.ts
|
|
220
|
+
var SEARCH_BASE_ROUTE = "imoveis";
|
|
221
|
+
var MAX_PAGE = 1e4;
|
|
222
|
+
var MAX_LOC_GROUPS = 20;
|
|
223
|
+
var DEFAULT_MIN_PRICE = 0;
|
|
224
|
+
var DEFAULT_MAX_PRICE = 1e9;
|
|
225
|
+
var DEFAULT_MIN_AREA = 0;
|
|
226
|
+
var DEFAULT_MAX_AREA = 1e5;
|
|
227
|
+
var SORT_URL_TOKENS = [
|
|
228
|
+
"preco-asc",
|
|
229
|
+
"preco-desc",
|
|
230
|
+
"area-asc",
|
|
231
|
+
"area-desc"
|
|
232
|
+
];
|
|
233
|
+
|
|
234
|
+
// ../search-url/slugify.ts
|
|
235
|
+
function slugifyForUrl(text) {
|
|
236
|
+
if (!text) return "";
|
|
237
|
+
const withDashes = text.replace(/([a-z])([A-Z])/g, "$1-$2");
|
|
238
|
+
return withDashes.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").trim();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// ../search-url/catalog.ts
|
|
242
|
+
var PROPERTY_TYPE_SLUG_ALIASES = {
|
|
243
|
+
rural: ["chacara", "fazenda", "sitio"]
|
|
244
|
+
};
|
|
245
|
+
function buildListingTypeOptions(enabled) {
|
|
246
|
+
const flags = enabled ?? { sale: true, rental: true };
|
|
247
|
+
const out = [];
|
|
248
|
+
if (flags.sale !== false) {
|
|
249
|
+
out.push({ id: "sale", slug: "venda", label: "Venda" });
|
|
250
|
+
}
|
|
251
|
+
if (flags.rental !== false) {
|
|
252
|
+
out.push({ id: "rental", slug: "aluguel", label: "Aluguel" });
|
|
253
|
+
}
|
|
254
|
+
return out;
|
|
255
|
+
}
|
|
256
|
+
function emptySearchUrlDictionary() {
|
|
257
|
+
return {
|
|
258
|
+
listingTypes: buildListingTypeOptions(null),
|
|
259
|
+
propertyTypes: [],
|
|
260
|
+
propertyFeatures: [],
|
|
261
|
+
buildingAmenities: []
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
function norm(value) {
|
|
265
|
+
return slugifyForUrl(value) || value.toLowerCase();
|
|
266
|
+
}
|
|
267
|
+
function matchOptionId(segment, options, extraAliases) {
|
|
268
|
+
const n = norm(segment);
|
|
269
|
+
for (const option of options) {
|
|
270
|
+
const aliases = extraAliases?.[option.id] ?? [];
|
|
271
|
+
const candidates = [option.id, option.slug, option.label, ...aliases];
|
|
272
|
+
if (candidates.some((c) => norm(c) === n)) return option.id;
|
|
273
|
+
}
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
function optionSlugById(id, options) {
|
|
277
|
+
const option = options.find((item) => item.id === id);
|
|
278
|
+
return option?.slug ?? null;
|
|
279
|
+
}
|
|
280
|
+
var LISTING_TYPE_ALIASES = {
|
|
281
|
+
sale: ["comprar"],
|
|
282
|
+
rental: ["alugar"]
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// ../search-url/path.ts
|
|
286
|
+
function toArray(value) {
|
|
287
|
+
if (value === void 0) return [];
|
|
288
|
+
return Array.isArray(value) ? value : [value];
|
|
289
|
+
}
|
|
290
|
+
function formatNumeric(value) {
|
|
291
|
+
return Array.isArray(value) ? value.join("-") : String(value);
|
|
292
|
+
}
|
|
293
|
+
function formatRange(min, max, unit) {
|
|
294
|
+
return `de-${min}-a-${max}-${unit}`;
|
|
295
|
+
}
|
|
296
|
+
function formatSuiteSuffix(value) {
|
|
297
|
+
const values = Array.isArray(value) ? value : [value];
|
|
298
|
+
const firstValue = values[0] ?? 0;
|
|
299
|
+
return firstValue === 0 || firstValue === 1 ? "suite" : "suites";
|
|
300
|
+
}
|
|
301
|
+
function composeSearchPublicPath(filters, dictionary = emptySearchUrlDictionary()) {
|
|
302
|
+
const segments = [];
|
|
303
|
+
const listingType = filters.listingType;
|
|
304
|
+
if (listingType) {
|
|
305
|
+
segments.push(
|
|
306
|
+
optionSlugById(listingType, dictionary.listingTypes) || slugifyForUrl(listingType)
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
for (const propertyType of toArray(filters.propertyType)) {
|
|
310
|
+
segments.push(
|
|
311
|
+
optionSlugById(propertyType, dictionary.propertyTypes) || slugifyForUrl(propertyType)
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
const location = filters.location;
|
|
315
|
+
if (location) {
|
|
316
|
+
if (location.state) segments.push(slugifyForUrl(location.state));
|
|
317
|
+
if (location.city) segments.push(slugifyForUrl(location.city));
|
|
318
|
+
if (location.neighborhood)
|
|
319
|
+
segments.push(slugifyForUrl(location.neighborhood));
|
|
320
|
+
if (location.street) segments.push(slugifyForUrl(location.street));
|
|
321
|
+
}
|
|
322
|
+
if (filters.bedrooms !== void 0) {
|
|
323
|
+
segments.push(`${formatNumeric(filters.bedrooms)}-quartos`);
|
|
324
|
+
}
|
|
325
|
+
if (filters.bathrooms !== void 0) {
|
|
326
|
+
segments.push(`${formatNumeric(filters.bathrooms)}-banheiros`);
|
|
327
|
+
}
|
|
328
|
+
if (filters.suites !== void 0) {
|
|
329
|
+
const suffix = formatSuiteSuffix(filters.suites);
|
|
330
|
+
segments.push(`${formatNumeric(filters.suites)}-${suffix}`);
|
|
331
|
+
}
|
|
332
|
+
if (filters.parkingSpots !== void 0) {
|
|
333
|
+
segments.push(`${formatNumeric(filters.parkingSpots)}-vagas`);
|
|
334
|
+
}
|
|
335
|
+
if (filters.price && (filters.price.min !== void 0 || filters.price.max !== void 0)) {
|
|
336
|
+
const min = filters.price.min ?? DEFAULT_MIN_PRICE;
|
|
337
|
+
const max = filters.price.max ?? DEFAULT_MAX_PRICE;
|
|
338
|
+
segments.push(formatRange(min, max, "reais"));
|
|
339
|
+
}
|
|
340
|
+
if (filters.area && (filters.area.min !== void 0 || filters.area.max !== void 0)) {
|
|
341
|
+
const min = filters.area.min ?? DEFAULT_MIN_AREA;
|
|
342
|
+
const max = filters.area.max ?? DEFAULT_MAX_AREA;
|
|
343
|
+
segments.push(formatRange(min, max, "m2"));
|
|
344
|
+
}
|
|
345
|
+
const seenAmenities = /* @__PURE__ */ new Set();
|
|
346
|
+
for (const id of filters.propertyFeatures ?? []) {
|
|
347
|
+
const slug = optionSlugById(id, dictionary.propertyFeatures) || slugifyForUrl(id);
|
|
348
|
+
if (!slug || seenAmenities.has(slug)) continue;
|
|
349
|
+
seenAmenities.add(slug);
|
|
350
|
+
segments.push(slug);
|
|
351
|
+
}
|
|
352
|
+
for (const id of filters.buildingAmenities ?? []) {
|
|
353
|
+
const slug = optionSlugById(id, dictionary.buildingAmenities) || slugifyForUrl(id);
|
|
354
|
+
if (!slug || seenAmenities.has(slug)) continue;
|
|
355
|
+
seenAmenities.add(slug);
|
|
356
|
+
segments.push(slug);
|
|
357
|
+
}
|
|
358
|
+
const path = segments.filter(Boolean).join("/");
|
|
359
|
+
return path ? `/${SEARCH_BASE_ROUTE}/${path}` : `/${SEARCH_BASE_ROUTE}`;
|
|
360
|
+
}
|
|
361
|
+
var BEDROOMS = /^(\d+(?:-\d+)*)-quartos?$/;
|
|
362
|
+
var BATHROOMS = /^(\d+(?:-\d+)*)-banheiros?$/;
|
|
363
|
+
var SUITES = /^(\d+(?:-\d+)*)-suites?$/;
|
|
364
|
+
var PARKING = /^(\d+(?:-\d+)*)-vagas?$/;
|
|
365
|
+
var PRICE = /^de-(\d+)-a-(\d+)-(reais|real)$/;
|
|
366
|
+
var AREA = /^de-(\d+)-a-(\d+)-(m2|m²)$/;
|
|
367
|
+
function parseNumericList(raw) {
|
|
368
|
+
return raw.split("-").map((part) => Number(part)).filter((n) => Number.isFinite(n));
|
|
369
|
+
}
|
|
370
|
+
function collapse(values) {
|
|
371
|
+
return values.length === 1 ? values[0] : values;
|
|
372
|
+
}
|
|
373
|
+
function parseSearchPublicPath(pathname, dictionary = emptySearchUrlDictionary()) {
|
|
374
|
+
const raw = pathname.split(/[?#]/)[0] ?? "";
|
|
375
|
+
let segments = raw.replace(/^\//, "").split("/").filter(Boolean);
|
|
376
|
+
if (segments[0] === SEARCH_BASE_ROUTE) segments = segments.slice(1);
|
|
377
|
+
if (segments.some((segment) => segment.includes("."))) return null;
|
|
378
|
+
if (segments.some((segment) => segment.toLowerCase().startsWith("id-"))) {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
const filters = {};
|
|
382
|
+
const locationParts = [];
|
|
383
|
+
const propertyTypes = [];
|
|
384
|
+
const propertyFeatures = [];
|
|
385
|
+
const buildingAmenities = [];
|
|
386
|
+
for (const segment of segments) {
|
|
387
|
+
const lower = segment.toLowerCase();
|
|
388
|
+
const listingType = matchOptionId(
|
|
389
|
+
segment,
|
|
390
|
+
dictionary.listingTypes,
|
|
391
|
+
LISTING_TYPE_ALIASES
|
|
392
|
+
);
|
|
393
|
+
if (listingType && !filters.listingType) {
|
|
394
|
+
filters.listingType = listingType;
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
const propertyType = matchOptionId(
|
|
398
|
+
segment,
|
|
399
|
+
dictionary.propertyTypes,
|
|
400
|
+
PROPERTY_TYPE_SLUG_ALIASES
|
|
401
|
+
);
|
|
402
|
+
if (propertyType) {
|
|
403
|
+
propertyTypes.push(propertyType);
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
const bedrooms = lower.match(BEDROOMS);
|
|
407
|
+
if (bedrooms) {
|
|
408
|
+
filters.bedrooms = collapse(parseNumericList(bedrooms[1]));
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
const bathrooms = lower.match(BATHROOMS);
|
|
412
|
+
if (bathrooms) {
|
|
413
|
+
filters.bathrooms = collapse(parseNumericList(bathrooms[1]));
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
const suites = lower.match(SUITES);
|
|
417
|
+
if (suites) {
|
|
418
|
+
filters.suites = collapse(parseNumericList(suites[1]));
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
const parking = lower.match(PARKING);
|
|
422
|
+
if (parking) {
|
|
423
|
+
filters.parkingSpots = collapse(parseNumericList(parking[1]));
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
const price = lower.match(PRICE);
|
|
427
|
+
if (price) {
|
|
428
|
+
filters.price = { min: Number(price[1]), max: Number(price[2]) };
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
const area = lower.match(AREA);
|
|
432
|
+
if (area) {
|
|
433
|
+
filters.area = { min: Number(area[1]), max: Number(area[2]) };
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
const featureId = matchOptionId(segment, dictionary.propertyFeatures);
|
|
437
|
+
if (featureId) {
|
|
438
|
+
propertyFeatures.push(featureId);
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
const amenityId = matchOptionId(segment, dictionary.buildingAmenities);
|
|
442
|
+
if (amenityId) {
|
|
443
|
+
buildingAmenities.push(amenityId);
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
locationParts.push(segment);
|
|
447
|
+
}
|
|
448
|
+
if (propertyTypes.length === 1) filters.propertyType = propertyTypes[0];
|
|
449
|
+
else if (propertyTypes.length > 1) filters.propertyType = propertyTypes;
|
|
450
|
+
if (propertyFeatures.length) filters.propertyFeatures = propertyFeatures;
|
|
451
|
+
if (buildingAmenities.length) filters.buildingAmenities = buildingAmenities;
|
|
452
|
+
const location = locationFromPathLeftovers(locationParts);
|
|
453
|
+
if (location) filters.location = location;
|
|
454
|
+
return filters;
|
|
455
|
+
}
|
|
456
|
+
var PATH_STREET_PREFIX = /^(rua|r|avenida|av|alameda|al|travessa|tv|estrada|rodovia|rod)-/i;
|
|
457
|
+
function locationFromPathLeftovers(parts) {
|
|
458
|
+
if (parts.length === 0) return void 0;
|
|
459
|
+
if (parts.length === 1) {
|
|
460
|
+
const value = parts[0];
|
|
461
|
+
if (PATH_STREET_PREFIX.test(value)) return { street: value };
|
|
462
|
+
if (/^[a-z]{2}$/i.test(value)) return { state: value };
|
|
463
|
+
return { neighborhood: value };
|
|
464
|
+
}
|
|
465
|
+
const [state, city, neighborhood, street] = parts;
|
|
466
|
+
return {
|
|
467
|
+
...state ? { state } : {},
|
|
468
|
+
...city ? { city } : {},
|
|
469
|
+
...neighborhood ? { neighborhood } : {},
|
|
470
|
+
...street ? { street } : {}
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// ../search-url/applied-query.ts
|
|
475
|
+
var SORT_SET = new Set(SORT_URL_TOKENS);
|
|
476
|
+
function isSortToken(value) {
|
|
477
|
+
return SORT_SET.has(value);
|
|
478
|
+
}
|
|
479
|
+
function normalizeAppliedSearchQuery(query) {
|
|
480
|
+
if (query.loc && query.loc.length > 0) {
|
|
481
|
+
const { query: _query, ...rest } = query;
|
|
482
|
+
return rest;
|
|
483
|
+
}
|
|
484
|
+
return query;
|
|
485
|
+
}
|
|
486
|
+
function parseAppliedSearchQuery(search) {
|
|
487
|
+
const params = search instanceof URLSearchParams ? search : new URLSearchParams(search.startsWith("?") ? search.slice(1) : search);
|
|
488
|
+
const result = {};
|
|
489
|
+
const pageRaw = params.get("page");
|
|
490
|
+
if (pageRaw) {
|
|
491
|
+
const page = Number.parseInt(pageRaw, 10);
|
|
492
|
+
if (Number.isFinite(page) && page > 1) {
|
|
493
|
+
result.page = Math.min(page, MAX_PAGE);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
const sort = params.get("ordenar");
|
|
497
|
+
if (sort && isSortToken(sort)) result.sort = sort;
|
|
498
|
+
const q = params.get("q")?.trim();
|
|
499
|
+
if (q) result.query = q;
|
|
500
|
+
const loc = params.getAll("loc").map((value) => value.trim()).filter(Boolean).slice(0, MAX_LOC_GROUPS);
|
|
501
|
+
if (loc.length > 0) result.loc = loc;
|
|
502
|
+
return normalizeAppliedSearchQuery(result);
|
|
503
|
+
}
|
|
504
|
+
var APPLIED_QUERY_KEYS = ["page", "ordenar", "q", "loc"];
|
|
505
|
+
function serializeAppliedSearchQuery(query) {
|
|
506
|
+
const normalized = normalizeAppliedSearchQuery(query);
|
|
507
|
+
const params = new URLSearchParams();
|
|
508
|
+
if (normalized.page !== void 0 && normalized.page > 1) {
|
|
509
|
+
params.set("page", String(Math.min(normalized.page, MAX_PAGE)));
|
|
510
|
+
}
|
|
511
|
+
if (normalized.sort && isSortToken(normalized.sort)) {
|
|
512
|
+
params.set("ordenar", normalized.sort);
|
|
513
|
+
}
|
|
514
|
+
const text = normalized.query?.trim();
|
|
515
|
+
if (text) params.set("q", text);
|
|
516
|
+
for (const value of (normalized.loc ?? []).slice(0, MAX_LOC_GROUPS)) {
|
|
517
|
+
const trimmed = value.trim();
|
|
518
|
+
if (trimmed) params.append("loc", trimmed);
|
|
519
|
+
}
|
|
520
|
+
return params;
|
|
521
|
+
}
|
|
522
|
+
function mergeAppliedSearchQueryIntoSearch(existing, query) {
|
|
523
|
+
const params = existing instanceof URLSearchParams ? new URLSearchParams(existing) : new URLSearchParams(
|
|
524
|
+
existing.startsWith("?") ? existing.slice(1) : existing
|
|
525
|
+
);
|
|
526
|
+
for (const key of APPLIED_QUERY_KEYS) {
|
|
527
|
+
params.delete(key);
|
|
528
|
+
}
|
|
529
|
+
const serialized = serializeAppliedSearchQuery(query);
|
|
530
|
+
serialized.forEach((value, key) => {
|
|
531
|
+
if (key === "loc") {
|
|
532
|
+
params.append("loc", value);
|
|
533
|
+
} else {
|
|
534
|
+
params.set(key, value);
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
return params;
|
|
538
|
+
}
|
|
539
|
+
function reduceAppliedSearchQuery(prev, change) {
|
|
540
|
+
switch (change.type) {
|
|
541
|
+
case "sort": {
|
|
542
|
+
const next = { ...prev };
|
|
543
|
+
delete next.page;
|
|
544
|
+
if (change.sort) next.sort = change.sort;
|
|
545
|
+
else delete next.sort;
|
|
546
|
+
return normalizeAppliedSearchQuery(next);
|
|
547
|
+
}
|
|
548
|
+
case "applyFilters": {
|
|
549
|
+
const next = { ...prev };
|
|
550
|
+
delete next.page;
|
|
551
|
+
return normalizeAppliedSearchQuery(next);
|
|
552
|
+
}
|
|
553
|
+
case "query": {
|
|
554
|
+
const next = { ...prev };
|
|
555
|
+
delete next.page;
|
|
556
|
+
const trimmed = change.query.trim();
|
|
557
|
+
if (trimmed) {
|
|
558
|
+
next.query = trimmed;
|
|
559
|
+
delete next.loc;
|
|
560
|
+
} else {
|
|
561
|
+
delete next.query;
|
|
562
|
+
}
|
|
563
|
+
return normalizeAppliedSearchQuery(next);
|
|
564
|
+
}
|
|
565
|
+
case "loc": {
|
|
566
|
+
const next = { ...prev };
|
|
567
|
+
delete next.page;
|
|
568
|
+
delete next.query;
|
|
569
|
+
const loc = change.loc.map((value) => value.trim()).filter(Boolean).slice(0, MAX_LOC_GROUPS);
|
|
570
|
+
if (loc.length > 0) next.loc = loc;
|
|
571
|
+
else delete next.loc;
|
|
572
|
+
return normalizeAppliedSearchQuery(next);
|
|
573
|
+
}
|
|
574
|
+
case "page": {
|
|
575
|
+
const next = { ...prev };
|
|
576
|
+
if (change.page <= 1) delete next.page;
|
|
577
|
+
else next.page = Math.min(change.page, MAX_PAGE);
|
|
578
|
+
return normalizeAppliedSearchQuery(next);
|
|
579
|
+
}
|
|
580
|
+
default: {
|
|
581
|
+
const _exhaustive = change;
|
|
582
|
+
return _exhaustive;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
function composeSearchPublicHref(pathname, query, existingSearch) {
|
|
587
|
+
const params = existingSearch ? mergeAppliedSearchQueryIntoSearch(existingSearch, query) : serializeAppliedSearchQuery(query);
|
|
588
|
+
const qs = params.toString();
|
|
589
|
+
return qs ? `${pathname}?${qs}` : pathname;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// src/applied-query.ts
|
|
593
|
+
function parseAppliedSearchQuery2(search) {
|
|
594
|
+
return parseAppliedSearchQuery(search);
|
|
595
|
+
}
|
|
596
|
+
function reduceAppliedSearchQuery2(prev, change) {
|
|
597
|
+
return reduceAppliedSearchQuery(prev, change);
|
|
598
|
+
}
|
|
599
|
+
function composeSearchPublicHref2(pathname, query, existingSearch) {
|
|
600
|
+
return composeSearchPublicHref(pathname, query, existingSearch);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// src/loc-params.ts
|
|
604
|
+
function pathLocationToFilterInput(location) {
|
|
605
|
+
if (!location || typeof location !== "object") return null;
|
|
606
|
+
const { state, city, neighborhood, street } = location;
|
|
607
|
+
const levels = [];
|
|
608
|
+
if (state) levels.push(state);
|
|
609
|
+
if (city) levels.push(city);
|
|
610
|
+
if (neighborhood) levels.push(neighborhood);
|
|
611
|
+
if (street) levels.push(street);
|
|
612
|
+
if (levels.length === 0) return null;
|
|
613
|
+
if (levels.length === 1) {
|
|
614
|
+
if (state) return { type: "state", value: state };
|
|
615
|
+
if (city) return { type: "city", value: city };
|
|
616
|
+
if (neighborhood) return { type: "neighborhood", value: neighborhood };
|
|
617
|
+
if (street) return { type: "street", value: street };
|
|
618
|
+
}
|
|
619
|
+
return { type: "path", value: levels.join("/") };
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// src/path.ts
|
|
623
|
+
function composeSearchPublicPath2(filters, dictionary) {
|
|
624
|
+
return dictionary ? composeSearchPublicPath(filters, dictionary) : composeSearchPublicPath(filters);
|
|
625
|
+
}
|
|
626
|
+
function parseSearchPublicPath2(pathname, dictionary) {
|
|
627
|
+
return dictionary ? parseSearchPublicPath(pathname, dictionary) : parseSearchPublicPath(pathname);
|
|
628
|
+
}
|
|
629
|
+
function pathFiltersToQueryFilters(pathFilters) {
|
|
630
|
+
const result = {};
|
|
631
|
+
if (pathFilters.listingType !== void 0) {
|
|
632
|
+
result.listing_type = pathFilters.listingType;
|
|
633
|
+
}
|
|
634
|
+
if (pathFilters.propertyType !== void 0) {
|
|
635
|
+
result.property_type = pathFilters.propertyType;
|
|
636
|
+
}
|
|
637
|
+
if (pathFilters.bedrooms !== void 0) {
|
|
638
|
+
result.property_bedrooms = pathFilters.bedrooms;
|
|
639
|
+
}
|
|
640
|
+
if (pathFilters.bathrooms !== void 0) {
|
|
641
|
+
result.property_bathrooms = pathFilters.bathrooms;
|
|
642
|
+
}
|
|
643
|
+
if (pathFilters.suites !== void 0) {
|
|
644
|
+
result.property_suites = pathFilters.suites;
|
|
645
|
+
}
|
|
646
|
+
if (pathFilters.parkingSpots !== void 0) {
|
|
647
|
+
result.property_parking_spots = pathFilters.parkingSpots;
|
|
648
|
+
}
|
|
649
|
+
if (pathFilters.price !== void 0) {
|
|
650
|
+
result.price = pathFilters.price;
|
|
651
|
+
}
|
|
652
|
+
if (pathFilters.area !== void 0) {
|
|
653
|
+
result.property_area_total = pathFilters.area;
|
|
654
|
+
}
|
|
655
|
+
if (pathFilters.propertyFeatures !== void 0) {
|
|
656
|
+
result.propertyFeatures = pathFilters.propertyFeatures;
|
|
657
|
+
}
|
|
658
|
+
if (pathFilters.buildingAmenities !== void 0) {
|
|
659
|
+
result.buildingAmenities = pathFilters.buildingAmenities;
|
|
660
|
+
}
|
|
661
|
+
return result;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// src/search-engine.ts
|
|
665
|
+
var PATH_FILTER_IDS = {
|
|
666
|
+
listing_type: "listingType",
|
|
667
|
+
property_type: "propertyType",
|
|
668
|
+
property_bedrooms: "bedrooms",
|
|
669
|
+
property_bathrooms: "bathrooms",
|
|
670
|
+
property_suites: "suites",
|
|
671
|
+
property_parking_spots: "parkingSpots",
|
|
672
|
+
price: "price",
|
|
673
|
+
property_area_total: "area",
|
|
674
|
+
propertyFeatures: "propertyFeatures",
|
|
675
|
+
buildingAmenities: "buildingAmenities"
|
|
676
|
+
};
|
|
677
|
+
var SEARCH_SORT_RELEVANCE = {
|
|
678
|
+
id: "",
|
|
679
|
+
label: "Mais relevantes"
|
|
680
|
+
};
|
|
681
|
+
function searchSortOptions(sorts) {
|
|
682
|
+
const fromApi = (sorts || []).filter((sort) => sort.id);
|
|
683
|
+
return [
|
|
684
|
+
{ id: SEARCH_SORT_RELEVANCE.id, label: SEARCH_SORT_RELEVANCE.label },
|
|
685
|
+
...fromApi
|
|
686
|
+
];
|
|
687
|
+
}
|
|
688
|
+
var TOOLBAR_PRIMARY_FILTER_IDS = [
|
|
689
|
+
"price",
|
|
690
|
+
"property_bedrooms"
|
|
691
|
+
];
|
|
692
|
+
var HIDDEN_FILTER_IDS = /* @__PURE__ */ new Set(["property_suites"]);
|
|
693
|
+
function toFiniteNumber(value) {
|
|
694
|
+
if (value === "" || value == null) return void 0;
|
|
695
|
+
const n = Number(value);
|
|
696
|
+
return Number.isFinite(n) ? n : void 0;
|
|
697
|
+
}
|
|
698
|
+
function pathnameOnly(pathname) {
|
|
699
|
+
return String(pathname || "").split(/[?#]/)[0] || "/";
|
|
700
|
+
}
|
|
701
|
+
function readPublicSearch(pathname, search, dictionary) {
|
|
702
|
+
const pathFilters = parseSearchPublicPath2(pathnameOnly(pathname), dictionary) || {};
|
|
703
|
+
const applied = parseAppliedSearchQuery2(search || "");
|
|
704
|
+
return { pathFilters, applied };
|
|
705
|
+
}
|
|
706
|
+
function lookupDisplay(table, slug) {
|
|
707
|
+
if (!slug || !table) return slug;
|
|
708
|
+
return table[slug] || table[String(slug).toLowerCase()] || slug;
|
|
709
|
+
}
|
|
710
|
+
function displayPathLocation(location, values) {
|
|
711
|
+
if (!location) return null;
|
|
712
|
+
const table = values || {};
|
|
713
|
+
return {
|
|
714
|
+
state: lookupDisplay(table.states, location.state),
|
|
715
|
+
city: lookupDisplay(table.cities, location.city),
|
|
716
|
+
neighborhood: lookupDisplay(table.neighborhoods, location.neighborhood),
|
|
717
|
+
street: lookupDisplay(table.streets, location.street)
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
function buildQueryListingsParams(pathFilters, applied, schema, locationValues) {
|
|
721
|
+
const filters = pathFiltersToQueryFilters(pathFilters || {});
|
|
722
|
+
const locations = [];
|
|
723
|
+
const displayed = displayPathLocation(pathFilters?.location, locationValues);
|
|
724
|
+
const pathLoc = displayed ? pathLocationToFilterInput(displayed) : null;
|
|
725
|
+
if (pathLoc) locations.push(pathLoc);
|
|
726
|
+
for (const value of applied?.loc || []) {
|
|
727
|
+
locations.push({ type: "loc", value });
|
|
728
|
+
}
|
|
729
|
+
const params = {
|
|
730
|
+
page: applied?.page || 1,
|
|
731
|
+
limit: schema?.defaultLimit || 12,
|
|
732
|
+
filters
|
|
733
|
+
};
|
|
734
|
+
if (applied?.sort) params.sort = applied.sort;
|
|
735
|
+
const hasLocation = locations.length > 0;
|
|
736
|
+
if (applied?.query && !hasLocation) params.q = applied.query;
|
|
737
|
+
if (hasLocation) params.location = locations;
|
|
738
|
+
return params;
|
|
739
|
+
}
|
|
740
|
+
function applyPathFilter(pathFilters, filterId, value) {
|
|
741
|
+
const next = { ...pathFilters || {} };
|
|
742
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
743
|
+
if (!key) return next;
|
|
744
|
+
if (value === "" || value == null) {
|
|
745
|
+
delete next[key];
|
|
746
|
+
return next;
|
|
747
|
+
}
|
|
748
|
+
if (key === "price" || key === "area") {
|
|
749
|
+
const range = value || {};
|
|
750
|
+
const parse = key === "price" ? parseGroupedInteger : toFiniteNumber;
|
|
751
|
+
const min = parse(range.min);
|
|
752
|
+
const max = parse(range.max);
|
|
753
|
+
if (min == null && max == null) {
|
|
754
|
+
delete next[key];
|
|
755
|
+
return next;
|
|
756
|
+
}
|
|
757
|
+
next[key] = {
|
|
758
|
+
...min != null ? { min } : {},
|
|
759
|
+
...max != null ? { max } : {}
|
|
760
|
+
};
|
|
761
|
+
return next;
|
|
762
|
+
}
|
|
763
|
+
if (key === "propertyFeatures" || key === "buildingAmenities") {
|
|
764
|
+
const current = Array.isArray(next[key]) ? [...next[key]] : [];
|
|
765
|
+
const id = String(value);
|
|
766
|
+
const i = current.indexOf(id);
|
|
767
|
+
if (i >= 0) current.splice(i, 1);
|
|
768
|
+
else current.push(id);
|
|
769
|
+
if (current.length) next[key] = current;
|
|
770
|
+
else delete next[key];
|
|
771
|
+
return next;
|
|
772
|
+
}
|
|
773
|
+
if (key === "propertyType") {
|
|
774
|
+
const id = String(value);
|
|
775
|
+
const current = Array.isArray(next.propertyType) ? [...next.propertyType] : next.propertyType ? [String(next.propertyType)] : [];
|
|
776
|
+
const i = current.indexOf(id);
|
|
777
|
+
if (i >= 0) current.splice(i, 1);
|
|
778
|
+
else current.push(id);
|
|
779
|
+
if (current.length === 0) delete next.propertyType;
|
|
780
|
+
else if (current.length === 1) next.propertyType = current[0];
|
|
781
|
+
else next.propertyType = current;
|
|
782
|
+
return next;
|
|
783
|
+
}
|
|
784
|
+
if (key === "listingType") {
|
|
785
|
+
const id = String(value);
|
|
786
|
+
if (next.listingType === id) delete next.listingType;
|
|
787
|
+
else next.listingType = id;
|
|
788
|
+
return next;
|
|
789
|
+
}
|
|
790
|
+
if (key === "bedrooms" || key === "bathrooms" || key === "suites" || key === "parkingSpots") {
|
|
791
|
+
const n = Number(value);
|
|
792
|
+
if (!Number.isFinite(n)) {
|
|
793
|
+
delete next[key];
|
|
794
|
+
return next;
|
|
795
|
+
}
|
|
796
|
+
if (next[key] === n) delete next[key];
|
|
797
|
+
else next[key] = n;
|
|
798
|
+
return next;
|
|
799
|
+
}
|
|
800
|
+
return next;
|
|
801
|
+
}
|
|
802
|
+
function pathFilterValue(pathFilters, filterId) {
|
|
803
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
804
|
+
const value = pathFilters && key ? pathFilters[key] : void 0;
|
|
805
|
+
if (value == null) return "";
|
|
806
|
+
if (Array.isArray(value)) return value[0] != null ? String(value[0]) : "";
|
|
807
|
+
if (typeof value === "object") return "";
|
|
808
|
+
return String(value);
|
|
809
|
+
}
|
|
810
|
+
function pathFilterHasOption(pathFilters, filterId, optionId) {
|
|
811
|
+
const key = PATH_FILTER_IDS[filterId];
|
|
812
|
+
const value = pathFilters && key ? pathFilters[key] : void 0;
|
|
813
|
+
if (value == null) return false;
|
|
814
|
+
if (Array.isArray(value)) return value.map(String).includes(optionId);
|
|
815
|
+
if (typeof value === "object") return false;
|
|
816
|
+
return String(value) === optionId;
|
|
817
|
+
}
|
|
818
|
+
function publicSearchHref(pathFilters, applied, dictionary, existingSearch) {
|
|
819
|
+
const pathname = composeSearchPublicPath2(pathFilters || {}, dictionary);
|
|
820
|
+
return composeSearchPublicHref2(pathname, applied || {}, existingSearch);
|
|
821
|
+
}
|
|
822
|
+
function hrefForPathFilters(pathname, search, dictionary, nextPathFilters) {
|
|
823
|
+
const { applied } = readPublicSearch(pathname, search, dictionary);
|
|
824
|
+
const nextApplied = reduceAppliedSearchQuery2(applied, {
|
|
825
|
+
type: "applyFilters"
|
|
826
|
+
});
|
|
827
|
+
return publicSearchHref(nextPathFilters, nextApplied, dictionary, search);
|
|
828
|
+
}
|
|
829
|
+
function hrefForAppliedChange(pathname, search, dictionary, change) {
|
|
830
|
+
const { pathFilters, applied } = readPublicSearch(
|
|
831
|
+
pathname,
|
|
832
|
+
search,
|
|
833
|
+
dictionary
|
|
834
|
+
);
|
|
835
|
+
let nextPath = pathFilters;
|
|
836
|
+
if (change && change.type === "query") {
|
|
837
|
+
nextPath = { ...pathFilters };
|
|
838
|
+
delete nextPath.location;
|
|
839
|
+
}
|
|
840
|
+
const nextApplied = reduceAppliedSearchQuery2(applied, change);
|
|
841
|
+
return publicSearchHref(nextPath, nextApplied, dictionary, search);
|
|
842
|
+
}
|
|
843
|
+
function currentSearchHref(pathname, search) {
|
|
844
|
+
const path = pathnameOnly(pathname);
|
|
845
|
+
const qs = search.replace(/^\?/, "");
|
|
846
|
+
return qs ? `${path}?${qs}` : path;
|
|
847
|
+
}
|
|
848
|
+
function canonicalizeSearchHref(pathname, search, dictionary) {
|
|
849
|
+
const { pathFilters, applied } = readPublicSearch(
|
|
850
|
+
pathname,
|
|
851
|
+
search,
|
|
852
|
+
dictionary
|
|
853
|
+
);
|
|
854
|
+
const href = publicSearchHref(pathFilters, applied, dictionary, search);
|
|
855
|
+
if (href === currentSearchHref(pathname, search)) return null;
|
|
856
|
+
return href;
|
|
857
|
+
}
|
|
858
|
+
function clearStagedPathFilters(current, keepFilterIds = []) {
|
|
859
|
+
const next = current.location ? { location: current.location } : {};
|
|
860
|
+
for (const id of keepFilterIds) {
|
|
861
|
+
const key = PATH_FILTER_IDS[id];
|
|
862
|
+
if (!key || key === "location") continue;
|
|
863
|
+
const value = current[key];
|
|
864
|
+
if (value != null) Object.assign(next, { [key]: value });
|
|
865
|
+
}
|
|
866
|
+
return next;
|
|
867
|
+
}
|
|
868
|
+
function visibleSearchFilters(schema) {
|
|
869
|
+
if (!schema?.filters) return [];
|
|
870
|
+
return schema.filters.filter((filter) => {
|
|
871
|
+
if (HIDDEN_FILTER_IDS.has(filter.id)) return false;
|
|
872
|
+
if (filter.id === "listing_type" && (filter.options?.length ?? 0) <= 1) {
|
|
873
|
+
return false;
|
|
874
|
+
}
|
|
875
|
+
return true;
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
function toolbarFilterIds(schema) {
|
|
879
|
+
const visible = new Set(visibleSearchFilters(schema).map((f) => f.id));
|
|
880
|
+
return TOOLBAR_PRIMARY_FILTER_IDS.filter((id) => visible.has(id));
|
|
881
|
+
}
|
|
882
|
+
function countOptionLabel(option) {
|
|
883
|
+
const label = String(option?.label ?? "");
|
|
884
|
+
if (/^[1-9]\d*$/.test(label)) return `${label}+`;
|
|
885
|
+
return label;
|
|
886
|
+
}
|
|
887
|
+
function countFacetChoices(options) {
|
|
888
|
+
const list = options || [];
|
|
889
|
+
const zero = list.find((o) => o.id === "0" || o.label === "Studio");
|
|
890
|
+
const isStudio = Boolean(
|
|
891
|
+
zero && /studio/i.test(String(zero.label)) && zero.id === "0"
|
|
892
|
+
);
|
|
893
|
+
const max = isStudio ? 3 : 4;
|
|
894
|
+
const out = [];
|
|
895
|
+
if (zero) out.push({ id: zero.id, label: countOptionLabel(zero) });
|
|
896
|
+
for (let n = 1; n <= max; n += 1) {
|
|
897
|
+
const option = list.find((o) => o.id === String(n));
|
|
898
|
+
out.push({
|
|
899
|
+
id: String(n),
|
|
900
|
+
label: countOptionLabel(option || { label: String(n) })
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
return out;
|
|
904
|
+
}
|
|
905
|
+
var FEMININE_HEADING = /(casa|cobertura|kitnet|loja|sala|fazenda|chácara|chacara)s?$/i;
|
|
906
|
+
function pluralizePt(label) {
|
|
907
|
+
const text = label.trim();
|
|
908
|
+
if (!text || /s$/i.test(text)) return text;
|
|
909
|
+
if (/il$/i.test(text)) return `${text.slice(0, -1)}is`;
|
|
910
|
+
if (/m$/i.test(text)) return `${text.slice(0, -1)}ns`;
|
|
911
|
+
return `${text}s`;
|
|
912
|
+
}
|
|
913
|
+
function headingLocationSuffix(location) {
|
|
914
|
+
if (!location) return "";
|
|
915
|
+
if (location.street && location.neighborhood) {
|
|
916
|
+
return `${location.street}, ${location.neighborhood}`;
|
|
917
|
+
}
|
|
918
|
+
if (location.neighborhood && location.city) {
|
|
919
|
+
return `${location.neighborhood}, ${location.city}`;
|
|
920
|
+
}
|
|
921
|
+
if (location.city && location.state) {
|
|
922
|
+
return `${location.city} - ${location.state}`;
|
|
923
|
+
}
|
|
924
|
+
return location.city || location.neighborhood || location.street || location.state || "";
|
|
925
|
+
}
|
|
926
|
+
function searchResultsHeading(pathFilters, dictionary, locationNames) {
|
|
927
|
+
const types = [].concat(pathFilters.propertyType || []).filter(Boolean);
|
|
928
|
+
let noun = "Im\xF3veis";
|
|
929
|
+
let found = "encontrados";
|
|
930
|
+
if (types.length === 1) {
|
|
931
|
+
const id = String(types[0]);
|
|
932
|
+
const option = dictionary?.propertyTypes?.find(
|
|
933
|
+
(entry) => entry.id === id || entry.slug === id
|
|
934
|
+
);
|
|
935
|
+
const label = option?.label;
|
|
936
|
+
if (label) {
|
|
937
|
+
noun = pluralizePt(label.charAt(0).toUpperCase() + label.slice(1));
|
|
938
|
+
if (FEMININE_HEADING.test(id) || FEMININE_HEADING.test(label)) {
|
|
939
|
+
found = "encontradas";
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
const place = locationNames ? headingLocationSuffix(
|
|
944
|
+
displayPathLocation(pathFilters.location, locationNames)
|
|
945
|
+
) : "";
|
|
946
|
+
if (place) return `${noun} ${found} em ${place}`;
|
|
947
|
+
return `${noun} ${found}`;
|
|
948
|
+
}
|
|
949
|
+
function hrefWithExplicitPage(href, page) {
|
|
950
|
+
if (page !== 1 || /(?:\?|&)page=/.test(href)) return href;
|
|
951
|
+
return href.includes("?") ? `${href}&page=1` : `${href}?page=1`;
|
|
952
|
+
}
|
|
953
|
+
function paginationPages(currentPage, totalPages, padding) {
|
|
954
|
+
if (totalPages < 1) return [];
|
|
955
|
+
const current = Math.min(Math.max(1, currentPage), totalPages);
|
|
956
|
+
const start = Math.max(1, current - padding);
|
|
957
|
+
const end = Math.min(totalPages, current + padding);
|
|
958
|
+
const pages = [];
|
|
959
|
+
for (let i = start; i <= end; i += 1) pages.push(i);
|
|
960
|
+
return pages;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
// src/react/filter-panel.tsx
|
|
964
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
965
|
+
function RangeFields({
|
|
966
|
+
filter,
|
|
967
|
+
rangeDraft,
|
|
968
|
+
onRangePatch,
|
|
969
|
+
onRangeCommit
|
|
970
|
+
}) {
|
|
971
|
+
const draft = rangeDraft[filter.id] || { min: "", max: "" };
|
|
972
|
+
const isPrice = filter.id === "price";
|
|
973
|
+
const patch = (side, raw) => {
|
|
974
|
+
onRangePatch(filter.id, side, isPrice ? formatGroupedInteger(raw) : raw);
|
|
975
|
+
};
|
|
976
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("fieldset", { "data-slot": "search-filter", children: [
|
|
977
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("legend", { children: filter.label }),
|
|
978
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-slot": "search-range-row", children: [
|
|
979
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
980
|
+
RangeSide,
|
|
981
|
+
{
|
|
982
|
+
id: `${filter.id}-min`,
|
|
983
|
+
label: "M\xEDn",
|
|
984
|
+
isPrice,
|
|
985
|
+
value: draft.min,
|
|
986
|
+
onPatch: (raw) => patch("min", raw),
|
|
987
|
+
onCommit: () => onRangeCommit(filter.id, "blur"),
|
|
988
|
+
onEnter: () => onRangeCommit(filter.id, "enter")
|
|
989
|
+
}
|
|
990
|
+
),
|
|
991
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
992
|
+
RangeSide,
|
|
993
|
+
{
|
|
994
|
+
id: `${filter.id}-max`,
|
|
995
|
+
label: "M\xE1x",
|
|
996
|
+
isPrice,
|
|
997
|
+
value: draft.max,
|
|
998
|
+
onPatch: (raw) => patch("max", raw),
|
|
999
|
+
onCommit: () => onRangeCommit(filter.id, "blur"),
|
|
1000
|
+
onEnter: () => onRangeCommit(filter.id, "enter")
|
|
1001
|
+
}
|
|
1002
|
+
),
|
|
1003
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1004
|
+
"button",
|
|
1005
|
+
{
|
|
1006
|
+
type: "button",
|
|
1007
|
+
"data-slot": "search-range-apply",
|
|
1008
|
+
onClick: () => onRangeCommit(filter.id, "apply"),
|
|
1009
|
+
children: "Atualizar"
|
|
1010
|
+
}
|
|
1011
|
+
)
|
|
1012
|
+
] })
|
|
1013
|
+
] });
|
|
1014
|
+
}
|
|
1015
|
+
function RangeSide({
|
|
1016
|
+
id,
|
|
1017
|
+
label,
|
|
1018
|
+
isPrice,
|
|
1019
|
+
value,
|
|
1020
|
+
onPatch,
|
|
1021
|
+
onCommit,
|
|
1022
|
+
onEnter
|
|
1023
|
+
}) {
|
|
1024
|
+
const input = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1025
|
+
"input",
|
|
1026
|
+
{
|
|
1027
|
+
id,
|
|
1028
|
+
type: isPrice ? "text" : "number",
|
|
1029
|
+
inputMode: isPrice ? "numeric" : "decimal",
|
|
1030
|
+
min: isPrice ? void 0 : 0,
|
|
1031
|
+
step: isPrice ? void 0 : 0.01,
|
|
1032
|
+
value,
|
|
1033
|
+
placeholder: isPrice ? "0" : void 0,
|
|
1034
|
+
onChange: (event) => onPatch(event.target.value),
|
|
1035
|
+
onBlur: onCommit,
|
|
1036
|
+
onKeyDown: (event) => {
|
|
1037
|
+
if (event.key === "Enter") {
|
|
1038
|
+
event.preventDefault();
|
|
1039
|
+
onEnter();
|
|
1040
|
+
}
|
|
1041
|
+
},
|
|
1042
|
+
"data-slot": "search-range-input"
|
|
1043
|
+
}
|
|
1044
|
+
);
|
|
1045
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { "data-slot": "search-range-side", htmlFor: id, children: [
|
|
1046
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: label }),
|
|
1047
|
+
isPrice ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { "data-slot": "search-range-affix", children: [
|
|
1048
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-slot": "search-range-prefix", children: "R$" }),
|
|
1049
|
+
input
|
|
1050
|
+
] }) : input
|
|
1051
|
+
] });
|
|
1052
|
+
}
|
|
1053
|
+
function CountFields({
|
|
1054
|
+
filter,
|
|
1055
|
+
pathFilters,
|
|
1056
|
+
onChange
|
|
1057
|
+
}) {
|
|
1058
|
+
const selected = pathFilterValue(pathFilters, filter.id);
|
|
1059
|
+
const choices = countFacetChoices(filter.options);
|
|
1060
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("fieldset", { "data-slot": "search-filter", children: [
|
|
1061
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("legend", { children: filter.label }),
|
|
1062
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "data-slot": "search-count-group", role: "group", children: choices.map((choice) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1063
|
+
"button",
|
|
1064
|
+
{
|
|
1065
|
+
type: "button",
|
|
1066
|
+
"data-slot": "search-count-choice",
|
|
1067
|
+
"data-selected": selected === choice.id ? "true" : void 0,
|
|
1068
|
+
onClick: () => onChange(filter.id, Number(choice.id)),
|
|
1069
|
+
children: choice.label
|
|
1070
|
+
},
|
|
1071
|
+
choice.id
|
|
1072
|
+
)) })
|
|
1073
|
+
] });
|
|
1074
|
+
}
|
|
1075
|
+
function EnumFields({
|
|
1076
|
+
filter,
|
|
1077
|
+
pathFilters,
|
|
1078
|
+
onChange
|
|
1079
|
+
}) {
|
|
1080
|
+
const options = filter.options || [];
|
|
1081
|
+
const scroll = options.length > 8;
|
|
1082
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("fieldset", { "data-slot": "search-filter", children: [
|
|
1083
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("legend", { children: filter.label }),
|
|
1084
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "data-slot": scroll ? "search-scroll" : "search-enum-list", children: options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { "data-slot": "search-enum-option", children: [
|
|
1085
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1086
|
+
"input",
|
|
1087
|
+
{
|
|
1088
|
+
type: "checkbox",
|
|
1089
|
+
"data-slot": "search-checkbox",
|
|
1090
|
+
checked: pathFilterHasOption(pathFilters, filter.id, option.id),
|
|
1091
|
+
onChange: () => onChange(filter.id, option.id)
|
|
1092
|
+
}
|
|
1093
|
+
),
|
|
1094
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: option.label })
|
|
1095
|
+
] }, option.id)) })
|
|
1096
|
+
] });
|
|
1097
|
+
}
|
|
1098
|
+
function FilterPanel({
|
|
1099
|
+
filters,
|
|
1100
|
+
pathFilters,
|
|
1101
|
+
onChange,
|
|
1102
|
+
rangeDraft,
|
|
1103
|
+
onRangePatch,
|
|
1104
|
+
onRangeCommit
|
|
1105
|
+
}) {
|
|
1106
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "data-slot": "search-filters", children: filters.map((filter) => {
|
|
1107
|
+
if (filter.type === "range") {
|
|
1108
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1109
|
+
RangeFields,
|
|
1110
|
+
{
|
|
1111
|
+
filter,
|
|
1112
|
+
rangeDraft,
|
|
1113
|
+
onRangePatch,
|
|
1114
|
+
onRangeCommit
|
|
1115
|
+
},
|
|
1116
|
+
filter.id
|
|
1117
|
+
);
|
|
1118
|
+
}
|
|
1119
|
+
if (filter.type === "count") {
|
|
1120
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1121
|
+
CountFields,
|
|
1122
|
+
{
|
|
1123
|
+
filter,
|
|
1124
|
+
pathFilters,
|
|
1125
|
+
onChange
|
|
1126
|
+
},
|
|
1127
|
+
filter.id
|
|
1128
|
+
);
|
|
1129
|
+
}
|
|
1130
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1131
|
+
EnumFields,
|
|
1132
|
+
{
|
|
1133
|
+
filter,
|
|
1134
|
+
pathFilters,
|
|
1135
|
+
onChange
|
|
1136
|
+
},
|
|
1137
|
+
filter.id
|
|
1138
|
+
);
|
|
1139
|
+
}) });
|
|
1140
|
+
}
|
|
1141
|
+
function rangeDraftFromPath(pathFilters) {
|
|
1142
|
+
const price = pathFilters.price || {};
|
|
1143
|
+
const area = pathFilters.area || {};
|
|
1144
|
+
return {
|
|
1145
|
+
price: {
|
|
1146
|
+
min: price.min != null ? formatGroupedInteger(price.min) : "",
|
|
1147
|
+
max: price.max != null ? formatGroupedInteger(price.max) : ""
|
|
1148
|
+
},
|
|
1149
|
+
property_area_total: {
|
|
1150
|
+
min: area.min != null ? String(area.min) : "",
|
|
1151
|
+
max: area.max != null ? String(area.max) : ""
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
// src/react/styles/search-chrome-css.generated.ts
|
|
1157
|
+
var SEARCH_CHROME_CSS_VERSION = "0.4.1";
|
|
1158
|
+
var SEARCH_CHROME_CSS = `:root{--garagem-listing-card-radius:0.75rem;--garagem-listing-card-gap:1.5rem;--garagem-listing-price-size:1.125rem;--garagem-listing-media-ratio:4 / 3;--garagem-search-control-height:2.75rem;--garagem-search-icon-size:1.25rem;--garagem-search-radius:var(--radius,0.75rem);--garagem-skeleton:var(--muted,#e7e5e4)}[data-slot="search-page"]{margin-inline:auto;max-width:80rem;padding:3rem 1.5rem}[data-slot="search-heading"]{display:flex;min-width:0;align-items:baseline;gap:0.375rem;font-size:1.25rem;font-weight:600}[data-slot="search-heading-count"]{flex-shrink:0}[data-slot="search-heading-title"]{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:inherit;font-weight:inherit}[data-slot="search-query-sort"]{display:flex;flex-direction:column;gap:1rem}@media (min-width:1024px){[data-slot="search-query-sort"]{flex-direction:row;align-items:flex-end}}[data-slot="search-query"]{flex:1;min-width:0}[data-slot="search-query-input"],[data-slot="search-sort-trigger"],[data-slot="search-toolbar-trigger"],[data-slot="search-filters-trigger"]{min-height:var(--garagem-search-control-height)}[data-slot="search-query-field"]{position:relative}[data-slot="search-query-input"]{width:100%;border-radius:var(--garagem-search-radius);border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:0.5rem 5.5rem 0.5rem 1rem;outline:none}[data-slot="search-query-actions"]{position:absolute;top:50%;right:0.35rem;display:flex;transform:translateY(-50%);align-items:center;gap:0.15rem}[data-slot="search-icon-button"]{display:inline-flex;height:2.25rem;width:2.25rem;cursor:pointer;align-items:center;justify-content:center;border:0;border-radius:999px;background:var(--primary,#111);color:var(--primary-foreground,#fff)}[data-slot="search-icon-button"][data-kind="clear"]{background:transparent;color:var(--muted-foreground,#737373)}[data-slot="search-icon"]{width:var(--garagem-search-icon-size);height:var(--garagem-search-icon-size);display:block}[data-slot="search-sort"]{display:flex;flex-direction:column;gap:0.25rem}[data-slot="search-sort-trigger"]{appearance:none;cursor:pointer;border-radius:var(--garagem-search-radius);border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:0.5rem 2.25rem 0.5rem 0.75rem;background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23737373' stroke-width='2' viewBox='0 0 24 24'><path d='m6 9 6 6 6-6'/></svg>");background-repeat:no-repeat;background-position:right 0.65rem center}[data-slot="search-toolbar"]{display:flex;flex-wrap:wrap;align-items:flex-end;gap:0.5rem}[data-slot="search-toolbar-trigger"],[data-slot="search-filters-trigger"]{cursor:pointer;border-radius:var(--garagem-search-radius);border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:0.5rem 0.75rem;font-size:0.875rem}[data-slot="search-popover"]{position:absolute;z-index:30;margin-top:0.5rem;width:18rem;border-radius:0.75rem;border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:1rem;box-shadow:0 10px 30px rgb(0 0 0 / 0.12);animation:garagem-search-in 140ms ease-out}[data-slot="search-grid"],[data-slot="search-skeleton"]{display:grid;grid-template-columns:1fr;gap:var(--garagem-listing-card-gap)}@media (min-width:640px){[data-slot="search-grid"],[data-slot="search-skeleton"]{grid-template-columns:repeat(2,minmax(0,1fr))}}@media (min-width:1024px){[data-slot="search-grid"],[data-slot="search-skeleton"]{grid-template-columns:repeat(3,minmax(0,1fr))}}[data-slot="listing-card"]{overflow:hidden;border-radius:var(--garagem-listing-card-radius);border:1px solid var(--border,#e4e4e7);background:var(--card,var(--background,#fff))}[data-slot="listing-card-price-row"]{display:inline-flex;align-items:baseline;gap:0.25rem}[data-slot="listing-card-price"]{font-size:var(--garagem-listing-price-size);font-weight:600}[data-slot="listing-card-period"]{font-size:0.75rem;color:var(--muted-foreground,#737373)}[data-slot="search-checkbox"]{appearance:none;width:1.15rem;height:1.15rem;flex-shrink:0;cursor:pointer;border:1px solid var(--primary,#111);border-radius:0.25rem;background:var(--background,#fff)}[data-slot="search-checkbox"]:checked{background-color:var(--primary,#111);background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3'><path d='M5 12l5 5L20 7'/></svg>");background-repeat:no-repeat;background-position:center;background-size:0.8rem}[data-slot="search-scroll"]{max-height:12rem;overflow:auto;scrollbar-width:thin;scrollbar-color:var(--muted-foreground,#a1a1aa) transparent}[data-slot="search-range-apply"]{display:inline-flex;min-height:2.5rem;cursor:pointer;align-items:center;justify-content:center;border:0;border-radius:var(--garagem-search-radius);background:var(--primary,#111);color:var(--primary-foreground,#fff);padding:0 0.75rem;font-size:0.75rem;font-weight:600}[data-slot="search-sheet"]{position:fixed;inset:0;z-index:40}[data-slot="search-sheet-overlay"]{position:absolute;inset:0;border:0;cursor:pointer;background:rgb(0 0 0 / 0.4);animation:garagem-search-fade 160ms ease-out}[data-slot="search-sheet-panel"]{position:absolute;top:0;right:0;display:flex;height:100dvh;width:min(22rem,100%);flex-direction:column;background:var(--background,#fff);animation:garagem-search-sheet 180ms ease-out}[data-slot="search-sheet-body"]{min-height:0;flex:1;overflow:auto;padding:1.5rem 1.5rem 0;scrollbar-width:thin}[data-slot="search-sheet-footer"]{display:flex;gap:0.5rem;border-top:1px solid var(--border,#e4e4e7);padding:1rem 1.5rem}[data-slot="search-apply-bar"]{display:flex;width:100%;gap:0.5rem}[data-slot="search-apply-bar"] > button{min-height:2.5rem;flex:1;cursor:pointer;border-radius:var(--garagem-search-radius);padding:0 1rem}[data-slot="search-apply-bar"] > button[data-kind="clear"]{border:1px solid var(--border,#e4e4e7);background:transparent}[data-slot="search-apply-bar"] > button[data-kind="apply"]{border:0;background:var(--primary,#111);color:var(--primary-foreground,#fff);font-weight:600}[data-slot="search-pagination"]{margin-top:2.5rem;display:flex;justify-content:center}[data-slot="search-pagination"] ul{display:flex;flex-wrap:wrap;justify-content:center;gap:0.25rem;padding:0;margin:0;list-style:none}[data-slot="search-pagination-item"]{display:inline-flex;width:2.25rem;height:2.25rem;align-items:center;justify-content:center;border:1px solid var(--border,#e4e4e7);border-radius:0.375rem;font-size:0.75rem;font-weight:500}@media (min-width:768px){[data-slot="search-pagination-item"]{width:2.5rem;height:2.5rem}}[data-slot="search-pagination-item"] a,[data-slot="search-pagination-item"] span{display:flex;width:100%;height:100%;align-items:center;justify-content:center;color:inherit;text-decoration:none}[data-slot="search-pagination-item"][data-current="true"]{background:var(--primary,#111);color:var(--primary-foreground,#fff)}[data-slot="search-pagination-item"][data-disabled="true"]{cursor:not-allowed;color:var(--muted-foreground,#737373)}[data-slot="search-toolbar-item"]{position:relative}[data-slot="search-body"]{margin-top:2rem;display:flex;flex-direction:column;gap:1.5rem}[data-slot="search-label"]{margin-bottom:0.25rem;display:block;font-size:0.875rem;color:var(--muted-foreground,#737373)}[data-slot="search-sheet-title"]{padding:1.5rem 1.5rem 0;font-size:1.125rem;font-weight:600}[data-slot="search-layout"]{display:grid;gap:2rem}[data-slot="search-sidebar"]{display:none}[data-slot="search-layout"] > div > [data-slot="search-filters-trigger"]{margin-bottom:1rem}@media (min-width:1024px){[data-slot="search-layout"]{grid-template-columns:280px minmax(0,1fr)}[data-slot="search-sidebar"]{display:block;position:sticky;top:1.5rem;align-self:start}[data-slot="search-layout"] > div > [data-slot="search-filters-trigger"]{display:none}}[data-slot="listing-card-link"]{display:block;color:inherit;text-decoration:none;cursor:pointer}[data-slot="listing-card-media"]{position:relative;width:100%;overflow:hidden;background:var(--muted,#f5f5f4);aspect-ratio:var(--garagem-listing-media-ratio)}[data-slot="listing-card-media"] img{height:100%;width:100%;object-fit:cover;transition:transform 0.3s}[data-slot="listing-card"]:hover [data-slot="listing-card-media"] img{transform:scale(1.05)}@media (prefers-reduced-motion:reduce){[data-slot="listing-card-media"] img{transition:none}[data-slot="listing-card"]:hover [data-slot="listing-card-media"] img{transform:none}}[data-slot="listing-card-empty"]{display:flex;height:100%;width:100%;align-items:center;justify-content:center;font-size:0.75rem;color:var(--muted-foreground,#737373)}[data-slot="listing-card-cta"]{margin-top:0.75rem}[data-slot="search-filters"]{display:flex;flex-direction:column;gap:1.25rem}[data-slot="search-filter"]{margin:0;padding:0;border:0;font-size:0.875rem}[data-slot="search-filter"] legend{margin-bottom:0.5rem;padding:0;color:var(--muted-foreground,#737373)}[data-slot="search-range-row"]{display:flex;align-items:flex-end;gap:0.5rem}[data-slot="search-range-side"]{min-width:0;flex:1}[data-slot="search-range-side"] > span:first-child{margin-bottom:0.25rem;display:block;font-size:0.75rem;color:var(--muted-foreground,#737373)}[data-slot="search-range-affix"]{position:relative;display:block}[data-slot="search-range-prefix"]{pointer-events:none;position:absolute;inset-block:0;left:0;display:flex;align-items:center;padding-left:0.75rem;color:var(--muted-foreground,#737373)}[data-slot="search-range-input"]{min-height:2.5rem;width:100%;border-radius:var(--garagem-search-radius);border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:0 0.75rem}[data-slot="search-range-affix"] [data-slot="search-range-input"]{padding-left:2.5rem}[data-slot="search-count-group"]{display:flex;flex-wrap:wrap;gap:0.375rem}[data-slot="search-count-choice"]{min-height:2.5rem;cursor:pointer;border-radius:var(--garagem-search-radius);border:1px solid var(--border,#e4e4e7);background:var(--background,#fff);padding:0 0.75rem;font-size:0.875rem}[data-slot="search-count-choice"][data-selected="true"]{border-color:var(--primary,#111);background:color-mix(in srgb,var(--primary,#111) 10%,transparent)}[data-slot="search-enum-list"],[data-slot="search-scroll"]{display:flex;flex-direction:column;gap:0.375rem}[data-slot="search-enum-option"]{display:flex;cursor:pointer;align-items:center;gap:0.5rem}[data-slot="listing-card-badge"]{position:absolute;left:0.75rem;top:0.75rem;border-radius:999px;background:color-mix(in srgb,var(--background,#fff) 90%,transparent);padding:0.25rem 0.5rem;font-size:0.75rem;font-weight:500}[data-slot="listing-card-body"]{padding:1rem}[data-slot="listing-card-title"]{display:-webkit-box;margin-top:0.25rem;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1;font-size:0.875rem;font-weight:500}[data-slot="listing-card-location"]{margin-top:0.125rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:0.75rem;color:var(--muted-foreground,#737373)}[data-slot="listing-card-features"]{display:flex;flex-wrap:wrap;margin-top:0.75rem;gap:0.25rem 1rem;padding:0;list-style:none;font-size:0.75rem;color:var(--muted-foreground,#737373)}[data-slot="search-skeleton-block"]{animation:garagem-search-pulse 1.2s ease-in-out infinite;background:var(--garagem-skeleton);border-radius:0.375rem}[data-slot="search-skeleton-card"]{overflow:hidden;border-radius:var(--garagem-listing-card-radius);border:1px solid var(--border,#e4e4e7)}[data-slot="search-skeleton-body"]{display:flex;flex-direction:column;gap:0.5rem;padding:1rem}[data-slot="search-skeleton-block"][data-kind="media"]{aspect-ratio:var(--garagem-listing-media-ratio)}[data-slot="search-skeleton-block"][data-kind="line-lg"]{height:1.25rem;width:50%}[data-slot="search-skeleton-block"][data-kind="line-md"]{height:1rem;width:75%}[data-slot="search-skeleton-block"][data-kind="line-sm"]{height:0.75rem;width:66.666667%}[data-slot="search-skeleton-block"][data-kind="detail-media"]{max-width:45rem;aspect-ratio:4 / 3}[data-slot="search-skeleton-block"][data-kind="detail-title"]{width:66.666667%;height:2rem;margin-top:1.5rem}@media (prefers-reduced-motion:reduce){[data-slot="search-popover"],[data-slot="search-sheet-overlay"],[data-slot="search-sheet-panel"],[data-slot="search-skeleton-block"]{animation:none}}@keyframes garagem-search-in{from{opacity:0;transform:translateY(-4px) scale(0.98)}to{opacity:1;transform:none}}@keyframes garagem-search-fade{from{opacity:0}to{opacity:1}}@keyframes garagem-search-sheet{from{transform:translateX(100%)}to{transform:none}}@keyframes garagem-search-pulse{50%{opacity:0.55}}`;
|
|
1159
|
+
|
|
1160
|
+
// src/react/styles/search-chrome-styles.tsx
|
|
1161
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1162
|
+
var STYLE_ID = `garagem-search-chrome-${SEARCH_CHROME_CSS_VERSION}`;
|
|
1163
|
+
function SearchChromeStyles() {
|
|
1164
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("style", { id: STYLE_ID, children: SEARCH_CHROME_CSS });
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
// src/react/search-chrome.tsx
|
|
1168
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1169
|
+
function SearchSortSelect({
|
|
1170
|
+
value,
|
|
1171
|
+
onChange,
|
|
1172
|
+
sorts,
|
|
1173
|
+
className
|
|
1174
|
+
}) {
|
|
1175
|
+
const options = searchSortOptions(sorts);
|
|
1176
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { "data-slot": "search-sort", className, children: [
|
|
1177
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-slot": "search-label", children: "Ordenar" }),
|
|
1178
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1179
|
+
"select",
|
|
1180
|
+
{
|
|
1181
|
+
id: "garagem-search-sort",
|
|
1182
|
+
"data-slot": "search-sort-trigger",
|
|
1183
|
+
value,
|
|
1184
|
+
onChange: (event) => onChange(event.target.value || null),
|
|
1185
|
+
children: options.map((sort) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: sort.id, children: sort.label }, sort.id || "relevance"))
|
|
1186
|
+
}
|
|
1187
|
+
)
|
|
1188
|
+
] });
|
|
1189
|
+
}
|
|
1190
|
+
function ResultsSkeleton({
|
|
1191
|
+
className
|
|
1192
|
+
}) {
|
|
1193
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { "data-slot": "search-skeleton", className, children: Array.from({ length: 6 }, (_, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-slot": "search-skeleton-card", children: [
|
|
1194
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { "data-slot": "search-skeleton-block", "data-kind": "media" }),
|
|
1195
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-slot": "search-skeleton-body", children: [
|
|
1196
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { "data-slot": "search-skeleton-block", "data-kind": "line-lg" }),
|
|
1197
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { "data-slot": "search-skeleton-block", "data-kind": "line-md" }),
|
|
1198
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { "data-slot": "search-skeleton-block", "data-kind": "line-sm" })
|
|
1199
|
+
] })
|
|
1200
|
+
] }, i)) });
|
|
1201
|
+
}
|
|
1202
|
+
function SearchPageFallback({
|
|
1203
|
+
className
|
|
1204
|
+
}) {
|
|
1205
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("main", { "data-slot": "search-page", children: [
|
|
1206
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SearchChromeStyles, {}),
|
|
1207
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ResultsSkeleton, { className })
|
|
1208
|
+
] });
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
// src/react/search-pagination.tsx
|
|
1212
|
+
var import_link2 = __toESM(require("next/link"));
|
|
1213
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1214
|
+
function NavItem({
|
|
1215
|
+
href,
|
|
1216
|
+
label,
|
|
1217
|
+
disabled,
|
|
1218
|
+
current,
|
|
1219
|
+
onNavigate
|
|
1220
|
+
}) {
|
|
1221
|
+
if (disabled || !href || current) {
|
|
1222
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1223
|
+
"li",
|
|
1224
|
+
{
|
|
1225
|
+
"data-slot": "search-pagination-item",
|
|
1226
|
+
"data-current": current ? "true" : void 0,
|
|
1227
|
+
"data-disabled": disabled ? "true" : void 0,
|
|
1228
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: label })
|
|
1229
|
+
}
|
|
1230
|
+
);
|
|
1231
|
+
}
|
|
1232
|
+
function handleClick(event) {
|
|
1233
|
+
if (!onNavigate || !href) return;
|
|
1234
|
+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button !== 0) {
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
event.preventDefault();
|
|
1238
|
+
onNavigate(href);
|
|
1239
|
+
}
|
|
1240
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { "data-slot": "search-pagination-item", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_link2.default, { href, onClick: handleClick, "aria-label": label, children: label }) });
|
|
1241
|
+
}
|
|
1242
|
+
function SearchPagination({
|
|
1243
|
+
page,
|
|
1244
|
+
totalPages,
|
|
1245
|
+
hrefForPage,
|
|
1246
|
+
onNavigate,
|
|
1247
|
+
className
|
|
1248
|
+
}) {
|
|
1249
|
+
if (totalPages <= 1) return null;
|
|
1250
|
+
const pages = paginationPages(page, totalPages, 2);
|
|
1251
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1252
|
+
"nav",
|
|
1253
|
+
{
|
|
1254
|
+
"data-slot": "search-pagination",
|
|
1255
|
+
className,
|
|
1256
|
+
"aria-label": "Pagina\xE7\xE3o",
|
|
1257
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("ul", { children: [
|
|
1258
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1259
|
+
NavItem,
|
|
1260
|
+
{
|
|
1261
|
+
href: hrefWithExplicitPage(hrefForPage(1), 1),
|
|
1262
|
+
label: "\u2039\u2039",
|
|
1263
|
+
disabled: page <= 1,
|
|
1264
|
+
onNavigate
|
|
1265
|
+
}
|
|
1266
|
+
),
|
|
1267
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1268
|
+
NavItem,
|
|
1269
|
+
{
|
|
1270
|
+
href: hrefWithExplicitPage(
|
|
1271
|
+
hrefForPage(Math.max(1, page - 1)),
|
|
1272
|
+
Math.max(1, page - 1)
|
|
1273
|
+
),
|
|
1274
|
+
label: "\u2039",
|
|
1275
|
+
disabled: page <= 1,
|
|
1276
|
+
onNavigate
|
|
1277
|
+
}
|
|
1278
|
+
),
|
|
1279
|
+
pages.map((n) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1280
|
+
NavItem,
|
|
1281
|
+
{
|
|
1282
|
+
href: hrefWithExplicitPage(hrefForPage(n), n),
|
|
1283
|
+
label: String(n),
|
|
1284
|
+
current: n === page,
|
|
1285
|
+
onNavigate
|
|
1286
|
+
},
|
|
1287
|
+
n
|
|
1288
|
+
)),
|
|
1289
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1290
|
+
NavItem,
|
|
1291
|
+
{
|
|
1292
|
+
href: hrefForPage(Math.min(totalPages, page + 1)),
|
|
1293
|
+
label: "\u203A",
|
|
1294
|
+
disabled: page >= totalPages,
|
|
1295
|
+
onNavigate
|
|
1296
|
+
}
|
|
1297
|
+
),
|
|
1298
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1299
|
+
NavItem,
|
|
1300
|
+
{
|
|
1301
|
+
href: hrefForPage(totalPages),
|
|
1302
|
+
label: "\u203A\u203A",
|
|
1303
|
+
disabled: page >= totalPages,
|
|
1304
|
+
onNavigate
|
|
1305
|
+
}
|
|
1306
|
+
)
|
|
1307
|
+
] })
|
|
1308
|
+
}
|
|
1309
|
+
);
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
// src/react/icons.tsx
|
|
1313
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1314
|
+
function Icon({ children, ...props }) {
|
|
1315
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1316
|
+
"svg",
|
|
1317
|
+
{
|
|
1318
|
+
viewBox: "0 0 24 24",
|
|
1319
|
+
fill: "none",
|
|
1320
|
+
stroke: "currentColor",
|
|
1321
|
+
strokeWidth: 2,
|
|
1322
|
+
strokeLinecap: "round",
|
|
1323
|
+
strokeLinejoin: "round",
|
|
1324
|
+
"aria-hidden": true,
|
|
1325
|
+
"data-slot": "search-icon",
|
|
1326
|
+
...props,
|
|
1327
|
+
children
|
|
1328
|
+
}
|
|
1329
|
+
);
|
|
1330
|
+
}
|
|
1331
|
+
function SearchLensIcon(props) {
|
|
1332
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Icon, { ...props, children: [
|
|
1333
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("circle", { cx: "11", cy: "11", r: "7" }),
|
|
1334
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", { d: "M20 20l-3.5-3.5" })
|
|
1335
|
+
] });
|
|
1336
|
+
}
|
|
1337
|
+
function SearchClearIcon(props) {
|
|
1338
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { ...props, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", { d: "M6 6l12 12M18 6L6 18" }) });
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
// src/react/search-query-form.tsx
|
|
1342
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1343
|
+
function SearchQueryForm({
|
|
1344
|
+
value,
|
|
1345
|
+
onChange,
|
|
1346
|
+
onSubmit,
|
|
1347
|
+
onClear,
|
|
1348
|
+
className,
|
|
1349
|
+
iconClassName,
|
|
1350
|
+
searchIcon,
|
|
1351
|
+
clearIcon
|
|
1352
|
+
}) {
|
|
1353
|
+
function handleSubmit(event) {
|
|
1354
|
+
event.preventDefault();
|
|
1355
|
+
onSubmit();
|
|
1356
|
+
}
|
|
1357
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1358
|
+
"form",
|
|
1359
|
+
{
|
|
1360
|
+
role: "search",
|
|
1361
|
+
"data-slot": "search-query",
|
|
1362
|
+
onSubmit: handleSubmit,
|
|
1363
|
+
className,
|
|
1364
|
+
children: [
|
|
1365
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("label", { htmlFor: "garagem-search-q", "data-slot": "search-label", children: "Busca" }),
|
|
1366
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { "data-slot": "search-query-field", children: [
|
|
1367
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1368
|
+
"input",
|
|
1369
|
+
{
|
|
1370
|
+
id: "garagem-search-q",
|
|
1371
|
+
name: "q",
|
|
1372
|
+
type: "text",
|
|
1373
|
+
inputMode: "search",
|
|
1374
|
+
autoComplete: "off",
|
|
1375
|
+
enterKeyHint: "search",
|
|
1376
|
+
value,
|
|
1377
|
+
onChange: (event) => onChange(event.target.value),
|
|
1378
|
+
placeholder: "Busque por bairro, rua ou c\xF3digo",
|
|
1379
|
+
"data-slot": "search-query-input"
|
|
1380
|
+
}
|
|
1381
|
+
),
|
|
1382
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { "data-slot": "search-query-actions", children: [
|
|
1383
|
+
value ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1384
|
+
"button",
|
|
1385
|
+
{
|
|
1386
|
+
type: "button",
|
|
1387
|
+
title: "Limpar busca",
|
|
1388
|
+
"aria-label": "Limpar busca",
|
|
1389
|
+
onClick: onClear,
|
|
1390
|
+
"data-slot": "search-icon-button",
|
|
1391
|
+
"data-kind": "clear",
|
|
1392
|
+
children: clearIcon ?? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SearchClearIcon, { className: iconClassName })
|
|
1393
|
+
}
|
|
1394
|
+
) : null,
|
|
1395
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1396
|
+
"button",
|
|
1397
|
+
{
|
|
1398
|
+
type: "submit",
|
|
1399
|
+
title: "Buscar",
|
|
1400
|
+
"aria-label": "Buscar",
|
|
1401
|
+
"data-slot": "search-icon-button",
|
|
1402
|
+
children: searchIcon ?? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SearchLensIcon, { className: iconClassName })
|
|
1403
|
+
}
|
|
1404
|
+
)
|
|
1405
|
+
] })
|
|
1406
|
+
] })
|
|
1407
|
+
]
|
|
1408
|
+
}
|
|
1409
|
+
);
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
// src/react/use-public-search.ts
|
|
1413
|
+
var import_react = require("react");
|
|
1414
|
+
var import_navigation = require("next/navigation");
|
|
1415
|
+
|
|
1416
|
+
// src/internal/url.ts
|
|
1417
|
+
var DEFAULT_BASE_URL = "https://app.garagem.ai";
|
|
1418
|
+
function normalizeBaseUrl(baseUrl) {
|
|
1419
|
+
const url = baseUrl ?? DEFAULT_BASE_URL;
|
|
1420
|
+
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
1421
|
+
}
|
|
1422
|
+
async function coerceSiteId(siteId) {
|
|
1423
|
+
const value = await Promise.resolve(siteId);
|
|
1424
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
1425
|
+
throw new TypeError(
|
|
1426
|
+
"Garagem SDK: siteId must be a string. Await resolveSiteId(...) before getListings / getSearchUi / queryListings."
|
|
1427
|
+
);
|
|
1428
|
+
}
|
|
1429
|
+
return value;
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
// src/fetchers.ts
|
|
1433
|
+
async function callJson(url, init, fetchImpl) {
|
|
1434
|
+
const response = await fetchImpl(url, init);
|
|
1435
|
+
if (!response.ok) {
|
|
1436
|
+
const text = await response.text().catch(() => "");
|
|
1437
|
+
throw new GaragemSdkError(
|
|
1438
|
+
`Garagem SDK: request failed (${response.status} ${response.statusText}) for ${url}${text ? ` \u2014 ${text.slice(0, 200)}` : ""}`,
|
|
1439
|
+
{ status: response.status, url }
|
|
1440
|
+
);
|
|
1441
|
+
}
|
|
1442
|
+
return await response.json();
|
|
1443
|
+
}
|
|
1444
|
+
var GaragemSdkError = class extends Error {
|
|
1445
|
+
status;
|
|
1446
|
+
url;
|
|
1447
|
+
constructor(message, info) {
|
|
1448
|
+
super(message);
|
|
1449
|
+
this.name = "GaragemSdkError";
|
|
1450
|
+
this.status = info.status;
|
|
1451
|
+
this.url = info.url;
|
|
1452
|
+
}
|
|
1453
|
+
};
|
|
1454
|
+
async function getSearchUi(options) {
|
|
1455
|
+
const { baseUrl, fetch: fetchImpl, next } = options;
|
|
1456
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
1457
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
1458
|
+
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search-ui`;
|
|
1459
|
+
return callJson(
|
|
1460
|
+
url,
|
|
1461
|
+
{ method: "GET", headers: { Accept: "application/json" }, next },
|
|
1462
|
+
fetchImpl ?? fetch
|
|
1463
|
+
);
|
|
1464
|
+
}
|
|
1465
|
+
async function queryListings(options) {
|
|
1466
|
+
const { params, baseUrl, fetch: fetchImpl, next } = options;
|
|
1467
|
+
const siteId = await coerceSiteId(options.siteId);
|
|
1468
|
+
const base = normalizeBaseUrl(baseUrl);
|
|
1469
|
+
const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search/listings`;
|
|
1470
|
+
return callJson(
|
|
1471
|
+
url,
|
|
1472
|
+
{
|
|
1473
|
+
method: "POST",
|
|
1474
|
+
headers: {
|
|
1475
|
+
Accept: "application/json",
|
|
1476
|
+
"Content-Type": "application/json"
|
|
1477
|
+
},
|
|
1478
|
+
body: JSON.stringify(params ?? {}),
|
|
1479
|
+
next
|
|
1480
|
+
},
|
|
1481
|
+
fetchImpl ?? fetch
|
|
1482
|
+
);
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
// src/react/use-public-search.ts
|
|
1486
|
+
async function resolveSiteIdInput(siteId) {
|
|
1487
|
+
const value = typeof siteId === "function" ? siteId() : siteId;
|
|
1488
|
+
return coerceSiteId(value);
|
|
1489
|
+
}
|
|
1490
|
+
function currentHref(pathname, search) {
|
|
1491
|
+
return search ? `${pathname}?${search}` : pathname;
|
|
1492
|
+
}
|
|
1493
|
+
function usePublicSearch(options) {
|
|
1494
|
+
const { siteId, baseUrl } = options;
|
|
1495
|
+
const router = (0, import_navigation.useRouter)();
|
|
1496
|
+
const pathname = (0, import_navigation.usePathname)() || "/imoveis";
|
|
1497
|
+
const searchParams = (0, import_navigation.useSearchParams)();
|
|
1498
|
+
const search = searchParams.toString();
|
|
1499
|
+
const siteIdRef = (0, import_react.useRef)(siteId);
|
|
1500
|
+
siteIdRef.current = siteId;
|
|
1501
|
+
const siteIdToken = typeof siteId === "string" ? siteId : null;
|
|
1502
|
+
const [catalogId, setCatalogId] = (0, import_react.useState)(null);
|
|
1503
|
+
const [schema, setSchema] = (0, import_react.useState)(null);
|
|
1504
|
+
const [listings, setListings] = (0, import_react.useState)([]);
|
|
1505
|
+
const [page, setPage] = (0, import_react.useState)(1);
|
|
1506
|
+
const [total, setTotal] = (0, import_react.useState)(0);
|
|
1507
|
+
const [totalPages, setTotalPages] = (0, import_react.useState)(1);
|
|
1508
|
+
const [loading, setLoading] = (0, import_react.useState)(true);
|
|
1509
|
+
const [qDraft, setQDraft] = (0, import_react.useState)("");
|
|
1510
|
+
const [staged, setStaged] = (0, import_react.useState)({});
|
|
1511
|
+
const [locationNames, setLocationNames] = (0, import_react.useState)(
|
|
1512
|
+
null
|
|
1513
|
+
);
|
|
1514
|
+
const parsed = (0, import_react.useMemo)(
|
|
1515
|
+
() => readPublicSearch(pathname, search, schema?.dictionary),
|
|
1516
|
+
[pathname, search, schema?.dictionary]
|
|
1517
|
+
);
|
|
1518
|
+
(0, import_react.useEffect)(() => {
|
|
1519
|
+
setQDraft(parsed.applied.query || "");
|
|
1520
|
+
}, [parsed.applied.query]);
|
|
1521
|
+
const resetStagedFromUrl = (0, import_react.useCallback)(() => {
|
|
1522
|
+
setStaged({ ...parsed.pathFilters });
|
|
1523
|
+
}, [parsed.pathFilters]);
|
|
1524
|
+
(0, import_react.useEffect)(() => {
|
|
1525
|
+
setStaged({ ...parsed.pathFilters });
|
|
1526
|
+
}, [parsed.pathFilters]);
|
|
1527
|
+
const locationsRef = (0, import_react.useRef)(null);
|
|
1528
|
+
(0, import_react.useEffect)(() => {
|
|
1529
|
+
if (!schema) return;
|
|
1530
|
+
const canonical = canonicalizeSearchHref(
|
|
1531
|
+
pathname,
|
|
1532
|
+
search,
|
|
1533
|
+
schema.dictionary
|
|
1534
|
+
);
|
|
1535
|
+
if (canonical) router.replace(canonical);
|
|
1536
|
+
}, [pathname, search, schema, router]);
|
|
1537
|
+
(0, import_react.useEffect)(() => {
|
|
1538
|
+
let active = true;
|
|
1539
|
+
setCatalogId(null);
|
|
1540
|
+
setSchema(null);
|
|
1541
|
+
setListings([]);
|
|
1542
|
+
setLoading(true);
|
|
1543
|
+
resolveSiteIdInput(siteIdRef.current).then((id) => {
|
|
1544
|
+
if (active) setCatalogId(id);
|
|
1545
|
+
}).catch(() => {
|
|
1546
|
+
if (active) setLoading(false);
|
|
1547
|
+
});
|
|
1548
|
+
return () => {
|
|
1549
|
+
active = false;
|
|
1550
|
+
};
|
|
1551
|
+
}, [baseUrl, siteIdToken]);
|
|
1552
|
+
(0, import_react.useEffect)(() => {
|
|
1553
|
+
if (!catalogId) return;
|
|
1554
|
+
const id = catalogId;
|
|
1555
|
+
let active = true;
|
|
1556
|
+
locationsRef.current = null;
|
|
1557
|
+
setLocationNames(null);
|
|
1558
|
+
setSchema(null);
|
|
1559
|
+
setListings([]);
|
|
1560
|
+
setLoading(true);
|
|
1561
|
+
async function loadSchema() {
|
|
1562
|
+
try {
|
|
1563
|
+
const nextSchema = await getSearchUi({ siteId: id, baseUrl });
|
|
1564
|
+
if (!active) return;
|
|
1565
|
+
let locations = null;
|
|
1566
|
+
if (nextSchema.locationsPath.startsWith("/")) {
|
|
1567
|
+
try {
|
|
1568
|
+
const response = await fetch(
|
|
1569
|
+
`${normalizeBaseUrl(baseUrl)}${nextSchema.locationsPath}`
|
|
1570
|
+
);
|
|
1571
|
+
if (response.ok) {
|
|
1572
|
+
locations = await response.json();
|
|
1573
|
+
}
|
|
1574
|
+
} catch {
|
|
1575
|
+
locations = null;
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
if (!active) return;
|
|
1579
|
+
locationsRef.current = locations;
|
|
1580
|
+
setLocationNames(locations);
|
|
1581
|
+
setSchema(nextSchema);
|
|
1582
|
+
} catch {
|
|
1583
|
+
if (active) {
|
|
1584
|
+
locationsRef.current = null;
|
|
1585
|
+
setLocationNames(null);
|
|
1586
|
+
setSchema(null);
|
|
1587
|
+
setLoading(false);
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
loadSchema();
|
|
1592
|
+
return () => {
|
|
1593
|
+
active = false;
|
|
1594
|
+
};
|
|
1595
|
+
}, [baseUrl, catalogId]);
|
|
1596
|
+
(0, import_react.useEffect)(() => {
|
|
1597
|
+
if (!schema || !catalogId) return;
|
|
1598
|
+
const currentSchema = schema;
|
|
1599
|
+
const id = catalogId;
|
|
1600
|
+
let active = true;
|
|
1601
|
+
async function loadListings() {
|
|
1602
|
+
setLoading(true);
|
|
1603
|
+
try {
|
|
1604
|
+
const { pathFilters, applied } = readPublicSearch(
|
|
1605
|
+
pathname,
|
|
1606
|
+
search,
|
|
1607
|
+
currentSchema.dictionary
|
|
1608
|
+
);
|
|
1609
|
+
const response = await queryListings({
|
|
1610
|
+
siteId: id,
|
|
1611
|
+
baseUrl,
|
|
1612
|
+
params: buildQueryListingsParams(
|
|
1613
|
+
pathFilters,
|
|
1614
|
+
applied,
|
|
1615
|
+
currentSchema,
|
|
1616
|
+
locationsRef.current
|
|
1617
|
+
)
|
|
1618
|
+
});
|
|
1619
|
+
if (!active) return;
|
|
1620
|
+
setListings(response.listings || []);
|
|
1621
|
+
setPage(response.page || 1);
|
|
1622
|
+
setTotal(response.total || 0);
|
|
1623
|
+
setTotalPages(response.totalPages || 1);
|
|
1624
|
+
} catch {
|
|
1625
|
+
if (active) {
|
|
1626
|
+
setListings([]);
|
|
1627
|
+
setPage(1);
|
|
1628
|
+
setTotal(0);
|
|
1629
|
+
setTotalPages(1);
|
|
1630
|
+
}
|
|
1631
|
+
} finally {
|
|
1632
|
+
if (active) setLoading(false);
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
loadListings();
|
|
1636
|
+
return () => {
|
|
1637
|
+
active = false;
|
|
1638
|
+
};
|
|
1639
|
+
}, [pathname, search, baseUrl, schema, catalogId]);
|
|
1640
|
+
const go = (0, import_react.useCallback)(
|
|
1641
|
+
(href) => {
|
|
1642
|
+
if (href && href !== currentHref(pathname, search)) router.push(href);
|
|
1643
|
+
},
|
|
1644
|
+
[pathname, search, router]
|
|
1645
|
+
);
|
|
1646
|
+
const applyFilter = (0, import_react.useCallback)(
|
|
1647
|
+
(filterId, value) => {
|
|
1648
|
+
if (!schema) return;
|
|
1649
|
+
go(
|
|
1650
|
+
hrefForPathFilters(
|
|
1651
|
+
pathname,
|
|
1652
|
+
search,
|
|
1653
|
+
schema.dictionary,
|
|
1654
|
+
applyPathFilter(parsed.pathFilters, filterId, value)
|
|
1655
|
+
)
|
|
1656
|
+
);
|
|
1657
|
+
},
|
|
1658
|
+
[go, pathname, search, schema, parsed.pathFilters]
|
|
1659
|
+
);
|
|
1660
|
+
const stageFilter = (0, import_react.useCallback)((filterId, value) => {
|
|
1661
|
+
setStaged((current) => applyPathFilter(current, filterId, value));
|
|
1662
|
+
}, []);
|
|
1663
|
+
const applyStaged = (0, import_react.useCallback)(() => {
|
|
1664
|
+
if (!schema) return;
|
|
1665
|
+
go(hrefForPathFilters(pathname, search, schema.dictionary, staged));
|
|
1666
|
+
}, [go, pathname, search, schema, staged]);
|
|
1667
|
+
const clearStaged = (0, import_react.useCallback)(() => {
|
|
1668
|
+
setStaged((current) => clearStagedPathFilters(current));
|
|
1669
|
+
}, []);
|
|
1670
|
+
const submitQuery = (0, import_react.useCallback)(() => {
|
|
1671
|
+
if (!schema) return;
|
|
1672
|
+
go(
|
|
1673
|
+
hrefForAppliedChange(pathname, search, schema.dictionary, {
|
|
1674
|
+
type: "query",
|
|
1675
|
+
query: qDraft
|
|
1676
|
+
})
|
|
1677
|
+
);
|
|
1678
|
+
}, [go, pathname, search, schema, qDraft]);
|
|
1679
|
+
const clearQuery = (0, import_react.useCallback)(() => {
|
|
1680
|
+
setQDraft("");
|
|
1681
|
+
if (!schema) return;
|
|
1682
|
+
go(
|
|
1683
|
+
hrefForAppliedChange(pathname, search, schema.dictionary, {
|
|
1684
|
+
type: "query",
|
|
1685
|
+
query: ""
|
|
1686
|
+
})
|
|
1687
|
+
);
|
|
1688
|
+
}, [go, pathname, search, schema]);
|
|
1689
|
+
const setSort = (0, import_react.useCallback)(
|
|
1690
|
+
(sort) => {
|
|
1691
|
+
if (!schema) return;
|
|
1692
|
+
go(
|
|
1693
|
+
hrefForAppliedChange(pathname, search, schema.dictionary, {
|
|
1694
|
+
type: "sort",
|
|
1695
|
+
sort
|
|
1696
|
+
})
|
|
1697
|
+
);
|
|
1698
|
+
},
|
|
1699
|
+
[go, pathname, search, schema]
|
|
1700
|
+
);
|
|
1701
|
+
const hrefForPage = (0, import_react.useCallback)(
|
|
1702
|
+
(nextPage) => {
|
|
1703
|
+
if (!schema) return pathname;
|
|
1704
|
+
return hrefForAppliedChange(pathname, search, schema.dictionary, {
|
|
1705
|
+
type: "page",
|
|
1706
|
+
page: nextPage
|
|
1707
|
+
});
|
|
1708
|
+
},
|
|
1709
|
+
[pathname, search, schema]
|
|
1710
|
+
);
|
|
1711
|
+
return {
|
|
1712
|
+
schema,
|
|
1713
|
+
listings,
|
|
1714
|
+
page,
|
|
1715
|
+
total,
|
|
1716
|
+
totalPages,
|
|
1717
|
+
loading,
|
|
1718
|
+
pathname,
|
|
1719
|
+
search,
|
|
1720
|
+
pathFilters: parsed.pathFilters,
|
|
1721
|
+
applied: parsed.applied,
|
|
1722
|
+
qDraft,
|
|
1723
|
+
setQDraft,
|
|
1724
|
+
staged,
|
|
1725
|
+
setStaged,
|
|
1726
|
+
resetStagedFromUrl,
|
|
1727
|
+
applyFilter,
|
|
1728
|
+
stageFilter,
|
|
1729
|
+
applyStaged,
|
|
1730
|
+
clearStaged,
|
|
1731
|
+
submitQuery,
|
|
1732
|
+
clearQuery,
|
|
1733
|
+
setSort,
|
|
1734
|
+
hrefForPage,
|
|
1735
|
+
go,
|
|
1736
|
+
locationNames
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
// src/react/search-page.tsx
|
|
1741
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1742
|
+
function ToolbarPopover({
|
|
1743
|
+
id,
|
|
1744
|
+
label,
|
|
1745
|
+
open,
|
|
1746
|
+
onOpenChange,
|
|
1747
|
+
triggerClassName,
|
|
1748
|
+
popoverClassName,
|
|
1749
|
+
children
|
|
1750
|
+
}) {
|
|
1751
|
+
const rootRef = (0, import_react2.useRef)(null);
|
|
1752
|
+
(0, import_react2.useEffect)(() => {
|
|
1753
|
+
if (!open) return;
|
|
1754
|
+
function onPointer(event) {
|
|
1755
|
+
if (!rootRef.current?.contains(event.target)) {
|
|
1756
|
+
onOpenChange(null);
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
function onKey(event) {
|
|
1760
|
+
if (event.key === "Escape") onOpenChange(null);
|
|
1761
|
+
}
|
|
1762
|
+
document.addEventListener("mousedown", onPointer);
|
|
1763
|
+
document.addEventListener("keydown", onKey);
|
|
1764
|
+
return () => {
|
|
1765
|
+
document.removeEventListener("mousedown", onPointer);
|
|
1766
|
+
document.removeEventListener("keydown", onKey);
|
|
1767
|
+
};
|
|
1768
|
+
}, [open, onOpenChange]);
|
|
1769
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { "data-slot": "search-toolbar-item", ref: rootRef, children: [
|
|
1770
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1771
|
+
"button",
|
|
1772
|
+
{
|
|
1773
|
+
type: "button",
|
|
1774
|
+
"data-slot": "search-toolbar-trigger",
|
|
1775
|
+
className: triggerClassName,
|
|
1776
|
+
"aria-expanded": open,
|
|
1777
|
+
onClick: () => onOpenChange(open ? null : id),
|
|
1778
|
+
children: label
|
|
1779
|
+
}
|
|
1780
|
+
),
|
|
1781
|
+
open ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1782
|
+
"div",
|
|
1783
|
+
{
|
|
1784
|
+
"data-slot": "search-popover",
|
|
1785
|
+
className: popoverClassName,
|
|
1786
|
+
role: "dialog",
|
|
1787
|
+
children
|
|
1788
|
+
}
|
|
1789
|
+
) : null
|
|
1790
|
+
] });
|
|
1791
|
+
}
|
|
1792
|
+
function FiltersTrigger({
|
|
1793
|
+
onClick,
|
|
1794
|
+
className
|
|
1795
|
+
}) {
|
|
1796
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1797
|
+
"button",
|
|
1798
|
+
{
|
|
1799
|
+
type: "button",
|
|
1800
|
+
title: "Filtros",
|
|
1801
|
+
"data-slot": "search-filters-trigger",
|
|
1802
|
+
onClick,
|
|
1803
|
+
className,
|
|
1804
|
+
children: "Filtros"
|
|
1805
|
+
}
|
|
1806
|
+
);
|
|
1807
|
+
}
|
|
1808
|
+
function ApplyBar({
|
|
1809
|
+
onClear,
|
|
1810
|
+
onApply,
|
|
1811
|
+
className
|
|
1812
|
+
}) {
|
|
1813
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { "data-slot": "search-apply-bar", className, children: [
|
|
1814
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", "data-kind": "clear", onClick: onClear, children: "Limpar" }),
|
|
1815
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", "data-kind": "apply", onClick: onApply, children: "Ver resultados" })
|
|
1816
|
+
] });
|
|
1817
|
+
}
|
|
1818
|
+
function FilterSheet({
|
|
1819
|
+
open,
|
|
1820
|
+
title,
|
|
1821
|
+
onClose,
|
|
1822
|
+
overlayClassName,
|
|
1823
|
+
panelClassName,
|
|
1824
|
+
children,
|
|
1825
|
+
footer
|
|
1826
|
+
}) {
|
|
1827
|
+
const onCloseRef = (0, import_react2.useRef)(onClose);
|
|
1828
|
+
onCloseRef.current = onClose;
|
|
1829
|
+
(0, import_react2.useEffect)(() => {
|
|
1830
|
+
if (!open) return;
|
|
1831
|
+
function onKey(event) {
|
|
1832
|
+
if (event.key === "Escape") onCloseRef.current();
|
|
1833
|
+
}
|
|
1834
|
+
document.addEventListener("keydown", onKey);
|
|
1835
|
+
const previous = document.body.style.overflow;
|
|
1836
|
+
document.body.style.overflow = "hidden";
|
|
1837
|
+
return () => {
|
|
1838
|
+
document.removeEventListener("keydown", onKey);
|
|
1839
|
+
document.body.style.overflow = previous;
|
|
1840
|
+
};
|
|
1841
|
+
}, [open]);
|
|
1842
|
+
if (!open) return null;
|
|
1843
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { "data-slot": "search-sheet", children: [
|
|
1844
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1845
|
+
"button",
|
|
1846
|
+
{
|
|
1847
|
+
type: "button",
|
|
1848
|
+
"aria-label": "Fechar filtros",
|
|
1849
|
+
"data-slot": "search-sheet-overlay",
|
|
1850
|
+
className: overlayClassName,
|
|
1851
|
+
onClick: onClose
|
|
1852
|
+
}
|
|
1853
|
+
),
|
|
1854
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
1855
|
+
"div",
|
|
1856
|
+
{
|
|
1857
|
+
"data-slot": "search-sheet-panel",
|
|
1858
|
+
className: panelClassName,
|
|
1859
|
+
role: "dialog",
|
|
1860
|
+
"aria-modal": "true",
|
|
1861
|
+
"aria-label": title,
|
|
1862
|
+
children: [
|
|
1863
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { "data-slot": "search-sheet-title", children: title }),
|
|
1864
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { "data-slot": "search-sheet-body", children }),
|
|
1865
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { "data-slot": "search-sheet-footer", children: footer })
|
|
1866
|
+
]
|
|
1867
|
+
}
|
|
1868
|
+
)
|
|
1869
|
+
] });
|
|
1870
|
+
}
|
|
1871
|
+
function SearchHeading({
|
|
1872
|
+
total,
|
|
1873
|
+
title,
|
|
1874
|
+
classNames,
|
|
1875
|
+
loading
|
|
1876
|
+
}) {
|
|
1877
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { "data-slot": "search-heading", className: classNames?.heading, children: [
|
|
1878
|
+
!loading ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1879
|
+
"span",
|
|
1880
|
+
{
|
|
1881
|
+
"data-slot": "search-heading-count",
|
|
1882
|
+
className: classNames?.headingCount,
|
|
1883
|
+
children: total.toLocaleString("pt-BR")
|
|
1884
|
+
}
|
|
1885
|
+
) : null,
|
|
1886
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("h1", { "data-slot": "search-heading-title", className: classNames?.headingTitle, children: title })
|
|
1887
|
+
] });
|
|
1888
|
+
}
|
|
1889
|
+
function SearchPage({
|
|
1890
|
+
siteId,
|
|
1891
|
+
baseUrl,
|
|
1892
|
+
variant = "toolbar",
|
|
1893
|
+
className,
|
|
1894
|
+
classNames,
|
|
1895
|
+
heading,
|
|
1896
|
+
icons,
|
|
1897
|
+
listingCard: Card = ListingCard
|
|
1898
|
+
}) {
|
|
1899
|
+
const search = usePublicSearch({ siteId, baseUrl });
|
|
1900
|
+
const [sheetOpen, setSheetOpen] = (0, import_react2.useState)(false);
|
|
1901
|
+
const [openToolbar, setOpenToolbar] = (0, import_react2.useState)(null);
|
|
1902
|
+
const [rangeDraft, setRangeDraft] = (0, import_react2.useState)(
|
|
1903
|
+
() => rangeDraftFromPath(search.pathFilters)
|
|
1904
|
+
);
|
|
1905
|
+
(0, import_react2.useEffect)(() => {
|
|
1906
|
+
setRangeDraft(rangeDraftFromPath(search.pathFilters));
|
|
1907
|
+
}, [search.pathFilters]);
|
|
1908
|
+
const filters = visibleSearchFilters(search.schema);
|
|
1909
|
+
const toolbarIds = new Set(toolbarFilterIds(search.schema));
|
|
1910
|
+
const toolbarFilters = filters.filter((filter) => toolbarIds.has(filter.id));
|
|
1911
|
+
const extraFilters = filters.filter((filter) => !toolbarIds.has(filter.id));
|
|
1912
|
+
const headingTitle = searchResultsHeading(
|
|
1913
|
+
search.pathFilters,
|
|
1914
|
+
search.schema?.dictionary,
|
|
1915
|
+
search.locationNames
|
|
1916
|
+
);
|
|
1917
|
+
function patchRange(filterId, side, value) {
|
|
1918
|
+
setRangeDraft((prev) => ({
|
|
1919
|
+
...prev,
|
|
1920
|
+
[filterId]: {
|
|
1921
|
+
min: prev[filterId]?.min ?? "",
|
|
1922
|
+
max: prev[filterId]?.max ?? "",
|
|
1923
|
+
[side]: value
|
|
1924
|
+
}
|
|
1925
|
+
}));
|
|
1926
|
+
}
|
|
1927
|
+
function commitRange(filterId, immediate) {
|
|
1928
|
+
const draft = rangeDraft[filterId] || { min: "", max: "" };
|
|
1929
|
+
if (immediate) search.applyFilter(filterId, draft);
|
|
1930
|
+
else search.stageFilter(filterId, draft);
|
|
1931
|
+
}
|
|
1932
|
+
function openStagedFilters() {
|
|
1933
|
+
search.resetStagedFromUrl();
|
|
1934
|
+
setRangeDraft(rangeDraftFromPath(search.pathFilters));
|
|
1935
|
+
setOpenToolbar(null);
|
|
1936
|
+
setSheetOpen(true);
|
|
1937
|
+
}
|
|
1938
|
+
const closeSheet = (0, import_react2.useCallback)(() => {
|
|
1939
|
+
setSheetOpen(false);
|
|
1940
|
+
}, []);
|
|
1941
|
+
function clearStagedFilters() {
|
|
1942
|
+
const keepIds = variant === "toolbar" ? [...toolbarIds] : [];
|
|
1943
|
+
const source = variant === "toolbar" ? search.pathFilters : search.staged;
|
|
1944
|
+
const next = clearStagedPathFilters(source, keepIds);
|
|
1945
|
+
search.setStaged(next);
|
|
1946
|
+
setRangeDraft((prev) => {
|
|
1947
|
+
const cleared = rangeDraftFromPath(next);
|
|
1948
|
+
if (variant !== "toolbar") return cleared;
|
|
1949
|
+
const kept = { ...cleared };
|
|
1950
|
+
for (const id of keepIds) {
|
|
1951
|
+
if (prev[id]) kept[id] = prev[id];
|
|
1952
|
+
}
|
|
1953
|
+
return kept;
|
|
1954
|
+
});
|
|
1955
|
+
}
|
|
1956
|
+
function applyStagedAndClose() {
|
|
1957
|
+
search.applyStaged();
|
|
1958
|
+
closeSheet();
|
|
1959
|
+
}
|
|
1960
|
+
const results = search.loading ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ResultsSkeleton, { className: classNames?.skeleton ?? classNames?.grid }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
1961
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { "data-slot": "search-grid", className: classNames?.grid, children: search.listings.map((listing) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1962
|
+
Card,
|
|
1963
|
+
{
|
|
1964
|
+
listing,
|
|
1965
|
+
className: classNames?.card
|
|
1966
|
+
},
|
|
1967
|
+
listing.id
|
|
1968
|
+
)) }),
|
|
1969
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1970
|
+
SearchPagination,
|
|
1971
|
+
{
|
|
1972
|
+
page: search.page,
|
|
1973
|
+
totalPages: search.totalPages,
|
|
1974
|
+
hrefForPage: search.hrefForPage,
|
|
1975
|
+
onNavigate: search.go,
|
|
1976
|
+
className: classNames?.pagination
|
|
1977
|
+
}
|
|
1978
|
+
)
|
|
1979
|
+
] });
|
|
1980
|
+
const queryAndSort = /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { "data-slot": "search-query-sort", children: [
|
|
1981
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1982
|
+
SearchQueryForm,
|
|
1983
|
+
{
|
|
1984
|
+
value: search.qDraft,
|
|
1985
|
+
onChange: search.setQDraft,
|
|
1986
|
+
onSubmit: search.submitQuery,
|
|
1987
|
+
onClear: search.clearQuery,
|
|
1988
|
+
className: classNames?.query,
|
|
1989
|
+
iconClassName: classNames?.icon,
|
|
1990
|
+
searchIcon: icons?.search,
|
|
1991
|
+
clearIcon: icons?.clear
|
|
1992
|
+
}
|
|
1993
|
+
),
|
|
1994
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1995
|
+
SearchSortSelect,
|
|
1996
|
+
{
|
|
1997
|
+
value: search.applied.sort || "",
|
|
1998
|
+
onChange: search.setSort,
|
|
1999
|
+
sorts: search.schema?.sorts,
|
|
2000
|
+
className: classNames?.sort
|
|
2001
|
+
}
|
|
2002
|
+
)
|
|
2003
|
+
] });
|
|
2004
|
+
const header = heading ?? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2005
|
+
SearchHeading,
|
|
2006
|
+
{
|
|
2007
|
+
total: search.total,
|
|
2008
|
+
title: headingTitle,
|
|
2009
|
+
classNames,
|
|
2010
|
+
loading: search.loading
|
|
2011
|
+
}
|
|
2012
|
+
);
|
|
2013
|
+
const stagedPanel = (items) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2014
|
+
FilterPanel,
|
|
2015
|
+
{
|
|
2016
|
+
filters: items,
|
|
2017
|
+
pathFilters: search.staged,
|
|
2018
|
+
onChange: search.stageFilter,
|
|
2019
|
+
rangeDraft,
|
|
2020
|
+
onRangePatch: patchRange,
|
|
2021
|
+
onRangeCommit: (id) => commitRange(id, false)
|
|
2022
|
+
}
|
|
2023
|
+
);
|
|
2024
|
+
const sheet = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2025
|
+
FilterSheet,
|
|
2026
|
+
{
|
|
2027
|
+
open: sheetOpen,
|
|
2028
|
+
title: "Filtros",
|
|
2029
|
+
onClose: closeSheet,
|
|
2030
|
+
overlayClassName: classNames?.dialogOverlay,
|
|
2031
|
+
panelClassName: cn(classNames?.dialog, classNames?.dialogPanel),
|
|
2032
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2033
|
+
ApplyBar,
|
|
2034
|
+
{
|
|
2035
|
+
onClear: clearStagedFilters,
|
|
2036
|
+
onApply: applyStagedAndClose,
|
|
2037
|
+
className: classNames?.applyBar
|
|
2038
|
+
}
|
|
2039
|
+
),
|
|
2040
|
+
children: stagedPanel(variant === "toolbar" ? extraFilters : filters)
|
|
2041
|
+
}
|
|
2042
|
+
);
|
|
2043
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
2044
|
+
"main",
|
|
2045
|
+
{
|
|
2046
|
+
"data-slot": "search-page",
|
|
2047
|
+
"data-variant": variant,
|
|
2048
|
+
className: cn(className, classNames?.root),
|
|
2049
|
+
children: [
|
|
2050
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SearchChromeStyles, {}),
|
|
2051
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: classNames?.header, children: header }),
|
|
2052
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { "data-slot": "search-body", children: [
|
|
2053
|
+
queryAndSort,
|
|
2054
|
+
variant === "toolbar" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { "data-slot": "search-toolbar", className: classNames?.toolbar, children: [
|
|
2055
|
+
toolbarFilters.map((filter) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2056
|
+
ToolbarPopover,
|
|
2057
|
+
{
|
|
2058
|
+
id: filter.id,
|
|
2059
|
+
label: filter.label,
|
|
2060
|
+
open: openToolbar === filter.id,
|
|
2061
|
+
onOpenChange: setOpenToolbar,
|
|
2062
|
+
triggerClassName: classNames?.toolbarTrigger,
|
|
2063
|
+
popoverClassName: classNames?.popover,
|
|
2064
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2065
|
+
FilterPanel,
|
|
2066
|
+
{
|
|
2067
|
+
filters: [filter],
|
|
2068
|
+
pathFilters: search.pathFilters,
|
|
2069
|
+
onChange: (id, value) => {
|
|
2070
|
+
search.applyFilter(id, value);
|
|
2071
|
+
if (filter.type !== "range") setOpenToolbar(null);
|
|
2072
|
+
},
|
|
2073
|
+
rangeDraft,
|
|
2074
|
+
onRangePatch: patchRange,
|
|
2075
|
+
onRangeCommit: (id, source) => {
|
|
2076
|
+
commitRange(id, true);
|
|
2077
|
+
if (source === "apply") setOpenToolbar(null);
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
)
|
|
2081
|
+
},
|
|
2082
|
+
filter.id
|
|
2083
|
+
)),
|
|
2084
|
+
extraFilters.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(FiltersTrigger, { onClick: openStagedFilters }) : null
|
|
2085
|
+
] }) : null,
|
|
2086
|
+
variant === "dialog" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(FiltersTrigger, { onClick: openStagedFilters }) : null,
|
|
2087
|
+
variant === "sidebar" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { "data-slot": "search-layout", children: [
|
|
2088
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("aside", { "data-slot": "search-sidebar", className: classNames?.sidebar, children: [
|
|
2089
|
+
stagedPanel(filters),
|
|
2090
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2091
|
+
ApplyBar,
|
|
2092
|
+
{
|
|
2093
|
+
onClear: clearStagedFilters,
|
|
2094
|
+
onApply: search.applyStaged,
|
|
2095
|
+
className: classNames?.applyBar
|
|
2096
|
+
}
|
|
2097
|
+
)
|
|
2098
|
+
] }),
|
|
2099
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { children: [
|
|
2100
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(FiltersTrigger, { onClick: openStagedFilters }),
|
|
2101
|
+
results
|
|
2102
|
+
] })
|
|
2103
|
+
] }) : results
|
|
2104
|
+
] }),
|
|
2105
|
+
sheet
|
|
2106
|
+
]
|
|
2107
|
+
}
|
|
2108
|
+
);
|
|
2109
|
+
}
|
|
2110
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2111
|
+
0 && (module.exports = {
|
|
2112
|
+
FilterPanel,
|
|
2113
|
+
ListingCard,
|
|
2114
|
+
ResultsSkeleton,
|
|
2115
|
+
SearchChromeStyles,
|
|
2116
|
+
SearchPage,
|
|
2117
|
+
SearchPageFallback,
|
|
2118
|
+
SearchPagination,
|
|
2119
|
+
SearchQueryForm,
|
|
2120
|
+
SearchSortSelect,
|
|
2121
|
+
rangeDraftFromPath,
|
|
2122
|
+
usePublicSearch
|
|
2123
|
+
});
|
|
2124
|
+
//# sourceMappingURL=react.js.map
|