<input type="hidden" value="{{ $employee->tag_id ? $employee->tag->uid : '' }}" id="tag"/>
<table class="table table-bordered  data-list-table" id="wrapper" data-table="simpleDataTables">
    <thead>
    <tr>
        <th colspan="6" style="text-align: center">{{ __('messages.details_info') }}</th>
    </tr>
    </thead>
    <tbody>
        <tr>
            <td class="text-end" style="font-weight: bold">{{ __('messages.name') }}</td>
            <td style="font-weight: bold" colspan="2">{{ $employee->employee_name }}</td>
            <td>
                <img class="user-profile" style="width:100px; height:auto"
                src="{{ isset($employee->employee_image) ? url('storage/employee_images/'.$employee->employee_image) : asset('assets/image/fake-user.jpg') }}" alt="">
            </td>
            <td colspan="2" rowspan="7">
                <h5><u>Documents</u></h5>
                <div style="height: 350px; overflow-y:scroll; width:100%">
                    @if($employee->employee_images)
                        @foreach ($employee->employee_images as $key => $item)
                            <div style="width:100%">
                                <span>
                                    {{($key+1) . ') ' . substr($item->image, 0, 10)}}
                                    <a href="{{ url('storage/employee_images/'.$item->image) }}" title="Click to download the files" style="font-size: 14px;line-height: 1;color:green" download="{{($key+1) . ') ' . $item->image}}">Download</a>
                                    <br>
                                    <?php
                                    $arr = explode(".", strtolower($item->image));
                                    $extension = $arr[(count($arr) - 1)];
                                    if (in_array($extension, ['jpg', 'jpeg', 'png', 'gif'])) {
                                        ?>
                                        <img class="user-profile" style="width:100px; height:auto" src="{{ url('storage/employee_images/'.$item->image) }}" alt="">
                                        <?php
                                    } else {
                                        echo 'Not Image File';
                                    } ?>
                                    <br>
                                    <br>
                                </span>
                            </div>
                        @endforeach
                    @endif
                </div>
            </td>
        </tr>
        <tr>
            <td class="text-end" style="font-weight: bold">{{ __('messages.employee_no') }}</td>
            <td>{{ $employee->employee_no ?: '' }}</td>
            <td class="text-end">{{ __('messages.nid_no') }}</td>
            <td>{{ $employee->nid_no ?? 'N/A' }}</td>
        </tr>
        <tr>
            <td class="text-end">{{ __('messages.sex') }}</td>
            <td>{{ $employee->sex ?: '' }}</td>
            <td class="text-end">{{ __('messages.birth_date') }}</td>
            <td>{{ date('d-m-Y', strtotime($employee->birth_date)) }}</td>
        </tr>
            {{-- @php
                // $weight = App\Models\BodyWeight::where('employee_id', $employee->id);
            @endphp --}}

        <tr>
            <td class="text-end" style="font-weight: bold">{{ __('messages.father_name') }}</td>
            <td>{{ $employee->father_name ?? 'N/A' }}</td>
            <td class="text-end" style="font-weight: bold">{{ __('messages.mother_name') }}</td>
            <td>{{ $employee->mother_name ?? 'N/A' }}</td>
        </tr>
        <tr>
            <td class="text-end">{{ __('messages.present_address') }}</td>
            <td>{{ $employee->present_address ?? 'N/A' }}</td>
            <td class="text-end">{{ __('messages.permanent_address') }}</td>
            <td>{{ $employee->permanent_address ?? 'N/A' }}</td>
        </tr>
        <tr>
            <td class="text-end">{{ __('messages.mobile_no') }}</td>
            <td>{{ $employee->mobile_no ?? 'N/A' }}</td>
            <td class="text-end">{{ __('messages.email') }}</td>
            <td>{{ $employee->email ?? 'N/A' }}</td>
        </tr>
        <tr>
            <td class="text-end">{{ __('messages.created_by') }}</td>
            <td>{{ $employee->added_by ? App\Models\User::where('id', $employee->added_by)->pluck('name')->first() : 'N/A' }}</td>
            <td class="text-end">{{ __('messages.created_at') }}</td>
            <td>{{ date('d-m-Y',strtotime($employee->added_on)) }}</td>
        </tr>
        <tr>
            <th colspan="6" style="text-align: center">{{ __('messages.service_record') }}</th>
        </tr>
        <tr>
            <th>{{ __('messages.sl') }}</th>
            <th>{{ __('messages.branch') }}</th>
            <th>{{ __('messages.designation') }}</th>
            <th>{{ __('messages.department') }}</th>
            <th>{{ __('messages.rec_date') }}</th>
            <th>{{ __('messages.record_type') }}</th>
        </tr>
        <?php
        if($jobsRecord) {
            foreach ($jobsRecord as $key => $value) {
                ?>
                <tr>
                    <td>{{ ($key+1) }}</td>
                    <td>{{ $value->org_name }}</td>
                    <td>{{ $value->designation_name }}</td>
                    <td>{{ $value->department_name }}</td>
                    <td>{{ date('d-M-Y', strtotime($value->rec_date)) }}</td>
                    <td>{{ ($value->rec_type == 1) ? "promotion" : (($value->rec_type == 2) ? "Demotion" : (($value->rec_type == 3) ? "Resign" : "Others")) }}</td>
                </tr>
                <?php
            }
        }
        ?>

    </tbody>
</table>
<script type="text/javascript">
    var tag = $("#tag").val();

    function saveAs(uri, filename) {
        var link = document.createElement('a');
        if (typeof link.download === 'string') {
            link.href = uri;
            link.download = filename;
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        } else {
            window.open(uri);
        }
    }

    $(document).ready(function () {
        $('#carouselExampleCaption').carousel({
            interval: 20000
        });
        let items = document.querySelectorAll('.carousel .carousel-item')
        items.forEach((el) => {
            const minPerSlide = 3
            let next = el.nextElementSibling
            for (var i = 1; i < minPerSlide; i++) {
                if (!next) {
                    next = items[0]
                }
                let cloneChild = next.cloneNode(true)
                el.appendChild(cloneChild.children[0])
                next = next.nextElementSibling
            }
        })
    });
</script>
