@meetelise/chat 1.64.0 → 1.66.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.
@@ -0,0 +1,657 @@
1
+ import { css, html, LitElement, TemplateResult } from "lit";
2
+ import { customElement, property, state } from "lit/decorators.js";
3
+ import { classMap } from "lit/directives/class-map.js";
4
+ import "../actions/action-confirm-button";
5
+ import "../shared/simple-tooltip";
6
+ import { tourSchedulerStyles } from "../Scheduler/tourSchedulerStyles";
7
+ import { InputStyles } from "../actions/InputStyles";
8
+ import floorplanImageCardStyles from "../FeeCalculator/components/floorplan-image-card/floorplan-image-card-styles";
9
+ import floorPlanSelectorStyles from "../FeeCalculator/components/floor-plan-selector/floor-plan-selector-styles";
10
+ import { BuildingIcon } from "../icons/BuildingIcon";
11
+ import { XOutlineIcon } from "../icons/XOutlineIcon";
12
+ import {
13
+ CommunitiesResponse,
14
+ Community,
15
+ CommunityFilters,
16
+ CommunitySummary,
17
+ formatAddress,
18
+ toCommunitySummary,
19
+ } from "./tourItineraryApi";
20
+ import { formatHourMinute, formatShortDate } from "./tourTimes";
21
+ import { formatCurrency } from "../../utils";
22
+
23
+ export type CommunityLoader = (
24
+ filters: CommunityFilters
25
+ ) => Promise<CommunitiesResponse>;
26
+
27
+ const EMPTY_FILTERS: CommunityFilters = {
28
+ bedrooms: [],
29
+ moveIn: null,
30
+ maxBudget: null,
31
+ };
32
+
33
+ const BEDROOM_OPTIONS = [
34
+ { value: 0, label: "Studio" },
35
+ { value: 1, label: "1 bd" },
36
+ { value: 2, label: "2 bd" },
37
+ { value: 3, label: "3+ bd" },
38
+ ];
39
+
40
+ type FilterId = "bedrooms" | "moveIn" | "budget";
41
+
42
+ const FILTER_IDS: FilterId[] = ["bedrooms", "moveIn", "budget"];
43
+
44
+ /**
45
+ * Lists a central group's top communities so the prospect can pick up to the
46
+ * number of stops left. In the "extend" variant it offers more communities
47
+ * after a booking. Ranking and every reason come from the server. The cards and
48
+ * badges are the fee calculator's. The scheduler holds the picks and shows them,
49
+ * with Continue, in its footer (`renderSelectionTray`).
50
+ */
51
+ @customElement("community-picker")
52
+ export class CommunityPicker extends LitElement {
53
+ @property({ type: String })
54
+ variant: "select" | "extend" = "select";
55
+
56
+ @property({ attribute: false })
57
+ load: CommunityLoader | null = null;
58
+
59
+ /** The first, unfiltered page, when the scheduler already has it. */
60
+ @property({ attribute: false })
61
+ initial: CommunitiesResponse | null = null;
62
+
63
+ /** The picks so far; a click asks for a change with `selection-change`. */
64
+ @property({ attribute: false })
65
+ selected: CommunitySummary[] = [];
66
+
67
+ /** How many communities may be picked: the stops left in the itinerary. */
68
+ @property({ type: Number })
69
+ maxSelectable = 0;
70
+
71
+ @state() private filters: CommunityFilters = EMPTY_FILTERS;
72
+ @state() private openFilter: FilterId | null = null;
73
+ @state() private communities: Community[] = [];
74
+ @state() private loading = false;
75
+ @state() private error: string | null = null;
76
+
77
+ private requestId = 0;
78
+
79
+ willUpdate(): void {
80
+ // Show the page the scheduler already has from the first paint.
81
+ if (!this.hasUpdated && this.initial) {
82
+ this.communities = this.initial.communities;
83
+ }
84
+ }
85
+
86
+ firstUpdated(): void {
87
+ if (!this.initial) void this.reload();
88
+ }
89
+
90
+ private async reload(): Promise<void> {
91
+ if (!this.load) return;
92
+ const id = ++this.requestId;
93
+ this.loading = true;
94
+ this.error = null;
95
+ try {
96
+ const response = await this.load(this.filters);
97
+ if (id !== this.requestId) return;
98
+ this.communities = response.communities;
99
+ } catch (e) {
100
+ if (id !== this.requestId) return;
101
+ this.error = (e as Error).message;
102
+ } finally {
103
+ if (id === this.requestId) this.loading = false;
104
+ }
105
+ }
106
+
107
+ private setFilters(next: Partial<CommunityFilters>): void {
108
+ this.filters = { ...this.filters, ...next };
109
+ void this.reload();
110
+ }
111
+
112
+ private isSelected(id: number): boolean {
113
+ return this.selected.some((s) => s.building_id === id);
114
+ }
115
+
116
+ private toggle(community: Community): void {
117
+ if (!community.tourable) return;
118
+ if (this.isSelected(community.building_id)) {
119
+ this.emitSelection(
120
+ this.selected.filter((s) => s.building_id !== community.building_id)
121
+ );
122
+ } else if (this.selected.length < this.maxSelectable) {
123
+ this.emitSelection([...this.selected, toCommunitySummary(community)]);
124
+ }
125
+ }
126
+
127
+ private emitSelection(communities: CommunitySummary[]): void {
128
+ this.dispatchEvent(
129
+ new CustomEvent("selection-change", {
130
+ detail: { communities },
131
+ bubbles: true,
132
+ composed: true,
133
+ })
134
+ );
135
+ }
136
+
137
+ private heading(): string {
138
+ if (this.variant === "extend") {
139
+ return "Add Nearby Communities to Your Tour";
140
+ }
141
+ return this.maxSelectable > 1
142
+ ? `Select Up to ${this.maxSelectable} Communities to Tour`
143
+ : "Select a Community to Tour";
144
+ }
145
+
146
+ private isFilterActive(id: FilterId): boolean {
147
+ const f = this.filters;
148
+ if (id === "bedrooms") return f.bedrooms.length > 0;
149
+ if (id === "moveIn") return !!f.moveIn;
150
+ return f.maxBudget !== null;
151
+ }
152
+
153
+ /** The chip's name, or the value picked once there is one. */
154
+ private filterLabel(id: FilterId): string {
155
+ const f = this.filters;
156
+ if (id === "bedrooms") {
157
+ return f.bedrooms.length
158
+ ? BEDROOM_OPTIONS.filter((o) => f.bedrooms.includes(o.value))
159
+ .map((o) => o.label)
160
+ .join(", ")
161
+ : "Bedrooms";
162
+ }
163
+ if (id === "moveIn") {
164
+ return f.moveIn ? `Move-in ${formatShortDate(f.moveIn)}` : "Move-In Date";
165
+ }
166
+ return f.maxBudget !== null
167
+ ? `Up to ${formatCurrency(f.maxBudget)}`
168
+ : "Budget";
169
+ }
170
+
171
+ private renderFilters(): TemplateResult {
172
+ const f = this.filters;
173
+ const open = this.openFilter;
174
+ return html`<div class="picker-toolbar" role="group" aria-label="Filters">
175
+ ${FILTER_IDS.map(
176
+ (id) => html`<button
177
+ class=${classMap({
178
+ "floor-plan-badge": true,
179
+ selected: this.isFilterActive(id),
180
+ })}
181
+ aria-expanded=${String(open === id)}
182
+ aria-controls="picker-filters"
183
+ @click=${() => (this.openFilter = open === id ? null : id)}
184
+ >
185
+ ${this.filterLabel(id)}
186
+ </button>`
187
+ )}
188
+ ${FILTER_IDS.some((id) => this.isFilterActive(id))
189
+ ? html`<button
190
+ class="clear-filters"
191
+ @click=${() => {
192
+ this.openFilter = null;
193
+ this.setFilters(EMPTY_FILTERS);
194
+ }}
195
+ >
196
+ Clear all
197
+ </button>`
198
+ : ""}
199
+ </div>
200
+ <div
201
+ id="picker-filters"
202
+ class=${classMap({ "advanced-section": true, open: open !== null })}
203
+ >
204
+ <div
205
+ class="floor-plan-selector-badges"
206
+ role="group"
207
+ aria-label="Bedrooms"
208
+ ?hidden=${open !== "bedrooms"}
209
+ >
210
+ ${BEDROOM_OPTIONS.map(
211
+ (o) => html`<button
212
+ class=${classMap({
213
+ "floor-plan-badge": true,
214
+ selected: f.bedrooms.includes(o.value),
215
+ })}
216
+ aria-pressed=${String(f.bedrooms.includes(o.value))}
217
+ @click=${() =>
218
+ this.setFilters({
219
+ bedrooms: f.bedrooms.includes(o.value)
220
+ ? f.bedrooms.filter((b) => b !== o.value)
221
+ : [...f.bedrooms, o.value].sort(),
222
+ })}
223
+ >
224
+ ${o.label}
225
+ </button>`
226
+ )}
227
+ </div>
228
+ <div class="date-field" ?hidden=${open !== "moveIn"}>
229
+ <label for="move-in">Move-in date</label>
230
+ <input
231
+ id="move-in"
232
+ type="date"
233
+ .value=${f.moveIn ?? ""}
234
+ @change=${(e: Event) =>
235
+ this.setFilters({
236
+ moveIn: (e.target as HTMLInputElement).value || null,
237
+ })}
238
+ />
239
+ </div>
240
+ <div class="date-field" ?hidden=${open !== "budget"}>
241
+ <label for="max-budget">Max monthly rent ($)</label>
242
+ <input
243
+ id="max-budget"
244
+ type="number"
245
+ inputmode="numeric"
246
+ min="0"
247
+ step="50"
248
+ .value=${f.maxBudget === null ? "" : String(f.maxBudget)}
249
+ @change=${(e: Event) => {
250
+ const value = parseInt((e.target as HTMLInputElement).value, 10);
251
+ this.setFilters({
252
+ maxBudget: Number.isFinite(value) && value > 0 ? value : null,
253
+ });
254
+ }}
255
+ />
256
+ </div>
257
+ </div>`;
258
+ }
259
+
260
+ private renderCard(c: Community): TemplateResult {
261
+ const selected = this.isSelected(c.building_id);
262
+ const full = !selected && this.selected.length >= this.maxSelectable;
263
+ const next = c.next_available;
264
+ // Extension times are all on the day already booked.
265
+ const sameDay = !!next && this.variant === "extend";
266
+ const price = c.price_from
267
+ ? `${
268
+ c.price_from.bedrooms === 0 ? "Studio" : `${c.price_from.bedrooms} BR`
269
+ } from ${formatCurrency(c.price_from.amount)}`
270
+ : "";
271
+ const card = html`<button
272
+ class=${classMap({
273
+ "floorplan-image-card": true,
274
+ selected,
275
+ disabled: !c.tourable || full,
276
+ })}
277
+ aria-pressed=${String(selected)}
278
+ aria-disabled=${String(!c.tourable || full)}
279
+ @click=${() => this.toggle(c)}
280
+ >
281
+ ${c.image_url
282
+ ? html`<span class="section-left"
283
+ ><img src=${c.image_url} alt=""
284
+ /></span>`
285
+ : ""}
286
+ <span class="section-right">
287
+ ${c.best_match || price || c.distance_mi !== null
288
+ ? html`<span class="card-tags">
289
+ ${c.best_match
290
+ ? html`<span class="floor-plan-badge">Best match</span>`
291
+ : ""}
292
+ ${price
293
+ ? html`<span class="floor-plan-badge">${price}</span>`
294
+ : ""}
295
+ ${c.distance_mi !== null
296
+ ? html`<span class="distance"
297
+ >${c.distance_mi.toFixed(1)} mi</span
298
+ >`
299
+ : ""}
300
+ </span>`
301
+ : ""}
302
+ <span class="image-card-title">${c.name}</span>
303
+ <span class="image-card-subtitle">${formatAddress(c.address)}</span>
304
+ ${!c.tourable
305
+ ? html`<span class="image-card-subtitle"
306
+ >${c.unavailable_reason ?? ""}</span
307
+ >`
308
+ : next
309
+ ? html`<span class="next-available"
310
+ >Next available:
311
+ ${formatShortDate(next.date)}${this.variant === "extend"
312
+ ? ` · ${formatHourMinute(next.time)}`
313
+ : ""}</span
314
+ >`
315
+ : ""}
316
+ ${sameDay ? html`<span class="same-day">Same day</span>` : ""}
317
+ </span>
318
+ </button>`;
319
+ return html`<li>
320
+ ${full && c.tourable
321
+ ? html`<simple-tooltip
322
+ tooltip=${`You can choose up to ${this.maxSelectable}`}
323
+ >${card}</simple-tooltip
324
+ >`
325
+ : card}
326
+ </li>`;
327
+ }
328
+
329
+ private renderList(): TemplateResult {
330
+ if (this.loading && this.communities.length === 0) {
331
+ return html`<div class="community-grid" role="status">
332
+ <span class="sr-only">Loading communities</span>
333
+ ${[0, 1, 2, 3].map(
334
+ () => html`<div class="unit-card-skeleton shimmer"></div>`
335
+ )}
336
+ </div>`;
337
+ }
338
+ if (this.error) {
339
+ return html`<p class="error-message" role="alert">${this.error}</p>
340
+ <action-confirm-button
341
+ text="Try again"
342
+ height="40px"
343
+ .onClick=${() => this.reload()}
344
+ ></action-confirm-button>`;
345
+ }
346
+ if (this.communities.length === 0) {
347
+ return html`<p class="explanation" role="status">
348
+ No communities match these filters.
349
+ </p>`;
350
+ }
351
+ return html`<ul
352
+ class=${classMap({ "community-grid": true, refreshing: this.loading })}
353
+ aria-busy=${String(this.loading)}
354
+ >
355
+ ${this.communities.map((c) => this.renderCard(c))}
356
+ </ul>`;
357
+ }
358
+
359
+ render(): TemplateResult {
360
+ return html`<div class=${classMap({ extend: this.variant === "extend" })}>
361
+ <div class="picker-heading">
362
+ ${BuildingIcon()}
363
+ <h2>${this.heading()}</h2>
364
+ </div>
365
+ ${this.renderFilters()}
366
+ <span class="sr-only" role="status" aria-live="polite">
367
+ ${this.loading
368
+ ? "Loading communities"
369
+ : `${this.communities.length} communities`}
370
+ </span>
371
+ ${this.renderList()}
372
+ </div>`;
373
+ }
374
+
375
+ static styles = [
376
+ tourSchedulerStyles,
377
+ InputStyles,
378
+ floorPlanSelectorStyles,
379
+ floorplanImageCardStyles,
380
+ css`
381
+ /* New layout only: the filter chips and the card grid. */
382
+ :host {
383
+ display: block;
384
+ }
385
+
386
+ .picker-heading {
387
+ align-items: center;
388
+ display: flex;
389
+ flex-direction: column;
390
+ gap: 8px;
391
+ margin-bottom: 16px;
392
+ text-align: center;
393
+ }
394
+
395
+ .picker-heading h2 {
396
+ font-size: 20px;
397
+ font-weight: 400;
398
+ margin: 0;
399
+ }
400
+
401
+ .picker-toolbar {
402
+ align-items: center;
403
+ display: flex;
404
+ flex-wrap: wrap;
405
+ gap: 8px;
406
+ justify-content: center;
407
+ margin-bottom: 16px;
408
+ }
409
+
410
+ .picker-toolbar .floor-plan-badge:not(.selected) {
411
+ background: #ffffff;
412
+ border-color: #e7e7e7;
413
+ }
414
+
415
+ .picker-toolbar .floor-plan-badge:not(.selected):hover {
416
+ background: #f8f9fa;
417
+ }
418
+
419
+ .clear-filters {
420
+ background: none;
421
+ border: none;
422
+ color: #737373;
423
+ cursor: pointer;
424
+ font: inherit;
425
+ font-size: 0.9rem;
426
+ text-decoration: underline;
427
+ }
428
+
429
+ #picker-filters [hidden] {
430
+ display: none;
431
+ }
432
+
433
+ #picker-filters .floor-plan-selector-badges {
434
+ justify-content: center;
435
+ margin-bottom: 12px;
436
+ }
437
+
438
+ #picker-filters .date-field {
439
+ margin: 0 auto 12px;
440
+ max-width: 16rem;
441
+ }
442
+
443
+ .floor-plan-selector-badges {
444
+ list-style: none;
445
+ margin-top: 4px;
446
+ max-width: none;
447
+ padding: 0;
448
+ }
449
+
450
+ .community-grid {
451
+ display: grid;
452
+ gap: 12px;
453
+ grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
454
+ list-style: none;
455
+ margin: 0 auto;
456
+ max-width: 60rem;
457
+ padding: 0;
458
+ }
459
+
460
+ .community-grid.refreshing {
461
+ opacity: 0.6;
462
+ }
463
+
464
+ /* White and outlined, as in the Central Agent design; the ring adds no width. */
465
+ button.floorplan-image-card {
466
+ background: #ffffff;
467
+ border: 1px solid #e7e7e7;
468
+ border-radius: 8px;
469
+ color: inherit;
470
+ cursor: pointer;
471
+ font: inherit;
472
+ height: 100%;
473
+ padding: 12px 14px;
474
+ text-align: left;
475
+ transition: border-color 0.1s ease-in-out, box-shadow 0.1s ease-in-out;
476
+ }
477
+
478
+ button.floorplan-image-card:not(.disabled):hover {
479
+ border-color: #c4c4c4;
480
+ }
481
+
482
+ button.floorplan-image-card.selected,
483
+ button.floorplan-image-card.selected:hover {
484
+ background: color-mix(
485
+ in srgb,
486
+ var(--primary-color, #646987) 4%,
487
+ #ffffff
488
+ );
489
+ border-color: var(--primary-color, #646987);
490
+ box-shadow: 0 0 0 1px var(--primary-color, #646987);
491
+ }
492
+
493
+ button.floorplan-image-card img {
494
+ height: 3.5rem;
495
+ width: 3.5rem;
496
+ }
497
+
498
+ .image-card-title {
499
+ color: #202020;
500
+ font-size: 15px;
501
+ font-weight: 500;
502
+ }
503
+
504
+ .image-card-subtitle {
505
+ color: #868e96;
506
+ font-size: 12px;
507
+ }
508
+
509
+ .section-right {
510
+ min-width: 0;
511
+ }
512
+
513
+ .image-card-subtitle {
514
+ overflow: hidden;
515
+ text-overflow: ellipsis;
516
+ white-space: nowrap;
517
+ }
518
+
519
+ .card-tags {
520
+ align-items: center;
521
+ display: flex;
522
+ gap: 4px;
523
+ margin-bottom: 2px;
524
+ }
525
+
526
+ .card-tags .floor-plan-badge {
527
+ background: #f3f3f3;
528
+ border: none;
529
+ color: #404040;
530
+ cursor: inherit;
531
+ font-size: 11px;
532
+ padding: 2px 8px;
533
+ white-space: nowrap;
534
+ }
535
+
536
+ .distance {
537
+ color: #868e96;
538
+ font-size: 11px;
539
+ margin-left: auto;
540
+ white-space: nowrap;
541
+ }
542
+
543
+ .next-available {
544
+ color: #202020;
545
+ font-size: 12px;
546
+ }
547
+
548
+ .same-day {
549
+ color: #2f855a;
550
+ font-size: 11px;
551
+ font-weight: 500;
552
+ }
553
+
554
+ .extend {
555
+ border-top: 1px solid #e7e7e7;
556
+ padding-top: 24px;
557
+ }
558
+ `,
559
+ ];
560
+ }
561
+
562
+ /**
563
+ * The picks and Continue, in the scheduler's footer under either picker. The
564
+ * scheduler renders it so the footer stays its own, as on every other step.
565
+ */
566
+ export const renderSelectionTray = ({
567
+ selected,
568
+ mobile,
569
+ onRemove,
570
+ onContinue,
571
+ }: {
572
+ selected: CommunitySummary[];
573
+ mobile: boolean;
574
+ onRemove: (buildingId: number) => void;
575
+ onContinue: () => void;
576
+ }): TemplateResult | string =>
577
+ selected.length === 0
578
+ ? ""
579
+ : html`<div
580
+ id="tour-scheduler-footer"
581
+ class=${classMap({ tray: true, stacked: mobile })}
582
+ >
583
+ <ul
584
+ class="floor-plan-selector-badges"
585
+ aria-label="Selected communities"
586
+ >
587
+ ${selected.map(
588
+ (s) => html`<li class="floor-plan-badge">
589
+ ${s.name}
590
+ <button
591
+ class="remove"
592
+ aria-label=${`Remove ${s.name}`}
593
+ @click=${() => onRemove(s.building_id)}
594
+ >
595
+ ${XOutlineIcon("#737373")}
596
+ </button>
597
+ </li>`
598
+ )}
599
+ </ul>
600
+ <action-confirm-button
601
+ id="continue-bttn"
602
+ text="Continue"
603
+ height="50px"
604
+ width=${mobile ? "100%" : "145px"}
605
+ .onClick=${onContinue}
606
+ ></action-confirm-button>
607
+ </div>`;
608
+
609
+ /**
610
+ * Styles for `renderSelectionTray`: the fee calculator's badges (its padding and
611
+ * radius), without the rest of its stylesheet, which also styles `:host`.
612
+ */
613
+ export const selectionTrayStyles = css`
614
+ .tray {
615
+ gap: 12px;
616
+ }
617
+
618
+ .tray .floor-plan-selector-badges {
619
+ display: flex;
620
+ flex-wrap: wrap;
621
+ gap: 8px;
622
+ list-style: none;
623
+ margin: 0;
624
+ padding: 0;
625
+ }
626
+
627
+ .tray .floor-plan-badge {
628
+ align-items: center;
629
+ background: #f3f3f3;
630
+ border: 1px solid #e7e7e7;
631
+ border-radius: 16px;
632
+ display: inline-flex;
633
+ font-size: 13px;
634
+ gap: 6px;
635
+ padding: 6px 12px;
636
+ white-space: nowrap;
637
+ }
638
+
639
+ .remove {
640
+ background: none;
641
+ border: none;
642
+ cursor: pointer;
643
+ display: inline-flex;
644
+ padding: 0;
645
+ }
646
+
647
+ .remove svg {
648
+ height: 9px;
649
+ width: 9px;
650
+ }
651
+ `;
652
+
653
+ declare global {
654
+ interface HTMLElementTagNameMap {
655
+ "community-picker": CommunityPicker;
656
+ }
657
+ }