@extends('layouts.app_admin')
@section('title', 'Blogs')
@push('css')
@endpush

@section('content')

<!-- Main Content -->
<div class="main-content">
    <section class="section">
        <div class="col-12 section-header">
            <div class="col-6">
                <h1> Edit </h1>
            </div>

        </div>
        @if ($errors->any())
        <div class="col-sm-12">
            <div class="alert  alert-warning alert-dismissible fade show" role="alert">
                @foreach ($errors->all() as $error)
                <span>
                    <p>{{ $error }}</p>
                </span>
                @endforeach
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
        </div>
        @endif

        @include('flash-message')

        <div class="section-body">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">
                        <form method="POST" action="{{ route('blog.update', $id) }}" id="editForm" enctype="multipart/form-data">
                            {{ method_field('PATCH') }}
                            {{ csrf_field() }}
                            <ul class="nav nav-tabs" id="languageTabs">
                                <li class="nav-item">
                                    <a class="nav-link active" id="english-tab" data-toggle="tab" href="#english-section">English</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" id="arabic-tab" data-toggle="tab" href="#arabic-section">Arabic</a>
                                </li>
                            </ul>
                            <div class="tab-content">
                                <div class="tab-pane fade show active" id="english-section">
                                    <!-- English form fields -->
                                    <div class="form-group">
                                        <label for="title_en">Title (English)</label>
                                        <input type="text" name="title_en" class="form-control form-control-lg" value="{{ $data->title_en }}">
                                    </div>

                                    <div class="form-group">
                                        <label for="author_name">Author Name</label>
                                        <input type="text" name="author_name" class="form-control form-control-lg" value="{{ $data->author_name }}">
                                    </div>



                                    <div class="form-group">
                                        <label for="details_en">Details (English)</label><br>
                                        <textarea name="ck_editor_text">{{ $data->details_en }}</textarea>
                                    </div>
                                </div>

                                <div class="tab-pane fade" id="arabic-section">
                                    <!-- Arabic form fields -->
                                    <div class="form-group">
                                        <label for="title_ar">Title (Arabic)</label>
                                        <input type="text" name="title_ar" class="form-control form-control-lg" value="{{ $data->title_ar }}">
                                    </div>

                                    <div class="form-group">
                                        <label for="details_ar">Details (Arabic)</label><br>
                                        <textarea name="ck_editor_text_ar">{{ $data->details_ar }}</textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                @if ($data->image != null)
                                <div class="col-lg-3 detail__title">
                                    <div class="form-group">
                                        <label for="blood_group">Existing Image</label>
                                        <input type="hidden" class="form-control" name="existing_image" value="{{ $data->image }}" readonly />
                                        <img src="{{ asset('images/blog/' . $data->image) }}" width="300" alt="user photo" style="padding-left: 0px;" /><br>
                                    </div>
                                </div>
                                <div class="col-lg-3 detail__title">
                                    <div class="form-group">
                                        <label for="file">Image</label>
                                        <input type="file" name="image" class="form-control form-control-lg" />
                                    </div>
                                </div>
                                @else
                                <div class="col-lg-6 detail__title">
                                    <div class="form-group">
                                        <label for="file">Image</label>
                                        <input type="file" name="image" class="form-control form-control-lg" />
                                    </div>
                                </div>
                                @endif
                            </div>
                            <div class="card-footer text-right">
                                <button class="btn btn-primary mr-1" type="submit">Update</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </section>
    <!-- End -->
</div>



@endsection

@section('extra-js')
<script type="text/javascript">
    function myFunction() {
        // Get the checkbox
        var checkBox = document.getElementById("main_menu");
        console.log(checkBox);
        if (checkBox.checked == true) {
            checkBox.value = 1;
        } else {
            checkBox.value = 0;
        }

    }

    function myFunction2() {
        // Get the checkbox
        var checkBox2 = document.getElementById("home_page");
        console.log(checkBox2);
        if (checkBox2.checked == true) {
            checkBox2.value = 1;
        } else {
            checkBox2.value = 0;
        }

    }
</script>


@endsection