@extends('admin.layouts.container')

@section('content')
<div class="side-title">
    <h3>{{ $head ?? '' }}</h3>
</div>

<div class="border-item">
    <form class="form-row" method="post" action="{{ $action }}">
        @if($doctor ?? ''  && $doctor->id)
            @method('PUT')
        @endif
        @CSRF
         @if($doctor ?? ''  && $doctor->id)
         @for ($i = 1; $i < 13 ; $i++)
        @if (array_key_exists($i, $monthVisitCounts))
            @continue
        @endif
        @php $monthVisitCounts[$i] = 0; @endphp
    @endfor

    @php ksort($monthVisitCounts); @endphp



    @foreach ($monthVisitCounts as $month => $count)
            <input type="hidden" name="{{$month}}" value="{{$count}}" class="monthVisitCounts">
    @endforeach
    
         <input type="hidden" value="{{$allreservations}}" class="allVisitorCounts">
    <div class="col-lg-12">
        <h5 class="text-uppercase font-weight-bold">Reservations in this year</h5>
        <canvas class="border-item lineChart" width="400" height="150"></canvas>
    </div>
    @endif
        

        <div class="form-group col-lg-6">
            <label>{{ meta('name', getCurrentLocale()) ?? __('doctors.name') }} </label>
            <input type="text" class="form-control {{ $errors->has('name') ? 'is-invalid' : '' }}" name="name" placeholder="{{ meta('name', getCurrentLocale()) ??__('doctors.name') }}" value='{{ old("name", $doctor->name ?? "") }}'/>
        </div>
         <div class="form-group col-lg-6">
            <label>{{ meta('email', getCurrentLocale()) ?? __('doctors.email') }} </label>
            <input type="email" class="form-control {{ $errors->has('email') ? 'is-invalid' : '' }}" name="email" placeholder="{{ meta('email', getCurrentLocale()) ??__('doctors.email') }}" value='{{ old("email", $doctor->email ?? "") }}'/>
        </div>
         <div class="form-group col-lg-6">
            <label>{{ meta('password', getCurrentLocale()) ?? __('doctors.password') }} </label>
            <input type="password" class="form-control {{ $errors->has('password') ? 'is-invalid' : '' }}" name="password" placeholder="{{ meta('password', getCurrentLocale()) ??__('doctors.password') }}" value='{{ old("password") }}'/>
        </div>

        <div class="form-group col-lg-6">
            <label>{{ meta('description', getCurrentLocale()) ?? __('doctors.description') }} </label>
            <input type="text" class="form-control {{ $errors->has('description') ? 'is-invalid' : '' }}" name="description" placeholder="{{ meta('description', getCurrentLocale()) ?? __('doctors.description') }}" value='{{ old("description", $doctor->details->description ?? "") }}'/>
        </div>
        
        <div class="form-group col-lg-6">
            <label>{{ meta('salary', getCurrentLocale()) ?? __('doctors.salary') }} </label>
            <input type="number" step="0.01" class="form-control {{ $errors->has('salary') ? 'is-invalid' : '' }}" name="salary" placeholder="{{ meta('salary', getCurrentLocale()) ?? __('doctors.salary') }}" value='{{ old("salary", $doctor->details->salary ?? "") }}'/>
        </div>
        
        <div class="form-group col-lg-6">
            <label>{{ meta('percentage', getCurrentLocale()) ?? __('doctors.percentage') }} </label>
            <input type="number" step="0.01" class="form-control {{ $errors->has('percentage') ? 'is-invalid' : '' }}" name="percentage" placeholder="{{ meta('percentage', getCurrentLocale()) ?? __('doctors.percentage') }}" value='{{ old("percentage", $doctor->details->percentage ?? "") }}'/>
        </div>
        
        <div class="form-group col-lg-6">
            <label>{{ meta('percentage_new', getCurrentLocale()) ?? __('doctors.percentage_new') }} </label>
            <input type="number" step="0.01" class="form-control {{ $errors->has('percentage_new') ? 'is-invalid' : '' }}" name="percentage_new" placeholder="{{ meta('percentage_new', getCurrentLocale()) ?? __('doctors.percentage_new') }}" value='{{ old("percentage_new", $doctor->details->percentage_new ?? "") }}'/>
        </div>
             <div class="form-group col-lg-6">
            <label>{{ meta('joinned', getCurrentLocale()) ?? __('main.joinned') }} </label>
            <input type="date" class="form-control {{ $errors->has('joinned') ? 'is-invalid' : '' }}" name="joinned" placeholder="{{ meta('joinned', getCurrentLocale()) ?? __('main.joinned') }}" value='{{ old("joinned", $user->details->joinned ?? "") }}'/>
        </div>
        <div class="form-group col-lg-6">
            <label>{{ meta('degree', getCurrentLocale()) ?? __('doctors.degree') }} </label>
            <input type="text" class="form-control {{ $errors->has('degree') ? 'is-invalid' : '' }}" name="degree" placeholder="{{ meta('degree', getCurrentLocale()) ?? __('doctors.degree') }}" value='{{ old("degree", $doctor->details->degree ?? "") }}'/>
        </div>
        <div class="form-group col-lg-6">
            <label>{{ meta('work_days', getCurrentLocale()) ?? __('doctors.work_days') }} </label>
            <input type="text" class="form-control {{ $errors->has('work_days') ? 'is-invalid' : '' }}" name="work_days" placeholder="{{ meta('work_days', getCurrentLocale()) ?? __('doctors.work_days') }}" value='{{ old("work_days", $doctor->details->work_days ?? "") }}'/>
        </div>
         <div class="form-group col-lg-6">
            <label>{{ meta('facebook', getCurrentLocale()) ?? __('doctors.facebook') }} </label>
            <input type="text" class="form-control {{ $errors->has('facebook') ? 'is-invalid' : '' }}" name="facebook" placeholder="{{ meta('facebook', getCurrentLocale()) ?? __('doctors.facebook') }}" value='{{ old("facebook", $doctor->details->facebook ?? "") }}'/>
        </div>
         <div class="form-group col-lg-6">
            <label>{{ meta('twitter', getCurrentLocale()) ?? __('doctors.twitter') }} </label>
            <input type="text" class="form-control {{ $errors->has('twitter') ? 'is-invalid' : '' }}" name="twitter" placeholder="{{ meta('twitter', getCurrentLocale()) ?? __('doctors.twitter') }}" value='{{ old("twitter", $doctor->details->twitter ?? "") }}'/>
        </div>
         <div class="form-group col-lg-6">
            <label>{{ meta('instagram', getCurrentLocale()) ?? __('doctors.instagram') }} </label>
            <input type="text" class="form-control {{ $errors->has('instagram') ? 'is-invalid' : '' }}" name="instagram" placeholder="{{ meta('instagram', getCurrentLocale()) ?? __('doctors.instagram') }}" value='{{ old("instagram", $doctor->details->instagram ?? "") }}'/>
        </div>
         <div class="form-group col-lg-6">
            <label>{{ meta('whatsapp', getCurrentLocale()) ?? __('doctors.whatsapp') }} </label>
            <input type="text" class="form-control {{ $errors->has('whatsapp') ? 'is-invalid' : '' }}" name="whatsapp" placeholder="{{ meta('whatsapp', getCurrentLocale()) ?? __('doctors.whatsapp') }}" value='{{ old("whatsapp", $doctor->details->whatsapp ?? "") }}'/>
        </div>
        
        
        
         <div class="col-lg-12">
         <div class="row pricing-list-item border-item mb-4"  @if(!($doctor ?? ""  && $doctor->id)) style="display:none" @endif id="experiences">
                    <div class="col-lg-12"><h3>{{__('doctors.experiences')}}</h3></div>
               
                 @if($doctor ?? ""  && $doctor->id)
        <div class="form-group col-lg-12">         
       @foreach(experiences($doctor->id) as $key=>$row)

        <div class="row">
         <div class="form-group col-lg-6">
            <label>{{ __('doctors.element') }} </label>
             <input type="text" class="form-control" name="experiences[{{$key}}][name]" value='{{ $row->name }}'/>
        </div>
          <div class="form-group col-lg-6">
            <label>{{ __('doctors.description') }} </label>
            <input type="text" class="form-control" name="experiences[{{$key}}][description]" value='{{ $row->description }}'/>
        </div>
        </div>
        @endforeach
         </div>
         
       @endif
       </div>
