@garagem-ai/site-sdk 0.5.2 → 0.5.3

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.js CHANGED
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  "use client";
3
- var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
7
  var __export = (target, all) => {
10
8
  for (var name in all)
@@ -18,564 +16,87 @@ var __copyProps = (to, from, except, desc) => {
18
16
  }
19
17
  return to;
20
18
  };
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
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
20
 
31
21
  // src/react/index.ts
32
22
  var react_exports = {};
33
23
  __export(react_exports, {
34
- ListingCard: () => ListingCard,
35
- ListingDetailFields: () => ListingDetailFields,
36
- ResultsSkeleton: () => ResultsSkeleton,
37
- SearchChromeStyles: () => SearchChromeStyles,
38
24
  usePublicSearch: () => usePublicSearch
39
25
  });
40
26
  module.exports = __toCommonJS(react_exports);
41
27
 
42
- // src/react/listing-card.tsx
43
- var import_link = __toESM(require("next/link"));
44
-
45
- // src/presentation.ts
46
- var SEARCH_CSS_VARS = {
47
- cardRadius: "--garagem-listing-card-radius",
48
- cardGap: "--garagem-listing-card-gap",
49
- priceSize: "--garagem-listing-price-size",
50
- mediaRatio: "--garagem-listing-media-ratio",
51
- controlHeight: "--garagem-search-control-height",
52
- iconSize: "--garagem-search-icon-size",
53
- skeleton: "--garagem-skeleton"
54
- };
55
- var SEARCH_CSS_RECIPE = `:root {
56
- ${SEARCH_CSS_VARS.cardRadius}: 0.75rem;
57
- ${SEARCH_CSS_VARS.cardGap}: 1.5rem;
58
- ${SEARCH_CSS_VARS.priceSize}: 1.125rem;
59
- ${SEARCH_CSS_VARS.mediaRatio}: 4 / 3;
60
- ${SEARCH_CSS_VARS.controlHeight}: 2.75rem;
61
- ${SEARCH_CSS_VARS.iconSize}: 1.25rem;
62
- ${SEARCH_CSS_VARS.skeleton}: var(--muted, #e7e5e4);
63
- }
64
- `;
65
- function formatListingPrice(amount, locale = "pt-BR", currency = "BRL") {
66
- if (amount == null) return "Sob consulta";
67
- try {
68
- return new Intl.NumberFormat(locale, {
69
- style: "currency",
70
- currency,
71
- minimumFractionDigits: 0,
72
- maximumFractionDigits: 0
73
- }).format(amount);
74
- } catch {
75
- return `${currency} ${amount}`;
76
- }
77
- }
78
- function parseGroupedInteger(value) {
79
- if (typeof value === "number") {
80
- return Number.isFinite(value) ? Math.trunc(value) : void 0;
81
- }
82
- const digits = String(value ?? "").replace(/\D/g, "");
83
- if (!digits) return void 0;
84
- const amount = Number.parseInt(digits, 10);
85
- return Number.isFinite(amount) ? amount : void 0;
86
- }
87
- function formatAreaM2(area) {
88
- if (area == null || !Number.isFinite(area)) return null;
89
- return `${area} m\xB2`;
90
- }
91
- function listingBusinessLabel(businessType) {
92
- return businessType === "rental" ? "Aluguel" : "Venda";
93
- }
94
-
95
- // src/listing-path.ts
96
- function listingPublicPath(listing) {
97
- const composed = listing.path?.trim() ?? "";
98
- if (composed.startsWith("/") && !composed.startsWith("//")) return composed;
99
- const identity = listing.listingCode?.trim() || listing.id?.trim() || "";
100
- if (!identity || identity === "undefined" || identity === "null") {
101
- throw new TypeError("listingPublicPath: listing has no listingCode or id");
102
- }
103
- return `/imoveis/id-${identity}`;
104
- }
105
-
106
- // src/listing-card-model.ts
107
- function listingLocationLabel(location) {
108
- return [location.neighborhood, location.city, location.state].map((part) => part ? String(part).trim() : "").filter(Boolean).join(", ");
109
- }
110
- function toListingCardModel(listing) {
111
- const isPrivate = listing.priceVisibility === "private";
112
- const area = listing.property?.usableArea ?? listing.property?.totalArea;
113
- return {
114
- href: listingPublicPath(listing),
115
- title: listing.title,
116
- businessType: listing.businessType,
117
- businessLabel: listingBusinessLabel(listing.businessType),
118
- priceVisibility: listing.priceVisibility,
119
- price: listing.price,
120
- priceLabel: isPrivate ? "Sob consulta" : formatListingPrice(listing.price),
121
- pricePeriod: listing.businessType === "rental" && !isPrivate && listing.price != null ? "/m\xEAs" : null,
122
- locationLabel: listingLocationLabel(listing.location || {}),
123
- propertyType: listing.property?.type ?? null,
124
- coverSrc: listing.coverImage?.src ?? null,
125
- coverAlt: listing.coverImage?.alt ?? listing.title,
126
- bedrooms: listing.property?.bedrooms ?? null,
127
- bathrooms: listing.property?.bathrooms ?? null,
128
- parkingSpaces: listing.property?.parkingSpaces ?? null,
129
- areaM2: area ?? null
130
- };
131
- }
132
-
133
- // src/react/cn.ts
134
- function cn(...parts) {
135
- return parts.filter(Boolean).join(" ");
136
- }
137
-
138
- // src/react/styles/search-chrome-styles.tsx
28
+ // src/react/use-public-search.ts
139
29
  var import_react = require("react");
30
+ var import_navigation = require("next/navigation");
140
31
 
