@extends('layouts.layout-2')

@section('content')

    <style>
        body {
        }
        .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;
        }
    </style>

    <div class="float-right mt-3">
        <a href="{{route('customers')}}" class="btn btn-sm btn-default">{{ __('zur Übersicht') }}</a>
        <a href="{{ make_old_url('/index.php/customer/'.$customer->id.'/edit') }}" class="btn btn-sm btn-default float-right">{{ __('zurück ins CRM v2') }}</a>
    </div>

    <h4 class="font-weight-bold py-3 mb-1">
        Kunden verwalten
    </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="#collapseCustomerDetail">
                Kunde
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="javascript:void(0)" data-collapse="#collapseCustomerBooking">
                Anfrage / Buchung
            </a>
        </li>
    </ul>


    {!! Form::open(['url' => route('customer_detail', [$id]), 'class' => 'form-horizontal', 'id'=>'customer-form-validation']) !!}
    <input type="hidden" name="id" id="id" value="{{$id}}">
   
    <!-- Kunde -->
    @include('customer._detail_customer')

    @if($id !== "new" && $customer)
        @include('customer._detail_booking')
    @endif

    <div class="float-right mt-3">
        <a href="{{route('customers')}}" class="btn btn-sm btn-default">{{ __('zur Übersicht') }}</a>
        <a href="{{ make_old_url('/index.php/customer/'.$customer->id.'/edit') }}" class="btn btn-sm btn-default float-right">{{ __('zurück ins CRM v2') }}</a>
    </div>

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

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

            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('customer_collapse', $(this).attr('id'));
                window.location.hash = "#"+$(this).attr('id');

            });

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

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

@endsection