@extends('admin.layouts.app')

@section('content')
@if (session('post_action_msg'))
<div class="alert alert-success">
    {{ session('post_action_msg') }}
</div>
@endif
@if ($errors->any())
<div class="alert alert-danger">
    <ul class="m-0">
        @foreach ($errors->all() as $error)
        <li>{{ $error }}</li>
        @endforeach
    </ul>
</div>
@endif
<h2 class="mb-3">{{ awtTrans('Edit Post') }}</h2>
{!! Form::model($post , ['method' => 'PATCH', 'route' => ['admin.posts.update', $post->id], 'files'=>true]) !!}
<div class="row">

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

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

<div class="row">

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

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

</div>

<div class="row">

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

    <div class="form-group col-lg-6">
        {!! Form::label('photo', awtTrans('الصورة')) !!}
        <div class="input-group">
            <span class="input-group-btn">
                <a id="lfm" data-input="photo" data-preview="holder" 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 holder" id="holder">
            <img width="100" src="{{ $post->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-keyword"><i class="fas fa-plus"></i></button>
    </div>
</div>

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

    @if ($post->keywords->isNotEmpty())
    @foreach ($post->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>

{!! Form::submit(awtTrans('Update Post'), ['class' => 'btn btn-info']) !!}
<a class="btn btn-primary" href="{{ route('admin.posts.index') }}" role="button"><i class="fas fa-arrow-alt-circle-left   mr-2 "></i>{{awtTrans('Back')}}</a>

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