# Agent Islamic Will Format - Display Fix

## Problem
When agents viewed or edited Islamic wills in the agent portal, they would always open the **individual will format**, not the Islamic-specific format. The same view was used for all will types (individual, islamic, joint).

## Solution Implemented

### 1. Controller Routing (AgentController.php)
Updated the `viewWill()` method to detect Islamic wills and redirect to the Islamic-specific interface:

```php
// Route to different views based on will type
if ($will->will_type === 'islamic') {
    // For Islamic wills, show the Islamic-specific view
    return redirect()->route('agent.islamic.info', $will)
        ->with('message', 'Viewing Islamic Will Format');
}
```

**Location:** `app/Http/Controllers/AgentController.php` - viewWill method (line ~2524)

**What it does:**
- Intercepts will viewing requests
- Checks if the will type is 'islamic' or 'islamic_will'
- Redirects to the Islamic-specific info page instead of the generic individual will view
- Shows Islamic-specific sections: Info, Wasi, Religious Obligations, Funeral Instructions, Wasiyyah, Hibah

### 2. View Navigation (index.blade.php)
Updated the will list view to route buttons correctly based on will type:

#### A. "Start with" Button
```blade
@if($will->will_type === 'islamic' || $will->will_type === 'islamic_will')
    <a href="{{ route('agent.islamic.info', $will) }}" class="...">
        Start with Islamic Information →
    </a>
@else
    <a href="{{ route('agent.wills.testator', $will) }}" class="...">
        Start with Testator Information →
    </a>
@endif
```

#### B. "Edit Will" Button (For drafting wills)
```blade
@if($will->will_type === 'islamic' || $will->will_type === 'islamic_will')
    <a href="{{ route('agent.islamic.info', $will) }}" class="...">
        Edit Islamic Will
    </a>
@else
    <a href="{{ route('agent.wills.testator', $will) }}" class="...">
        Edit Will
    </a>
@endif
```

#### C. "Edit Corrections" Button (For rejected wills)
```blade
@if($will->will_type === 'islamic' || $will->will_type === 'islamic_will')
    <a href="{{ route('agent.islamic.info', $will) }}" class="...">
        Edit Corrections
    </a>
@else
    <a href="{{ route('agent.wills.testator', $will) }}" class="...">
        Edit Corrections
    </a>
@endif
```

**Location:** `resources/views/agent/wills/index.blade.php` - Multiple button sections

## How It Works

### User Flow:

1. **Agent Viewing Islamic Will in List:**
   - List shows Islamic wills with will type badge
   - Clicking any action button routes to Islamic-specific view
   - "Edit Islamic Will" label instead of generic "Edit Will"

2. **Agent Viewing Individual/Joint Will in List:**
   - List shows with will type badge
   - Clicking any action button routes to individual will view
   - "Edit Will" label as before

3. **Clicking into an Islamic Will:**
   - Agent clicks on an Islamic will
   - `viewWill()` controller detects it's Islamic
   - Automatically redirects to `agent.islamic.info` route
   - Shows Islamic-specific form with sections:
     - Islamic Information
     - Wasi (Islamic Trustee)
     - Religious Obligations
     - Funeral Instructions
     - Wasiyyah (Bequests)
     - Hibah & Arrangements
     - Family Members
     - Witnesses

### Button Routing:
- **Islamic Wills:** All buttons route to `agent.islamic.info`
- **Individual/Joint Wills:** All buttons route to `agent.wills.testator`

## Files Modified
1. **app/Http/Controllers/AgentController.php**
   - Updated `viewWill()` method to detect and redirect Islamic wills
   - Added joint will loading (for future enhancement)
   - Maintained backward compatibility for individual wills

2. **resources/views/agent/wills/index.blade.php**
   - Added conditional routing for "Start with" button
   - Added conditional routing for "Edit Will" button (drafting status)
   - Added conditional routing for "Edit Corrections" button (rejected status)

## Testing Checklist

- [ ] Create an Islamic will in agent portal
- [ ] Navigate to agent will list
- [ ] Click "Start with Islamic Information" button
- [ ] Verify Islamic-specific form appears
- [ ] Complete Islamic sections
- [ ] Click "Edit Islamic Will" button
- [ ] Verify redirects to Islamic info page (not individual will)
- [ ] Create corrections for Islamic will
- [ ] Verify "Edit Corrections" routes to Islamic view
- [ ] Verify individual wills still route correctly
- [ ] Verify joint wills still route correctly

## Benefits

1. **Correct Format:** Islamic wills now display with Islamic-specific sections
2. **User Experience:** Agents see "Islamic" labels and interface appropriate to will type
3. **Consistency:** All will types route to their appropriate format
4. **Maintainability:** Routing logic centralized in controller and view
5. **Backward Compatible:** Individual and joint wills continue working as before

## Notes

- The resume route logic in the index view already had proper handling for Islamic wills
- This fix ensures that when agents explicitly click on a will, they get the right format
- The Islamic-specific routes (`agent.islamic.info`, `agent.islamic.wasi`, etc.) were already in place and working
- This fix just ensures they're called correctly from the list view
