@garagem-ai/site-sdk 0.4.14 → 0.5.0

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 CHANGED
@@ -36,15 +36,6 @@ function formatListingPrice(amount, locale = "pt-BR", currency = "BRL") {
36
36
  return `${currency} ${amount}`;
37
37
  }
38
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
39
  function parseGroupedInteger(value) {
49
40
  if (typeof value === "number") {
50
41
  return Number.isFinite(value) ? Math.trunc(value) : void 0;
@@ -109,8 +100,8 @@ function cn(...parts) {
109
100
  import { useLayoutEffect } from "react";
110
101
 
111
102
  // src/react/styles/search-chrome-css.generated.ts
112
- var SEARCH_CHROME_CSS_VERSION = "0.4.14";
113
- 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-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}}`;
103
+ var SEARCH_CHROME_CSS_VERSION = "0.5.0";
104
+ 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}}';
114
105
 
115
106
  // src/react/styles/search-chrome-styles.tsx
116
107
  var STYLE_ID = `garagem-search-chrome-${SEARCH_CHROME_CSS_VERSION}`;
@@ -1006,22 +997,6 @@ var PATH_FILTER_IDS = {
1006
997
  propertyFeatures: "propertyFeatures",
1007
998
  buildingAmenities: "buildingAmenities"
1008
999
  };
1009
- var SEARCH_SORT_RELEVANCE = {
1010
- id: "",
1011
- label: "Mais relevantes"
1012
- };
1013
- function searchSortOptions(sorts) {
1014
- const fromApi = (sorts || []).filter((sort) => sort.id);
1015
- return [
1016
- { id: SEARCH_SORT_RELEVANCE.id, label: SEARCH_SORT_RELEVANCE.label },
1017
- ...fromApi
1018
- ];
1019
- }
1020
- var TOOLBAR_PRIMARY_FILTER_IDS = [
1021
- "price",
1022
- "property_bedrooms"
1023
- ];
1024
- var HIDDEN_FILTER_IDS = /* @__PURE__ */ new Set(["property_suites"]);
1025
1000
  function toFiniteNumber(value) {
1026
1001
  if (value === "" || value == null) return void 0;
1027
1002
  const n = Number(value);
@@ -1131,22 +1106,6 @@ function applyPathFilter(pathFilters, filterId, value) {
1131
1106
  }
1132
1107
  return next;
1133
1108
  }
1134
- function pathFilterValue(pathFilters, filterId) {
1135
- const key = PATH_FILTER_IDS[filterId];
1136
- const value = pathFilters && key ? pathFilters[key] : void 0;
1137
- if (value == null) return "";
1138
- if (Array.isArray(value)) return value[0] != null ? String(value[0]) : "";
1139
- if (typeof value === "object") return "";
1140
- return String(value);
1141
- }
1142
- function pathFilterHasOption(pathFilters, filterId, optionId) {
1143
- const key = PATH_FILTER_IDS[filterId];
1144
- const value = pathFilters && key ? pathFilters[key] : void 0;
1145
- if (value == null) return false;
1146
- if (Array.isArray(value)) return value.map(String).includes(optionId);
1147
- if (typeof value === "object") return false;
1148
- return String(value) === optionId;
1149
- }
1150
1109
  function publicSearchHref(pathFilters, applied, dictionary, existingSearch) {
1151
1110
  const pathname = composeSearchPublicPath2(pathFilters || {}, dictionary);
1152
1111
  return composeSearchPublicHref2(pathname, applied || {}, existingSearch);
@@ -1197,100 +1156,6 @@ function clearStagedPathFilters(current, keepFilterIds = []) {
1197
1156
  }
1198
1157
  return next;
1199
1158
  }
1200
- function visibleSearchFilters(schema) {
1201
- if (!schema?.filters) return [];
1202
- return schema.filters.filter((filter) => {
1203
- if (HIDDEN_FILTER_IDS.has(filter.id)) return false;
1204
- if (filter.id === "listing_type" && (filter.options?.length ?? 0) <= 1) {
1205
- return false;
1206
- }
1207
- return true;
1208
- });
1209
- }
1210
- function toolbarFilterIds(schema) {
1211
- const visible = new Set(visibleSearchFilters(schema).map((f) => f.id));
1212
- return TOOLBAR_PRIMARY_FILTER_IDS.filter((id) => visible.has(id));
1213
- }
1214
- function countOptionLabel(option) {
1215
- const label = String(option?.label ?? "");
1216
- if (/^[1-9]\d*$/.test(label)) return `${label}+`;
1217
- return label;
1218
- }
1219
- function countFacetChoices(options) {
1220
- const list = options || [];
1221
- const zero = list.find((o) => o.id === "0" || o.label === "Studio");
1222
- const isStudio = Boolean(
1223
- zero && /studio/i.test(String(zero.label)) && zero.id === "0"
1224
- );
1225
- const max = isStudio ? 3 : 4;
1226
- const out = [];
1227
- if (zero) out.push({ id: zero.id, label: countOptionLabel(zero) });
1228
- for (let n = 1; n <= max; n += 1) {
1229
- const option = list.find((o) => o.id === String(n));
1230
- out.push({
1231
- id: String(n),
1232
- label: countOptionLabel(option || { label: String(n) })
1233
- });
1234
- }
1235
- return out;
1236
- }
1237
- var FEMININE_HEADING = /(casa|cobertura|kitnet|loja|sala|fazenda|chácara|chacara)s?$/i;
1238
- function pluralizePt(label) {
1239
- const text = label.trim();
1240
- if (!text || /s$/i.test(text)) return text;
1241
- if (/il$/i.test(text)) return `${text.slice(0, -1)}is`;
1242
- if (/m$/i.test(text)) return `${text.slice(0, -1)}ns`;
1243
- return `${text}s`;
1244
- }
1245
- function headingLocationSuffix(location) {
1246
- if (!location) return "";
1247
- if (location.street && location.neighborhood) {
1248
- return `${location.street}, ${location.neighborhood}`;
1249
- }
1250
- if (location.neighborhood && location.city) {
1251
- return `${location.neighborhood}, ${location.city}`;
1252
- }
1253
- if (location.city && location.state) {
1254
- return `${location.city} - ${location.state}`;
1255
- }
1256
- return location.city || location.neighborhood || location.street || location.state || "";
1257
- }
1258
- function searchResultsHeading(pathFilters, dictionary, locationNames) {
1259
- const types = [].concat(pathFilters.propertyType || []).filter(Boolean);
1260
- let noun = "Im\xF3veis";
1261
- let found = "encontrados";
1262
- if (types.length === 1) {
1263
- const id = String(types[0]);
1264
- const option = dictionary?.propertyTypes?.find(
1265
- (entry) => entry.id === id || entry.slug === id
1266
- );
1267
- const label = option?.label;
1268
- if (label) {
1269
- noun = pluralizePt(label.charAt(0).toUpperCase() + label.slice(1));
1270
- if (FEMININE_HEADING.test(id) || FEMININE_HEADING.test(label)) {
1271
- found = "encontradas";
1272
- }
1273
- }
1274
- }
1275
- const place = locationNames ? headingLocationSuffix(
1276
- displayPathLocation(pathFilters.location, locationNames)
1277
- ) : "";
1278
- if (place) return `${noun} ${found} em ${place}`;
1279
- return `${noun} ${found}`;
1280
- }
1281
- function hrefWithExplicitPage(href, page) {
1282
- if (page !== 1 || /(?:\?|&)page=/.test(href)) return href;
1283
- return href.includes("?") ? `${href}&page=1` : `${href}?page=1`;
1284
- }
1285
- function paginationPages(currentPage, totalPages, padding) {
1286
- if (totalPages < 1) return [];
1287
- const current = Math.min(Math.max(1, currentPage), totalPages);
1288
- const start = Math.max(1, current - padding);
1289
- const end = Math.min(totalPages, current + padding);
1290
- const pages = [];
1291
- for (let i = start; i <= end; i += 1) pages.push(i);
1292
- return pages;
1293
- }
1294
1159
 
1295
1160
  // src/listing-detail.ts
1296
1161
  function finiteNumber(value) {
@@ -1489,452 +1354,23 @@ function ListingDetailFields({
1489
1354
  );
1490
1355
  }
1491
1356
 
1492
- // src/react/search-page.tsx
1493
- import {
1494
- useCallback as useCallback2,
1495
- useEffect as useEffect2,
1496
- useRef as useRef2,
1497
- useState as useState2
1498
- } from "react";
1499
-
1500
- // src/react/filter-panel.tsx
1501
- import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
1502
- function RangeFields({
1503
- filter,
1504
- rangeDraft,
1505
- onRangePatch,
1506
- onRangeCommit
1507
- }) {
1508
- const draft = rangeDraft[filter.id] || { min: "", max: "" };
1509
- const isPrice = filter.id === "price";
1510
- const patch = (side, raw) => {
1511
- onRangePatch(filter.id, side, isPrice ? formatGroupedInteger(raw) : raw);
1512
- };
1513
- return /* @__PURE__ */ jsxs3("fieldset", { "data-slot": "search-filter", children: [
1514
- /* @__PURE__ */ jsx3("legend", { children: filter.label }),
1515
- /* @__PURE__ */ jsxs3("div", { "data-slot": "search-range-row", children: [
1516
- /* @__PURE__ */ jsx3(
1517
- RangeSide,
1518
- {
1519
- id: `${filter.id}-min`,
1520
- label: "M\xEDn",
1521
- isPrice,
1522
- value: draft.min,
1523
- onPatch: (raw) => patch("min", raw),
1524
- onCommit: () => onRangeCommit(filter.id, "blur"),
1525
- onEnter: () => onRangeCommit(filter.id, "enter")
1526
- }
1527
- ),
1528
- /* @__PURE__ */ jsx3(
1529
- RangeSide,
1530
- {
1531
- id: `${filter.id}-max`,
1532
- label: "M\xE1x",
1533
- isPrice,
1534
- value: draft.max,
1535
- onPatch: (raw) => patch("max", raw),
1536
- onCommit: () => onRangeCommit(filter.id, "blur"),
1537
- onEnter: () => onRangeCommit(filter.id, "enter")
1538
- }
1539
- ),
1540
- /* @__PURE__ */ jsx3(
1541
- "button",
1542
- {
1543
- type: "button",
1544
- "data-slot": "search-range-apply",
1545
- onClick: () => onRangeCommit(filter.id, "apply"),
1546
- children: "Atualizar"
1547
- }
1548
- )
1549
- ] })
1550
- ] });
1551
- }
1552
- function RangeSide({
1553
- id,
1554
- label,
1555
- isPrice,
1556
- value,
1557
- onPatch,
1558
- onCommit,
1559
- onEnter
1560
- }) {
1561
- const input = /* @__PURE__ */ jsx3(
1562
- "input",
1563
- {
1564
- id,
1565
- type: isPrice ? "text" : "number",
1566
- inputMode: isPrice ? "numeric" : "decimal",
1567
- min: isPrice ? void 0 : 0,
1568
- step: isPrice ? void 0 : 0.01,
1569
- value,
1570
- placeholder: isPrice ? "0" : void 0,
1571
- onChange: (event) => onPatch(event.target.value),
1572
- onBlur: onCommit,
1573
- onKeyDown: (event) => {
1574
- if (event.key === "Enter") {
1575
- event.preventDefault();
1576
- onEnter();
1577
- }
1578
- },
1579
- "data-slot": "search-range-input"
1580
- }
1581
- );
1582
- return /* @__PURE__ */ jsxs3("label", { "data-slot": "search-range-side", htmlFor: id, children: [
1583
- /* @__PURE__ */ jsx3("span", { children: label }),
1584
- isPrice ? /* @__PURE__ */ jsxs3("span", { "data-slot": "search-range-affix", children: [
1585
- /* @__PURE__ */ jsx3("span", { "data-slot": "search-range-prefix", children: "R$" }),
1586
- input
1587
- ] }) : input
1588
- ] });
1589
- }
1590
- function CountFields({
1591
- filter,
1592
- pathFilters,
1593
- onChange
1594
- }) {
1595
- const selected = pathFilterValue(pathFilters, filter.id);
1596
- const choices = countFacetChoices(filter.options);
1597
- return /* @__PURE__ */ jsxs3("fieldset", { "data-slot": "search-filter", children: [
1598
- /* @__PURE__ */ jsx3("legend", { children: filter.label }),
1599
- /* @__PURE__ */ jsx3("div", { "data-slot": "search-count-group", role: "group", children: choices.map((choice) => /* @__PURE__ */ jsx3(
1600
- "button",
1601
- {
1602
- type: "button",
1603
- "data-slot": "search-count-choice",
1604
- "data-selected": selected === choice.id ? "true" : void 0,
1605
- onClick: () => onChange(filter.id, Number(choice.id)),
1606
- children: choice.label
1607
- },
1608
- choice.id
1609
- )) })
1610
- ] });
1611
- }
1612
- function EnumFields({
1613
- filter,
1614
- pathFilters,
1615
- onChange
1616
- }) {
1617
- const options = filter.options || [];
1618
- const scroll = options.length > 8;
1619
- return /* @__PURE__ */ jsxs3("fieldset", { "data-slot": "search-filter", children: [
1620
- /* @__PURE__ */ jsx3("legend", { children: filter.label }),
1621
- /* @__PURE__ */ jsx3("div", { "data-slot": scroll ? "search-scroll" : "search-enum-list", children: options.map((option) => /* @__PURE__ */ jsxs3("label", { "data-slot": "search-enum-option", children: [
1622
- /* @__PURE__ */ jsx3(
1623
- "input",
1624
- {
1625
- type: "checkbox",
1626
- "data-slot": "search-checkbox",
1627
- checked: pathFilterHasOption(pathFilters, filter.id, option.id),
1628
- onChange: () => onChange(filter.id, option.id)
1629
- }
1630
- ),
1631
- /* @__PURE__ */ jsx3("span", { children: option.label })
1632
- ] }, option.id)) })
1633
- ] });
1634
- }
1635
- function FilterPanel({
1636
- filters,
1637
- pathFilters,
1638
- onChange,
1639
- rangeDraft,
1640
- onRangePatch,
1641
- onRangeCommit
1642
- }) {
1643
- return /* @__PURE__ */ jsx3("div", { "data-slot": "search-filters", children: filters.map((filter) => {
1644
- if (filter.type === "range") {
1645
- return /* @__PURE__ */ jsx3(
1646
- RangeFields,
1647
- {
1648
- filter,
1649
- rangeDraft,
1650
- onRangePatch,
1651
- onRangeCommit
1652
- },
1653
- filter.id
1654
- );
1655
- }
1656
- if (filter.type === "count") {
1657
- return /* @__PURE__ */ jsx3(
1658
- CountFields,
1659
- {
1660
- filter,
1661
- pathFilters,
1662
- onChange
1663
- },
1664
- filter.id
1665
- );
1666
- }
1667
- return /* @__PURE__ */ jsx3(
1668
- EnumFields,
1669
- {
1670
- filter,
1671
- pathFilters,
1672
- onChange
1673
- },
1674
- filter.id
1675
- );
1676
- }) });
1677
- }
1678
- function rangeDraftFromPath(pathFilters) {
1679
- const price = pathFilters.price || {};
1680
- const area = pathFilters.area || {};
1681
- return {
1682
- price: {
1683
- min: price.min != null ? formatGroupedInteger(price.min) : "",
1684
- max: price.max != null ? formatGroupedInteger(price.max) : ""
1685
- },
1686
- property_area_total: {
1687
- min: area.min != null ? String(area.min) : "",
1688
- max: area.max != null ? String(area.max) : ""
1689
- }
1690
- };
1691
- }
1692
-
1693
1357
  // src/react/search-chrome.tsx
1694
- import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
1695
- function SearchSortSelect({
1696
- value,
1697
- onChange,
1698
- sorts,
1699
- className
1700
- }) {
1701
- const options = searchSortOptions(sorts);
1702
- return /* @__PURE__ */ jsxs4("label", { "data-slot": "search-sort", className, children: [
1703
- /* @__PURE__ */ jsx4("span", { "data-slot": "search-label", children: "Ordenar" }),
1704
- /* @__PURE__ */ jsx4(
1705
- "select",
1706
- {
1707
- id: "garagem-search-sort",
1708
- "data-slot": "search-sort-trigger",
1709
- value,
1710
- onChange: (event) => onChange(event.target.value || null),
1711
- children: options.map((sort) => /* @__PURE__ */ jsx4("option", { value: sort.id, children: sort.label }, sort.id || "relevance"))
1712
- }
1713
- )
1714
- ] });
1715
- }
1358
+ import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
1716
1359
  function ResultsSkeleton({
1717
1360
  className
1718
1361
  }) {
1719
- return /* @__PURE__ */ jsxs4(Fragment2, { children: [
1720
- /* @__PURE__ */ jsx4(SearchChromeStyles, {}),
1721
- /* @__PURE__ */ jsx4("div", { "data-slot": "search-skeleton", className, children: Array.from({ length: 6 }, (_, i) => /* @__PURE__ */ jsxs4("div", { "data-slot": "search-skeleton-card", children: [
1722
- /* @__PURE__ */ jsx4("div", { "data-slot": "search-skeleton-block", "data-kind": "media" }),
1723
- /* @__PURE__ */ jsxs4("div", { "data-slot": "search-skeleton-body", children: [
1724
- /* @__PURE__ */ jsx4("div", { "data-slot": "search-skeleton-block", "data-kind": "line-lg" }),
1725
- /* @__PURE__ */ jsx4("div", { "data-slot": "search-skeleton-block", "data-kind": "line-md" }),
1726
- /* @__PURE__ */ jsx4("div", { "data-slot": "search-skeleton-block", "data-kind": "line-sm" })
1362
+ return /* @__PURE__ */ jsxs3(Fragment2, { children: [
1363
+ /* @__PURE__ */ jsx3(SearchChromeStyles, {}),
1364
+ /* @__PURE__ */ jsx3("div", { "data-slot": "search-skeleton", className, children: Array.from({ length: 6 }, (_, i) => /* @__PURE__ */ jsxs3("div", { "data-slot": "search-skeleton-card", children: [
1365
+ /* @__PURE__ */ jsx3("div", { "data-slot": "search-skeleton-block", "data-kind": "media" }),
1366
+ /* @__PURE__ */ jsxs3("div", { "data-slot": "search-skeleton-body", children: [
1367
+ /* @__PURE__ */ jsx3("div", { "data-slot": "search-skeleton-block", "data-kind": "line-lg" }),
1368
+ /* @__PURE__ */ jsx3("div", { "data-slot": "search-skeleton-block", "data-kind": "line-md" }),
1369
+ /* @__PURE__ */ jsx3("div", { "data-slot": "search-skeleton-block", "data-kind": "line-sm" })
1727
1370
  ] })
1728
1371
  ] }, i)) })
1729
1372
  ] });
1730
1373
  }
1731
- function SearchPageFallback({
1732
- className,
1733
- as: Root = "main"
1734
- }) {
1735
- return /* @__PURE__ */ jsx4(Root, { "data-slot": "search-page", children: /* @__PURE__ */ jsx4(ResultsSkeleton, { className }) });
1736
- }
1737
-
1738
- // src/react/search-pagination.tsx
1739
- import Link2 from "next/link";
1740
- import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
1741
- function NavItem({
1742
- href,
1743
- label,
1744
- disabled,
1745
- current,
1746
- onNavigate
1747
- }) {
1748
- if (disabled || !href || current) {
1749
- return /* @__PURE__ */ jsx5(
1750
- "li",
1751
- {
1752
- "data-slot": "search-pagination-item",
1753
- "data-current": current ? "true" : void 0,
1754
- "data-disabled": disabled ? "true" : void 0,
1755
- children: /* @__PURE__ */ jsx5("span", { children: label })
1756
- }
1757
- );
1758
- }
1759
- function handleClick(event) {
1760
- if (!onNavigate || !href) return;
1761
- if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button !== 0) {
1762
- return;
1763
- }
1764
- event.preventDefault();
1765
- onNavigate(href);
1766
- }
1767
- return /* @__PURE__ */ jsx5("li", { "data-slot": "search-pagination-item", children: /* @__PURE__ */ jsx5(Link2, { href, onClick: handleClick, "aria-label": label, children: label }) });
1768
- }
1769
- function SearchPagination({
1770
- page,
1771
- totalPages,
1772
- hrefForPage,
1773
- onNavigate,
1774
- className
1775
- }) {
1776
- if (totalPages <= 1) return null;
1777
- const pages = paginationPages(page, totalPages, 2);
1778
- return /* @__PURE__ */ jsx5(
1779
- "nav",
1780
- {
1781
- "data-slot": "search-pagination",
1782
- className,
1783
- "aria-label": "Pagina\xE7\xE3o",
1784
- children: /* @__PURE__ */ jsxs5("ul", { children: [
1785
- /* @__PURE__ */ jsx5(
1786
- NavItem,
1787
- {
1788
- href: hrefWithExplicitPage(hrefForPage(1), 1),
1789
- label: "\u2039\u2039",
1790
- disabled: page <= 1,
1791
- onNavigate
1792
- }
1793
- ),
1794
- /* @__PURE__ */ jsx5(
1795
- NavItem,
1796
- {
1797
- href: hrefWithExplicitPage(
1798
- hrefForPage(Math.max(1, page - 1)),
1799
- Math.max(1, page - 1)
1800
- ),
1801
- label: "\u2039",
1802
- disabled: page <= 1,
1803
- onNavigate
1804
- }
1805
- ),
1806
- pages.map((n) => /* @__PURE__ */ jsx5(
1807
- NavItem,
1808
- {
1809
- href: hrefWithExplicitPage(hrefForPage(n), n),
1810
- label: String(n),
1811
- current: n === page,
1812
- onNavigate
1813
- },
1814
- n
1815
- )),
1816
- /* @__PURE__ */ jsx5(
1817
- NavItem,
1818
- {
1819
- href: hrefForPage(Math.min(totalPages, page + 1)),
1820
- label: "\u203A",
1821
- disabled: page >= totalPages,
1822
- onNavigate
1823
- }
1824
- ),
1825
- /* @__PURE__ */ jsx5(
1826
- NavItem,
1827
- {
1828
- href: hrefForPage(totalPages),
1829
- label: "\u203A\u203A",
1830
- disabled: page >= totalPages,
1831
- onNavigate
1832
- }
1833
- )
1834
- ] })
1835
- }
1836
- );
1837
- }
1838
-
1839
- // src/react/icons.tsx
1840
- import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
1841
- function Icon({ children, ...props }) {
1842
- return /* @__PURE__ */ jsx6(
1843
- "svg",
1844
- {
1845
- viewBox: "0 0 24 24",
1846
- fill: "none",
1847
- stroke: "currentColor",
1848
- strokeWidth: 2,
1849
- strokeLinecap: "round",
1850
- strokeLinejoin: "round",
1851
- "aria-hidden": true,
1852
- "data-slot": "search-icon",
1853
- ...props,
1854
- children
1855
- }
1856
- );
1857
- }
1858
- function SearchLensIcon(props) {
1859
- return /* @__PURE__ */ jsxs6(Icon, { ...props, children: [
1860
- /* @__PURE__ */ jsx6("circle", { cx: "11", cy: "11", r: "7" }),
1861
- /* @__PURE__ */ jsx6("path", { d: "M20 20l-3.5-3.5" })
1862
- ] });
1863
- }
1864
- function SearchClearIcon(props) {
1865
- return /* @__PURE__ */ jsx6(Icon, { ...props, children: /* @__PURE__ */ jsx6("path", { d: "M6 6l12 12M18 6L6 18" }) });
1866
- }
1867
-
1868
- // src/react/search-query-form.tsx
1869
- import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
1870
- function SearchQueryForm({
1871
- value,
1872
- onChange,
1873
- onSubmit,
1874
- onClear,
1875
- className,
1876
- iconClassName,
1877
- searchIcon,
1878
- clearIcon
1879
- }) {
1880
- function handleSubmit(event) {
1881
- event.preventDefault();
1882
- onSubmit();
1883
- }
1884
- return /* @__PURE__ */ jsxs7(
1885
- "form",
1886
- {
1887
- role: "search",
1888
- "data-slot": "search-query",
1889
- onSubmit: handleSubmit,
1890
- className,
1891
- children: [
1892
- /* @__PURE__ */ jsx7("label", { htmlFor: "garagem-search-q", "data-slot": "search-label", children: "Busca" }),
1893
- /* @__PURE__ */ jsxs7("div", { "data-slot": "search-query-field", children: [
1894
- /* @__PURE__ */ jsx7(
1895
- "input",
1896
- {
1897
- id: "garagem-search-q",
1898
- name: "q",
1899
- type: "text",
1900
- inputMode: "search",
1901
- autoComplete: "off",
1902
- enterKeyHint: "search",
1903
- value,
1904
- onChange: (event) => onChange(event.target.value),
1905
- placeholder: "Busque por bairro, rua ou c\xF3digo",
1906
- "data-slot": "search-query-input"
1907
- }
1908
- ),
1909
- /* @__PURE__ */ jsxs7("div", { "data-slot": "search-query-actions", children: [
1910
- value ? /* @__PURE__ */ jsx7(
1911
- "button",
1912
- {
1913
- type: "button",
1914
- title: "Limpar busca",
1915
- "aria-label": "Limpar busca",
1916
- onClick: onClear,
1917
- "data-slot": "search-icon-button",
1918
- "data-kind": "clear",
1919
- children: clearIcon ?? /* @__PURE__ */ jsx7(SearchClearIcon, { className: iconClassName })
1920
- }
1921
- ) : null,
1922
- /* @__PURE__ */ jsx7(
1923
- "button",
1924
- {
1925
- type: "submit",
1926
- title: "Buscar",
1927
- "aria-label": "Buscar",
1928
- "data-slot": "search-icon-button",
1929
- children: searchIcon ?? /* @__PURE__ */ jsx7(SearchLensIcon, { className: iconClassName })
1930
- }
1931
- )
1932
- ] })
1933
- ] })
1934
- ]
1935
- }
1936
- );
1937
- }
1938
1374
 
1939
1375
  // src/react/use-public-search.ts
1940
1376
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
@@ -2264,391 +1700,11 @@ function usePublicSearch(options) {
2264
1700
  locationNames
2265
1701
  };
2266
1702
  }
2267
-
2268
- // src/react/search-page.tsx
2269
- import { Fragment as Fragment3, jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
2270
- var SEARCH_EMPTY_COPY = "Nenhum im\xF3vel encontrado. Ajuste a busca ou os filtros.";
2271
- function ToolbarPopover({
2272
- id,
2273
- label,
2274
- open,
2275
- onOpenChange,
2276
- triggerClassName,
2277
- popoverClassName,
2278
- children
2279
- }) {
2280
- const rootRef = useRef2(null);
2281
- useEffect2(() => {
2282
- if (!open) return;
2283
- function onPointer(event) {
2284
- if (!rootRef.current?.contains(event.target)) {
2285
- onOpenChange(null);
2286
- }
2287
- }
2288
- function onKey(event) {
2289
- if (event.key === "Escape") onOpenChange(null);
2290
- }
2291
- document.addEventListener("mousedown", onPointer);
2292
- document.addEventListener("keydown", onKey);
2293
- return () => {
2294
- document.removeEventListener("mousedown", onPointer);
2295
- document.removeEventListener("keydown", onKey);
2296
- };
2297
- }, [open, onOpenChange]);
2298
- return /* @__PURE__ */ jsxs8("div", { "data-slot": "search-toolbar-item", ref: rootRef, children: [
2299
- /* @__PURE__ */ jsx8(
2300
- "button",
2301
- {
2302
- type: "button",
2303
- "data-slot": "search-toolbar-trigger",
2304
- className: triggerClassName,
2305
- "aria-expanded": open,
2306
- onClick: () => onOpenChange(open ? null : id),
2307
- children: label
2308
- }
2309
- ),
2310
- open ? /* @__PURE__ */ jsx8(
2311
- "div",
2312
- {
2313
- "data-slot": "search-popover",
2314
- className: popoverClassName,
2315
- role: "dialog",
2316
- children
2317
- }
2318
- ) : null
2319
- ] });
2320
- }
2321
- function FiltersTrigger({
2322
- onClick,
2323
- className
2324
- }) {
2325
- return /* @__PURE__ */ jsx8(
2326
- "button",
2327
- {
2328
- type: "button",
2329
- title: "Filtros",
2330
- "data-slot": "search-filters-trigger",
2331
- onClick,
2332
- className,
2333
- children: "Filtros"
2334
- }
2335
- );
2336
- }
2337
- function ApplyBar({
2338
- onClear,
2339
- onApply,
2340
- className
2341
- }) {
2342
- return /* @__PURE__ */ jsxs8("div", { "data-slot": "search-apply-bar", className, children: [
2343
- /* @__PURE__ */ jsx8("button", { type: "button", "data-kind": "clear", onClick: onClear, children: "Limpar" }),
2344
- /* @__PURE__ */ jsx8("button", { type: "button", "data-kind": "apply", onClick: onApply, children: "Ver resultados" })
2345
- ] });
2346
- }
2347
- function FilterSheet({
2348
- open,
2349
- title,
2350
- onClose,
2351
- overlayClassName,
2352
- panelClassName,
2353
- children,
2354
- footer
2355
- }) {
2356
- const onCloseRef = useRef2(onClose);
2357
- onCloseRef.current = onClose;
2358
- useEffect2(() => {
2359
- if (!open) return;
2360
- function onKey(event) {
2361
- if (event.key === "Escape") onCloseRef.current();
2362
- }
2363
- document.addEventListener("keydown", onKey);
2364
- const previous = document.body.style.overflow;
2365
- document.body.style.overflow = "hidden";
2366
- return () => {
2367
- document.removeEventListener("keydown", onKey);
2368
- document.body.style.overflow = previous;
2369
- };
2370
- }, [open]);
2371
- if (!open) return null;
2372
- return /* @__PURE__ */ jsxs8("div", { "data-slot": "search-sheet", children: [
2373
- /* @__PURE__ */ jsx8(
2374
- "button",
2375
- {
2376
- type: "button",
2377
- "aria-label": "Fechar filtros",
2378
- "data-slot": "search-sheet-overlay",
2379
- className: overlayClassName,
2380
- onClick: onClose
2381
- }
2382
- ),
2383
- /* @__PURE__ */ jsxs8(
2384
- "div",
2385
- {
2386
- "data-slot": "search-sheet-panel",
2387
- className: panelClassName,
2388
- role: "dialog",
2389
- "aria-modal": "true",
2390
- "aria-label": title,
2391
- children: [
2392
- /* @__PURE__ */ jsx8("p", { "data-slot": "search-sheet-title", children: title }),
2393
- /* @__PURE__ */ jsx8("div", { "data-slot": "search-sheet-body", children }),
2394
- /* @__PURE__ */ jsx8("div", { "data-slot": "search-sheet-footer", children: footer })
2395
- ]
2396
- }
2397
- )
2398
- ] });
2399
- }
2400
- function SearchHeading({
2401
- total,
2402
- title,
2403
- classNames,
2404
- loading
2405
- }) {
2406
- return /* @__PURE__ */ jsxs8("div", { "data-slot": "search-heading", className: classNames?.heading, children: [
2407
- !loading ? /* @__PURE__ */ jsx8(
2408
- "span",
2409
- {
2410
- "data-slot": "search-heading-count",
2411
- className: classNames?.headingCount,
2412
- children: total.toLocaleString("pt-BR")
2413
- }
2414
- ) : null,
2415
- /* @__PURE__ */ jsx8("h1", { "data-slot": "search-heading-title", className: classNames?.headingTitle, children: title })
2416
- ] });
2417
- }
2418
- function SearchPage({
2419
- siteId,
2420
- baseUrl,
2421
- variant = "toolbar",
2422
- as: Root = "main",
2423
- className,
2424
- classNames,
2425
- heading,
2426
- icons,
2427
- listingCard: Card = ListingCard
2428
- }) {
2429
- const search = usePublicSearch({ siteId, baseUrl });
2430
- const [sheetOpen, setSheetOpen] = useState2(false);
2431
- const [openToolbar, setOpenToolbar] = useState2(null);
2432
- const [rangeDraft, setRangeDraft] = useState2(
2433
- () => rangeDraftFromPath(search.pathFilters)
2434
- );
2435
- useEffect2(() => {
2436
- setRangeDraft(rangeDraftFromPath(search.pathFilters));
2437
- }, [search.pathFilters]);
2438
- const filters = visibleSearchFilters(search.schema);
2439
- const toolbarIds = new Set(toolbarFilterIds(search.schema));
2440
- const toolbarFilters = filters.filter((filter) => toolbarIds.has(filter.id));
2441
- const extraFilters = filters.filter((filter) => !toolbarIds.has(filter.id));
2442
- const headingTitle = searchResultsHeading(
2443
- search.pathFilters,
2444
- search.schema?.dictionary,
2445
- search.locationNames
2446
- );
2447
- function patchRange(filterId, side, value) {
2448
- setRangeDraft((prev) => ({
2449
- ...prev,
2450
- [filterId]: {
2451
- min: prev[filterId]?.min ?? "",
2452
- max: prev[filterId]?.max ?? "",
2453
- [side]: value
2454
- }
2455
- }));
2456
- }
2457
- function commitRange(filterId, immediate) {
2458
- const draft = rangeDraft[filterId] || { min: "", max: "" };
2459
- if (immediate) search.applyFilter(filterId, draft);
2460
- else search.stageFilter(filterId, draft);
2461
- }
2462
- function openStagedFilters() {
2463
- search.resetStagedFromUrl();
2464
- setRangeDraft(rangeDraftFromPath(search.pathFilters));
2465
- setOpenToolbar(null);
2466
- setSheetOpen(true);
2467
- }
2468
- const closeSheet = useCallback2(() => {
2469
- setSheetOpen(false);
2470
- }, []);
2471
- function clearStagedFilters() {
2472
- const keepIds = variant === "toolbar" ? [...toolbarIds] : [];
2473
- const source = variant === "toolbar" ? search.pathFilters : search.staged;
2474
- const next = clearStagedPathFilters(source, keepIds);
2475
- search.setStaged(next);
2476
- setRangeDraft((prev) => {
2477
- const cleared = rangeDraftFromPath(next);
2478
- if (variant !== "toolbar") return cleared;
2479
- const kept = { ...cleared };
2480
- for (const id of keepIds) {
2481
- if (prev[id]) kept[id] = prev[id];
2482
- }
2483
- return kept;
2484
- });
2485
- }
2486
- function applyStagedAndClose() {
2487
- search.applyStaged();
2488
- closeSheet();
2489
- }
2490
- const results = search.loading ? /* @__PURE__ */ jsx8(ResultsSkeleton, { className: classNames?.skeleton ?? classNames?.grid }) : search.listings.length === 0 ? /* @__PURE__ */ jsx8("p", { "data-slot": "search-empty", className: classNames?.empty, children: SEARCH_EMPTY_COPY }) : /* @__PURE__ */ jsxs8(Fragment3, { children: [
2491
- /* @__PURE__ */ jsx8("div", { "data-slot": "search-grid", className: classNames?.grid, children: search.listings.map((listing) => /* @__PURE__ */ jsx8(
2492
- Card,
2493
- {
2494
- listing,
2495
- className: classNames?.card
2496
- },
2497
- listing.id
2498
- )) }),
2499
- /* @__PURE__ */ jsx8(
2500
- SearchPagination,
2501
- {
2502
- page: search.page,
2503
- totalPages: search.totalPages,
2504
- hrefForPage: search.hrefForPage,
2505
- onNavigate: search.go,
2506
- className: classNames?.pagination
2507
- }
2508
- )
2509
- ] });
2510
- const queryAndSort = /* @__PURE__ */ jsxs8("div", { "data-slot": "search-query-sort", children: [
2511
- /* @__PURE__ */ jsx8(
2512
- SearchQueryForm,
2513
- {
2514
- value: search.qDraft,
2515
- onChange: search.setQDraft,
2516
- onSubmit: search.submitQuery,
2517
- onClear: search.clearQuery,
2518
- className: classNames?.query,
2519
- iconClassName: classNames?.icon,
2520
- searchIcon: icons?.search,
2521
- clearIcon: icons?.clear
2522
- }
2523
- ),
2524
- /* @__PURE__ */ jsx8(
2525
- SearchSortSelect,
2526
- {
2527
- value: search.applied.sort || "",
2528
- onChange: search.setSort,
2529
- sorts: search.schema?.sorts,
2530
- className: classNames?.sort
2531
- }
2532
- )
2533
- ] });
2534
- const header = heading ?? /* @__PURE__ */ jsx8(
2535
- SearchHeading,
2536
- {
2537
- total: search.total,
2538
- title: headingTitle,
2539
- classNames,
2540
- loading: search.loading
2541
- }
2542
- );
2543
- const stagedPanel = (items) => /* @__PURE__ */ jsx8(
2544
- FilterPanel,
2545
- {
2546
- filters: items,
2547
- pathFilters: search.staged,
2548
- onChange: search.stageFilter,
2549
- rangeDraft,
2550
- onRangePatch: patchRange,
2551
- onRangeCommit: (id) => commitRange(id, false)
2552
- }
2553
- );
2554
- const sheet = /* @__PURE__ */ jsx8(
2555
- FilterSheet,
2556
- {
2557
- open: sheetOpen,
2558
- title: "Filtros",
2559
- onClose: closeSheet,
2560
- overlayClassName: classNames?.dialogOverlay,
2561
- panelClassName: cn(classNames?.dialog, classNames?.dialogPanel),
2562
- footer: /* @__PURE__ */ jsx8(
2563
- ApplyBar,
2564
- {
2565
- onClear: clearStagedFilters,
2566
- onApply: applyStagedAndClose,
2567
- className: classNames?.applyBar
2568
- }
2569
- ),
2570
- children: stagedPanel(variant === "toolbar" ? extraFilters : filters)
2571
- }
2572
- );
2573
- return /* @__PURE__ */ jsxs8(
2574
- Root,
2575
- {
2576
- "data-slot": "search-page",
2577
- "data-variant": variant,
2578
- className: cn(className, classNames?.root),
2579
- children: [
2580
- /* @__PURE__ */ jsx8(SearchChromeStyles, {}),
2581
- /* @__PURE__ */ jsx8("div", { className: classNames?.header, children: header }),
2582
- /* @__PURE__ */ jsxs8("div", { "data-slot": "search-body", children: [
2583
- queryAndSort,
2584
- variant === "toolbar" ? /* @__PURE__ */ jsxs8("div", { "data-slot": "search-toolbar", className: classNames?.toolbar, children: [
2585
- toolbarFilters.map((filter) => /* @__PURE__ */ jsx8(
2586
- ToolbarPopover,
2587
- {
2588
- id: filter.id,
2589
- label: filter.label,
2590
- open: openToolbar === filter.id,
2591
- onOpenChange: setOpenToolbar,
2592
- triggerClassName: classNames?.toolbarTrigger,
2593
- popoverClassName: classNames?.popover,
2594
- children: /* @__PURE__ */ jsx8(
2595
- FilterPanel,
2596
- {
2597
- filters: [filter],
2598
- pathFilters: search.pathFilters,
2599
- onChange: (id, value) => {
2600
- search.applyFilter(id, value);
2601
- if (filter.type !== "range") setOpenToolbar(null);
2602
- },
2603
- rangeDraft,
2604
- onRangePatch: patchRange,
2605
- onRangeCommit: (id, source) => {
2606
- commitRange(id, true);
2607
- if (source === "apply") setOpenToolbar(null);
2608
- }
2609
- }
2610
- )
2611
- },
2612
- filter.id
2613
- )),
2614
- extraFilters.length > 0 ? /* @__PURE__ */ jsx8(FiltersTrigger, { onClick: openStagedFilters }) : null
2615
- ] }) : null,
2616
- variant === "dialog" ? /* @__PURE__ */ jsx8(FiltersTrigger, { onClick: openStagedFilters }) : null,
2617
- variant === "sidebar" ? /* @__PURE__ */ jsxs8("div", { "data-slot": "search-layout", children: [
2618
- /* @__PURE__ */ jsxs8("aside", { "data-slot": "search-sidebar", className: classNames?.sidebar, children: [
2619
- stagedPanel(filters),
2620
- /* @__PURE__ */ jsx8(
2621
- ApplyBar,
2622
- {
2623
- onClear: clearStagedFilters,
2624
- onApply: search.applyStaged,
2625
- className: classNames?.applyBar
2626
- }
2627
- )
2628
- ] }),
2629
- /* @__PURE__ */ jsxs8("div", { children: [
2630
- /* @__PURE__ */ jsx8(FiltersTrigger, { onClick: openStagedFilters }),
2631
- results
2632
- ] })
2633
- ] }) : results
2634
- ] }),
2635
- sheet
2636
- ]
2637
- }
2638
- );
2639
- }
2640
1703
  export {
2641
- FilterPanel,
2642
1704
  ListingCard,
2643
1705
  ListingDetailFields,
2644
1706
  ResultsSkeleton,
2645
1707
  SearchChromeStyles,
2646
- SearchPage,
2647
- SearchPageFallback,
2648
- SearchPagination,
2649
- SearchQueryForm,
2650
- SearchSortSelect,
2651
- rangeDraftFromPath,
2652
1708
  usePublicSearch
2653
1709
  };
2654
1710
  //# sourceMappingURL=react.mjs.map