</div>
         <div class="col-lg-12">
       <a style="cursor: pointer;"   @if($doctor ?? ""  && $doctor->id) data-id="{{count(experiences($doctor->id))}}" @else  data-id="0"   @endif onclick="addexperience(this)" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i>{{__("doctors.add_experience")}}</a>
      
                   
</div>
<div class="col-lg-12">
         <div class="row pricing-list-item border-item mb-4"  @if(!($doctor ?? ""  && $doctor->id)) style="display:none" @endif id="langs">
                    <div class="col-lg-12"><h3>{{__('doctors.langs')}}</h3></div>
               
                 @if($doctor ?? ""  && $doctor->id)
        <div class="form-group col-lg-12">         
       @foreach(langs($doctor->id) as $key=>$row)

        <div class="row">
        
          <div class="form-group col-lg-6">
            <label>{{ __('doctors.count') }} </label>
            <input type="text" class="form-control" name="langs[{{$key}}][lang]" value='{{ $row->language }}'/>
        </div>
         <div class="form-group col-lg-6"></div>
        </div>
        @endforeach
         </div>
         
       @endif
       </div>
</div>
 <div class="col-lg-12">
       <a style="cursor: pointer;"   @if($doctor ?? ""  && $doctor->id) data-id="{{count(langs($doctor->id))}}" @else  data-id="0"   @endif onclick="addlang(this)" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i>{{__("doctors.add_lang")}}</a>
      
                   
