@extends('admin.layouts.app')


@section('content')

@if (session('service_update_msg'))
<div class="alert alert-success">
    {{ session('service_update_msg') }}
</div>
@endif

<h2 class="mb-3">{{ awtTrans('Edit Service') }}</h2>

{!! Form::model($service, ['method' => 'PATCH', 'route' => ['admin.services.update', $service->id], 'files' => true]) !!}
<div class="row">
    <div class="col-md-12">

        <div class="row">
            <div class="form-group col-lg-12">
                {!! Form::label('parent_id', awtTrans('Main Services')) !!}
                {!! Form::select('parent_id', [''=>awtTrans('Choose Main Service'),] + $services, null, ['class' => 'form-control']) !!}
                <small class="text-danger">{{ $errors->first('parent_id') }}</small>
            </div>
        </div>

        <div class="row">
            <div class="form-group col-md-6">
                {!! Form::label('name_ar', awtTrans('Name Arabic')) !!}
                {!! Form::text('name_ar', null, ['class' => $errors->has('name_ar') ? 'form-control is-invalid' : 'form-control']) !!}
                <small class="text-danger">{{ $errors->first('name_ar') }}</small>
            </div>

            <div class="form-group col-md-6">
                {!! Form::label('name_en', awtTrans('Name Arabic')) !!}
                {!! Form::text('name_en', null, ['class' => $errors->has('name_en') ? 'form-control is-invalid' : 'form-control']) !!}
                <small class="text-danger">{{ $errors->first('name_en') }}</small>
            </div>
        </div>


        <div class="row">

            <div class="form-group col-lg-6">
                {!! Form::label('desc_ar', awtTrans('Description Arabic')) !!}
                {!! Form::textarea('desc_ar', null, [ 'class' => 'form-control tinyEditor']) !!}
                <small class="text-danger">{{ $errors->first('desc_ar') }}</small>
            </div>

            <div class="form-group col-lg-6">
                {!! Form::label('desc_en', awtTrans('Description English')) !!}
                {!! Form::textarea('desc_en', null, [ 'class' => 'form-control tinyEditor']) !!}
                <small class="text-danger">{{ $errors->first('desc_en') }}</small>
            </div>

        </div>


        <div class="row">

            <div class="form-group col-lg-12">
                {!! Form::label('photo', awtTrans('الصورة')) !!}
                <div class="input-group">
                    <span class="input-group-btn">
                        <a id="lfm" data-input="photo" data-preview="photo" class="btn btn-secondary text-white px-4" style="border-top-right-radius: 0;border-bottom-right-radius: 0;border-top-left-radius: 0;border-bottom-left-radius: 0;">
                            <i class="fa fa-picture-o"></i> {{ awtTrans('اختر الصورة') }}
                        </a>
                    </span>
                    {!! Form::text('photo', null, ['class' => $errors->has('photo') ? 'form-control is-invalid photo' : 'form-control photo' , 'readonly' => 'readonly']) !!}
                </div>
                <div class="mb-3 mt-3 d-block slider-holder photo" id="photo">
                    <img width="100" src="{{ $service->photo }}" alt="">
                </div>
                <small class="text-danger">{{ $errors->first('photo') }}</small>
            </div>
        </div>



        <div class="row">

            <div class="form-group col-lg-12">
                <button type="button" class="btn btn-info btn-block" id="add-image-desc"><i class="fas fa-plus"></i> {{ awtTrans('Add Image With Description') }}</button>
            </div>
        </div>

        <div class="row" id="append-image-desc">

            @if ($service->imagewithdesc->isNotEmpty())
            @foreach ($service->imagewithdesc as $key2 => $imagewithdesc)
            <input type="hidden" name="id[]" value="{{ $imagewithdesc->id }}">
            @if ($key2 == 0)
            <div class="row col-lg-12">

                <div class="form-group col-lg-2">
                    {!! Form::label('image', 'الصورة:') !!}
                    <div class="input-group">
                        <div class="custom-file">
                            <input type="file" name="imageee[]" value="" data-id="image" multiple class="from-control image image_{{$imagewithdesc->id}}">
                        </div>
                    </div>
                    <img src="{{ url($imagewithdesc->image) }}" width="150px" alt="">
                    <div class="">
                        @if ($errors->has('image'))
                        <span class="help-block">
                            <strong style="color: red;">{{ $errors->first('image') }}</strong>
                        </span>
                        @endif
                    </div>

                </div>

                <div class="form-group col-lg-4">
                    <lable for="desc2_ar">الوصف بالعربي</lable>
                    <textarea type="text" name="desc2_arrr[]" class="form-control desc_ar_{{$imagewithdesc->id}}">{{ $imagewithdesc->desc_ar }}</textarea>
                </div>

                <div class="form-group col-lg-4">
                    <lable for="desc2_en">الوصف بالانجليزي</lable>
                    <textarea type="text" name="desc2_ennn[]" class="form-control desc_en_{{$imagewithdesc->id}}">{{ $imagewithdesc->desc_en }}</textarea>
                </div>

                <div class="form-group col-lg-2">
                    <lable for="desc2_en">تعديل</lable>
                    <button type="button" class="btn btn-info btn-block edit-image-desc-ajax" data-url="{{ route('admin.edit.imagewithdesc') }}" data-id="{{ $imagewithdesc->id }}"><i class="fas fa-edit"></i></button>
                </div>

            </div>
            @else

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


                <div class="form-group col-lg-2">
                    {!! Form::label('image', 'الصورة:') !!}
                    <div class="input-group">
                        <div class="custom-file">
                            <input type="file" name="imageee[]" data-id="image" multiple class="from-control image image_{{$imagewithdesc->id}}">
                        </div>
                    </div>
                    <img src="{{ url($imagewithdesc->image) }}" width="150px" alt="">

                    <div class="">
                        @if ($errors->has('image'))
                        <span class="help-block">
                            <strong style="color: red;">{{ $errors->first('image') }}</strong>
                        </span>
                        @endif
                    </div>

                </div>

                <div class="form-group col-lg-3">
                    <lable for="desc2_ar">الوصف بالعربي</lable>
                    <textarea type="text" name="desc2_arrr[]" class="form-control desc_ar_{{$imagewithdesc->id}}">{{ $imagewithdesc->desc_ar }}</textarea>
                </div>

                <div class="form-group col-lg-3">
                    <lable for="desc2_en">الوصف بالانجليزي</lable>
                    <textarea type="text" name="desc2_ennn[]" class="form-control desc_en_{{$imagewithdesc->id}}">{{ $imagewithdesc->desc_en }}</textarea>
                </div>

                <div class="form-group col-lg-2">
                    <lable for="desc2_en">تعديل</lable>
                    <button type="button" class="btn btn-info btn-block edit-image-desc-ajax" data-url="{{ route('admin.edit.imagewithdesc') }}" data-id="{{ $imagewithdesc->id }}"><i class="fas fa-edit"></i></button>
                </div>

                <div class="form-group col-lg-2">
                    <lable for="desc2_en">حذف</lable>
                    <button type="button" class="btn btn-danger btn-block delete-image-desc-ajax" data-url="{{ route('admin.remove.imagewithdesc') }}" data-id="{{ $imagewithdesc->id }}"><i class="fas fa-trash"></i></button>
                </div>

            </div>

            @endif
            @endforeach
            @endif
        </div>



        <div class="row">

            <div class="form-group col-lg-12">
                <button type="button" class="btn btn-info btn-block" id="add-keyword"><i class="fas fa-plus"></i></button>
            </div>
        </div>

        <div class="row" id="append-keyword">

            @if ($service->keywords->isNotEmpty())
            @foreach ($service->keywords as $key => $keyword)
            @if ($key == 0)

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


                <div class="form-group col-lg-5">
                    <lable for="keyword_ar">الكلمات المفتاحية بالعربي</lable>
                    <input type="text" name="keyword_ar[]" value="{{ $keyword->body_ar }}" class="form-control" />
                </div>

                <div class="form-group col-lg-5">
                    <lable for="keyword_en">الكلمات المفتاحية بالانجليزي</lable>
                    <input type="text" name="keyword_en[]" value="{{ $keyword->body_en }}" class="form-control" />
                </div>


            </div>

            @else

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


                <div class="form-group col-lg-5">
                    <lable for="keyword_ar">الكلمات المفتاحية بالعربي</lable>
                    <input type="text" name="keyword_ar[]" value="{{ $keyword->body_ar }}" class="form-control" />
                </div>

                <div class="form-group col-lg-5">
                    <lable for="keyword_en">الكلمات المفتاحية بالانجليزي</lable>
                    <input type="text" name="keyword_en[]" value="{{ $keyword->body_en }}" class="form-control" />
                </div>

                <div class="form-group col-lg-2">
                    <lable for="keyword_en">حذف</lable>
                    <button type="button" class="btn btn-danger btn-block" id="delete-keyword"><i class="fas fa-trash"></i></button>
                </div>

            </div>
            @endif
            @endforeach
            @endif
        </div>


    </div>
</div>


{!! Form::submit(awtTrans('Update Service'), ['class' => 'btn btn-success']) !!}
<a href="{{ route('admin.services.index') }}" class="btn btn-primary "><i class="fas fa-arrow-left  fa-sm  "></i> {{awtTrans('Back')}}</a>

{!! Form::close() !!}

@endsection