

<?php $__env->startSection('content'); ?>
<div class="card mb-3">
    <div class="card-header">
        <div class="row flex-between-end">
            <div class="col-auto align-self-center">
                <a href="<?php echo e(route('claims.show', $claim->id)); ?>" class="btn btn-primary btn-sm">
                    <i class="fas fa-arrow-circle-left"></i> Back to Claim
                </a>
                <br><br>
                <h5 class="mb-0">Edit Claim</h5>
            </div>
        </div>
    </div>

    <div class="card-body bg-light">

        
        <h5 class="text-primary">Policy Holder Information</h5>
        <p><strong>Name:</strong> <?php echo e($member->name); ?> <?php echo e($member->surname); ?></p>
        <p><strong>National ID:</strong> <?php echo e($member->national_id); ?></p>
        <p><strong>Phone:</strong> <?php echo e($member->cell_number); ?></p>
        <hr>

        
        <input type="hidden" id="ph_name" value="<?php echo e($member->name); ?>">
        <input type="hidden" id="ph_surname" value="<?php echo e($member->surname); ?>">
        <input type="hidden" id="ph_national_id" value="<?php echo e($member->national_id); ?>">
        <input type="hidden" id="ph_gender" value="<?php echo e($member->gender); ?>">
        <input type="hidden" id="ph_dob" value="<?php echo e($member->date_of_birth); ?>">

        
        <form method="POST" action="<?php echo e(route('claims.update', $claim->id)); ?>">
            <?php echo csrf_field(); ?>
            <?php echo method_field('PUT'); ?>

            <?php if($errors->any()): ?>
                <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <div class="alert alert-danger"><?php echo e($error); ?></div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <?php endif; ?>

            
            <h5 class="text-primary">Deceased Information</h5>

            <div class="row">
                <div class="col-md-6 mb-3">
                    <label><strong>Who is the Deceased?</strong></label>
                    <select name="deceased_type" id="deceased_type" class="form-control" required>
                        <option value="">-- Select --</option>
                        <option value="Policyholder"
                            <?php echo e($claim->deceased_type === 'Policyholder' ? 'selected' : ''); ?>>
                            Policy Holder
                        </option>
                        <option value="Dependant"
                            <?php echo e($claim->deceased_type === 'Dependant' ? 'selected' : ''); ?>>
                            Dependant
                        </option>
                    </select>
                </div>

                <div class="col-md-6 mb-3" id="dependant_div" style="display:none;">
                    <label><strong>Select Dependant</strong></label>
                    <select id="dependant_select" class="form-control">
                        <option value="">-- Select Dependant --</option>
                        <?php $__currentLoopData = $dependants; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $dependant): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option
                                data-name="<?php echo e($dependant->name); ?> <?php echo e($dependant->surname); ?>"
                                data-national-id="<?php echo e($dependant->national_id); ?>"
                                data-gender="<?php echo e($dependant->gender); ?>"
                                data-dob="<?php echo e($dependant->d_o_b); ?>">
                                <?php echo e($dependant->name); ?> <?php echo e($dependant->surname); ?> (<?php echo e($dependant->relationship); ?>)
                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
            </div>

            <div class="row">
                <div class="col-md-6 mb-3">
                    <label><strong>Deceased Full Name</strong></label>
                    <input type="text" name="deceased_full_name"
                           id="deceased_name"
                           value="<?php echo e(old('deceased_full_name', $claim->deceased_full_name)); ?>"
                           class="form-control" required>
                </div>

                <div class="col-md-6 mb-3">
                    <label><strong>Deceased National ID</strong></label>
                    <input type="text" name="deceased_national_id"
                           id="deceased_national_id"
                           value="<?php echo e(old('deceased_national_id', $claim->deceased_national_id)); ?>"
                           class="form-control" required>
                </div>

                <div class="col-md-6 mb-3">
                    <label><strong>Gender</strong></label>
                    <select id="deceased_gender" class="form-control" required>
                        <option value="">-- Select Gender --</option>
                        <option value="Male" <?php echo e($claim->deceased_gender === 'Male' ? 'selected' : ''); ?>>Male</option>
                        <option value="Female" <?php echo e($claim->deceased_gender === 'Female' ? 'selected' : ''); ?>>Female</option>
                    </select>
                    <input type="hidden"
                           name="deceased_gender"
                           id="hidden_deceased_gender"
                           value="<?php echo e($claim->deceased_gender); ?>">
                </div>

                <div class="col-md-6 mb-3">
                    <label><strong>Date of Birth</strong></label>
                    <input type="date" name="deceased_date_of_birth"
                           id="deceased_dob"
                           value="<?php echo e(old('deceased_date_of_birth', $claim->deceased_date_of_birth)); ?>"
                           class="form-control" required>
                </div>
            </div>

            <hr>

            
            <h5 class="text-primary">Claim Details</h5>

            <div class="row">
                <div class="col-md-6 mb-3">
                    <label><strong>Date of Death</strong></label>
                    <input type="date" name="date_of_death"
                           value="<?php echo e(old('date_of_death', $claim->date_of_death)); ?>"
                           class="form-control" required>
                </div>

                <div class="col-md-6 mb-3">
                    <label><strong>Cause of Death</strong></label>
                    <input type="text" name="cause_of_death"
                           value="<?php echo e(old('cause_of_death', $claim->cause_of_death)); ?>"
                           class="form-control" required>
                </div>
            </div>

            <div class="row">
                <div class="col-md-6 mb-3">
                    <label><strong>Relationship to Policy Holder</strong></label>
                    <select name="relationship_to_policyholder" class="form-control" required>
                        <?php $__currentLoopData = ['Self','Spouse','Child','Parent','Sibling','Executor','Other']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rel): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($rel); ?>"
                                <?php echo e($claim->relationship_to_policyholder === $rel ? 'selected' : ''); ?>>
                                <?php echo e($rel); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <div class="col-md-6 mb-3">
                    <label><strong>Remarks</strong></label>
                    <textarea name="remarks" class="form-control" rows="3"><?php echo e($claim->remarks); ?></textarea>
                </div>
            </div>

            <hr>

            
            <h5 class="text-primary">Claimant Information</h5>

            <div class="row">
                <div class="col-md-6 mb-3">
                    <label><strong>Claimant Full Name</strong></label>
                    <input type="text" name="claimant_full_name"
                           value="<?php echo e(old('claimant_full_name', $claim->claimant_full_name)); ?>"
                           class="form-control" required>
                </div>

                <div class="col-md-6 mb-3">
                    <label><strong>Claimant National ID</strong></label>
                    <input type="text" name="claimant_national_id"
                           value="<?php echo e(old('claimant_national_id', $claim->claimant_national_id)); ?>"
                           class="form-control">
                </div>
            </div>

            <div class="row">
                <div class="col-md-6 mb-3">
                    <label><strong>Claimant Phone</strong></label>
                    <input type="text" name="claimant_phone"
                           value="<?php echo e(old('claimant_phone', $claim->claimant_phone)); ?>"
                           class="form-control">
                </div>

                <div class="col-md-6 mb-3">
                    <label><strong>Claimant Address</strong></label>
                    <input type="text" name="claimant_address"
                           value="<?php echo e(old('claimant_address', $claim->claimant_address)); ?>"
                           class="form-control">
                </div>
            </div>

            <div class="text-center">
                <button class="btn btn-warning btn-sm">
                    <i class="far fa-save"></i> Update Claim
                </button>
            </div>
        </form>
    </div>