141
- // src/react/styles/search-chrome-css.generated.ts
142
- var SEARCH_CHROME_CSS_VERSION = "0.5.2";
143
- 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-skeleton:var(--muted,#e7e5e4)}[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="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="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-skeleton-block"]{animation:none}}@keyframes garagem-search-pulse{50%{opacity:0.55}}';
144
-
145
- // src/react/styles/search-chrome-styles.tsx
146
- var STYLE_ID = `garagem-search-chrome-${SEARCH_CHROME_CSS_VERSION}`;
147
- function injectSearchChromeOnce() {
148
- if (typeof document === "undefined") return;
149
- if (document.getElementById(STYLE_ID)) return;
150
- const el = document.createElement("style");
151
- el.id = STYLE_ID;
152
- el.textContent = SEARCH_CHROME_CSS;
153
- document.head.appendChild(el);
32
+ // src/internal/url.ts
33
+ var DEFAULT_BASE_URL = "https://app.garagem.ai";
34
+ function normalizeBaseUrl(baseUrl) {
35
+ const url = baseUrl ?? DEFAULT_BASE_URL;
36
+ return url.endsWith("/") ? url.slice(0, -1) : url;
154
37
  }
155
- function SearchChromeStyles() {
156
- if (typeof document !== "undefined") {
157
- injectSearchChromeOnce();
38
+ async function coerceSiteId(siteId) {
39
+ const raw = typeof siteId === "function" ? siteId() : siteId;
40
+ const value = await Promise.resolve(raw);
41
+ if (typeof value !== "string" || !value.trim()) {
42
+ throw new TypeError(
43
+ "Garagem SDK: siteId must be a string. Await resolveSiteId(...) before getListings / getSearchUi / queryListings."
44
+ );
158
45
  }
159
- (0, import_react.useLayoutEffect)(() => {
160
- injectSearchChromeOnce();
161
- }, []);
162
- return null;
163
- }
164
-
165
- // src/react/listing-card.tsx
166
- var import_jsx_runtime = require("react/jsx-runtime");
167
- function isListing(value) {
168
- return "priceVisibility" in value && "businessType" in value && "title" in value;
169
- }
170
- function ListingCard({
171
- listing,
172
- href,
173
- className,
174
- classNames,
175
- slots,
176
- style
177
- }) {
178
- const model = isListing(listing) ? toListingCardModel(listing) : listing;
179
- const target = href ?? model.href;
180
- const areaLabel = formatAreaM2(model.areaM2);
181
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
182
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SearchChromeStyles, {}),
183
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
184
- "article",
185
- {
186
- "data-slot": "listing-card",
187
- className: cn(className, classNames?.root),
188
- style,
189
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_link.default, { href: target, "data-slot": "listing-card-link", children: [
190
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { "data-slot": "listing-card-media", className: classNames?.media, children: [
191
- 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" })),
192
- slots?.badge ?? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
193
- "span",
194
- {
195
- "data-slot": "listing-card-badge",
196
- className: classNames?.badge,
197
- children: model.businessLabel
198
- }
199
- )
200
- ] }),
201
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { "data-slot": "listing-card-body", className: classNames?.body, children: [
202
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { "data-slot": "listing-card-price-row", children: [
203
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { "data-slot": "listing-card-price", className: classNames?.price, children: model.priceLabel }),
204
- model.pricePeriod ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "data-slot": "listing-card-period", children: model.pricePeriod }) : null
205
- ] }),
206
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { "data-slot": "listing-card-title", className: classNames?.title, children: model.title }),
207
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
208
- "p",
209
- {
210
- "data-slot": "listing-card-location",
211
- className: classNames?.location,
212
- children: model.locationLabel || model.propertyType || ""
213
- }
214
- ),
215
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
216
- "ul",
217
- {
218
- "data-slot": "listing-card-features",
219
- className: classNames?.features,
220
- children: [
221
- model.bedrooms != null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [
222
- model.bedrooms,
223
- " quartos"
224
- ] }) : null,
225
- model.bathrooms != null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [
226
- model.bathrooms,
227
- " banheiros"
228
- ] }) : null,
229
- model.parkingSpaces != null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [
230
- model.parkingSpaces,
231
- " vagas"
232
- ] }) : null,
233
- areaLabel ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: areaLabel }) : null
234
- ]
235
- }
236
- ),
237
- slots?.cta ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { "data-slot": "listing-card-cta", className: classNames?.cta, children: slots.cta }) : null
238
- ] })
239
- ] })
240
- }
241
- )
242
- ] });
46
+ return value;
243
47
  }
244
48
 
