<div class="card mb-2  border-primary">
    <h6 class="card-header  bg-primary text-white py-2" data-toggle="collapse" data-target="#collapseLeadStatus" aria-expanded="false" aria-controls="collapseLeadStatus">
        <strong style="line-height: 1.6em">Status {!! $lead->getStatusBadge() !!}</strong>
    </h6>
    <div class="collapse" id="collapseLeadStatus">
        <div class="card-body">
            @if($lead->count())
            <div class="row">

                <div class="col-sm-6">
                    <label class="custom-control custom-checkbox mt-2">
                        {!! Form::checkbox('is_closed', 1, $lead->is_closed, ['class'=>'custom-control-input', 'readonly']) !!}
                        <span class="custom-control-label">{{__('Vorgang abgeschlossen')}}</span>
                    </label>
                </div>

                <div class="col-sm-6">
                    <label class="custom-control custom-checkbox mt-2">
                        {!! Form::checkbox('is_rebook', 1, $lead->is_rebook, ['class'=>'custom-control-input', 'readonly']) !!}
                        <span class="custom-control-label">{{__('Umbuchung abgeschlossen')}}</span>
                    </label>
                </div>

                <div class="col-sm-12">
                    <hr>
                </div>
                <div class="form-group col-sm-6 col-md-6">
                    <label class="form-label" for="status_id">{{ __('Status ändern') }}  </label>
                    {{ Form::select('status[id]', \App\Models\Lead::getStatusArray() , $lead->status_id, array('class'=>'custom-select')) }}
                </div>

                <div class="form-group col-sm-12">
                    <label for="status_remarks" class="form-label">{{ __('Bemerkung für Statusänderung') }}</label>
                    {{ Form::textarea('status[remarks]', '',  array('placeholder'=>__('Bemerkung'), 'class'=>'form-control autoExpand', 'id'=>'status_remarks', 'rows'=>'1', 'data-min-rows'=>'1')) }}
                </div>

                <div class="form-group col-sm-12">
                    <label class="form-label" for="status[date]">{{ __('Datum für Statusänderung') }}</label>
                    {{ Form::text('status[date]', _format_date(now()),  array('placeholder'=>__('dd.mm.YY'), 'class'=>'form-control  datepicker-base', 'id'=>'status[date]')) }}
                </div>

                <div class="col-sm-12">
                    <div class="text-left mt-2">
                        <button type="submit" name="action" value="saveStatus" class="btn btn-sm btn-secondary">Änderungen speichern</button>&nbsp;
                        <a href="{{route('leads')}}" class="btn btn-sm  btn-default">{{ __('zur Übersicht') }}</a>
                    </div>
                </div>
            </div>
            
            @if($lead->status_histories)
            <div class="row">
                <div class="col-sm-12"><hr></div>
                <div class="col-sm-12">
                    <table class="table table-striped table-sm">
                        <thead>
                        <tr>
                            <th>Status</th>
                            <th>Sachbearbeiter</th>
                            <th>Datum</th>
                            <th>Zieldatum</th>
                            <th>Bemerkungen</th>
                        </tr>
                        </thead>
                        <tbody>
                            @foreach ($lead->status_histories as $status_history)
                            <tr>
                                <th scope="row">
                                    @if($status_history->status)
                                        {!! $status_history->status->getStatusBadge() !!}
                                    @endif
                                </th>
                                <td>
                                    @if($status_history->lead->sf_guard_user)
                                     {{ $status_history->lead->sf_guard_user->fullname }}
                                    @endif
                                </td>
                                <td>{{ _format_date($status_history->date) }}</td>
                                <td>{{ _format_date($status_history->target_date) }}</td>
                                <td>{{  $status_history->remarks }}</td>                               
                            </tr>
                            @endforeach

                        </tbody>
                    </table>
                </div>
            </div>
            @endif

            @endif
        </div>
    </div>
</div>