@extends('layouts.masteruser')
@section('title', 'Addiction Test')
@section('styles')
    <link rel="stylesheet" href="{{ asset('assets/vendors/flatpickr/flatpickr.min.css') }}">
@endsection
@section('content')
    <div class="page-content">
        <div class="row">
            <div class="col-12">
                <div class="row justify-content-center">
                    <div class="col-md-8 grid-margin stretch-card">
                        <div class="card">
                            <div class="card-header">
                                <h4 class="card-title mb-0">Addiction Test</h4>
                            </div>
                            <div class="card-body">
                                <form id="addiction-form" action="{{ route('user.addiction.store') }}" method="post" autocomplete="off">
                                    @csrf
                                    @method('POST')
                                    <table class="table table-bordered w-100 text-wrap align-middle">
                                        <thead>
                                            <tr>
                                                <th>Item Content</th>
                                                <th class="text-center">Select Answer</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @foreach ($items as $item)
                                                <tr>
                                                    <td class="text-wrap">{{ $item->content }}</td>
                                                    <td class="text-center">
                                                        <input type="hidden" name="values[]" value="{{ $item->value }}">
                                                        <select name="answers[]" class="form-select" required>
                                                            <option value="" hidden>Select Answer</option>
                                                            @foreach ($likerts as $likert)
                                                                <option value="{{ $likert->score }}" {{ in_array($likert->score, old('answers', [])) ? 'selected' : '' }}>
                                                                    {{ $likert->name }}
                                                                </option>
                                                            @endforeach
                                                        </select>
                                                    </td>
                                                </tr>
                                            @endforeach
                                        </tbody>
                                    </table>
                                </form>
                            </div>
                            <div class="card-footer text-end">
                                <button type="submit" form="addiction-form" class="btn btn-primary">Submit</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('scripts')
    <script src="{{ asset('assets/vendors/flatpickr/flatpickr.min.js') }}"></script>
    <script src="{{ asset('assets/vendors/apexcharts/apexcharts.min.js') }}"></script>
    <script src="{{ asset('assets/js/dashboard.js') }}"></script>
@endsection
