@extends('layouts.app')
@section('title', 'Detail Survei')
@section('content')

    <!-- button back -->
    <a href="{{ URL::to('admin/surveys') }}" class="mb-3 badge text-bg-light text-primary">
        <i class="ti ti-arrow-left">&nbsp;</i> Kembali
    </a>

    <!-- Surveys -->
    <div class="row d-flex align-items-strech">
        <div class="col-lg-12 mx-auto">
            <div class="card">
                <div class="card-header text-white bg-primary">
                    <h3 class="form-label mt-2 text-white border-bottom pb-3">{{ $survey->name }}</h3>
                    <pre for="description" class="mt-3 text-wrap">{{ $survey->description }}</pre>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-12 col-lg-12">
            <div class="card">
                <div class="card-body table-responsive">
                    <table class="table table-responsive table-bordered text-nowrap mb-0 align-middle">
                        <thead class="text-dark fs-4">
                            <tr>
                                <th class="border-bottom-0 align-middle" width="45px">
                                    <h6 class="fw-semibold mb-0 text-center">No.</h6>
                                </th>
                                <th class="border-bottom-0 align-middle" width="100px">
                                    <h6 class="fw-semibold mb-0 text-center">Tahun</h6>
                                </th>
                                <th class="border-bottom-0 align-middle">
                                    <h6 class="fw-semibold mb-0">NIK</h6>
                                </th>
                                <th class="border-bottom-0 align-middle" width="100px">
                                    <h6 class="fw-semibold mb-0 text-center">Nama</h6>
                                </th>
                                <th class="border-bottom-0 align-middle" width="100px">
                                    <h6 class="fw-semibold mb-0 text-center">Jenis Kelamin</h6>
                                </th>
                                <th class="border-bottom-0 align-middle" width="100px">
                                    <h6 class="fw-semibold mb-0 text-center">Tempat Lahir</h6>
                                </th>
                                <th class="border-bottom-0 align-middle" width="100px">
                                    <h6 class="fw-semibold mb-0 text-center">Usia</h6>
                                </th>
                                @foreach ($survey->questionSurveys as $_question)
                                    <th class="border-bottom-0 align-middle" width="300px">
                                        <h6 class="fw-semibold mb-0 text-wrap text-center">
                                            {{ $_question->name }}
                                        </h6>
                                    </th>
                                @endforeach
                            </tr>
                        </thead>
                        <tbody>
                            @php
                                $no = 1;
                                $answer_user = '';
                            @endphp

                            @foreach ($answerPerson as $_person)
                                <tr>
                                    <td class="text-center">{{ $no++ }}</td>
                                    <td>{{ $survey->years }}</td>
                                    <td>{{ $_person->users->nik }}</td>
                                    <td class="text-center">{{ $_person->users->name }}</td>
                                    <td class="text-center">{{ $_person->users->gender }}</td>
                                    <td class="text-center">{{ $_person->users->place_of_birth }}</td>
                                    <td class="text-center">{{ Carbon\Carbon::parse($_person->users->date_of_birth)->age }}</td>
                                    @php
                                        $questionAnswers = App\Models\QuestionAnswers::where(
                                            'survey_id',
                                            $_person->survey_id,
                                        )
                                            ->where('user_id', $_person->user_id)
                                            ->get();

                                    @endphp
                                    @foreach ($questionAnswers as $_answer)
                                        <td class="text-center">
                                            {{ $_answer->answer }}
                                        </td>
                                    @endforeach
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

@stop
