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