<form method="post" onsubmit="saveForm(this)" action="{{ $action }}" enctype="multipart/form-data">
    @if($dailyLog ?? ''  && $dailyLog->id)
        @method('PUT')
    @endif
    @csrf
    <div class="modal-header">
        <h1 class="modal-title fs-6" id="exampleModalLabel"> <i class="fal fa-user me-1"></i> {{$head ?? ''}} </h1>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
    </div>
    <div class="modal-body">
        <div class="modal-form">
            <div class="row">

                <div class="form-group mb-3" >
                    <label for="" class="d-block mb-2"> {{ __('daily_logs.employee_id') }} </label>
                    <select id="employee_id" name="employee_id" class="form-control form-select">
                        <option value="">{{ __('dashboard.select') }}</option>
                        @foreach($employees as $row)
                            <option {{ ($dailyLog->employee_id ?? '' ) == $row->id ? 'selected' : '' }} value="{{ $row->id }}"> {{ $row->name }} </option>
                        @endforeach
                    </select>
                </div>
     
                
                <div class="cs-wrapper mb-3 h-100" data-search="Search...">
                        <label class="form-label">{{ __('daily_logs.contact_list_id') }}</label>
                        <select id="contact_list_id" onchange="fetchContactList()" name="contact_list_id" class="cs-source">
                            <option value="">{{ __('dashboard.select') }}</option>
                            @foreach($contact_lists as $row)
                                <option {{ ($dailyLog->contact_list_id ?? '' ) == $row->id ? 'selected' : '' }} value="{{ $row->id }}"> {{ $row->title }} </option>
                            @endforeach
                        </select>
                </div>
                
                <div class="form-group mb-3 row" id="contact_list_info">

                </div>
             

                <div class="form-group mb-3">
                    <label for="" class="d-block mb-2"> {{ __('daily_logs.date') }} </label>
                    <input type="date" name="date" class="form-control" value="{{$dailyLog->date ?? ''}}" placeholder="{{ __('daily_logs.date') }}">
                </div>

                <div class="form-group mb-3" >
                    <label for="" class="d-block mb-2"> {{ __('daily_logs.type') }} </label>
                    <select id="type" name="type" class="form-control form-select">
                        @foreach($types as $row)
                            <option {{ ($dailyLog->type ?? '' ) == $row ? 'selected' : '' }} value="{{ $row }}"> {{ __('daily_logs.types.'.$row) }} </option>
                        @endforeach
                    </select>
                </div>

                <div class="form-group mb-3" >
                    <label for="" class="d-block mb-2"> {{ __('daily_logs.objective') }} </label>
                    <select id="objective" onchange='SelectObjective()' name="objective" class="form-control form-select">
                        @foreach($objectives as $row)
                            <option {{ ($dailyLog->objective ?? '' ) == $row ? 'selected' : '' }} value="{{ $row }}"> {{ __('daily_logs.objectives.'.$row) }} </option>
                        @endforeach
                    </select>
                </div>

                <div class="form-group mb-3" id="other">
                    <label for="" class="d-block mb-2"> {{ __('daily_logs.objective_other') }} </label>
                    <input type="text" name="objective_other" class="form-control" value="{{$dailyLog->objective_other ?? ''}}" placeholder="{{ __('daily_logs.objective_other') }}">
                </div>

                <div class="form-group mb-3">
                    <label for="" class="d-block mb-2"> {{ __('daily_logs.estimated_sale') }} </label>
                    <input type="text" name="estimated_sale" class="form-control" value="{{$dailyLog->estimated_sale ?? ''}}" placeholder="{{ __('daily_logs.estimated_sale') }}">
                </div>

                <div class="form-group mb-3" >
                    <label for="" class="d-block mb-2"> {{ __('daily_logs.next_action') }} </label>
                    <select id="next_action" name="next_action" class="form-control form-select">
                        @foreach($next_actions as $row)
                            <option {{ ($dailyLog->next_action ?? '' ) == $row ? 'selected' : '' }} value="{{ $row }}"> {{ __('daily_logs.next_actions.'.$row) }} </option>
                        @endforeach
                    </select>
                </div>

                <div class="form-group mb-3">
                    <label for="" class="d-block mb-2"> {{ __('daily_logs.next_contact') }} </label>
                    <input type="date" name="next_contact" class="form-control" value="{{$dailyLog->next_contact ?? ''}}" placeholder="{{ __('daily_logs.next_contact') }}">
                </div>


                <div class="form-group mb-3" id="statuses">

                </div>


            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button type="button" class="line-butn butn-st2 butn-md" data-bs-dismiss="modal" aria-label="Close"><span> {{ __('dashboard.cancel') }} </span></button>
        <button type="submit" class="blue-butn butn-st2 butn-md"><span> {{ __('dashboard.save') }} </span></button>
    </div>
</form>

 <script>

//     $(document).ready(function() {
//         $('.js-example-basic-single').select2();
//     });
    function SelectObjective()
    {
        let objective = $('#objective').val()
        if(objective == "{{$other}}")
        {
            $('#other').show();
        }
        else
        {
            $('#other').hide();
        }
    }
    $('#objective').trigger('change')
    function fetchContactList()
    {
        let contact_list_id = $('#contact_list_id').val();
        if(contact_list_id)
        {
            $.ajax({
                url : "{{route('admin.fetch.contact_list')}}",
                type : 'GET',
                data : 'contact_list_id='+contact_list_id,
                success:function(data)
                {
                    $('#contact_list_info').html(data.info);
                    $('#statuses').html(data.statuses);
                }
            })
        }
    }
    $('#contact_list_id').trigger('change');
    
</script>
<script src="{{url('')}}/assets/admin/js/lib/select-search.js"></script>
<script>
    $(".cs-wrapper").customSelect();
</script>
