@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">
            @csrf


            <div class="form-group col-lg-6">
                <label>{{ __('payment_logs.acc_status') }} </label>
                <select id="acc_status" onchange="selectStatus(this)" class="form-control {{ $errors->has('acc_status') ? 'is-invalid' : '' }}" name="acc_status">
                    <option value="">{{__('dashboard.select')}}</option>
                    @foreach($acc_statuses as $row)
                        <option {{$request->acc_status == $row ? 'selected' : ''}} value="{{$row}}">{{ __('payment_logs.acc_statuses.'.$row) }}</option>
                    @endforeach
                </select>
            </div>


            <div class="col-lg-6" id="acc">

            </div>

            <div class="col-lg-12 row" id="form-data">

                <div class="form-group col-lg-12">
                    <hr>
                </div>
                <div class="form-group col-lg-6">
                    <label>{{ __('payment_logs.status') }} </label>
                    <select class="form-control {{ $errors->has('status') ? 'is-invalid' : '' }}" name="status">
                        @foreach($statuses as $row)
                            <option  value="{{$row}}">{{ __('payment_logs.statuses.'.$row) }}</option>
                        @endforeach
                    </select>
                </div>
                <div class="form-group col-lg-6">
                    <label>{{ __('payment_logs.price') }} </label>
                    <input type="number" step=".01" name="price" class="form-control" placeholder="{{ __('payment_logs.price') }}">
                </div>
                <div class="form-group col-lg-12">
                    <label>{{ __('payment_logs.description') }} </label>
                    <textarea name="description" class="form-control" placeholder="{{ __('payment_logs.description') }}"></textarea>
                </div>

                <div class="form-group col-lg-12">
                    <hr>
                </div>
            </div>

            <div class="col-lg-12 row" id="info">

            </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>
        let route_prefix = "{{ url(config('lfm.prefix')) }}",
            url = "{{url('/')}}/",
            url_status = "{{route('admin.selectStatus')}}",
            url_info = "{{route('admin.paymentInfo')}}",
            currentLanguage = "{{getCurrentLocale()}}",
            imagePath = "{{asset('')}}";
    </script>
    <script>
        async function selectStatus()
        {
            let status = $('#acc_status').val()

            await $.ajax({
                url : url_status,
                type : 'GET',
                data : 'acc_status='+status+'&id='+"{{$request->id}}",
                success:function(data)
                {
                    $('#acc').html(data);
                    $('#info').html('')
                }
            })
        }
        async function selectAcc()
        {
            let id = $('#acc_id').val()
            if(id == null)
            {
                id = "{{$request->id}}"
            }
            let status = $('#acc_status').val()
            await $.ajax({
                url : url_info,
                type : 'GET',
                data : 'acc_status='+status+'&id='+id,
                success:function(data)
                {
                    $('#info').html(data)
                    $('#form-data').show()
                }
            })
        }
        if("{{$request->acc_status}}")
        {
             selectStatus()
            if("{{$request->id}}")
            {
                setTimeout(
                function()
                {
                    selectAcc()
                }, 500);
            }
        }
        else
        {
            $('#form-data').hide()
        }
    </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



