-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilder.html
More file actions
831 lines (771 loc) · 42 KB
/
Copy pathbuilder.html
File metadata and controls
831 lines (771 loc) · 42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Trust Builder — SovereignTrust</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,500;0,600;1,400&family=DM+Sans:wght@300;400;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/css/main.css">
<script src="/js/auth.js"></script>
<script src="/js/trust-api.js"></script>
<script>requireAuth();</script>
</head>
<body>
<nav>
<a class="nav-logo" href="/">
<div class="nav-logo-mark">S</div>
<div class="nav-logo-text">Sovereign Trust</div>
</a>
<div class="nav-links" id="navLinks">
<a class="nav-link" href="/education.html">Education</a>
<a class="nav-link" href="/dashboard.html">Dashboard</a>
<a class="nav-link" href="/settings.html">Settings</a>
<a class="nav-link" href="/login.html">Sign in</a>
<a class="nav-cta" href="/register.html">Create Account</a>
</div>
<button class="nav-hamburger" onclick="toggleMobileMenu()" aria-label="Open menu">
<span></span><span></span><span></span>
</button>
</nav>
<!-- LEELA CONVERSATIONAL ONBOARDING -->
<div class="leela-onboarding" id="leelaOnboarding">
<div class="leela-onboarding-inner">
<div class="leela-onboarding-header">
<div class="leela-onboarding-avatar">✨</div>
<div>
<div class="leela-onboarding-name">Leela</div>
<div class="leela-onboarding-sub">Sovereign Trust AI Assistant</div>
</div>
</div>
<div class="leela-onboarding-messages" id="onboardingMessages"></div>
<div class="leela-onboarding-choices" id="onboardingChoices"></div>
<div class="leela-onboarding-footer">
<a href="#" onclick="skipOnboarding(); return false;">Skip — take me straight to the builder</a>
</div>
</div>
</div>
<div class="builder-layout">
<!-- SIDEBAR -->
<div class="builder-sidebar">
<h3>Trust Builder</h3>
<div class="progress-bar-wrap">
<div class="progress-bar-fill" id="builderProgress" style="width:14%"></div>
</div>
<div class="sidebar-step active" id="nav-0" onclick="goStep(0)">
<div class="step-dot">1</div>
<div class="step-label">Trust Overview</div>
</div>
<div class="sidebar-step" id="nav-1" onclick="goStep(1)">
<div class="step-dot">2</div>
<div class="step-label">Settlor Details</div>
</div>
<div class="sidebar-step" id="nav-2" onclick="goStep(2)">
<div class="step-dot">3</div>
<div class="step-label">Trustee(s)</div>
</div>
<div class="sidebar-step" id="nav-3" onclick="goStep(3)">
<div class="step-dot">4</div>
<div class="step-label">Beneficiaries</div>
</div>
<div class="sidebar-step" id="nav-4" onclick="goStep(4)">
<div class="step-dot">5</div>
<div class="step-label">Protector</div>
</div>
<div class="sidebar-step" id="nav-5" onclick="goStep(5)">
<div class="step-dot">6</div>
<div class="step-label">Signing Details</div>
</div>
<div class="sidebar-step" id="nav-6" onclick="goStep(6)">
<div class="step-dot">7</div>
<div class="step-label">Review</div>
</div>
<div style="margin-top:32px; padding:16px; background:var(--cream); border-radius:var(--radius-md);">
<div style="font-size:12px; color:var(--text-muted); font-weight:300;">Need help? Ask Leela AI — your AI assistant is available throughout the builder.</div>
</div>
</div>
<!-- MAIN CONTENT -->
<div class="builder-main">
<!-- STEP 0: Overview -->
<div class="builder-step-content active" id="step-0">
<h1 class="builder-section-title">Trust Overview</h1>
<p class="builder-section-sub">Begin by providing the fundamental details that will identify and define your express private trust.</p>
<div class="field-group">
<label class="field-label">Trust Name <span style="color:var(--gold)">*</span></label>
<input type="text" class="field-input" id="f-trustName" placeholder="e.g. The Harrison Family Trust">
<div class="field-help">The formal name of your trust as it will appear on all documentation.</div>
<div class="field-example">Example: "The [Your Surname] Family Trust" or "The [Purpose] Trust 2025"</div>
<div class="field-why"><strong>Why this matters:</strong> The trust name is used to formally identify the trust in all legal documents, correspondence, and records.</div>
</div>
<div class="field-group">
<label class="field-label">Trust Creation Date <span style="color:var(--gold)">*</span></label>
<input type="date" class="field-input" id="f-creationDate">
<div class="field-help">The date on which this trust deed is to be dated.</div>
<div class="field-why"><strong>Why this matters:</strong> The creation date establishes when the trust legally comes into existence.</div>
</div>
<div class="field-group">
<label class="field-label">Trust Purpose <span style="color:var(--gold)">*</span></label>
<textarea class="field-input" id="f-purpose" placeholder="e.g. To hold, manage and distribute assets for the benefit of the beneficiaries named herein..."></textarea>
<div class="field-help">A plain-English statement of the primary purpose of this trust.</div>
<div class="field-why"><strong>Why this matters:</strong> The purpose clause defines the intention of the trust and guides Trustees in their administration.</div>
</div>
<div class="field-group">
<label class="field-label">Governing Jurisdiction <span style="color:var(--gold)">*</span></label>
<select class="field-input" id="f-jurisdiction">
<option value="">Select jurisdiction...</option>
<option>England & Wales</option>
<option>Scotland</option>
<option>Northern Ireland</option>
<option>Isle of Man</option>
<option>Jersey</option>
<option>Guernsey</option>
<option>Gibraltar</option>
<option>Other</option>
</select>
<div class="field-help">The legal jurisdiction whose laws will govern this trust.</div>
<div class="field-why"><strong>Why this matters:</strong> Trust law varies significantly between jurisdictions. The governing law affects how the trust is administered and interpreted.</div>
</div>
<div class="field-group">
<label class="field-label">Initial Trust Property <span style="color:var(--gold)">*</span></label>
<input type="text" class="field-input" id="f-initialProperty" placeholder="e.g. £10 settled sum">
<div class="field-help">The property or nominal sum being settled into the trust at its creation.</div>
<div class="field-example">Example: "£10 settled sum" (a nominal amount is typical for initial settlement)</div>
<div class="field-why"><strong>Why this matters:</strong> A trust requires that property be transferred to it. An initial nominal sum is commonly used to constitute the trust before further assets are added.</div>
</div>
<div class="builder-nav">
<div class="autosave-note"><div class="autosave-dot"></div> Draft auto-saved</div>
<button class="btn-navy" onclick="nextStep()">Continue to Settlor →</button>
</div>
</div>
<!-- STEP 1: Settlor -->
<div class="builder-step-content" id="step-1">
<h1 class="builder-section-title">Settlor Details</h1>
<p class="builder-section-sub">The Settlor is the person who creates and funds the trust. Please provide their full legal details.</p>
<div class="field-group">
<label class="field-label">Full Legal Name <span style="color:var(--gold)">*</span></label>
<input type="text" class="field-input" id="f-settlorName" placeholder="e.g. James Edward Harrison">
<div class="field-help">Enter the Settlor's full legal name exactly as it appears on official identification.</div>
</div>
<div class="field-group">
<label class="field-label">Full Address <span style="color:var(--gold)">*</span></label>
<textarea class="field-input" id="f-settlorAddress" placeholder="Full address including postcode/zip code" style="min-height:80px;"></textarea>
</div>
<div class="grid-2">
<div class="field-group">
<label class="field-label">Email Address <span style="color:var(--gold)">*</span></label>
<input type="email" class="field-input" id="f-settlorEmail" placeholder="settlor@example.com">
</div>
<div class="field-group">
<label class="field-label">Phone Number</label>
<input type="tel" class="field-input" id="f-settlorPhone" placeholder="+44 7700 000000">
</div>
</div>
<div class="builder-nav">
<button class="btn-outline" onclick="prevStep()">← Back</button>
<div class="autosave-note"><div class="autosave-dot"></div> Draft auto-saved</div>
<button class="btn-navy" onclick="nextStep()">Continue to Trustees →</button>
</div>
</div>
<!-- STEP 2: Trustees -->
<div class="builder-step-content" id="step-2">
<h1 class="builder-section-title">Trustee Details</h1>
<p class="builder-section-sub">Trustees are the legal holders and administrators of trust assets. You may appoint one or more trustees.</p>
<div id="trustees-container">
<div class="party-card">
<div class="party-card-header">
<div class="party-card-title">Trustee 1</div>
</div>
<div class="field-group">
<label class="field-label">Full Legal Name <span style="color:var(--gold)">*</span></label>
<input type="text" class="field-input" data-field="name" placeholder="e.g. Sarah Margaret Harrison">
</div>
<div class="field-group">
<label class="field-label">Full Address <span style="color:var(--gold)">*</span></label>
<textarea class="field-input" data-field="address" placeholder="Full address including postcode" style="min-height:72px;"></textarea>
</div>
<div class="grid-2">
<div class="field-group">
<label class="field-label">Email</label>
<input type="email" class="field-input" data-field="email" placeholder="trustee@example.com">
</div>
<div class="field-group">
<label class="field-label">Phone</label>
<input type="tel" class="field-input" data-field="phone" placeholder="+44 7700 000000">
</div>
</div>
</div>
</div>
<button class="btn-add" onclick="addTrustee()">+ Add Another Trustee</button>
<div class="builder-nav">
<button class="btn-outline" onclick="prevStep()">← Back</button>
<div class="autosave-note"><div class="autosave-dot"></div> Draft auto-saved</div>
<button class="btn-navy" onclick="nextStep()">Continue to Beneficiaries →</button>
</div>
</div>
<!-- STEP 3: Beneficiaries -->
<div class="builder-step-content" id="step-3">
<h1 class="builder-section-title">Beneficiary Details</h1>
<p class="builder-section-sub">Beneficiaries are those who receive the benefit of the trust. You may add one or more beneficiaries.</p>
<div id="beneficiaries-container">
<div class="party-card">
<div class="party-card-header">
<div class="party-card-title">Beneficiary 1</div>
</div>
<div class="field-group">
<label class="field-label">Full Legal Name <span style="color:var(--gold)">*</span></label>
<input type="text" class="field-input" data-field="name" placeholder="e.g. Thomas James Harrison">
</div>
<div class="field-group">
<label class="field-label">Full Address <span style="color:var(--gold)">*</span></label>
<textarea class="field-input" data-field="address" placeholder="Full address including postcode" style="min-height:72px;"></textarea>
</div>
<div class="grid-2">
<div class="field-group">
<label class="field-label">Relationship to Settlor</label>
<input type="text" class="field-input" data-field="relationship" placeholder="e.g. Son, Daughter, Spouse">
</div>
<div class="field-group">
<label class="field-label">Beneficiary Type</label>
<select class="field-input" data-field="type">
<option>Fixed Beneficiary</option>
<option>Discretionary Beneficiary</option>
<option>Remainder Beneficiary</option>
</select>
</div>
</div>
</div>
</div>
<button class="btn-add" onclick="addBeneficiary()">+ Add Another Beneficiary</button>
<div class="builder-nav">
<button class="btn-outline" onclick="prevStep()">← Back</button>
<div class="autosave-note"><div class="autosave-dot"></div> Draft auto-saved</div>
<button class="btn-navy" onclick="nextStep()">Continue to Protector →</button>
</div>
</div>
<!-- STEP 4: Protector -->
<div class="builder-step-content" id="step-4">
<h1 class="builder-section-title">Protector Details <span class="optional-badge">Optional</span></h1>
<p class="builder-section-sub">A Protector provides an additional layer of oversight for the trust. This section is entirely optional — leave blank if you do not wish to appoint a Protector.</p>
<div class="party-card">
<div class="field-group">
<label class="field-label">Full Legal Name</label>
<input type="text" class="field-input" id="f-protectorName" placeholder="e.g. Robert Andrew Williams">
<div class="field-help">Leave blank if not appointing a Protector.</div>
</div>
<div class="field-group">
<label class="field-label">Full Address</label>
<textarea class="field-input" id="f-protectorAddress" placeholder="Full address including postcode" style="min-height:72px;"></textarea>
</div>
<div class="field-group">
<label class="field-label">Email Address</label>
<input type="email" class="field-input" id="f-protectorEmail" placeholder="protector@example.com">
</div>
</div>
<div class="builder-nav">
<button class="btn-outline" onclick="prevStep()">← Back</button>
<div class="autosave-note"><div class="autosave-dot"></div> Draft auto-saved</div>
<button class="btn-navy" onclick="nextStep()">Continue to Signing →</button>
</div>
</div>
<!-- STEP 5: Signing -->
<div class="builder-step-content" id="step-5">
<h1 class="builder-section-title">Signing Details</h1>
<p class="builder-section-sub">These details will appear on the execution page of your trust deed.</p>
<div class="field-group">
<label class="field-label">Place of Signing <span style="color:var(--gold)">*</span></label>
<input type="text" class="field-input" id="f-signingPlace" placeholder="e.g. London, England">
<div class="field-help">The town or city where the trust deed will be signed and executed.</div>
</div>
<div class="divider"></div>
<div class="party-card">
<div class="party-card-title" style="margin-bottom:16px;">Witness 1</div>
<div class="field-group">
<label class="field-label">Full Name <span style="color:var(--gold)">*</span></label>
<input type="text" class="field-input" id="f-witness1Name" placeholder="Witness full legal name">
</div>
<div class="field-group">
<label class="field-label">Full Address <span style="color:var(--gold)">*</span></label>
<textarea class="field-input" id="f-witness1Address" placeholder="Witness address" style="min-height:72px;"></textarea>
</div>
</div>
<div class="party-card">
<div class="party-card-title" style="margin-bottom:16px;">Witness 2</div>
<div class="field-group">
<label class="field-label">Full Name <span style="color:var(--gold)">*</span></label>
<input type="text" class="field-input" id="f-witness2Name" placeholder="Witness full legal name">
</div>
<div class="field-group">
<label class="field-label">Full Address <span style="color:var(--gold)">*</span></label>
<textarea class="field-input" id="f-witness2Address" placeholder="Witness address" style="min-height:72px;"></textarea>
</div>
</div>
<div class="builder-nav">
<button class="btn-outline" onclick="prevStep()">← Back</button>
<div class="autosave-note"><div class="autosave-dot"></div> Draft auto-saved</div>
<button class="btn-navy" onclick="nextStep()">Review Your Trust →</button>
</div>
</div>
<!-- STEP 6: Review -->
<div class="builder-step-content" id="step-6">
<h1 class="builder-section-title">Review & Preview</h1>
<p class="builder-section-sub">Your trust documentation is ready for review. Please check all details carefully before proceeding to payment.</p>
<div id="review-complete-banner" style="background:var(--success-bg); border:1px solid rgba(45,106,79,0.2); border-radius:var(--radius-md); padding:16px 20px; margin-bottom:28px; display:flex; align-items:center; gap:12px;">
<span style="font-size:20px;">✓</span>
<div style="font-size:14px; color:var(--success); font-weight:400;">All required sections are complete. Your trust deed is ready to preview.</div>
</div>
<div style="background:var(--white); border:1px solid var(--grey-light); border-radius:var(--radius-lg); padding:24px 28px; box-shadow:var(--shadow-sm); margin-bottom:20px;">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:16px;">
<h3 style="font-size:16px; color:var(--navy);">Trust Overview</h3>
<button class="btn-outline" onclick="goStep(0)" style="font-size:12px; padding:6px 12px;">Edit</button>
</div>
<div class="doc-field"><div class="doc-field-label">Trust Name</div><div class="doc-field-val" id="rv-trustName">—</div></div>
<div class="doc-field"><div class="doc-field-label">Jurisdiction</div><div class="doc-field-val" id="rv-jurisdiction">—</div></div>
<div class="doc-field"><div class="doc-field-label">Initial Property</div><div class="doc-field-val" id="rv-initialProperty">—</div></div>
</div>
<div style="background:var(--white); border:1px solid var(--grey-light); border-radius:var(--radius-lg); padding:24px 28px; box-shadow:var(--shadow-sm); margin-bottom:20px;">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:16px;">
<h3 style="font-size:16px; color:var(--navy);">Parties</h3>
<button class="btn-outline" onclick="goStep(1)" style="font-size:12px; padding:6px 12px;">Edit</button>
</div>
<div class="doc-field"><div class="doc-field-label">Settlor</div><div class="doc-field-val" id="rv-settlor">—</div></div>
<div class="doc-field"><div class="doc-field-label">Trustee(s)</div><div class="doc-field-val" id="rv-trustees">—</div></div>
<div class="doc-field"><div class="doc-field-label">Beneficiary</div><div class="doc-field-val" id="rv-beneficiaries">—</div></div>
<div class="doc-field"><div class="doc-field-label">Protector</div><div class="doc-field-val" id="rv-protector" style="color:var(--text-muted); font-style:italic;">Not appointed</div></div>
</div>
<div class="builder-nav">
<button class="btn-outline" onclick="prevStep()">← Back</button>
<button class="btn-gold" style="padding:12px 28px; width:auto;" onclick="completeTrust()">Preview Trust Deed →</button>
</div>
</div>
</div><!-- /.builder-main -->
</div><!-- /.builder-layout -->
<!-- LEELA -->
<div class="lumina-float" id="leela">
<div class="lumina-panel" id="leelaPanel">
<div class="lumina-header">
<div class="lumina-avatar">✨</div>
<div>
<div class="lumina-name">Leela</div>
<div class="lumina-sub">Trust Document Assistant</div>
</div>
<a class="lumina-settings" href="/settings.html" title="AI settings">⚙</a>
<button class="lumina-close" onclick="toggleLeela()">×</button>
</div>
<div class="leela-messages" id="leelaMessages"
data-greeting="Hello! I'm Leela, your trust document assistant. I'm here to help you fill in each section of the trust builder. What would you like to know?"
data-suggestions='["What is a Settlor?","How many trustees do I need?","What is initial trust property?","What should I put as the trust purpose?"]'>
</div>
<div class="leela-disclaimer">I explain concepts and assist with document preparation only — not legal, tax or financial advice.</div>
<div class="leela-input-row">
<input class="leela-input" id="leelaInput" type="text" placeholder="Ask Leela anything…" />
<button class="leela-send" id="leelaSend" aria-label="Send">→</button>
</div>
</div>
<button class="lumina-btn" onclick="toggleLeela()"><span>✨</span></button>
</div>
<script src="/js/app.js"></script>
<script src="/js/leela.js"></script>
<script>
let currentStep = 0;
const totalSteps = 7;
let trusteeCount = 1;
let beneficiaryCount = 1;
let trustId = new URLSearchParams(window.location.search).get('id') || null;
let saveTimer = null;
function goStep(n) {
document.querySelectorAll('.builder-step-content').forEach(s => s.classList.remove('active'));
document.getElementById('step-' + n).classList.add('active');
document.querySelectorAll('.sidebar-step').forEach(s => s.classList.remove('active'));
document.getElementById('nav-' + n).classList.add('active');
currentStep = n;
document.getElementById('builderProgress').style.width = (((n + 1) / totalSteps) * 100) + '%';
window.scrollTo(0, 0);
if (n === totalSteps - 1) renderReview();
setLeelaContext({ page: 'builder', step: n, trustName: document.getElementById('f-trustName')?.value || '' });
}
function nextStep() { if (currentStep < totalSteps - 1) goStep(currentStep + 1); }
function prevStep() { if (currentStep > 0) goStep(currentStep - 1); }
function addTrustee() {
trusteeCount++;
const c = document.getElementById('trustees-container');
const d = document.createElement('div');
d.className = 'party-card';
d.innerHTML = `<div class="party-card-header"><div class="party-card-title">Trustee ${trusteeCount}</div><button class="btn-remove" onclick="this.closest('.party-card').remove()">Remove ×</button></div><div class="field-group"><label class="field-label">Full Legal Name</label><input type="text" class="field-input" data-field="name" placeholder="Trustee full name"></div><div class="field-group"><label class="field-label">Full Address</label><textarea class="field-input" data-field="address" placeholder="Full address" style="min-height:72px;"></textarea></div><div class="grid-2"><div class="field-group"><label class="field-label">Email</label><input type="email" class="field-input" data-field="email" placeholder="Email"></div><div class="field-group"><label class="field-label">Phone</label><input type="tel" class="field-input" data-field="phone" placeholder="Phone"></div></div>`;
c.appendChild(d);
}
function addBeneficiary() {
beneficiaryCount++;
const c = document.getElementById('beneficiaries-container');
const d = document.createElement('div');
d.className = 'party-card';
d.innerHTML = `<div class="party-card-header"><div class="party-card-title">Beneficiary ${beneficiaryCount}</div><button class="btn-remove" onclick="this.closest('.party-card').remove()">Remove ×</button></div><div class="field-group"><label class="field-label">Full Legal Name</label><input type="text" class="field-input" data-field="name" placeholder="Beneficiary full name"></div><div class="field-group"><label class="field-label">Full Address</label><textarea class="field-input" data-field="address" placeholder="Full address" style="min-height:72px;"></textarea></div><div class="grid-2"><div class="field-group"><label class="field-label">Relationship</label><input type="text" class="field-input" data-field="relationship" placeholder="e.g. Son, Daughter"></div><div class="field-group"><label class="field-label">Type</label><select class="field-input" data-field="type"><option>Fixed Beneficiary</option><option>Discretionary Beneficiary</option><option>Remainder Beneficiary</option></select></div></div>`;
c.appendChild(d);
}
function collectParty(card) {
const party = {};
card.querySelectorAll('[data-field]').forEach(el => { party[el.dataset.field] = el.value; });
return party;
}
function collectTrustData() {
return {
overview: {
name: document.getElementById('f-trustName').value,
creationDate: document.getElementById('f-creationDate').value,
purpose: document.getElementById('f-purpose').value,
jurisdiction: document.getElementById('f-jurisdiction').value,
initialProperty: document.getElementById('f-initialProperty').value
},
settlor: {
name: document.getElementById('f-settlorName').value,
address: document.getElementById('f-settlorAddress').value,
email: document.getElementById('f-settlorEmail').value,
phone: document.getElementById('f-settlorPhone').value
},
trustees: [...document.querySelectorAll('#trustees-container .party-card')].map(collectParty),
beneficiaries: [...document.querySelectorAll('#beneficiaries-container .party-card')].map(collectParty),
protector: {
name: document.getElementById('f-protectorName').value,
address: document.getElementById('f-protectorAddress').value,
email: document.getElementById('f-protectorEmail').value
},
signing: {
place: document.getElementById('f-signingPlace').value,
witness1: { name: document.getElementById('f-witness1Name').value, address: document.getElementById('f-witness1Address').value },
witness2: { name: document.getElementById('f-witness2Name').value, address: document.getElementById('f-witness2Address').value }
}
};
}
function populateTrustData(data) {
if (!data) return;
const o = data.overview || {};
if (document.getElementById('f-trustName')) document.getElementById('f-trustName').value = o.name || '';
if (document.getElementById('f-creationDate')) document.getElementById('f-creationDate').value = o.creationDate || '';
if (document.getElementById('f-purpose')) document.getElementById('f-purpose').value = o.purpose || '';
if (document.getElementById('f-jurisdiction')) document.getElementById('f-jurisdiction').value = o.jurisdiction || '';
if (document.getElementById('f-initialProperty')) document.getElementById('f-initialProperty').value = o.initialProperty || '';
const s = data.settlor || {};
if (document.getElementById('f-settlorName')) document.getElementById('f-settlorName').value = s.name || '';
if (document.getElementById('f-settlorAddress')) document.getElementById('f-settlorAddress').value = s.address || '';
if (document.getElementById('f-settlorEmail')) document.getElementById('f-settlorEmail').value = s.email || '';
if (document.getElementById('f-settlorPhone')) document.getElementById('f-settlorPhone').value = s.phone || '';
const fillParties = (containerId, items, addFn) => {
const container = document.getElementById(containerId);
const cards = container.querySelectorAll('.party-card');
while (container.querySelectorAll('.party-card').length < (items.length || 1)) addFn();
const updated = container.querySelectorAll('.party-card');
(items || []).forEach((item, i) => {
const card = updated[i];
if (!card) return;
card.querySelectorAll('[data-field]').forEach(el => { el.value = item[el.dataset.field] || ''; });
});
};
fillParties('trustees-container', data.trustees || [], addTrustee);
fillParties('beneficiaries-container', data.beneficiaries || [], addBeneficiary);
const p = data.protector || {};
if (document.getElementById('f-protectorName')) document.getElementById('f-protectorName').value = p.name || '';
if (document.getElementById('f-protectorAddress')) document.getElementById('f-protectorAddress').value = p.address || '';
if (document.getElementById('f-protectorEmail')) document.getElementById('f-protectorEmail').value = p.email || '';
const sg = data.signing || {};
if (document.getElementById('f-signingPlace')) document.getElementById('f-signingPlace').value = sg.place || '';
if (sg.witness1) {
document.getElementById('f-witness1Name').value = sg.witness1.name || '';
document.getElementById('f-witness1Address').value = sg.witness1.address || '';
}
if (sg.witness2) {
document.getElementById('f-witness2Name').value = sg.witness2.name || '';
document.getElementById('f-witness2Address').value = sg.witness2.address || '';
}
}
function renderReview() {
const data = collectTrustData();
document.getElementById('rv-trustName').textContent = data.overview.name || '—';
document.getElementById('rv-jurisdiction').textContent = data.overview.jurisdiction || '—';
document.getElementById('rv-initialProperty').textContent = data.overview.initialProperty || '—';
document.getElementById('rv-settlor').textContent = data.settlor.name || '—';
document.getElementById('rv-trustees').textContent = data.trustees.map(t => t.name).filter(Boolean).join(', ') || '—';
document.getElementById('rv-beneficiaries').textContent = data.beneficiaries.map(b => b.name).filter(Boolean).join(', ') || '—';
const protectorEl = document.getElementById('rv-protector');
if (data.protector.name) {
protectorEl.textContent = data.protector.name;
protectorEl.style.fontStyle = 'normal';
protectorEl.style.color = '';
} else {
protectorEl.textContent = 'Not appointed';
protectorEl.style.fontStyle = 'italic';
}
const errors = validateTrustData(data);
document.getElementById('review-complete-banner').style.display = errors.length ? 'none' : '';
showValidationBanner(errors);
}
async function autosave() {
const data = collectTrustData();
const name = data.overview.name || 'Untitled Trust';
try {
const result = await saveTrust({ id: trustId, name, status: 'Draft', data });
if (result.trust && (result.trust.id || result.trust.Id)) {
trustId = result.trust.id || result.trust.Id;
const url = new URL(window.location);
url.searchParams.set('id', trustId);
window.history.replaceState({}, '', url);
}
} catch (err) {
console.error('[autosave]', err);
}
}
function scheduleAutosave() {
clearTimeout(saveTimer);
saveTimer = setTimeout(autosave, 1200);
}
function validateTrustData(data) {
const errors = [];
const req = (fieldId, label, step) => {
const el = document.getElementById(fieldId);
if (!el || !el.value.trim()) {
errors.push({ fieldId, label, step });
}
};
req('f-trustName', 'Trust Name', 0);
req('f-creationDate', 'Trust Creation Date', 0);
req('f-purpose', 'Trust Purpose', 0);
req('f-jurisdiction', 'Governing Jurisdiction', 0);
req('f-initialProperty', 'Initial Trust Property', 0);
req('f-settlorName', 'Settlor Full Legal Name', 1);
req('f-settlorAddress', 'Settlor Full Address', 1);
req('f-settlorEmail', 'Settlor Email Address', 1);
const trustees = [...document.querySelectorAll('#trustees-container .party-card')];
trustees.forEach((card, i) => {
const nameEl = card.querySelector('[data-field="name"]');
const addrEl = card.querySelector('[data-field="address"]');
if (!nameEl?.value.trim()) errors.push({ fieldId: null, label: `Trustee ${i + 1} Full Legal Name`, step: 2 });
if (!addrEl?.value.trim()) errors.push({ fieldId: null, label: `Trustee ${i + 1} Full Address`, step: 2 });
});
const beneficiaries = [...document.querySelectorAll('#beneficiaries-container .party-card')];
beneficiaries.forEach((card, i) => {
const nameEl = card.querySelector('[data-field="name"]');
const addrEl = card.querySelector('[data-field="address"]');
if (!nameEl?.value.trim()) errors.push({ fieldId: null, label: `Beneficiary ${i + 1} Full Legal Name`, step: 3 });
if (!addrEl?.value.trim()) errors.push({ fieldId: null, label: `Beneficiary ${i + 1} Full Address`, step: 3 });
});
req('f-signingPlace', 'Place of Signing', 5);
req('f-witness1Name', 'Witness 1 Full Name', 5);
req('f-witness1Address','Witness 1 Address', 5);
req('f-witness2Name', 'Witness 2 Full Name', 5);
req('f-witness2Address','Witness 2 Address', 5);
return errors;
}
function getOrCreateBanner() {
let banner = document.getElementById('validation-banner');
if (!banner) {
banner = document.createElement('div');
banner.id = 'validation-banner';
banner.className = 'validation-banner';
const reviewStep = document.getElementById('step-6');
reviewStep.insertBefore(banner, reviewStep.firstChild);
}
return banner;
}
function applyFieldErrors(errors) {
document.querySelectorAll('.field-input--error').forEach(el => el.classList.remove('field-input--error'));
document.querySelectorAll('.field-error-msg').forEach(el => el.remove());
errors.forEach(e => {
if (!e.fieldId) return;
const el = document.getElementById(e.fieldId);
if (!el) return;
el.classList.add('field-input--error');
const msg = document.createElement('div');
msg.className = 'field-error-msg';
msg.textContent = e.label + ' is required.';
el.parentNode.insertBefore(msg, el.nextSibling);
});
}
function showValidationBanner(errors) {
const banner = getOrCreateBanner();
if (!errors.length) { banner.style.display = 'none'; return; }
banner.style.display = '';
const stepNames = ['Trust Overview','Settlor Details','Trustee(s)','Beneficiaries','Protector','Signing Details'];
banner.innerHTML = '<div class="validation-banner-title">Please complete the following required fields before previewing:</div><ul>' +
errors.map(e => `<li onclick="goStep(${e.step})">${e.label} <span style="opacity:.7;font-size:11px;">(${stepNames[e.step]})</span></li>`).join('') +
'</ul>';
}
function scrollToBanner() {
const banner = document.getElementById('validation-banner');
if (!banner) return;
const top = banner.getBoundingClientRect().top + window.scrollY - 80;
window.scrollTo({ top: Math.max(0, top), behavior: 'smooth' });
}
async function completeTrust() {
const data = collectTrustData();
const errors = validateTrustData(data);
if (errors.length) {
showValidationBanner(errors);
applyFieldErrors(errors);
scrollToBanner();
return;
}
showValidationBanner([]);
applyFieldErrors([]);
const name = data.overview.name || 'Untitled Trust';
try {
const result = await saveTrust({ id: trustId, name, status: 'Generated', data });
trustId = result.trust?.id || result.trust?.Id || trustId;
sessionStorage.setItem('trustData_' + trustId, JSON.stringify({ id: trustId, name, data }));
await awardKarma('TrustCompleted');
window.location.href = '/preview.html?id=' + encodeURIComponent(trustId);
} catch (err) {
const banner = getOrCreateBanner();
banner.style.display = '';
banner.innerHTML = '<div class="validation-banner-title">Could not save your trust</div><ul><li style="cursor:default;text-decoration:none">' + err.message + '</li></ul>';
document.getElementById('review-complete-banner').style.display = 'none';
scrollToBanner();
}
}
// ── Leela Conversational Onboarding ─────────────────────
const onboardingAnswers = {};
let onboardingStep = 0;
const onboardingFlow = [
{
message: "Hello! I'm Leela, your Sovereign Trust assistant. Before we open the builder, I'd like to ask you three quick questions — this helps me recommend the right trust structure and pre-fill some details for you.",
choices: null
},
{
message: "What are you hoping to protect?",
key: "protect",
choices: ["Property & real estate", "Financial savings & investments", "Business interests", "Family wealth & heirlooms", "Digital assets", "A mix of different assets"]
},
{
message: "Who would you like your trust to benefit?",
key: "beneficiaries",
choices: ["My children", "My spouse or partner", "My wider family", "Myself", "A combination of people", "I'm not sure yet"]
},
{
message: "What kind of assets are you planning to place into the trust?",
key: "assets",
choices: ["Residential property", "Savings & bank accounts", "Business shares or interests", "Investments & securities", "A mix of asset types", "I'll decide later"]
}
];
function addOnboardingBubble(text, role) {
const msgs = document.getElementById('onboardingMessages');
const b = document.createElement('div');
b.className = 'leela-bubble ' + role;
b.textContent = text;
msgs.appendChild(b);
msgs.scrollTop = msgs.scrollHeight;
return b;
}
function showTypingThenBubble(text, callback) {
const msgs = document.getElementById('onboardingMessages');
const t = document.createElement('div');
t.className = 'leela-typing';
t.innerHTML = '<span></span><span></span><span></span>';
msgs.appendChild(t);
msgs.scrollTop = msgs.scrollHeight;
setTimeout(() => {
t.remove();
addOnboardingBubble(text, 'leela');
if (callback) callback();
}, 900);
}
function renderOnboardingChoices(choices) {
const container = document.getElementById('onboardingChoices');
container.innerHTML = '';
choices.forEach(c => {
const btn = document.createElement('button');
btn.className = 'leela-choice';
btn.textContent = c;
btn.onclick = () => onboardingChoose(c);
container.appendChild(btn);
});
}
function buildRecommendation() {
const protect = onboardingAnswers.protect || '';
const bens = onboardingAnswers.beneficiaries || '';
const assets = onboardingAnswers.assets || '';
const benMap = {
"My children": "your children",
"My spouse or partner": "your spouse or partner",
"My wider family": "your wider family",
"Myself": "yourself",
"A combination of people": "your chosen beneficiaries",
"I'm not sure yet": "your chosen beneficiaries"
};
const benText = benMap[bens] || "your chosen beneficiaries";
const purposeText = `To hold, manage and protect ${assets.toLowerCase() === "i'll decide later" ? "assets to be settled" : assets.toLowerCase()} for the benefit of ${benText}, and to carry out the wishes of the Settlor in relation to the trust property as set out herein.`;
return { purposeText, benText, protect, assets };
}
function onboardingChoose(choice) {
const step = onboardingFlow[onboardingStep];
if (step.key) onboardingAnswers[step.key] = choice;
document.getElementById('onboardingChoices').innerHTML = '';
addOnboardingBubble(choice, 'user');
onboardingStep++;
if (onboardingStep < onboardingFlow.length) {
const next = onboardingFlow[onboardingStep];
showTypingThenBubble(next.message, () => {
if (next.choices) renderOnboardingChoices(next.choices);
});
} else {
// All questions answered — show recommendation
const rec = buildRecommendation();
const msg = `Perfect. Based on what you've told me, I recommend an Express Private Trust — well-suited for protecting ${rec.protect.toLowerCase()} for ${rec.benText}. I've pre-filled your trust purpose to get you started. You can edit anything in the builder.`;
showTypingThenBubble(msg, () => {
const container = document.getElementById('onboardingChoices');
container.style.paddingTop = '4px';
const btn = document.createElement('button');
btn.className = 'leela-onboarding-begin';
btn.textContent = 'Begin Building My Trust →';
btn.onclick = () => launchBuilderFromOnboarding(rec.purposeText);
container.appendChild(btn);
});
}
}
function launchBuilderFromOnboarding(purposeText) {
const overlay = document.getElementById('leelaOnboarding');
overlay.classList.add('hidden');
setTimeout(() => {
overlay.style.display = 'none';
const purposeEl = document.getElementById('f-purpose');
if (purposeText && purposeEl) {
purposeEl.value = purposeText;
purposeEl.classList.add('field-prefilled');
purposeEl.addEventListener('input', () => purposeEl.classList.remove('field-prefilled'), { once: true });
scheduleAutosave();
// Scroll the pre-filled field into view with a short delay so the page has settled
setTimeout(() => {
purposeEl.scrollIntoView({ behavior: 'smooth', block: 'center' });
purposeEl.focus();
}, 120);
}
}, 420);
}
function skipOnboarding() {
const overlay = document.getElementById('leelaOnboarding');
overlay.classList.add('hidden');
setTimeout(() => { overlay.style.display = 'none'; }, 420);
}
function initOnboarding() {
// Show onboarding only for new trusts (no id in URL)
if (trustId) { skipOnboarding(); return; }
onboardingStep = 0;
showTypingThenBubble(onboardingFlow[0].message, () => {
onboardingStep = 1;
showTypingThenBubble(onboardingFlow[1].message, () => {
renderOnboardingChoices(onboardingFlow[1].choices);
});
});
}
document.querySelectorAll('.builder-main').forEach(el => el.addEventListener('input', scheduleAutosave));
(async function init() {
if (trustId) {
try {
const trusts = await listTrusts();
const existing = trusts.find(t => t.id === trustId);
if (existing) populateTrustData(existing.data);
} catch (err) {
console.error('[builder init]', err);
}
}
initOnboarding();
})();
</script>
</body>
</html>