<div>
    
    <table class="table">
        <thead>
        <tr>
            <th><?php echo e(__('administrator.no.')); ?></th>
            <th><?php echo e(__('administrator.relation')); ?></th>
            <th><?php echo e(__('administrator.name')); ?></th>
            <th><?php echo e(__('administrator.sex')); ?></th>
            <th><?php echo e(__('administrator.dob')); ?></th>
            <th><?php echo e(__('administrator.job')); ?></th>
            <th><?php echo e(__('administrator.type')); ?></th>
            <th><?php echo e(__('administrator.alive')); ?></th>
            <th style="width: 100px;"><a href="javascript:void(0)" class="btn btn-xs btn-default r-add-family"><i class="fa fa-plus"></i> +
                </a></th>
        </tr>
        </thead>
        <tbody class="tbody-family_">
        <?php if(isset($emp->family)): ?>
            <?php if(is_array($emp->family)): ?>
                <?php if(count($emp->family)>0): ?>
                    <?php $__currentLoopData = $emp->family; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $k => $r): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php
                        $relation = isset($r['relation']) ? $r['relation'] : '';
                        $name = isset($r['name']) ? $r['name'] : '';
                        $sex = isset($r['sex']) ? $r['sex'] : '';
                        $dob = isset($r['dob']) ? $r['dob'] : '';
                        $job = isset($r['job']) ? $r['job'] : '';
                        $type = isset($r['type']) ? $r['type'] : '';

                        ?>
                        <tr>
                            <td class="r-no-family">1</td>
                            <td>
                                <select class="form-control" name="family[<?php echo e($k); ?>][relation]">
                                    <option value=""></option>
                                    <option <?php echo e($relation=='Father'?' selected="selected" ':''); ?>  value="Father">Father
                                    </option>
                                    <option <?php echo e($relation=='Mother'?' selected="selected" ':''); ?>  value="Mother">Mother
                                    </option>
                                    <option <?php echo e($relation=='Spouse'?' selected="selected" ':''); ?>  value="Spouse">Spouse
                                    </option>
                                    <option <?php echo e($relation=='Sibling'?' selected="selected" ':''); ?>  value="Sibling">Sibling
                                    </option>
                                    <option <?php echo e($relation=='Children'?' selected="selected" ':''); ?>  value="Children">
                                        Children
                                    </option>
                                </select>
                            </td>
                            <td>
                                <input class="form-control" value="<?php echo e($name); ?>" type="text" name="family[<?php echo e($k); ?>][name]">
                            </td>
                            <td>
                                <select class="form-control" name="family[<?php echo e($k); ?>][sex]">
                                    <option value=""></option>
                                    <option <?php echo e($sex=='M'?' selected="selected" ':''); ?>  value="M">Male</option>
                                    <option <?php echo e($sex=='F'?' selected="selected" ':''); ?>  value="F">Female</option>
                                </select>
                            </td>
                            <td>
                                <input type="text" value="<?php echo e($dob); ?>" name="family[<?php echo e($k); ?>][dob]" class="form-control dob">
                            </td>
                            <td>
                                <select class="form-control" name="family[<?php echo e($k); ?>][job]">
                                    <option value=""></option>
                                    <option <?php echo e($job=='Work'?' selected="selected" ':''); ?>  value="Work">Work</option>
                                    <option <?php echo e($job=='Study'?' selected="selected" ':''); ?>  value="Study">Study</option>
                                    <option <?php echo e($job=='Free'?' selected="selected" ':''); ?>  value="Free">Free</option>
                                    <option <?php echo e($job=='Retirement'?' selected="selected" ':''); ?>  value="Retirement">
                                        Retirement
                                    </option>
                                </select>
                            </td>
                            <td>
                                <select class="form-control" name="family[<?php echo e($k); ?>][type]">
                                    <option value=""></option>
                                    <option <?php echo e($type=='Dependent'?' selected="selected" ':''); ?>  value="Dependent">Dependent
                                    </option>
                                    <option <?php echo e($type=='Independent'?' selected="selected" ':''); ?>  value="Independent">
                                        Independent
                                    </option>
                                </select>
                            </td>
                            <td>
                                <select class="form-control" name="family[<?php echo e($k); ?>][alive]">
                                    <option <?php echo e($type=='alive'?' selected="selected" ':''); ?>  value="alive">alive</option>
                                    <option <?php echo e($type=='die'?' selected="selected" ':''); ?>  value="die">die</option>
                                </select>
                            </td>
                            <td style="text-align:center">
                                <a href="javascript:void(0)" class="btn btn-xs btn-default r-del"><i
                                            class="fa fa-trash"></i> - </a>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php endif; ?>
            <?php endif; ?>
        <?php endif; ?>
        </tbody>
    </table>
