@extends('layouts.layout-2')

@section('content')
    <h4 class="font-weight-bold py-3 mb-1">
        Airline
    </h4>
    <div class="card">
        <div class="card-datatable table-responsive">
            <table class="datatables-default table table-striped table-bordered">
                <thead>
                <tr>
                    <th style="max-width: 60px;">&nbsp;</th>
                    <th>{{__('#')}}</th>
                    <th>{{__('Name')}}</th>
                    <th>{{__('E-Mail(s)')}}</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                @foreach($airline as $value)
                    <tr>
                        <td>
                            <button type="button" class="btn icon-btn btn-sm btn-primary" data-toggle="modal" data-target="#modals-default"
                                    data-id="{{ $value->id }}"
                                    data-name="{{ $value->name }}"
                                    data-name_full="{{ $value->name_full }}"
                                    data-contact_emails="{{\App\Services\Util::_implodeLines($value->contact_emails)}}">
                                <span class="fa fa-edit"></span>
                            </button>
                        </td>
                        <td data-sort="{{ $value->name }}">{{ $value->name  }}</td>
                        <td data-sort="{{ $value->name_full }}">{{ $value->name_full  }}</td>
                        <td>{!! \App\Services\Util::_implodeLines($value->contact_emails, "<br>") !!}</td>
                        <td><a class="text-danger" href="{{ route('admin_settings_airline_delete', [$value->id]) }}"  onclick="return confirm('{{__('Wirklich löschen?')}}');"><i class="fa fa-trash-alt"></i></a></td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            <div class="mt-4 col">
                <button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#modals-default"
                        data-id="new"
                        data-name=""
                        data-name_full=""
                        data-contact_emails=""
                >Neue Airline anlegen</button>
            </div>
        </div>
    </div>
        <!-- Modal template -->
        <div class="modal fade" id="modals-default">
            <div class="modal-dialog">
                <form class="modal-content" action="{{ route('admin_settings_airline_update') }}" method="post">
                    @csrf
                    <input type="hidden" class="form-control" name="id">
                    <div class="modal-header">
                        <h5 class="modal-title">Airline <span class="font-weight-light">anlegen/bearbeiten</span></h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">×</button>
                    </div>
                    <div class="modal-body">
                        <div class="form-row">
                            <div class="form-group col">
                                <label for="name" class="form-label">Kürzel*</label>
                                <input type="text" class="form-control" name="name" placeholder="{{__('Kürzel')}}" required>
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group col">
                                <label for="name_full" class="form-label">Name*</label>
                                <input type="text" class="form-control" name="name_full" placeholder="{{__('Name')}}" required>
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group col">
                                <label class="form-label" for="contact_emails">Für interene Mails <span class="text-muted">(jede E-Mail in eine extra Zeile)</span></label>
                                <textarea class="form-control" rows="4" name="contact_emails" cols="50"></textarea>
                            </div>
                        </div>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">{{__('close')}}</button>
                        <button type="submit" class="btn btn-primary">{{__('save')}}</button>
                    </div>
                </form>
            </div>
        </div>

        <script>
            $( document ).ready(function() {

                $('#modals-default').on('show.bs.modal', function (event) {
                    var button = $(event.relatedTarget);
                    $(this).find(".modal-content input[name='id']").val(button.data('id'));
                    $(this).find(".modal-body input[name='name']").val(button.data('name'));
                    $(this).find(".modal-body input[name='name_full']").val(button.data('name_full'));
                    $(this).find(".modal-body textarea[name='contact_emails']").val(button.data('contact_emails'));
                });
                $('.datatables-default').dataTable({
                    "bLengthChange": false,
                    "iDisplayLength": 50,
                    "order": [[ 1, "asc" ]],
                    "language": {
                        "url": "/js/German.json"
                    }
                });
            });
        </script>
@endsection