@extends('admin.layouts.app')
@section('contentSection')
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header">
                    <div class="pull-left"><i class="fa fa-table"></i> Leads (<span
                            id="module_total_count"></span>)
                    </div>
                    <div class="pull-right">
                        <form action="{{route('export-leads')}}" method="get">
                            <button style="display: none" id="deleteAllBtn" type="button" class="btn btn-danger"><i
                                    class="fa fa-trash"></i> Delete Selected
                            </button>
                            <button data-toggle="modal" data-target="#bulkModal" style="display: none" id="bulkActionsBtn"
                                    type="button" class="btn btn-primary"><i
                                    class="fa fa-pencil"></i> Bulk Actions
                            </button>
                            <button type="button" data-toggle="modal" data-target="#addLeadModal"
                                    class="btn btn-primary"><i
                                    class="fa fa-plus"></i> Add New
                            </button>
                            <button type="submit"
                                    class="btn btn-primary"><i
                                    class="fa fa-download"></i> Export Leads
                            </button>
                        </form>
                    </div>
                </div>
                <div class="card-header">
                    <div class="row">
                        <div class="col-md-3 form-group">
                            <i class="fa fa-filter"></i> Filters
                        </div>
                    </div>
                    <form id="leadSearchFrom">
                        <div class="row">
                            <div class="col-md-3 form-group">
                                <label class="control-label">Lead Category</label>
                                <select data-live-search="true" name="lead_category_search" id="lead_category_search"
                                        class="form-control selectpicker show-tick">
                                    <option value="">Select Lead Status</option>
                                    @foreach (App\Models\Attribute::orderBy('name')->where('type', 'leadCategory')->get() as $attr)
                                        <option value="{{ $attr->id }}">
                                            {{ $attr->name }}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="col-md-3 form-group">
                                <label class="control-label">Lead Type</label>
                                <select data-live-search="true" name="lead_type_search" id="lead_type_search"
                                        class="form-control selectpicker show-tick">
                                    <option value="">Select Lead Type</option>
                                    @foreach (App\Models\Attribute::orderBy('name')->where('type', 'leadType')->get() as $attr)
                                        <option value="{{ $attr->id }}">
                                            {{ $attr->name }}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="col-md-3 form-group">
                                <label class="control-label">Lead Status</label>
                                <select data-live-search="true" name="lead_status_search" id="lead_status_search"
                                        class="form-control selectpicker show-tick">
                                    <option value="">Select Lead Status</option>
                                    @foreach (App\Models\Attribute::orderBy('name')->where('type', 'leadStatus')->get() as $attr)
                                        <option value="{{ $attr->id }}">
                                            {{ $attr->name }}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="col-md-3 form-group">
                                <label class="control-label">Lead Primary Source</label>
                                <select data-live-search="true" name="lead_ps_search" id="lead_ps_search"
                                        class="form-control selectpicker show-tick">
                                    <option value="">Select Primary Source</option>
                                    @foreach (App\Models\Attribute::orderBy('name')->where(['type' => 'leadSource', 'is_primary' => 1])->get() as $attr)
                                        <option value="{{ $attr->id }}">
                                            {{ $attr->name }}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="col-md-3 form-group">
                                <label class="control-label">Lead Secondary Source</label>
                                <select data-live-search="true" name="lead_ss_search" id="lead_ss_search"
                                        class="form-control selectpicker show-tick">
                                    <option value="">Select Secondary Source</option>
                                    @foreach (App\Models\Attribute::orderBy('name')->where(['type' => 'leadSource', 'is_primary' => 2])->get() as $attr)
                                        <option value="{{ $attr->id }}">
                                            {{ $attr->name }}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                            @if(auth()->user()->type == 1 || auth()->user()->type == 2)
                                <div class="col-md-3 form-group">
                                    <label class="control-label">Assign To</label>
                                    <select data-live-search="true" multiple name="at_search[]" id="at_search"
                                            class="form-control selectpicker show-tick">
                                        <option value="">Select User</option>
                                        @if(auth()->user()->type == 1)
                                            @foreach (App\Models\User::orderBy('name')->where('type', 3)->get() as $attr)
                                                <option value="{{ $attr->id }}">
                                                    {{ $attr->name }}
                                                </option>
                                            @endforeach
                                        @else
                                            @foreach (App\Models\User::orderBy('name')->where('parent_id', auth()->id())->get() as $attr)
                                                <option value="{{ $attr->id }}">
                                                    {{ $attr->name }}
                                                </option>
                                            @endforeach
                                        @endif
                                    </select>
                                </div>
                            @endif
                            <div class="col-md-3 form-group">
                                <label class="control-label">Assign Status</label>
                                <select name="assign_search"
                                        class="form-control">
                                    <option value="">Select Assign Status</option>
                                    <option value="1">Assigned</option>
                                    <option value="2">Un Assigned</option>
                                </select>
                            </div>
                        </div>
                        <br>
                        <div class="row">
                            <div class="col-md-12 text-right">
                                <button class="btn btn-primary">Search</button>
                                <button type="reset" id="leadSearchFormReset" class="btn btn-primary">Reset</button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table id="leadsListTable" class="table table-bordered" style="width: 100%"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('pageSpecificScripts')
    @include('admin.leads.leadsListTemplate')
    @include('admin.leads.modals.addLeadModal')
    @include('admin.leads.modals.editLeadModal')
    @include('admin.leads.modals.bulkModal')
    <script src="{{asset('back_assets/assets/plugins/summernote/dist/summernote-bs4.min.js')}}"></script>
    <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 type="text/javascript" src="{{ asset('assets/js/ajax-bs.js') }}"></script>
    <script src="{{asset('back_assets/assets/js/app/leadsScript.js')}}?{{ app_version() }}"></script>
    @if (Session::has('bsuccess'))
        <script type="text/javascript">
            swal({
                title: "",
                text: '{{Session::get('bsuccess')}}',
                type: "success"
            });
        </script>
    @endif
@endsection