</div>


<script>
document.addEventListener('DOMContentLoaded', function () {

    const deceasedType = document.getElementById('deceased_type');
    const dependantDiv = document.getElementById('dependant_div');
    const dependantSelect = document.getElementById('dependant_select');

    const name = document.getElementById('deceased_name');
    const nid = document.getElementById('deceased_national_id');
    const gender = document.getElementById('deceased_gender');
    const hiddenGender = document.getElementById('hidden_deceased_gender');
    const dob = document.getElementById('deceased_dob');

    const ph = {
        name: document.getElementById('ph_name').value + ' ' +
              document.getElementById('ph_surname').value,
        nid: document.getElementById('ph_national_id').value,
        gender: document.getElementById('ph_gender').value,
        dob: document.getElementById('ph_dob').value
    };

    function lock() {
        name.readOnly = nid.readOnly = dob.readOnly = true;
        gender.disabled = true;
    }

    function unlock() {
        name.readOnly = nid.readOnly = dob.readOnly = false;
        gender.disabled = false;
    }

    function init() {
        if (deceasedType.value === 'Policyholder') {
            dependantDiv.style.display = 'none';
            lock();
        }
        if (deceasedType.value === 'Dependant') {
            dependantDiv.style.display = 'block';
            lock();
        }
    }

    deceasedType.addEventListener('change', function () {
        unlock();
        dependantDiv.style.display = 'none';

        if (this.value === 'Policyholder') {
            name.value = ph.name;
            nid.value = ph.nid;
            gender.value = ph.gender;
            hiddenGender.value = ph.gender;
            dob.value = ph.dob;
            lock();
        }

        if (this.value === 'Dependant') {
            dependantDiv.style.display = 'block';
        }
    });

    dependantSelect.addEventListener('change', function () {
        const opt = this.options[this.selectedIndex];
        if (!opt.value) return;

        name.value = opt.dataset.name;
        nid.value = opt.dataset.nationalId;
        gender.value = opt.dataset.gender;
        hiddenGender.value = opt.dataset.gender;
        dob.value = opt.dataset.dob;
        lock();
    });

    gender.addEventListener('change', () => {
        hiddenGender.value = gender.value;
    });

    init();
});
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\WORK-STATION\MBBS\Insurance-Version Controls\03-01-2026\resources\views/claims/edit.blade.php ENDPATH**/ ?>