@extends('admin.layouts.container')

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

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

                <div class="form-group col-lg-4">
                    <label>{{ meta('documentation_date', $local) ?? __('documentations.documentation_date') }} </label>
                    <input type="date" class="form-control" name="documentation_date" placeholder="{{ meta('documentation_date', $local) ?? __('documentations.documentation_date') }}" value='{{ $documentation->documentation_date ?? "" }}'/>
                </div>
                <div class="form-group col-lg-4">
                    <label>{{ meta('documentation_time', $local) ?? __('documentations.documentation_time') }} </label>
                    <input type="time" class="form-control" name="documentation_time" placeholder="{{ meta('documentation_time', $local) ?? __('documentations.documentation_time') }}" value='{{ $documentation->documentation_time ?? "" }}'/>
                </div>
                <div class="form-group col-lg-4">
                    <label>{{ meta('status', $local) ?? __('documentations.status') }} </label>
                    <select name="status" id="status" class="form-control">
                        <option value="">{{ meta('status', $local) ?? __('documentations.status') }}</option>
                        <option {{ ($documentation->status ?? null) == '1' ? 'selected' : '' }} value="1">{{__('documentations.active')}}</option>
                        <option {{ ($documentation->status ?? null) == '0' ? 'selected' : '' }} value="0">{{__('documentations.not_active')}}</option>
                    </select>
                </div>

                <div class="card col-md-12 mb-3">
                    <div class="card-header">
                        <h3>{{__('documentations.type')}}</h3>
                    </div>
                    <div class="card-body row justify-content-around">
                        <div class="col-md-2">
                            <div class="custom-control custom-checkbox mb-2">
                                <input type="radio" {{ ($documentation->type ?? null) == 'inside_office' ? 'checked' : '' }} value="inside_office" class="custom-control-input" id="inside_office" name="type">
                                <label class="custom-control-label" for="inside_office"> {{__('documentations.inside_office')}}</label>
                            </div>
                        </div>
                        <div class="col-md-2">
                            <div class="custom-control custom-checkbox mb-2">
                                <input type="radio" {{ ($documentation->type ?? null) == 'outside_office' ? 'checked' : '' }} value="outside_office" class="custom-control-input" id="outside_office" name="type">
                                <label class="custom-control-label" for="outside_office"> {{__('documentations.outside_office')}}</label>
                            </div>
                        </div>
                    </div>
                </div>

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



@endsection

@section('inner_js')
    <!-- 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>
        var route_prefix = "{{ url(config('lfm.prefix')) }}";
        var url = "{{url('/')}}/",
            currentLanguage = "{{$local}}",
            inputName = '';
    </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/lib/toastr.min.js') }}"></script>



    <script>

        $('.add_consulting_button').click(async function (e) {
            e.preventDefault();
            $(this).prop('disabled', true);

            let form = $('.add_consulting_from'),
                data = new FormData(form[0]),
                url = form.attr('action'),
                method = form.attr('method');

            $('.discount_dates_input').each(function () {
                if ($(this).prop('checked') === false){
                    data.append('discount_dates[]', 0);
                    data.append('discount_percentage[]', 'empty');
                } else {
                    data.append('discount_dates[]', 1);
                    let inputSibling = $(this).siblings('.discount_percentage');
                    data.append('discount_percentage[]', inputSibling.val());

                }});


            const response=await ajax({
                url,
                data,
                dataType: 'json',
                method
            });

            if (response.url){
                window.location.href = response.url;
            }

            if (response.errors){
                $(this).prop('disabled', true);
                toasterError(response.errors);
            }


        });

        $(document).on('click', '.active_hall' , async function (e) {
            e.preventDefault();
            let url = $(this).data('href'),
                method = 'get';

            const response=await ajax({
                url,
                dataType: 'json',
                method,
            });
            if (response.message) {
                $(this).children('i').toggleClass('fa-check text-success fa-times text-danger')

            }
        });
    </script>

    @endsection