</div>


<?php $__env->startPush('script'); ?>
    <script>
        $(function () {


            $('body').on('click', '.r-del', function (e) {
                e.preventDefault();
                $(this).parent().parent().remove();
                updateNo_();
            });

            $('body').on('click', '.r-add-family', function (e) {
                e.preventDefault();
                var r = Math.floor(Math.random() * 26) + Date.now();

                var tr = '<tr>\n' +
                    '                <td class="r-no-family">1</td>\n' +
                    '                <td>\n' +
                    '                    <select class="form-control" name="family[' + r + '][relation]">\n' +
                    '                        <option value=""></option>\n' +
                    '                        <option value="Father">Father</option>\n' +
                    '                        <option value="Mother">Mother</option>\n' +
                    '                        <option value="Spouse">Spouse</option>\n' +
                    '                        <option value="Sibling">Sibling</option>\n' +
                    '                        <option value="Children">Children</option>\n' +
                    '                    </select>\n' +
                    '                </td>\n' +
                    '                <td>\n' +
                    '                    <input class="form-control" type="text" name="family[' + r + '][name]">\n' +
                    '                </td>\n' +
                    '                <td>\n' +
                    '                    <select class="form-control" name="family[' + r + '][sex]">\n' +
                    '                        <option value=""></option>\n' +
                    '                        <option value="M">Male</option>\n' +
                    '                        <option value="F">Female</option>\n' +
                    '                    </select>\n' +
                    '                </td>\n' +
                    '                <td>\n' +
                    '                    <input type="text" name="family[' + r + '][dob]" class="form-control dob">\n' +
                    '                </td>\n' +
                    '                <td>\n' +
                    '                    <select class="form-control" name="family[' + r + '][job]">\n' +
                    '                        <option value=""></option>\n' +
                    '                        <option value="Work">Work</option>\n' +
                    '                        <option value="Study">Study</option>\n' +
                    '                        <option value="Free">Free</option>\n' +
                    '                        <option value="Retirement">Retirement</option>\n' +
                    '                    </select>\n' +
                    '                </td>\n' +
                    '                <td>\n' +
                    '                    <select class="form-control" name="family[' + r + '][type]">\n' +
                    '                        <option value=""></option>\n' +
                    '                        <option value="Dependent">Dependent</option>\n' +
                    '                        <option value="Independent">Independent</option>\n' +
                    '                    </select>\n' +
                    '                </td>\n' +
                    '                <td>\n' +
                    '                   <select class="form-control" name="family[' + r + '][alive]">\n' +
                    '                       <option value="alive">alive</option>\n' +
                    '                       <option value="die">die</option>\n' +
                    '                   </select>\n' +
                    '               </td>' +
                    '                <td style="text-align:center">\n' +
                    '                    <a href="javascript:void(0)"  class="btn btn-xs btn-default r-del"><i class="fa fa-trash"></i> - </a>\n' +
                    '                </td>\n' +
                    '            </tr>';

                $('.tbody-family_').append(tr);

                // $('.dob').bootstrapDP({
                //     format: 'yyyy-mm-dd'
                // });
                updateNo_();
            });

            // $('.dob').bootstrapDP({
            //     format: 'yyyy-mm-dd'
            // });

            updateNo_();

            <?php if(!isset($emp->family)): ?>
            $('.r-add-family').trigger('click');
            <?php endif; ?>
        });

        function updateNo_() {

            $('.r-no-family').each(function (i, item) {
                $(this).text(i + 1);
            });
        }
    </script>
<?php $__env->stopPush(); ?><?php /**PATH /home/nsowos/public_html/shr-brand/resources/views/hr/employee/emp-family-script.blade.php ENDPATH**/ ?>