245
- // src/amenity-labels.ts
246
- var LISTING_AMENITY_TITLES = {
247
- unit: "Comodidades",
248
- building: "Comodidades do condom\xEDnio"
249
- };
250
- var AMENITY_FALLBACK_LABELS = {
251
- // ==================== PROPERTY FEATURES ====================
252
- // Amenities
253
- arCondicionado: "Ar condicionado",
254
- banheira: "Banheira",
255
- carregadorEletrico: "Carregador el\xE9trico",
256
- churrasqueira: "Churrasqueira",
257
- chuveiroGas: "Chuveiro a g\xE1s",
258
- chuveiroEletrico: "Chuveiro el\xE9trico",
259
- energiaSolar: "Energia solar",
260
- fechaduraDigital: "Fechadura digital",
261
- fechaduraEletronica: "Fechadura eletr\xF4nica",
262
- geradorEletrico: "Gerador el\xE9trico",
263
- gesso: "Gesso",
264
- hidromassagem: "Hidromassagem",
265
- lareira: "Lareira",
266
- ofuro: "Ofur\xF4",
267
- spa: "Spa",
268
- painelSolar: "Painel solar",
269
- portaoEletronico: "Port\xE3o eletr\xF4nico",
270
- sistemaAlarme: "Sistema de alarme",
271
- homeTheater: "Home theater",
272
- adega: "Adega",
273
- split: "Split",
274
- arCentral: "Ar central",
275
- esperaSplit: "Espera para split",
276
- vistaMar: "Vista para o mar",
277
- vistaPanoramica: "Vista panor\xE2mica",
278
- aguaQuente: "\xC1gua quente",
279
- reformado: "Reformado",
280
- tvCabo: "TV a cabo",
281
- gradeado: "Gradeado",
282
- antenaParabolica: "Antena parab\xF3lica",
283
- aquecimento: "Aquecimento",
284
- aquecimentoEletrico: "Aquecimento el\xE9trico",
285
- aquecimentoCentral: "Aquecimento central",
286
- cercaEletrica: "Cerca el\xE9trica",
287
- monitoramento: "Monitoramento",
288
- vigiaInterno: "Vigia interno",
289
- vigiaExterno: "Vigia externo",
290
- alarme: "Alarme",
291
- agua: "\xC1gua",
292
- redeEsgoto: "Rede de esgoto",
293
- pavimentacao: "Pavimenta\xE7\xE3o",
294
- energiaEletrica: "Energia el\xE9trica",
295
- // Furniture
296
- mobiliado: "Mobiliado",
297
- armarioEmbutido: "Arm\xE1rio embutido",
298
- armarioEmbutidoQuarto: "Arm\xE1rio embutido quarto",
299
- armarioCozinha: "Arm\xE1rio cozinha",
300
- armarioBanheiro: "Arm\xE1rio banheiro",
301
- cozinhaPlanejada: "Cozinha planejada",
302
- fogao: "Fog\xE3o",
303
- fornoPizza: "Forno de pizza",
304
- freezer: "Freezer",
305
- dormitorioComArmario: "Dormit\xF3rio com arm\xE1rio",
306
- semiMobiliado: "Semi mobiliado",
307
- salaArmarios: "Sala com arm\xE1rios",
308
- // Structure
309
- piscina: "Piscina",
310
- piscinaAquecida: "Piscina aquecida",
311
- piscinaCoberta: "Piscina coberta",
312
- poco: "Po\xE7o",
313
- pocoArtesiano: "Po\xE7o artesiano",
314
- bar: "Bar",
315
- jardim: "Jardim",
316
- lago: "Lago",
317
- lavabo: "Lavabo",
318
- quintal: "Quintal",
319
- solarium: "Solarium",
320
- quartoServico: "Quarto de servi\xE7o",
321
- varanda: "Varanda",
322
- varandaFechadaVidro: "Varanda fechada com vidro",
323
- varandaGourmet: "Varanda gourmet",
324
- banheiroServico: "Banheiro de servi\xE7o",
325
- areaServico: "\xC1rea de servi\xE7o",
326
- cinema: "Cinema",
327
- closet: "Closet",
328
- cozinhaAmericana: "Cozinha americana",
329
- cozinhaGourmet: "Cozinha gourmet",
330
- despensa: "Despensa",
331
- escritorio: "Escrit\xF3rio",
332
- edicula: "Ed\xEDcula",
333
- horta: "Horta",
334
- sacada: "Sacada",
335
- salaJantar: "Sala de jantar",
336
- cozinha: "Cozinha",
337
- banheiroSocial: "Banheiro social",
338
- terraco: "Terra\xE7o",
339
- copa: "Copa",
340
- suiteMaster: "Su\xEDte master",
341
- wcEmpregada: "WC empregada",
342
- dependenciaEmpregada: "Depend\xEAncia de empregada",
343
- dependenciadeEmpregada: "Depend\xEAncia empregada",
344
- salaTv: "Sala de TV",
345
- copaCozinha: "Copa cozinha",
346
- sacadaComChurrasqueira: "Sacada com churrasqueira",
347
- hallPrivativo: "Hall privativo",
348
- estarIntimo: "Estar \xEDntimo",
349
- livingHall: "Living hall",
350
- piscinaInterna: "Piscina interna",
351
- deck: "Deck",
352
- jardimInverno: "Jardim de inverno",
353
- rouparia: "Rouparia",
354
- living: "Living",
355
- familyRoom: "Family room",
356
- salafitness: "Sala fitness",
357
- salaEstar: "Sala de estar",
358
- mezanino: "Mezanino",
359
- pisoElevado: "Piso elevado",
360
- entradaServicoIndependente: "Entrada de servi\xE7o independente",
361
- forro: "Forro",
362
- vitrine: "Vitrine",
363
- banheiroAuxiliar: "Banheiro auxiliar",
364
- gabinete: "Gabinete",
365
- quadraTenisPrivativa: "Quadra de t\xEAnis privativa",
366
- porao: "Por\xE3o",
367
- sotao: "S\xF3t\xE3o",
368
- patio: "P\xE1tio",
369
- canaletasNoRodape: "Canaletas no rodap\xE9",
370
- // Accessibility
371
- barraApoioVaso: "Barra de apoio vaso",
372
- barraApoioChuveiro: "Barra de apoio chuveiro",
373
- entradaSemDegrau: "Entrada sem degrau",
374
- rampasAcesso: "Rampas de acesso",
375
- vagaDeficientes: "Vaga para deficientes",
376
- // Flooring
377
- cimentoQueimado: "Cimento queimado",
378
- madeira: "Madeira",
379
- pisoFrio: "Piso frio",
380
- laminado: "Laminado",
381
- vinilico: "Vin\xEDlico",
382
- porcelanato: "Porcelanato",
383
- // ==================== BUILDING FEATURES ====================
384
- // Amenities
385
- elevador: "Elevador",
386
- bicicletario: "Biciclet\xE1rio",
387
- carregadorEletronico: "Carregador eletr\xF4nico",
388
- concierge: "Concierge",
389
- coworking: "Coworking",
390
- deposito: "Dep\xF3sito",
391
- lavanderia: "Lavanderia",
392
- petPlace: "Pet place",
393
- recebimentoEncomendas: "Recebimento de encomendas",
394
- salaReuniao: "Sala de reuni\xE3o",
395
- salaoFestas: "Sal\xE3o de festas",
396
- valet: "Valet",
397
- garagemCoberta: "Garagem coberta",
398
- elevadorServico: "Elevador de servi\xE7o",
399
- // Leisure
400
- academia: "Academia",
401
- campoFutebol: "Campo de futebol",
402
- espacoGourmet: "Espa\xE7o gourmet",
403
- piscinaInfantil: "Piscina infantil",
404
- pistaCaminhada: "Pista de caminhada",
405
- playground: "Playground",
406
- quadraPoliesportiva: "Quadra poliesportiva",
407
- quadraTenis: "Quadra de t\xEAnis",
408
- salaJogos: "Sala de jogos",
409
- salaVapor: "Sala de vapor",
410
- sauna: "Sauna",
411
- // Security
412
- circuitoTv: "Circuito fechado de TV",
413
- controleAcessoEletronico: "Controle de acesso eletr\xF4nico",
414
- interfone: "Interfone",
415
- portaria24h: "Portaria 24h",
416
- porteiroFisico: "Porteiro f\xEDsico",
417
- seguranca24h: "Seguran\xE7a 24h",
418
- segurancaPatrimonial: "Seguran\xE7a patrimonial",
419
- condominioFechado: "Condom\xEDnio fechado",
420
- // Accessibility
421
- banheiroAcessivel: "Banheiro acess\xEDvel",
422
- elevadorAcessivel: "Elevador acess\xEDvel",
423
- pisoTatil: "Piso t\xE1til",
424
- // ==================== CANONICAL HAS*/IS* KEYS ====================
425
- has24hConcierge: "Portaria 24h",
426
- has24hSecurity: "Seguran\xE7a 24h",
427
- hasAccessRamps: "Rampas de acesso",
428
- hasAccessibleBathroom: "Banheiro acess\xEDvel",
429
- hasAccessibleElevator: "Elevador acess\xEDvel",
430
- hasAirConditioning: "Ar condicionado",
431
- hasAlarmSystem: "Sistema de alarme",
432
- hasBalcony: "Varanda",
433
- hasBikeStorage: "Biciclet\xE1rio",
434
- hasBuiltInWardrobe: "Arm\xE1rio embutido",
435
- hasCCTV: "CFTV",
436
- hasCloset: "Closet",
437
- hasConcierge: "Portaria",
438
- hasControlledAccess: "Condom\xEDnio fechado",
439
- hasCoworking: "Coworking",
440
- hasDisabledParking: "Vaga para deficientes",
441
- hasElectricCharger: "Carregador eletr\xF4nico",
442
- hasElectronicGate: "Port\xE3o eletr\xF4nico",
443
- hasElevator: "Elevador",
444
- hasFireplace: "Lareira",
445
- hasGarden: "Jardim",
446
- hasGasShower: "Chuveiro a g\xE1s",
447
- hasGenerator: "Gerador",
448
- hasGourmetBalcony: "Varanda gourmet",
449
- hasGourmetKitchen: "Cozinha gourmet",
450
- hasGrill: "Churrasqueira",
451
- hasGuestParking: "Estacionamento para visitantes",
452
- hasGym: "Academia",
453
- hasHeating: "Aquecimento",
454
- hasHomeOffice: "Home office",
455
- hasIntercom: "Interfone",
456
- hasJacuzzi: "Hidromassagem",
457
- hasKidsPool: "Piscina infantil",
458
- hasLaundry: "Lavanderia",
459
- hasMeetingRoom: "Sala de reuni\xE3o",
460
- hasOffice: "Escrit\xF3rio",
461
- hasOpenKitchen: "Cozinha americana",
462
- hasPackageReceival: "Recebimento de encomendas",
463
- hasPantry: "Despensa",
464
- hasParkingGarage: "Garagem coberta",
465
- hasPartySaloon: "Sal\xE3o de festas",
466
- hasPetArea: "Pet place",
467
- hasPipedGas: "G\xE1s encanado",
468
- hasPlayground: "Playground",
469
- hasPowderRoom: "Lavabo",
470
- hasPrivatePool: "Piscina privativa",
471
- hasSauna: "Sauna",
472
- hasSecurity: "Seguran\xE7a",
473
- hasServiceArea: "\xC1rea de servi\xE7o",
474
- hasSolarPanel: "Painel solar",
475
- hasSpa: "Spa",
476
- hasSportsCourt: "Quadra de esportes",
477
- hasStepFreeEntrance: "Entrada sem degrau",
478
- hasStorage: "Dep\xF3sito",
479
- hasSwimmingPool: "Piscina",
480
- hasTennisCourt: "Quadra de t\xEAnis",
481
- hasValetParking: "Valet",
482
- homeOffice: "Home office",
483
- isPetFriendly: "Pet friendly",
484
- isFurnished: "Mobiliado",
485
- isPartiallyFurnished: "Semi-mobiliado",
486
- petFriendly: "Pet friendly",
487
- piscinaPrivativa: "Piscina privativa",
488
- pisoLaminado: "Piso laminado",
489
- pisoMadeira: "Piso de madeira",
490
- pisoPorcelanato: "Piso porcelanato",
491
- quadraEsportes: "Quadra de esportes",
492
- rooftop: "Rooftop",
493
- suite: "Su\xEDte",
494
- triplex: "Triplex",
495
- duplex: "Duplex",
496
- cobertura: "Cobertura",
497
- forroGesso: "Forro de gesso",
498
- gerador: "Gerador",
499
- armariosCozinha: "Arm\xE1rios na cozinha",
500
- armariosQuarto: "Arm\xE1rios nos quartos",
501
- cftv: "CFTV"
502
- };
503
- function lookupLabel(id, options) {
504
- const fromDictionary = options?.find((option) => option.id === id)?.label;
505
- if (fromDictionary?.trim()) return fromDictionary.trim();
506
- return AMENITY_FALLBACK_LABELS[id];
507
- }
508
- function labelAmenities(ids, dictionary) {
509
- if (!ids?.length) return [];
510
- const labels = [];
511
- const seen = /* @__PURE__ */ new Set();
512
- for (const id of ids) {
513
- if (!id) continue;
514
- const label = lookupLabel(id, dictionary);
515
- if (!label || seen.has(label)) continue;
516
- seen.add(label);
517
- labels.push(label);
518
- }
519
- return labels.sort((a, b) => a.localeCompare(b, "pt-BR"));
520
- }
521
- function presentIds(ids) {
522
- return (ids ?? []).filter((id) => Boolean(id));
523
- }
524
- function buildingIdsFromMergedAmenities(listing, unitIds) {
525
- if (!listing.amenities || listing.propertyFeatures == null) return [];
526
- const unitCounts = /* @__PURE__ */ new Map();
527
- for (const id of unitIds) {
528
- unitCounts.set(id, (unitCounts.get(id) ?? 0) + 1);
49
+ // src/fetchers.ts
50
+ async function callJson(url, init, fetchImpl) {
51
+ const response = await fetchImpl(url, init);
52
+ if (!response.ok) {
53
+ const text = await response.text().catch(() => "");
54
+ throw new GaragemSdkError(
55
+ `Garagem SDK: request failed (${response.status} ${response.statusText}) for ${url}${text ? ` \u2014 ${text.slice(0, 200)}` : ""}`,
56
+ { status: response.status, url }
57
+ );
529
58
  }
530
- return listing.amenities.filter((id) => {
531
- if (!id) return false;
532
- const count = unitCounts.get(id);
533
- if (count === void 0 || count === 0) return true;
534
- unitCounts.set(id, count - 1);
535
- return false;
536
- });
59
+ return await response.json();
537
60
  }
538
- function unitAmenityIds(listing) {
539
- if (listing.propertyFeatures != null) {
540
- return presentIds(listing.propertyFeatures);
61
+ var GaragemSdkError = class extends Error {
62
+ status;
63
+ url;
64
+ constructor(message, info) {
65
+ super(message);
66
+ this.name = "GaragemSdkError";
67
+ this.status = info.status;
68
+ this.url = info.url;
541
69
  }
542
- const building = new Set(
543
- listing.building?.amenities ?? listing.buildingAmenities ?? []
70
+ };
71
+ async function getSearchUi(options) {
72
+ const { baseUrl, fetch: fetchImpl, next } = options;
73
+ const siteId = await coerceSiteId(options.siteId);
74
+ const base = normalizeBaseUrl(baseUrl);
75
+ const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search-ui`;
76
+ return callJson(
77
+ url,
78
+ { method: "GET", headers: { Accept: "application/json" }, next },
79
+ fetchImpl ?? fetch
544
80
  );
545
- return (listing.amenities ?? []).filter((id) => id && !building.has(id));
546
- }
547
- function buildingAmenityIds(listing) {
548
- if (listing.building != null && listing.building.amenities != null) {
549
- return presentIds(listing.building.amenities);
550
- }
551
- if (listing.buildingAmenities != null) {
552
- return presentIds(listing.buildingAmenities);
553
- }
554
- return buildingIdsFromMergedAmenities(listing, unitAmenityIds(listing));
555
81
  }
556
- function listingAmenityGroups(listing, dictionary) {
557
- const groups = [];
558
- const unitIds = unitAmenityIds(listing);
559
- const unitLabels = labelAmenities(unitIds, dictionary?.propertyFeatures);
560
- if (unitLabels.length > 0) {
561
- groups.push({
562
- key: "unit",
563
- title: LISTING_AMENITY_TITLES.unit,
564
- labels: unitLabels
565
- });
566
- }
567
- const buildingLabels = labelAmenities(
568
- buildingAmenityIds(listing),
569
- dictionary?.buildingAmenities
82
+ async function queryListings(options) {
83
+ const { params, baseUrl, fetch: fetchImpl, next } = options;
84
+ const siteId = await coerceSiteId(options.siteId);
85
+ const base = normalizeBaseUrl(baseUrl);
86
+ const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search/listings`;
87
+ return callJson(
88
+ url,
89
+ {
90
+ method: "POST",
91
+ headers: {
92
+ Accept: "application/json",
93
+ "Content-Type": "application/json"
94
+ },
95
+ body: JSON.stringify(params ?? {}),
96
+ next
97
+ },
98
+ fetchImpl ?? fetch
570
99
  );
571
- if (buildingLabels.length > 0) {
572
- groups.push({
573
- key: "building",
574
- title: LISTING_AMENITY_TITLES.building,
575
- labels: buildingLabels
576
- });
577
- }
578
- return groups;
579
100
  }
580
101
 
581
102
  // ../search-url/types.ts
@@ -587,6 +108,7 @@ var DEFAULT_MAX_PRICE = 1e9;
587
108
  var DEFAULT_MIN_AREA = 0;
588
109
  var DEFAULT_MAX_AREA = 1e5;
589
110
  var SORT_URL_TOKENS = [
111
+ "recentes",
590
112
  "preco-asc",
591
113
  "preco-desc",
592
114
  "area-asc",
@@ -1023,6 +545,17 @@ function pathFiltersToQueryFilters(pathFilters) {
1023
545
  return result;
1024
546
  }
1025
547
 
548
+ // src/presentation.ts
549
+ function parseGroupedInteger(value) {
550
+ if (typeof value === "number") {
551
+ return Number.isFinite(value) ? Math.trunc(value) : void 0;
552
+ }
553
+ const digits = String(value ?? "").replace(/\D/g, "");
554
+ if (!digits) return void 0;
555
+ const amount = Number.parseInt(digits, 10);
556
+ return Number.isFinite(amount) ? amount : void 0;
557
+ }
558
+
1026
559
  // src/search-engine.ts
1027
560
  var PATH_FILTER_IDS = {
1028
561
  listing_type: "listingType",
@@ -1044,6 +577,11 @@ function toFiniteNumber(value) {
1044
577
  function pathnameOnly(pathname) {
1045
578
  return String(pathname || "").split(/[?#]/)[0] || "/";
1046
579
  }
580
+ function isListingDetailPath(pathname) {
581
+ const parts = pathnameOnly(pathname).split("/").filter(Boolean);
582
+ const last = parts[parts.length - 1] || "";
583
+ return last.toLowerCase().startsWith("id-");
584
+ }
1047
585
  function readPublicSearch(pathname, search, dictionary) {
1048
586
  const pathFilters = parseSearchPublicPath2(pathnameOnly(pathname), dictionary) || {};
1049
587
  const applied = parseAppliedSearchQuery2(search || "");
@@ -1176,6 +714,8 @@ function currentSearchHref(pathname, search) {
1176
714
  return qs ? `${path}?${qs}` : path;
1177
715
  }
1178
716
  function canonicalizeSearchHref(pathname, search, dictionary) {
717
+ if (pathname.includes("/api/v0-preview/")) return null;
718
+ if (isListingDetailPath(pathname)) return null;
1179
719
  const { pathFilters, applied } = readPublicSearch(
1180
720
  pathname,
1181
721
  search,
@@ -1196,294 +736,28 @@ function clearStagedPathFilters(current, keepFilterIds = []) {
1196
736
  return next;
1197
737
  }
1198
738
 
1199
- // src/listing-detail.ts
1200
- function finiteNumber(value) {
1201
- if (typeof value === "number" && Number.isFinite(value)) return value;
1202
- if (typeof value === "string" && value.trim() !== "") {
1203
- const parsed = Number(value);
1204
- if (Number.isFinite(parsed)) return parsed;
1205
- }
1206
- return null;
1207
- }
1208
- function positiveCount(value) {
1209
- const amount = finiteNumber(value);
1210
- return amount != null && amount > 0 ? amount : null;
1211
- }
1212
- function formatFloorFact(value) {
1213
- if (typeof value === "number" && Number.isFinite(value)) {
1214
- return value === 0 ? "T\xE9rreo" : String(value);
1215
- }
1216
- if (typeof value !== "string") return null;
1217
- const trimmed = value.trim();
1218
- if (!trimmed) return null;
1219
- const parsed = Number(trimmed);
1220
- if (Number.isFinite(parsed) && trimmed === String(parsed)) {
1221
- return parsed === 0 ? "T\xE9rreo" : trimmed;
1222
- }
1223
- return trimmed;
1224
- }
1225
- function listingValues(listing) {
1226
- const values = [
1227
- {
1228
- key: "price",
1229
- label: "Pre\xE7o",
1230
- text: listing.priceVisibility === "private" ? "Sob consulta" : formatListingPrice(listing.price)
1231
- }
1232
- ];
1233
- const condoFee = positiveCount(listing.property?.condoFee);
1234
- if (condoFee != null) {
1235
- values.push({
1236
- key: "condoFee",
1237
- label: "Condom\xEDnio",
1238
- text: formatListingPrice(condoFee)
1239
- });
739
+ // src/react/staged-filters-mirror.ts
740
+ var StagedFiltersMirror = class {
741
+ current;
742
+ constructor(initial = {}) {
743
+ this.current = initial;
1240
744
  }
1241
- const propertyTax = positiveCount(listing.property?.propertyTax);
1242
- if (propertyTax != null) {
1243
- values.push({
1244
- key: "propertyTax",
1245
- label: "IPTU",
1246
- text: formatListingPrice(propertyTax)
1247
- });
1248
- }
1249
- return values;
1250
- }
1251
- function listingFacts(listing) {
1252
- const property = listing.property ?? {};
1253
- const facts = [];
1254
- const area = formatAreaM2(
1255
- positiveCount(property.usableArea) ?? positiveCount(property.totalArea)
1256
- );
1257
- if (area) facts.push({ key: "area", label: "\xC1rea", text: area });
1258
- const bedrooms = positiveCount(property.bedrooms);
1259
- if (bedrooms != null) {
1260
- facts.push({
1261
- key: "bedrooms",
1262
- label: "Dormit\xF3rios",
1263
- text: String(bedrooms)
1264
- });
1265
- }
1266
- const suites = positiveCount(property.suites);
1267
- if (suites != null) {
1268
- facts.push({ key: "suites", label: "Su\xEDtes", text: String(suites) });
1269
- }
1270
- const parking = positiveCount(property.parkingSpaces);
1271
- if (parking != null) {
1272
- facts.push({ key: "parkingSpaces", label: "Vagas", text: String(parking) });
1273
- }
1274
- const rooms = positiveCount(property.rooms);
1275
- if (rooms != null) {
1276
- facts.push({ key: "rooms", label: "Salas", text: String(rooms) });
1277
- }
1278
- const floorText = formatFloorFact(property.floor);
1279
- if (floorText) {
1280
- facts.push({ key: "floor", label: "Andar", text: floorText });
1281
- }
1282
- return facts;
1283
- }
1284
-
1285
- // src/listing-detail-fields.ts
1286
- function visibleText(value) {
1287
- if (typeof value !== "string") return null;
1288
- const trimmed = value.trim();
1289
- if (!trimmed || trimmed === "undefined" || trimmed === "null") return null;
1290
- return trimmed;
1291
- }
1292
- function visibleRows(rows) {
1293
- return rows.filter((row) => {
1294
- const label = visibleText(row.label);
1295
- const text = visibleText(row.text);
1296
- return label != null && text != null;
1297
- });
1298
- }
1299
- function listingDetailFieldsModel(listing, dictionary) {
1300
- return {
1301
- facts: visibleRows(listingFacts(listing)),
1302
- values: visibleRows(listingValues(listing)),
1303
- amenityGroups: listingAmenityGroups(listing, dictionary).map((group) => ({
1304
- ...group,
1305
- labels: group.labels.map((label) => visibleText(label)).filter((label) => label != null)
1306
- })).filter((group) => group.labels.length > 0)
1307
- };
1308
- }
1309
-
1310
- // src/react/listing-detail-fields.tsx
1311
- var import_jsx_runtime2 = require("react/jsx-runtime");
1312
- function ListingDetailFields({
1313
- listing,
1314
- dictionary,
1315
- className,
1316
- classNames,
1317
- style
1318
- }) {
1319
- const model = listingDetailFieldsModel(listing, dictionary ?? void 0);
1320
- if (model.facts.length === 0 && model.values.length === 0 && model.amenityGroups.length === 0) {
1321
- return null;
745
+ get value() {
746
+ return this.current;
1322
747
  }
1323
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1324
- "div",
1325
- {
1326
- "data-slot": "listing-detail-fields",
1327
- className: cn(className, classNames?.root),
1328
- style,
1329
- children: [
1330
- model.facts.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ul", { "data-slot": "listing-facts", className: classNames?.facts, children: model.facts.map((fact) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1331
- "li",
1332
- {
1333
- "data-slot": "listing-fact",
1334
- "data-key": fact.key,
1335
- className: classNames?.fact,
1336
- children: [
1337
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-slot": "listing-fact-label", children: fact.label }),
1338
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-slot": "listing-fact-text", children: fact.text })
1339
- ]
1340
- },
1341
- fact.key
1342
- )) }) : null,
1343
- model.values.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("dl", { "data-slot": "listing-values", className: classNames?.values, children: model.values.map((value) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1344
- "div",
1345
- {
1346
- "data-slot": "listing-value",
1347
- "data-key": value.key,
1348
- className: classNames?.value,
1349
- children: [
1350
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("dt", { "data-slot": "listing-value-label", children: value.label }),
1351
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("dd", { "data-slot": "listing-value-text", children: value.text })
1352
- ]
1353
- },
1354
- value.key
1355
- )) }) : null,
1356
- model.amenityGroups.map((group) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1357
- "section",
1358
- {
1359
- "data-slot": "listing-amenities",
1360
- "data-key": group.key,
1361
- className: classNames?.amenityGroup,
1362
- children: [
1363
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1364
- "h2",
1365
- {
1366
- "data-slot": "listing-amenities-title",
1367
- className: classNames?.amenityTitle,
1368
- children: group.title
1369
- }
1370
- ),
1371
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1372
- "ul",
1373
- {
1374
- "data-slot": "listing-amenities-list",
1375
- className: classNames?.amenityList,
1376
- children: group.labels.map((label) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1377
- "li",
1378
- {
1379
- "data-slot": "listing-amenity-label",
1380
- className: classNames?.amenityLabel,
1381
- children: label
1382
- },
1383
- label
1384
- ))
1385
- }
1386
- )
1387
- ]
1388
- },
1389
- group.key
1390
- ))
1391
- ]
1392
- }
1393
- );
1394
- }
1395
-
1396
- // src/react/search-chrome.tsx
1397
- var import_jsx_runtime3 = require("react/jsx-runtime");
1398
- function ResultsSkeleton({
1399
- className
1400
- }) {
1401
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1402
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SearchChromeStyles, {}),
1403
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { "data-slot": "search-skeleton", className, children: Array.from({ length: 6 }, (_, i) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-slot": "search-skeleton-card", children: [
1404
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { "data-slot": "search-skeleton-block", "data-kind": "media" }),
1405
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-slot": "search-skeleton-body", children: [
1406
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { "data-slot": "search-skeleton-block", "data-kind": "line-lg" }),
1407
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { "data-slot": "search-skeleton-block", "data-kind": "line-md" }),
1408
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { "data-slot": "search-skeleton-block", "data-kind": "line-sm" })
1409
- ] })
1410
- ] }, i)) })
1411
- ] });
1412
- }
1413
-
1414
- // src/react/use-public-search.ts
1415
- var import_react2 = require("react");
1416
- var import_navigation = require("next/navigation");
1417
-
1418
- // src/internal/url.ts
1419
- var DEFAULT_BASE_URL = "https://app.garagem.ai";
1420
- function normalizeBaseUrl(baseUrl) {
1421
- const url = baseUrl ?? DEFAULT_BASE_URL;
1422
- return url.endsWith("/") ? url.slice(0, -1) : url;
1423
- }
1424
- async function coerceSiteId(siteId) {
1425
- const raw = typeof siteId === "function" ? siteId() : siteId;
1426
- const value = await Promise.resolve(raw);
1427
- if (typeof value !== "string" || !value.trim()) {
1428
- throw new TypeError(
1429
- "Garagem SDK: siteId must be a string. Await resolveSiteId(...) before getListings / getSearchUi / queryListings."
1430
- );
748
+ replace(next) {
749
+ this.current = next;
750
+ return this.current;
1431
751
  }
1432
- return value;
1433
- }
1434
-
1435
- // src/fetchers.ts
1436
- async function callJson(url, init, fetchImpl) {
1437
- const response = await fetchImpl(url, init);
1438
- if (!response.ok) {
1439
- const text = await response.text().catch(() => "");
1440
- throw new GaragemSdkError(
1441
- `Garagem SDK: request failed (${response.status} ${response.statusText}) for ${url}${text ? ` \u2014 ${text.slice(0, 200)}` : ""}`,
1442
- { status: response.status, url }
1443
- );
752
+ stage(filterId, value) {
753
+ this.current = applyPathFilter(this.current, filterId, value);
754
+ return this.current;
1444
755
  }
1445
- return await response.json();
1446
- }
1447
- var GaragemSdkError = class extends Error {
1448
- status;
1449
- url;
1450
- constructor(message, info) {
1451
- super(message);
1452
- this.name = "GaragemSdkError";
1453
- this.status = info.status;
1454
- this.url = info.url;
756
+ clear(keepFilterIds = []) {
757
+ this.current = clearStagedPathFilters(this.current, keepFilterIds);
758
+ return this.current;
1455
759
  }
1456
760
  };
1457
- async function getSearchUi(options) {
1458
- const { baseUrl, fetch: fetchImpl, next } = options;
1459
- const siteId = await coerceSiteId(options.siteId);
1460
- const base = normalizeBaseUrl(baseUrl);
1461
- const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search-ui`;
1462
- return callJson(
1463
- url,
1464
- { method: "GET", headers: { Accept: "application/json" }, next },
1465
- fetchImpl ?? fetch
1466
- );
1467
- }
1468
- async function queryListings(options) {
1469
- const { params, baseUrl, fetch: fetchImpl, next } = options;
1470
- const siteId = await coerceSiteId(options.siteId);
1471
- const base = normalizeBaseUrl(baseUrl);
1472
- const url = `${base}/api/sites/${encodeURIComponent(siteId)}/search/listings`;
1473
- return callJson(
1474
- url,
1475
- {
1476
- method: "POST",
1477
- headers: {
1478
- Accept: "application/json",
1479
- "Content-Type": "application/json"
1480
- },
1481
- body: JSON.stringify(params ?? {}),
1482
- next
1483
- },
1484
- fetchImpl ?? fetch
1485
- );
1486
- }
1487
761
 
1488
762
  // src/react/use-public-search.ts
1489
763
  async function resolveSiteIdInput(siteId) {
@@ -1499,36 +773,41 @@ function usePublicSearch(options) {
1499
773
  const pathname = (0, import_navigation.usePathname)() || "/imoveis";
1500
774
  const searchParams = (0, import_navigation.useSearchParams)();
1501
775
  const search = searchParams.toString();
1502
- const siteIdRef = (0, import_react2.useRef)(siteId);
776
+ const siteIdRef = (0, import_react.useRef)(siteId);
1503
777
  siteIdRef.current = siteId;
1504
778
  const siteIdToken = typeof siteId === "string" ? siteId : null;
1505
- const [catalogId, setCatalogId] = (0, import_react2.useState)(null);
1506
- const [schema, setSchema] = (0, import_react2.useState)(null);
1507
- const [listings, setListings] = (0, import_react2.useState)([]);
1508
- const [page, setPage] = (0, import_react2.useState)(1);
1509
- const [total, setTotal] = (0, import_react2.useState)(0);
1510
- const [totalPages, setTotalPages] = (0, import_react2.useState)(1);
1511
- const [loading, setLoading] = (0, import_react2.useState)(true);
1512
- const [qDraft, setQDraft] = (0, import_react2.useState)("");
1513
- const [staged, setStaged] = (0, import_react2.useState)({});
1514
- const [locationNames, setLocationNames] = (0, import_react2.useState)(
779
+ const [catalogId, setCatalogId] = (0, import_react.useState)(null);
780
+ const [schema, setSchema] = (0, import_react.useState)(null);
781
+ const [listings, setListings] = (0, import_react.useState)([]);
782
+ const [page, setPage] = (0, import_react.useState)(1);
783
+ const [total, setTotal] = (0, import_react.useState)(0);
784
+ const [totalPages, setTotalPages] = (0, import_react.useState)(1);
785
+ const [loading, setLoading] = (0, import_react.useState)(true);
786
+ const [qDraft, setQDraft] = (0, import_react.useState)("");
787
+ const stagedMirrorRef = (0, import_react.useRef)(new StagedFiltersMirror());
788
+ const [staged, setStagedState] = (0, import_react.useState)({});
789
+ const [locationNames, setLocationNames] = (0, import_react.useState)(
1515
790
  null
1516
791
  );
1517
- const parsed = (0, import_react2.useMemo)(
792
+ const replaceStaged = (0, import_react.useCallback)((next) => {
793
+ stagedMirrorRef.current.replace(next);
794
+ setStagedState(next);
795
+ }, []);
796
+ const parsed = (0, import_react.useMemo)(
1518
797
  () => readPublicSearch(pathname, search, schema?.dictionary),
1519
798
  [pathname, search, schema?.dictionary]
1520
799
  );
1521
- (0, import_react2.useEffect)(() => {
800
+ (0, import_react.useEffect)(() => {
1522
801
  setQDraft(parsed.applied.query || "");
1523
802
  }, [parsed.applied.query]);
1524
- const resetStagedFromUrl = (0, import_react2.useCallback)(() => {
1525
- setStaged({ ...parsed.pathFilters });
1526
- }, [parsed.pathFilters]);
1527
- (0, import_react2.useEffect)(() => {
1528
- setStaged({ ...parsed.pathFilters });
1529
- }, [parsed.pathFilters]);
1530
- const locationsRef = (0, import_react2.useRef)(null);
1531
- (0, import_react2.useEffect)(() => {
803
+ const resetStagedFromUrl = (0, import_react.useCallback)(() => {
804
+ replaceStaged({ ...parsed.pathFilters });
805
+ }, [parsed.pathFilters, replaceStaged]);
806
+ (0, import_react.useEffect)(() => {
807
+ replaceStaged({ ...parsed.pathFilters });
808
+ }, [parsed.pathFilters, replaceStaged]);
809
+ const locationsRef = (0, import_react.useRef)(null);
810
+ (0, import_react.useEffect)(() => {
1532
811
  if (!schema) return;
1533
812
  const canonical = canonicalizeSearchHref(
1534
813
  pathname,
@@ -1537,7 +816,7 @@ function usePublicSearch(options) {
1537
816
  );
1538
817
  if (canonical) router.replace(canonical);
1539
818
  }, [pathname, search, schema, router]);
1540
- (0, import_react2.useEffect)(() => {
819
+ (0, import_react.useEffect)(() => {
1541
820
  let active = true;
1542
821
  setCatalogId(null);
1543
822
  setSchema(null);
@@ -1552,7 +831,7 @@ function usePublicSearch(options) {
1552
831
  active = false;
1553
832
  };
1554
833
  }, [baseUrl, siteIdToken]);
1555
- (0, import_react2.useEffect)(() => {
834
+ (0, import_react.useEffect)(() => {
1556
835
  if (!catalogId) return;
1557
836
  const id = catalogId;
1558
837
  let active = true;
@@ -1596,7 +875,7 @@ function usePublicSearch(options) {
1596
875
  active = false;
1597
876
  };
1598
877
  }, [baseUrl, catalogId]);
1599
- (0, import_react2.useEffect)(() => {
878
+ (0, import_react.useEffect)(() => {
1600
879
  if (!schema || !catalogId) return;
1601
880
  const currentSchema = schema;
1602
881
  const id = catalogId;
@@ -1640,13 +919,13 @@ function usePublicSearch(options) {
1640
919
  active = false;
1641
920
  };
1642
921
  }, [pathname, search, baseUrl, schema, catalogId]);
1643
- const go = (0, import_react2.useCallback)(
922
+ const go = (0, import_react.useCallback)(
1644
923
  (href) => {
1645
924
  if (href && href !== currentHref(pathname, search)) router.push(href);
1646
925
  },
1647
926
  [pathname, search, router]
1648
927
  );
1649
- const applyFilter = (0, import_react2.useCallback)(
928
+ const applyFilter = (0, import_react.useCallback)(
1650
929
  (filterId, value) => {
1651
930
  if (!schema) return;
1652
931
  go(
@@ -1660,17 +939,30 @@ function usePublicSearch(options) {
1660
939
  },
1661
940
  [go, pathname, search, schema, parsed.pathFilters]
1662
941
  );
1663
- const stageFilter = (0, import_react2.useCallback)((filterId, value) => {
1664
- setStaged((current) => applyPathFilter(current, filterId, value));
942
+ const setStaged = (0, import_react.useCallback)(
943
+ (next) => {
944
+ replaceStaged(next);
945
+ },
946
+ [replaceStaged]
947
+ );
948
+ const stageFilter = (0, import_react.useCallback)((filterId, value) => {
949
+ setStagedState(stagedMirrorRef.current.stage(filterId, value));
1665
950
  }, []);
1666
- const applyStaged = (0, import_react2.useCallback)(() => {
951
+ const applyStaged = (0, import_react.useCallback)(() => {
1667
952
  if (!schema) return;
1668
- go(hrefForPathFilters(pathname, search, schema.dictionary, staged));
1669
- }, [go, pathname, search, schema, staged]);
1670
- const clearStaged = (0, import_react2.useCallback)(() => {
1671
- setStaged((current) => clearStagedPathFilters(current));
953
+ go(
954
+ hrefForPathFilters(
955
+ pathname,
956
+ search,
957
+ schema.dictionary,
958
+ stagedMirrorRef.current.value
959
+ )
960
+ );
961
+ }, [go, pathname, search, schema]);
962
+ const clearStaged = (0, import_react.useCallback)(() => {
963
+ setStagedState(stagedMirrorRef.current.clear());
1672
964
  }, []);
1673
- const submitQuery = (0, import_react2.useCallback)(() => {
965
+ const submitQuery = (0, import_react.useCallback)(() => {
1674
966
  if (!schema) return;
1675
967
  go(
1676
968
  hrefForAppliedChange(pathname, search, schema.dictionary, {
@@ -1679,7 +971,7 @@ function usePublicSearch(options) {
1679
971
  })
1680
972
  );
1681
973
  }, [go, pathname, search, schema, qDraft]);
1682
- const clearQuery = (0, import_react2.useCallback)(() => {
974
+ const clearQuery = (0, import_react.useCallback)(() => {
1683
975
  setQDraft("");
1684
976
  if (!schema) return;
1685
977
  go(
@@ -1689,7 +981,7 @@ function usePublicSearch(options) {
1689
981
  })
1690
982
  );
1691
983
  }, [go, pathname, search, schema]);
1692
- const setSort = (0, import_react2.useCallback)(
984
+ const setSort = (0, import_react.useCallback)(
1693
985
  (sort) => {
1694
986
  if (!schema) return;
1695
987
  go(
@@ -1701,7 +993,7 @@ function usePublicSearch(options) {
1701
993
  },
1702
994
  [go, pathname, search, schema]
1703
995
  );
1704
- const hrefForPage = (0, import_react2.useCallback)(
996
+ const hrefForPage = (0, import_react.useCallback)(
1705
997
  (nextPage) => {
1706
998
  if (!schema) return pathname;
1707
999
  return hrefForAppliedChange(pathname, search, schema.dictionary, {
@@ -1741,10 +1033,6 @@ function usePublicSearch(options) {
1741
1033
  }
1742
1034
  // Annotate the CommonJS export names for ESM import in node:
1743
1035
  0 && (module.exports = {
1744
- ListingCard,
1745
- ListingDetailFields,
1746
- ResultsSkeleton,
1747
- SearchChromeStyles,
1748
1036
  usePublicSearch
1749
1037
  });
1750
1038
  //# sourceMappingURL=react.js.map