</div>
          
          {{--Start image container--}}
        <div class="form-group col-lg-12">
            <label>{{ meta('photo', getCurrentLocale()) ?? __('doctors.photo') }} </label>
            <input id="image_thumbnail" class="image_thumbnail" type="hidden" name="photo" value="{{old("photo", $doctor->photo ?? "")}}"/>

            <div class="images main_image {{ old('photo', $doctor->photo ?? '') ? ' wow fadeInUp' : 'hide' }}">
                <div class="col-lg-4">
                    <div class="items">
                        <div class="img">
                            <a href="#" id="lfm" data-input=".image_thumbnail" data-preview=".image_holder" class="lfm" data-hide=".pick_button">
                                <img src="{{asset(old('photo', $doctor->photo ?? ''))}} "  id="image_holder" class="image_holder"/>
                            </a>
                        </div>
                        <a href="#" class="showHide resetImage close" data-empty=".image_thumbnail" data-hide=".main_image" data-show=".pick_button"><i class="fas fa-times"></i></a>
                    </div>
                </div>
            </div>

            <div class="clearfix"></div>
            <span class="input-group-btn pick_button {{ old('photo', $doctor->photo ?? '') ? 'hide' : '' }} ">
                <a id="lfm" data-input=".image_thumbnail" data-preview=".image_holder" data-show=".main_image" data-hide=".pick_button" class="lfm btn btn-primary text-light">
                    <i class="fas fa-camera-retro"></i> Choose
                </a>
            </span>
        </div>
        {{--End image container--}}
            {{--Start video container--}}
        <div class="form-group col-lg-12">
            <label>{{ meta('video', getCurrentLocale()) ?? __('doctors.video') }} </label>
            <input id="video_thumbnail" class="video_thumbnail" type="hidden" name="video" value="{{old("video", $doctor->details->video ?? "")}}"/>

            <div class="videos main_video {{ old('video', $doctor->details->video ?? '') ? ' wow fadeInUp' : 'hide' }}">
                <div class="col-lg-4">
                    <div class="items">
                        <div class="img">
                            <a href="#" id="lfm" data-input=".video_thumbnail" data-preview=".video_holder" class="lfm" data-hide=".pick_button_video">
                                <img src="{{asset(old('video', $doctor->details->video ?? ''))}} "  id="video_holder" class="video_holder"/>
                            </a>
                        </div>
                        <a href="#" class="showHide resetvideo close" data-empty=".video_thumbnail" data-hide=".main_video" data-show=".pick_button_video"><i class="fas fa-times"></i></a>
                    </div>
                </div>
            </div>

            <div class="clearfix"></div>
            <span class="input-group-btn pick_button_video {{ old('video', $doctor->details->video ?? '') ? 'hide' : '' }} ">
                <a id="lfm" data-input=".video_thumbnail" data-preview=".video_holder" data-show=".main_video" data-hide=".pick_button_video" class="lfm btn btn-primary text-light">
                    <i class="fas fa-camera-retro"></i> Choose
                </a>
            </span>
        </div>
        {{--End video container--}}
        
         
         <div class="form-group col-lg-12">
                <label>{{ meta('specialties', getCurrentLocale()) ?? __('doctors.specialties') }} </label>
               <select class="form-control {{ $errors->has('specialty_id') ? 'is-invalid' : '' }}" name="specialty_id">
                   <option selected disabled >{{__('doctors.select')}}</option>
                    @foreach($specialties as $row)
                    <option  @if($doctor ?? ''  && $doctor->id) @if($doctor->details->specialty_id == $row->id) selected @endif @endif value="{{$row->id}}">{{$row->name}}</option>
                    @endforeach
               </select>
                </div>
                <div class="form-group col-lg-12">
                <label>{{ meta('branches', getCurrentLocale()) ?? __('doctors.branches') }} </label>
               
                     <div class="row">
                    @foreach($branches as $row)
                    <div class="col-3"><input type="checkbox"  @if($doctor ?? ''  && $doctor->id) @if(branchestrue($row->id,$doctor->id,'2')) checked @endif @endif name="branches[]" value="{{$row->id}}"> {{$row->name}}</div>
                    @endforeach
               </div>
               
                </div>
       
 <div class="border-item photos col-md-12 other_image_container">
            <div class="row">
                @if ($doctor ?? false)
                    @foreach ($doctor['photos'] as $photo)
                        <div class="col-md-4">
                            <div class="items">
                                <div class="img">
                                    <a href="{{ asset($photo->image ?? '')}}" data-fancybox="gallery"><img src="{{ asset($photo->image ?? '')}}" alt=""></a>
                                </div>
                                <input type="hidden" name="images[]" value="{{ $photo->image ?? "" }}">
                                <a href="#" class="close"><i class="fas fa-times"></i></a>
                            </div>
                        </div>
                    @endforeach
                @endif
            </div>
            <div class="text-center">
                <input id="other_image_thumbnail" class="other_image_thumbnail" type="hidden"/>
                <div class="clearfix"></div>
                <span id="add">
                    <a id="lfm" data-width="" data-cache="article_gallery" data-input=".other_image_thumbnail" data-preview="" data-show="" data-hide="" class="lfm add">
                        Add New Item
                    </a>
                </span>
            </div>
        </div>
        

        <div class="text-center mt-5 col-12">
            <button class="butn"><span>{{ __('dashboard.save') }}</span></button>
        </div>
    </form>
