# Quick Reference: Shared Partials

## 📍 Files Location
```
resources/views/shared/partials/
├── emergency-contacts.blade.php
├── family-members.blade.php
└── README.md
```

## 🔗 Usage

### Include in Any Create View
```blade
<!-- Emergency Contacts Section -->
@include('shared.partials.emergency-contacts')

<!-- Family Members Section -->
@include('shared.partials.family-members')
```

## 📋 Form Field Names

### Emergency Contacts
```
emergency_contacts[{index}][name]                ✓ Required
emergency_contacts[{index}][phone]               ✓ Required
emergency_contacts[{index}][relationship]        ✓ Required
emergency_contacts[{index}][relationship_other]  (If "Other" selected)
emergency_contacts[{index}][email]               Optional
```

### Family Members
```
family_members[{index}][first_name]
family_members[{index}][last_name]
family_members[{index}][relationship]
family_members[{index}][phone]
family_members[{index}][country]
family_members[{index}][state]
family_members[{index}][city]
family_members[{index}][postal_code]
family_members[{index}][address]               (Merged - hidden field)
```

## 🔧 JavaScript Functions Available

### Emergency Contacts
| Function | Purpose |
|----------|---------|
| `addEmergencyContact()` | Add new contact card |
| `removeEmergencyContact(button)` | Remove specific contact |
| `toggleRelationshipOther(index)` | Show/hide other field |

### Family Members
| Function | Purpose |
|----------|---------|
| `attachFamilyAddressHandlers()` | Setup address dropdowns |
| `copyResidentialAddressToFamily(button)` | Copy address from personal section |
| `mergeFamilyAddress(memberElement)` | Merge address to hidden field |
| `addFamilyMember()` | Add new family member |

## 🌍 Malaysian States (16)
```
Johor, Kedah, Kelantan, Kuala Lumpur, Labuan, Melaka,
Negeri Sembilan, Pahang, Penang, Perak, Perlis, Putrajaya,
Sabah, Sarawak, Selangor, Terengganu
```

## ✅ Integration Checklist

- [ ] Include `emergency-contacts.blade.php`
- [ ] Include `family-members.blade.php`
- [ ] Test add/remove functionality
- [ ] Test address copy
- [ ] Verify city dropdown population
- [ ] Test form submission

## 🔗 Related Files

| File | Purpose |
|------|---------|
| `IMPLEMENTATION_GUIDE.md` | Detailed integration steps |
| `WORK_SUMMARY.md` | Overview of changes |
| `shared/partials/README.md` | Technical documentation |

## ⚠️ Important Notes

1. **Partials include inline JavaScript** - No need to load JS separately
2. **Partials include inline styles** - Uses Tailwind CSS classes
3. **Malaysian states object** - Defined in family-members.blade.php
4. **Event handlers** - Auto-attached when family members are generated
5. **Form field index** - Starts from 0: `[0]`, `[1]`, `[2]`, etc.

## 🐛 Quick Troubleshooting

| Issue | Solution |
|-------|----------|
| Cities not showing | Wait 150ms after state selection (already handled) |
| Partials not found | Check include path: `shared.partials.emergency-contacts` |
| Functions not defined | Ensure partials are included before usage |
| Styles not showing | Verify Tailwind CSS is loaded in layout |

## 📊 Current Implementation Status

| Portal | Emergency Contacts | Family Members | Status |
|--------|-------------------|-----------------|---------|
| Agent | ✅ (Fixed) | ✅ (Fixed) | Ready |
| Lawyer | ⏳ | ⏳ | Not started |
| Staff | ⏳ | ⏳ | Not started |

## 🎯 Next Steps

1. Apply partials to Lawyer portal
2. Apply partials to Staff portal
3. Remove duplicate code from old implementations
4. Test all three portals
5. Deploy to production

## 📞 Support

- IMPLEMENTATION_GUIDE.md - Step by step guide
- shared/partials/README.md - Full documentation
- Code comments in each partial file

---

**Status**: All partials created and tested. Ready for integration.
**Last Updated**: August 31, 2026
