@extends('admin.layouts.app')

@section('content')
<!-- @if ($errors->any())
        <div class="alert alert-danger">
            @foreach ($errors->all() as $error)
                <ul class="m-0">
                    <li>{{ $error }}</li>
                </ul>
            @endforeach
        </div>
    @endif -->

@if (session('category_create_msg'))
<div class="alert alert-success">
    {{ session('category_create_msg') }}
</div>
@elseif (session('category_update_msg'))
<div class="alert alert-success">
    {{ session('category_update_msg') }}
</div>
@elseif (session('category_delete_msg'))
<div class="alert alert-success">
    {{ session('category_delete_msg') }}
</div>

@endif
<h2 class="mb-3">{{awtTrans('All Categories')}}</h2>
<div class="row">

    <div class="col-lg-6">
        <div class="card shadow mb-4">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary">{{awtTrans('Add Categories')}}</h6>
            </div>
            <div class="card-body">
                {!! Form::open(['method' => 'POST', 'route' => 'admin.categories.store']) !!}
                <div class="row">
                    <div class="form-group col-lg-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-lg-6">
                        {!! Form::label('name_en', awtTrans('Name English')) !!}
                        {!! 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>
                {!! Form::submit(awtTrans('Add Category'), ['class' => 'btn btn-info']) !!}
                {!! Form::close() !!}
            </div>
        </div>
    </div>

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

        <div class="card shadow mb-4">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary">{{awtTrans('All Categories')}}</h6>
            </div>
            <div class="card-body">
                @if ($categories->isNotEmpty())
                <div class="table-responsive">
                    <table class="table table-bordered" id="dataTableCategories" width="100%" cellspacing="0">
                        <thead>
                            <tr>
                                <th>{{ awtTrans('Delete') }}</th>
                                <th>{{awtTrans('Name Arabic')}}</th>
                                <th>{{awtTrans('Name English')}}</th>
                                <th>{{awtTrans('Actions')}}</th>
                            </tr>
                        </thead>
                        <tfoot>
                            <tr>
                                <th>{{ awtTrans('Delete') }}</th>
                                <th>{{awtTrans('Name Arabic')}}</th>
                                <th>{{awtTrans('Name English')}}</th>
                                <th>{{awtTrans('Actions')}}</th>
                            </tr>
                        </tfoot>
                        <tbody>
                            @foreach ($categories as $category)
                            <tr>
                                <td>{{ $category->id }}</td>
                                <td><a href="{{ route('admin.categories.edit', $category->id) }}">{{ $category->name_ar }}</a></td>
                                <td><a href="{{ route('admin.categories.edit', $category->id) }}">{{ $category->name_en }}</a></td>
                                <td>
                                    <a href="{{ route('admin.categories.destroy', $category->id) }}" data-id="{{$category->id}}" class="btn btn-danger btn-circle btn-sm item-delete">
                                        <i class="fas fa-trash"></i>
                                    </a>
                                    <a href="{{ route('admin.categories.edit', $category->id) }}" class="btn btn-success btn-circle btn-sm">
                                        <i class="fas fa-edit"></i>
                                    </a>
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>

                @else
                <h3 class="text-center">{{awtTrans('No Categories Yet')}} !</h3>
                @endif
            </div>
        </div>
    </div>

</div>




@endsection



@section('scripts')
<script>
    $(document).ready(function() {
        $('#dataTableCategories').DataTable({
            order: [0, 'desc'],
            'language': {
                'url': "{{ app()->getLocale() == 'ar' ? 'https://cdn.datatables.net/plug-ins/1.10.12/i18n/Arabic.json' : 'https://cdn.datatables.net/plug-ins/1.10.12/i18n/English.json' }}",
            },
        });
    });
</script>
@endsection