@extends('layouts.layout-2')

@section('content')
    <style>
        .btn-xs {
            line-height: 1.3em;
        }
        .table tbody + tbody {
            border-top: 1px solid #9c9c9c;
        }
        .table th, .table td {
            border-top: none;
        }
        .table tr.border-none td, .table tr.border-none th  {
            border-top: none;
        }
        .table .thead-dark th {
            color: #4E5155;
            background-color: rgba(24, 28, 33, 0.1);
            border-color: rgba(63, 69, 74, 0.1);
        }

        .input-group-text {
            padding: 0.438rem 0.475rem;
        }
        .badge.indicator:not(.badge-dot) {
            -webkit-transform: translate(20%, -30%);
            transform: translate(20%, -30%);
        }
    </style>
    @if ($errors->any())
        <div class="row">
            <div class="col-sm-12">
                <div class="alert alert-danger">
                    <ul>
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            </div>
        </div>
    @endif


    <div class="float-right mt-3">
        <a href="{{route('travel_user_booking_fewos')}}" class="btn btn-default btn-sm">{{ __('zur Übersicht') }}</a>
    </div>
    <h4 class="font-weight-bold py-3 mb-1">
        Buchung FeWo @if($id === "new") <span class="text-primary">anlegen</span> @else {{"(ID: ".$id.")"}} verwalten @endif
    </h4>


    <ul class="nav nav-sm nav-tabs nav-justified tabs-alt mb-3" id="top-nav-quick-jump">
        <li class="nav-item">
            <a class="nav-link" href="javascript:void(0)" data-collapse="#collapseBookingInfo">
                Kunde / Buchung
            </a>
        </li>
        @if($travel_user_booking_fewo->id > 0)
        <li class="nav-item">
            <a class="nav-link" href="javascript:void(0)" data-collapse="#collapseBookingInvoice">
                @if($travel_user_booking_fewo->isInvoice())
                    <span class="badge badge-outline-secondary"><i class="fa fa-check-circle"></i></span>
                    @endif
                Mietbestätigung
                <span class="badge badge-outline-primary">{{my_count($travel_user_booking_fewo->send_user_mail)}}</span>
            </a>
        </li>

            <li class="nav-item">
                <a class="nav-link" href="javascript:void(0)" data-collapse="#collapseBookingTravelInfo">
                    @if($travel_user_booking_fewo->isTravelInfo())
                        <span class="badge badge-outline-secondary"><i class="fa fa-check-circle"></i></span>
                    @endif
                    Anreiseinfo
                    <span class="badge badge-outline-primary">{{my_count($travel_user_booking_fewo->send_info_mail)}}</span>
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="javascript:void(0)" data-collapse="#collapseBookingSMail">
                    Dienstleister Mail
                    <span class="badge badge-outline-primary">{{my_count($travel_user_booking_fewo->send_service_mail)}}</span>
                </a>
            </li>

            <li class="nav-item">
                <a class="nav-link" href="javascript:void(0)" data-collapse="#collapseBookingMMail">
                    Mitarbeiter Mail
                    <span class="badge badge-outline-primary">{{my_count($travel_user_booking_fewo->send_employee_mail)}}</span>
                </a>
            </li>

        <li class="nav-item">
            <a class="nav-link" href="javascript:void(0)" data-collapse="#collapseBookingMails">
                E-Mails
                <span class="badge badge-outline-primary">{{ $travel_user_booking_fewo->customer_fewo_mails->count() }}</span>
            </a>
        </li>
       <li class="nav-item">
            <a class="nav-link" href="javascript:void(0)" data-collapse="#collapseBookingFiles">
                PDF Dateien
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="javascript:void(0)" data-collapse="#collapseBookingNotice">
                Notizen
            </a>
        </li>
        @endif
    </ul>

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

    @include('travel.user.booking._detail_info')

    @if($id !== "new")
        @include('travel.user.booking._detail_invoice')
        @include('travel.user.booking._detail_sm_mails')
    @endif

    {!! Form::close() !!}
    @if($id !== "new")
        @include('travel.user.booking._detail_mails')
        @include('travel.user.booking._detail_files')
    @endif

    @include('travel.user.booking._detail_notice')

    <div class="float-right mt-2">
        <a href="{{route('travel_user_booking_fewos')}}" class="btn btn-default btn-sm">{{ __('zur Übersicht') }}</a>
    </div>

    <div class="modal fade" id="modals-load-next">
        <div class="modal-dialog modal-lg">

        </div>
    </div>

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

            $('#collapseTravelInfo').on('shown.bs.collapse', function () {
                $('#travel_info_user_text').keyup();
            });

            var collapseHashValue = null;
            $('[rel="tooltip"]').tooltip({trigger: "hover"});

            $('#top-nav-quick-jump .nav-link').on('click', function (e) {
                e.preventDefault();
                $('#top-nav-quick-jump .nav-link').removeClass('active');
                $(this).addClass('active');
                var collapse_id = $(this).data('collapse');
                //console.log(collapse_id);
                $(collapse_id).collapse('show');
                // animate
                $('html, body').animate({
                    scrollTop: $(collapse_id).parent('.card').offset().top
                }, 300, function(){
                    // when done, add hash to url
                    // (default click behaviour)
                    window.location.hash = collapse_id;
                });

            });

            $(".collapse").on('shown.bs.collapse', function (){
                if(collapseHashValue){
                    $('a[data-collapse="#'+collapseHashValue+'"]').click();
                    collapseHashValue = null;
                }
                CookiesAddJSONValue('booking_fewo_collapse', $(this).attr('id'));
                window.location.hash = "#"+$(this).attr('id');

            });

            $(".collapse").on('hidden.bs.collapse', function (){
                CookiesRemoveJSONValue('booking_fewo_collapse', $(this).attr('id'));
            });

            function init_site(){
                if(window.location.hash){
                    value = $(window.location.hash).attr('id');
                    if(value){
                        collapseHashValue = value;
                        CookiesAddJSONValue('booking_fewo_collapse', value);
                    }
                }
                var booking_collapses = Cookies.get('booking_fewo_collapse');
                if (booking_collapses != null)
                {
                    booking_collapses =  JSON.parse(booking_collapses);
                    for (var booking_collapse in booking_collapses){
                        $("#"+booking_collapses[booking_collapse]).collapse("show");
                    }
                }
            }
            init_site();

            var oTable = $('#datatables-customer-mails').DataTable({
                "processing": true,
                "serverSide": true,
                "searching": false,
                ajax: {
                    url: '{!! route( 'customer_fewo_mail_data_table' ) !!}',
                    data: function(d) {
                        d.model = 'CustomerFewoMail';
                        d.travel_user_booking_fewo_id = $('#customer_mails_table input[name=travel_user_booking_fewo_id]').val();
                        d.customer_mail_dir = $('#customer_mails_table input[name=customer_mail_dir]').val();
                        d.customer_mail_subdir = $('#customer_mails_table input[name=customer_mail_subdir]').val();
                        d.data_table_search = $('#dataTableInputSearchField').val();
                    }
                },
                "columns": [
                    /* { data: 'checkbox', width: '10px', orderable: false, searchable: false}, */
                    { data: 'important', width: '15px', searchable: false },
                    { data: 'subject', name: 'subject', width: '', orderable: false, },
                    { data: 'date', name: 'date', width: '' },
                    { data: 'action',  width: '100px', orderable: false, searchable: false},
                ],
                "bLengthChange": false,
                "iDisplayLength": 25,
                "orderSequence": ["desc", "asc"],
                "order": [[ 2, "desc" ]],
                "language": {
                    "url": "/js/German.json"
                },
                "drawCallback": function( settings ) {
                    $('#datatables-customer-mails [rel="tooltip"]').tooltip({trigger: "hover"});
                    $('#datatables-customer-mails .customer-mail-ajax-action').on('click', function (event) {
                        ajax_object_action(event, $(this), callback_customer_mails_data_table);
                    });
                }
            });
            function callback_customer_mails_data_table(data) {
                if(data.status === 'success'){
                    oTable.draw();
                }
            }

            $('.messages-wrapper .sidebox-nav-item').on('click', function (event) {
                event.preventDefault();
                if($(this).hasClass('active')){
                    return;
                }
                $('#customer_mails_table input[name=customer_mail_dir]').val($(this).data('dir'));
                $('#customer_mails_table input[name=customer_mail_subdir]').val($(this).data('subdir'));
                if($(this).data('dir') <= 10){
                    $('.btn-compare-customer-mails').data('customer_mail_dir', $(this).data('dir'));
                    $('.btn-compare-customer-mails').data('customer_mail_subdir', $(this).data('subdir'));
                    $('.btn-compare-customer-mails').prop('disabled', false);
                }else{
                    $('.btn-compare-customer-mails').prop('disabled', true);
                }
                oTable.draw();
                $('.messages-wrapper .sidebox-nav-item').removeClass('active');
                $(this).addClass('active');
                $('#message-sidebox-title-icon').removeClass().addClass('fa ' + $(this).data('icon'));
                $('#message-sidebox-title-name').html($(this).data('name'));
                $('.messages-wrapper .sidebox-nav-item').find('.badge-primary').removeClass('badge-primary').addClass('badge-outline-primary');
                $(this).find('.badge').removeClass('badge-outline-primary').addClass('badge-primary');
            });

            $('#dataTableInputSearchField').keyup(function(){
                oTable.search($(this).val()).draw();
            });

        });
    </script>
@endsection






