@extends('admin.layouts.app')


@section('content')

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

@endif

{!! Form::model($project, ['method' => 'PATCH', 'route' => ['admin.projects.update', $project->id], 'files' => true]) !!}
<div class="row">
    <div class="col-md-12">
        <div class="card shadow mb-4">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary">{{awtTrans('Update Project')}}</h6>
            </div>
            <div class="card-body">

                <div class="row">


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

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

                </div>

                <div class="row">

                    <div class="form-group col-lg-6">
                        {!! Form::label('customer_id', awtTrans('Customers')) !!}
                        {!! Form::select('customer_id', [''=>awtTrans('Choose Customer'),] + $customers, null, ['class' => 'form-control']) !!}
                        <small class="text-danger">{{ $errors->first('customer_id') }}</small>
                    </div>


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

                <div class="row">


                    <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 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>

                <div class="row">

                    <div class="form-group col-md-6">
                        {!! Form::label('completion_date', awtTrans('Complation Date')) !!}
                        <input type="date" name="completion_date" id="completion_date" value="{{ $project->completion_date->format('Y-m-d') }}" class="form-control">
                    </div>

                    <div class="form-group col-lg-6">
                        {!! Form::label('company_id', awtTrans('Companies')) !!}
                        {!! Form::select('company_id', [''=>awtTrans('Choose company'),] + $companies, null, ['class' => 'form-control']) !!}
                        <small class="text-danger">{{ $errors->first('company_id') }}</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 data-input="photo" data-preview="photo" class="lfm 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  photo" id="holder">
                            <img width="100" src="{{ $project->photo }}" alt="">
                        </div>
                        <small class="text-danger">{{ $errors->first('photo') }}</small>
                    </div>
                </div>

                <div class="row">

                    <div class="form-group col-lg-12">
                        {!! Form::label('images', awtTrans('Choose Images')) !!}
                        <div class="input-group">
                            <span class="input-group-btn">
                                <a data-input="images" data-preview="images" class="lfm 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>
                            <input type="text" name="images" class="{{ $errors->has('images') ? 'form-control is-invalid images' : 'form-control images' }}" id="images" value="@foreach ($project->images  as $image){{ $image->image }},@endforeach">
                        </div>
                        <div class="mb-3 mt-3 d-block images" id="holder">
                            @foreach ($project->images as $image)
                            <img src="{{ $image->image }}" width="70px" alt="">
                            @endforeach
                        </div>
                        <small class="text-danger">{{ $errors->first('images') }}</small>
                    </div>
                </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 ($project->keywords->isNotEmpty())
                    @foreach ($project->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>
    </div>
</div>


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

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

@endsection