@extends('admin.layouts.app')
@section('contentSection')
    <div class="row">
        <div class="col-lg-6">
            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-header">
                            <div class="card-title font-weight-bold">Basic Information</div>
                            <hr class="mt-0">
                            <p><strong>Reference Number: </strong><span
                                    class="font-weight-normal">{{$lead->reference_number}}</span></p>
                            <p><strong>Title: </strong><span
                                    class="font-weight-normal">{{$lead->title ? : 'N/A'}}</span></p>
                            <p><strong>Name: </strong><span class="font-weight-normal">{{$lead->name ? : 'N/A'}}</span>
                            </p>
                            <p><strong>Phone: </strong><span
                                    class="font-weight-normal">{{$lead->phone ? : 'N/A'}}</span></p>
                            <p><strong>Email: </strong><span
                                    class="font-weight-normal">{{$lead->email ? : 'N/A'}}</span></p>
                            <p><strong>Property Type: </strong><span
                                    class="font-weight-normal">{{$lead->property_type ? $lead->property_type->name : 'N/A'}}</span>
                            </p>
                            <p><strong>Lead Status: </strong><span
                                    class="font-weight-normal">{{$lead->lead_status ? $lead->lead_status->name : 'N/A'}}</span>
                            </p>
                            <p><strong>Lead Type: </strong><span
                                    class="font-weight-normal">{{$lead->lead_type ? $lead->lead_type->name : 'N/A'}}</span>
                            </p>
                            <p><strong>Lead Category: </strong><span
                                    class="font-weight-normal">{{$lead->lead_category ? $lead->lead_category->name : 'N/A'}}</span>
                            </p>
                            <p><strong>Lead Primary Source: </strong><span
                                    class="font-weight-normal">{{$lead->lead_primary_source ? $lead->lead_primary_source->name : 'N/A'}}</span>
                            </p>
                            <p><strong>Lead Interest Level: </strong><span
                                    class="font-weight-normal">{{$lead->lead_interest_level ? $lead->lead_interest_level->name : 'N/A'}}</span>
                            </p>
                            <p><strong>Assigned To: </strong><span
                                    class="font-weight-normal">{{$lead->assignee ? $lead->assignee->name : 'N/A'}}</span>
                            </p>
                            <p><strong>Additional info: </strong><span
                                    class="font-weight-normal">{{$lead->description ? : 'N/A'}}</span></p>
                            <div class="row">
                                <div class="col-xs-12 col-lg-12 text-right">
                                    <button data-id="{{$lead->id}}" type="button" class="btn btn-secondary edit-btn"><i
                                            class="fa fa-edit fa-lg"></i> Edit
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-header">
                            <div class="card-title font-weight-bold">Lead Status</div>
                            <hr class="mt-0">
                            <div class="row">
                                <div class="col-xs-12 col-lg-12">
                                    <select data-type="Status" data-column="lead_status_id" data-id="{{$lead->id}}"
                                            class="form-control update_lead_status">
                                        <option value="">Select Lead Status</option>
                                        @foreach (App\Models\Attribute::orderBy('name')->where('type', 'leadStatus')->get() as $attr)
                                            <option {{$lead->lead_status && $lead->lead_status->id == $attr->id ? 'selected' : ''}} value="{{ $attr->id }}">
                                                {{ $attr->name }}
                                            </option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-header">
                            <div class="card-title font-weight-bold">Lead Category</div>
                            <hr class="mt-0">
                            <div class="row">
                                <div class="col-xs-12 col-lg-12">
                                    <select data-type="Category" data-column="lead_category_id" data-id="{{$lead->id}}"
                                            class="form-control update_lead_status">
                                        <option value="">Select Lead Category</option>
                                        @foreach (App\Models\Attribute::orderBy('name')->where('type', 'leadCategory')->get() as $attr)
                                            <option {{$lead->lead_category && $lead->lead_category->id == $attr->id ? 'selected' : ''}} value="{{ $attr->id }}">
                                                {{ $attr->name }}
                                            </option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-header">
                            <div class="card-title font-weight-bold">Move to Contact</div>
                            <hr class="mt-0">
                            <div class="row">
                                <div class="col-xs-12 col-lg-12">
                                    @if($lead->converted_to)
                                        <p>Already moved</p>
                                    @else
                                        <button data-type="Contacts" data-id="{{$lead->id}}" type="button"
                                                class="btn btn-warning convert-btn"><i
                                                class="fa fa-exchange fa-lg"></i> Move to Contact
                                        </button>
                                    @endif
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-6">
            <div class="card">
                <div class="card-header">
                    <div class="card-title font-weight-bold">Lead Logs</div>
                    <hr class="mt-0">
                    <table id="logs-table"
                           class="table table-striped table-hover table-bordered"
                           style="width:100%">
                        <thead>
                        <tr>
                            <th>Log</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($lead->logs as $log)
                            <tr>
                                <td>{{$log->message}} by {{$log->user->name}}</td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="card">
                <div class="card-header">
                    <div class="card-title font-weight-bold">Lead Notes</div>
                    <hr class="mt-0">
                    <div class="row mb-3">
                        <div class="col-md-12">
                            <form action="{{route('save-lead-note')}}" method="post">
                                @csrf
                                <input type="hidden" value="{{$lead->id}}" name="lead_id" />
                                <textarea required minlength="3" maxlength="1000" name="note" cols="30" rows="2"
                                          class="form-control content_area"></textarea>
                                <button type="submit" class="btn btn-primary pull-right mt-3"><i class="fa fa-plus"></i> Add Note</button>
                            </form>
                        </div>
                    </div>
                    <table id="notes-table"
                           class="table table-striped table-hover table-bordered"
                           style="width:100%">
                        <thead>
                        <tr>
                            <th>Note</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($lead->notes as $note)
                            <tr>
                                <td>{!! $note->note !!}</td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('pageSpecificScripts')
    @include('admin.leads.modals.editLeadModal')
    <script src="{{asset('back_assets/assets/plugins/bootstrap-datatable/js/jquery.dataTables.min.js')}}"></script>
    <script src="{{asset('back_assets/assets/plugins/bootstrap-datatable/js/dataTables.bootstrap4.min.js')}}"></script>
    <script src="{{ asset('back_assets/assets/plugins/bootstrap-select/js/bootstrap-select.min.js') }}"></script>
    <script src="{{ asset('back_assets/assets/plugins/summernote/dist/summernote-bs4.min.js') }}"></script>
    <script src="{{asset('back_assets/assets/js/app/leadsScript.js')}}?{{ app_version() }}"></script>
    <script type="text/javascript">
        $('.content_area').summernote({
            onCreateLink: function (originalLink) {
                return originalLink; // return original link
            },
            dialogsInBody: true,
            height: 100,
            tabsize: 2
        });
        $('#logs-table').DataTable({
            "ordering": false,
            "searching": false,
            "lengthMenu": [[5, 10, 50], [5, 10, 50]],
            "pageLength": 5,
        });
        $('#notes-table').DataTable({
            "ordering": false,
            "lengthMenu": [[5, 10, 50], [5, 10, 50]],
            "pageLength": 5,
        });
    </script>
    @if (Session::has('bsuccess'))
        <script type="text/javascript">
            swal({
                title: "",
                text: '{{Session::get('bsuccess')}}',
                type: "success"
            });
        </script>
    @endif
@endsection
