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