@extends('admin.layouts.container')

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

    <div class="border-item">
        <form class="form-row" method="post" onsubmit="saveForm(this)" action="{{ $action }}" enctype="multipart/form-data">
            @if($workDay ?? ''  && $workDay->id)
                @method('PUT')
            @endif
            @csrf

            <div class="form-group col-lg-6">
                <label>{{  __('workDays.day')}}</label>
                <input type="text"  class="form-control" disabled value='{{ __('web.'.$workDay->day) }}'/>
            </div>
            <div class="form-group col-lg-6" >
                <label>{{ __('workDays.start_time') }} </label>
                <input type="time" class="form-control {{ $errors->has('start_time') ? 'is-invalid' : '' }}" name="start_time" placeholder="{{ __('workDays.start_time') }}" value='{{ old("start_time", $workDay->start_time ?? "") }}'/>
            </div>

            <div class="form-group col-lg-6" >
                <label>{{ __('workDays.end_time') }} </label>
                <input type="time" class="form-control {{ $errors->has('end_time') ? 'is-invalid' : '' }}" name="end_time" placeholder="{{ __('workDays.end_time') }}" value='{{ old("end_time", $workDay->end_time ?? "") }}'/>
            </div>

                <div class="tab-pane col-lg-12" id="section_items">
                    <div class="row">
                        <div class="col-lg-12">
                            <h3> {{__('workDays.dates')}} </h3>
                        </div>
                        <div class="col-lg-12" id="dates">
                            @foreach($dates as $key=>$row)
                                <div class="row pricing-list-item  mb-4 "  style="background-color: rgba(21,97,203,0.1);height:auto;padding: 20px">
                                    <div class="form-group col-lg-6">
                                        <label>{{  __('workDays.date') }} </label>
                                        <input type="date" class="form-control"  name="dates[]" placeholder="{{  __('workDays.date') }}" value="{{$row->date}}"/>
                                    </div>
                                    <div class="col-lg-4"></div>
                                    <div class="form-group col-lg-2" style="font-size: 30px;margin-top:35px;">
                                        <i class="fas fa-times-circle" onclick="remove(this)"></i>
                                    </div>
                                </div>
                            @endforeach
                        </div>
                        <div class="col-lg-12">
                            <a style="cursor: pointer;" data-id="{{count($dates)}}"onclick="addDate()" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i>{{__("workDays.add_new")}}</a>
                        </div>
                    </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')
    <!-- Editor JS orders -->
    <script src="{{ asset('/assets/admin/js/lib/tinymce.min.js') }}"></script>
    <script>
        function addDate()
        {
            $.ajax({
                url : url_date,
                type : 'GET',
                success:function(data)
                {
                    $('#dates').append(data);
                }
            })
        }
        function remove(elem)
        {
            $(elem).closest('.row').remove();
        }
    </script>
    <script>
        let route_prefix = "{{ url(config('lfm.prefix')) }}",
            url = "{{url('/')}}/",
            url_date = "{{route('dashboard.add_date')}}",
            currentLanguage = "{{getCurrentLocale()}}",
            imagePath = "{{asset('')}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
    <script src="{{ asset('assets/admin/js/articles.js') }}"></script>
@endsection



