@extends('layouts.layout-2')

@section('content')

    <h4 class="font-weight-bold py-3 mb-1">
        Programm verwalten
    </h4>

    {!! Form::open(['url' => route('travel_program_detail', [$id]), 'class' => 'form-horizontal']) !!}
    <input type="hidden" name="id" id="id" value="{{$id}}">

    <!-- draft -->
    <div class="card mb-2">
        <div class="card-body">
            <div class="form-group">
                    <label class="custom-control custom-checkbox float-right">
                        {!! Form::checkbox('status', 1, $program->status, ['class'=>'custom-control-input']) !!}
                        <span class="custom-control-label">{{__('aktiv')}}</span>
                    </label>

                <label class="form-label" for="program_title">{{ __('Title') }}*</label>
                {{ Form::text('title', $program->title,  array('placeholder'=>__('Title'), 'class'=>'form-control', 'id'=>'program_title', 'required'=>true)) }}
            </div>
            <div class="form-row">
                <div class="form-group col-sm-6">
                    <label class="form-label" for="program_subtitle">{{ __('Subtitle') }}*</label>
                    {{ Form::text('subtitle', $program->subtitle,  array('placeholder'=>__('Subtitle'), 'class'=>'form-control', 'id'=>'program_subtitle', 'required'=>true)) }}
                </div>

                <div class="form-group col-sm-6">
                    <label class="form-label" for="program_code">{{ __('Programm Code') }}*</label>
                    {{ Form::text('program_code', $program->program_code,  array('placeholder'=>__('Programm Code'), 'class'=>'form-control', 'id'=>'program_code', 'required'=>true)) }}
                </div>
            </div>
            <div class="form-row">
                <div class="form-group col">
                    <label for="weekdays" class="form-label">{{__('Wochentage')}}*</label>
                    <select class="selectpicker" data-style="btn-default" name="weekdays[]" multiple required>
                        {!!  HTMLHelper::getWeekdaysOptions(false, $program->getWeekdaysArray()) !!}
                    </select>
                </div>
            </div>
        </div>
    </div>

    <!-- program classes -->
    <div class="card mb-2">
        <h6 class="card-header">
            Eingetragene Kategorien/Klassen
        </h6>
        <div class="card-body">
            <table class="table table-striped">
                <thead>
                <tr>
                    <th>#</th>
                    <th>Name</th>
                    <th>Standard</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                @foreach($program->classes as $value)

                <tr>
                    <td>
                        <button type="button" class="btn icon-btn btn-sm btn-primary" data-toggle="modal" data-target="#modals-class"
                                 data-id="{{ $value->id }}"
                                 data-name="{{ $value->name }}"
                                 data-description="{{ $value->description }}"
                                 data-standard="{{ $value->standard }}">
                            <span class="far fa-edit"></span>
                        </button>
                    </td>
                    <td>{{ $value->name }}</td>
                    <td>@if($value->standard)
                            <span class="badge badge-pill badge-success"><i class="far fa-check"></i></span>
                        @else
                            <span class="badge badge-pill badge-danger"><i class="far fa-times"></i></span>
                        @endif
                    </td>
                    <td><a class="text-danger" href="{{ route('travel_program_class_delete', [$value->id]) }}"  onclick="return confirm('{{__('Wirklich löschen?')}}');"><i class="far fa-trash-alt"></i></a></td>
                </tr>
                @endforeach
                </tbody>
            </table>
            <div class="text-right">
                <button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#modals-class"
                        data-id="new"
                        data-name=""
                        data-description=""
                        data-active="1"
                >Neue Katagorie anlegen</button>
            </div>
        </div>
    </div>


    <!-- program classes -->
    <div class="card mb-2">
        <h6 class="card-header">
            Vorlagen Reiseprogramm (CRM)
        </h6>
        <div class="card-body">
            <table class="table table-striped">
                <thead>
                <tr>
                    <th>#</th>
                    <th>Name</th>
                    <th>Kategorie</th>
                    <th>Wochentage</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                @foreach($program->travel_program_drafts as $value)
                    <tr>
                        <td>
                            <button type="button" class="btn icon-btn btn-sm btn-primary" data-toggle="modal" data-target="#modals-draft"
                                    data-id="{{ $value->id }}"
                                    data-travel_class_id="{{ $value->travel_class_id }}"
                                    data-draft_id="{{ $value->draft_id }}"
                                    data-weekdays="{{ json_encode($value->weekdays) }}">
                                <span class="far fa-edit"></span>
                            </button>
                        </td>
                        <td>{{ $value->draft->name }}</td>
                        <td>@if( $value->travel_class)
                                {{  $value->travel_class->name  }}
                            @else
                                alle Kategorien
                            @endif
                        </td>
                        <td>
                            {!!  HTMLHelper::getWeekdaysString($value->weekdays) !!}
                        </td>
                        <td><a class="text-danger" href="{{ route('travel_program_draft_delete', [$value->id]) }}"  onclick="return confirm('{{__('Wirklich löschen?')}}');"><i class="far fa-trash-alt"></i></a></td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            <div class="text-right">
                <button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#modals-draft"
                        data-id="new"
                        data-travel_class_id=""
                        data-draft_id=""
                        data-weekdays=""
                >Neue Vorlage zuordnen</button>
            </div>
        </div>
    </div>


    <div class="text-left mt-3">
        <button type="submit" name="action" value="saveAll" class="btn btn-submit">{{ __('save changes') }}</button>&nbsp;
        <a href="{{route('travel_programs')}}" class="btn btn-default">{{ __('back') }}</a>
        <a href="{{ make_v2_url("/acp/travel_program/show/".$program->id."/") }}" class="btn btn-default float-right">{{ __('zurück ins v2 Programm') }}</a>
    </div>

    {!! Form::close() !!}




    <!-- Modal template -->
    <div class="modal fade" id="modals-class">
        <div class="modal-dialog">
            <form class="modal-content" action="{{ route('travel_program_class_update') }}" method="post">
                @csrf
                <input type="hidden" class="form-control" name="id">
                <input type="hidden" class="form-control" name="program_id" value="{{$program->id}}">


                <div class="modal-header">
                    <h5 class="modal-title">Programm Katagorie/Klassen <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 class="custom-control custom-checkbox float-right">
                                <input type="checkbox" class="custom-control-input" name="standard" checked>
                                <span class="custom-control-label">{{__('Standard')}}</span>
                            </label>
                            <label for="name" class="form-label">Name*</label>
                            <input type="text" class="form-control" name="name" placeholder="{{__('Description')}}" required>
                        </div>
                    </div>

                    <div class="form-row">
                        <div class="form-group col">
                            <label for="description" class="form-label">Beschreibung</label>
                            <input type="text" class="form-control" name="description" placeholder="{{__('Description')}}">
                        </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>


    <!-- Modal template -->
    <div class="modal fade" id="modals-draft">
        <div class="modal-dialog">
            <form class="modal-content" action="{{ route('travel_program_draft_update') }}" method="post">
                @csrf
                <input type="hidden" class="form-control" name="id">
                <input type="hidden" class="form-control" name="travel_program_id" value="{{$program->id}}">

                <div class="modal-header">
                    <h5 class="modal-title">Vorlage Reiseprogramm <span class="font-weight-light">zuordnen</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="draft_id" class="form-label">{{__('Vorlage')}}</label>
                            <select class="selectpicker" data-style="btn-default" name="draft_id" data-live-search="true" required>
                                {!!  HTMLHelper::getDraftOptions() !!}
                            </select>
                        </div>
                    </div>

                    <div class="form-row">
                        <div class="form-group col">
                            <label for="travel_class_id" class="form-label">{{__('Kategorie')}}</label>
                            <select class="selectpicker" data-style="btn-default" name="travel_class_id">
                                {!!  HTMLHelper::getTravelClassOptions($program->id) !!}
                            </select>
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="form-group col">
                            <label for="weekdays" class="form-label">{{__('Wochentage')}}</label>
                            <select class="selectpicker" data-style="btn-default" name="weekdays[]" multiple>
                                {!!  HTMLHelper::getWeekdaysOptions($program->id) !!}

                            </select>
                        </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-class').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='description']").val(button.data('description'));
                $(this).find(".modal-body input[name='standard']").prop( "checked", button.data('standard'));
            });

            $('#modals-draft').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 select[name='draft_id']").val(button.data('draft_id'));
                $(this).find(".modal-body select[name='travel_class_id']").val(button.data('travel_class_id'));
                $(this).find(".modal-body select[name='weekdays[]']").val(button.data('weekdays'));

                $('.selectpicker').selectpicker('refresh');
            });
        });
    </script>


@endsection