</div>

@endsection

@section('inner_js')
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<script src="{{asset('assets/admin/js/lib/Chart.min.js')}}"></script>
<script>
    $(document).ready(function () {
        let months = [],
            month_visits = [],
            allVisitorCounts = $('.allVisitorCounts').val(),
            ChartHtml = $('.lineChart').html('2d');

        $('.monthVisitCounts').each(function () {
            months.push($(this).attr('name'));
            month_visits.push($(this).val());
        });

        month_visits.push(allVisitorCounts);

        new Chart(ChartHtml, {
            type: 'line',
            data: {
                labels: months,
                datasets: [{
                    label: ' people',
                    data: month_visits,
                    backgroundColor: [
                        'rgba(255, 99, 132, 0.2)',
                        'rgba(54, 162, 235, 0.2)',
                        'rgba(255, 206, 86, 0.2)',
                        'rgba(75, 192, 192, 0.2)',
                        'rgba(153, 102, 255, 0.2)',
                        'rgba(255, 159, 64, 0.2)'
                    ],
                    borderColor: [
                        'rgba(255, 99, 132, 1)',
                        'rgba(54, 162, 235, 1)',
                        'rgba(255, 206, 86, 1)',
                        'rgba(75, 192, 192, 1)',
                        'rgba(153, 102, 255, 1)',
                        'rgba(255, 159, 64, 1)'
                    ],
                    borderWidth: 1
                }]
            },
            options: {
                scales: {
                    yAxes: [{
                        ticks: {
                            beginAtZero: true
                        }
                    }]
                }
            }
        });
    })
</script>


<script>
    new Chart(document.getElementById("chartjs-4"), {
        "type": "doughnut",
        "data": {
            "labels": ["completed Profiles", "uncompleted Profiles", "waiting Approval"],
            "datasets": [{
                "label": "My First Dataset",
                "data": [180, 90, 120],
                "backgroundColor": ["rgb(33, 255, 13)", "rgb(220, 53, 69)", "rgb(21, 97, 203)"]
            }]
        }
    });
</script>
<script>
    function addexperience(elem){
        $("#experiences").css("display", "block");
        var num = $(elem).attr('data-id');
        
        var newrow = parseInt(num)+1; 
        $(elem).attr('data-id', newrow);
        
         $.ajax({
          url : url_experience+'/'+num,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
            $('#experiences').append(data);
          }
        })
    }

    function addlang(elem){
        $("#langs").css("display", "block");
        var num = $(elem).attr('data-id');
        
        var newrow = parseInt(num)+1; 
        $(elem).attr('data-id', newrow);
        
         $.ajax({
          url : url_lang+'/'+num,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
            $('#langs').append(data);
          }
        })
    }
    
         function remove(elem){
            $(elem).closest('.row').remove();
        }
</script>
    <!-- Editor JS files -->
{{--    <script src="{{ asset('/assets/admin/js/lib/tinymce.min.js') }}"></script>--}}
            <script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
    <script>
        let route_prefix = "{{ url(config('lfm.prefix')) }}",
            url = "{{url('/')}}/",
            url_experience = "{{url('/')}}/admin/addexperience",
            url_lang = "{{url('/')}}/admin/addlang",
            imagePath = "{{asset('')}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
@endsection
