@php
    use App\Models\ChaosEvents;
@endphp

@extends('layout.app')

@section('scripts')
    <link rel="stylesheet" href="{{ asset('/css/application/edit.css') }}">
    <script>
        const i18n = {
            common: {
                error_occurred: "{{ __('app.common.error_occurred') }}"
            },
            blog: {
                confirm_save: "{{ __('app.blog.confirm_save') }}",
                confirm_delete: "{{ __('app.blog.confirm_delete') }}"
            }
        };
    </script>
    <script src="{{ asset('/js/preapplication/edit.js') }}"></script>
@endsection

@section('content')
    <h1>{{ __('app.preapplication.edit.download.title') }}</h1>
    <p>{{ __('app.preapplication.edit.download.description') }}</p>
    <div class="eingabemaske">
        <form action="{{ route('generatePDF') }}" method="GET">
            <label for="event_id">{{ __('app.preapplication.region') }}:</label>
            <select id="event_id" name="event_id">
                @foreach(ChaosEvents::all() as $event)
                    <option value="{{ $event->id }}">{{ $event->name }}</option>
                @endforeach
            </select>
            <br /><br />
            <button type="submit">{{ __('app.preapplication.edit.download.button') }}</button>
        </form>
    </div>
    <br /><br />

    <h1>{{ __("app.preapplication.edit.title") }}</h1>
    <p>{{ __("app.preapplication.edit.description") }}</p>

    <b>{{ __('app.preapplication.passport_type') }}:</b><br />
    d = {{ __('app.preapplication.passport.standard') }}<br />
    k = {{ __('app.preapplication.passport.kid') }}
    <br /><br />

    <div class="eingabemaske">
        <table class="eingabetabelle">
            <tr>
                <th>{{ __('app.preapplication.region') }}</th>
                <th>{{ __('app.preapplication.reference_number') }}</th>
                <th>{{ __('app.preapplication.firstname') }}</th>
                <th>{{ __('app.preapplication.lastname') }}</th>
                <th>{{ __('app.preapplication.location') }}</th>
                <th>{{ __('app.preapplication.notes') }}</th>
                <th>{{ __('app.preapplication.mail') }}</th>
                <th>{{ __('app.preapplication.passport_type') }}</th>
                <th>{{ __('app.preapplication.created_at') }}</th>
                <th>{{ __('app.preapplication.actions') }}</th>
            </tr>
        @foreach($applications as $appl)
                <tr id="application_{{ $appl->id }}">
                    <td>{{ $appl->event()->first()->name }}</td>
                    <td>{{ $appl->reference_number }}</td>
                    <td><input id="first_name_{{ $appl->id }}" class="first-name-input" type="text" value="{{ $appl->first_name }}"></td>
                    <td><input id="last_name_{{ $appl->id }}" class="last-name-input" type="text" value="{{ $appl->last_name }}"></td>
                    <td><input id="location_{{ $appl->id }}" class="location-input" type="text" value="{{ $appl->location }}"></td>
                    <td><textarea id="notes_{{ $appl->id }}" class="notes-input">{{ $appl->notes }}</textarea></td>
                    <td><input id="mail_{{ $appl->id }}" type="text" value="{{ $appl->email }}"></td>
                    <td>
                        <select id="passport_type_{{ $appl->id }}" class="passport-type-select">
                            <option value="d"{{ ( $appl->passport_type == "d" ? " selected" : "" ) }}>d</option>
                            <option value="k"{{ ( $appl->passport_type == "k" ? " selected" : "" ) }}>k</option>
                        </select>
                    </td>
                    <td>{{ $appl->created_at }}</td>
                    <td><button onclick="editApplication({{ $appl->id }})">{{ __('app.preapplication.edit.save') }}</button><button id="applicationDelete_{{ $appl->id }}" onclick="deleteApplication({{ $appl->id }})">{{ __('app.preapplication.edit.delete') }}</button></td>
                </tr>
        @endforeach
            <tr>
                <td>
                    <select id="region_new">
                        @foreach(ChaosEvents::getActiveEvents() as $region)
                            <option value="{{ $region->id }}">{{ $region->name }}</option>
                        @endforeach
                    </select>
                </td>
                <td>{{ __('app.preapplication.edit.generated') }}</td>
                <td><input id="first_name_new" class="first-name-input" type="text"></td>
                <td><input id="last_name_new" class="last-name-input" type="text"></td>
                <td><input id="location_new" class="location-input" type="text"></td>
                <td><textarea id="notes_new" class="notes-input"></textarea></td>
                <td><input id="mail_new" type="text"></td>
                <td><select id="passport_type_new" class="passport-type-select">
                        <option value="d">d</option>
                        <option value="k">k</option>
                    </select>
                </td>
                <td></td>
                <td><button onclick="addApplication()">{{ __('app.preapplication.edit.add') }}</button></td>
            </tr>
        </table>
    </div>

@endsection
