@extends('back-end.master.app')
@section('title', 'poets')
@section('pageCSS')
    <link href="{{ asset('back-end/style.css') }}" rel="stylesheet">
    <link href="{{ asset('back-end/vendor/summernote/summernote-bs4.css') }}" rel="stylesheet">
    <style>
        .form-control,
        option {
            direction: rtl !important;
        }
    </style>
@endsection
@section('body')
    <main class="app-content">
        <div class="card">
            <div class="card-header">
                <h4>Create</h4>
                @if ($errors->any())
                    @foreach ($errors->all() as $error)
                        <div>{{ $error }}</div>
                    @endforeach
                @endif
            </div>
            <div class="card-body">
                <form action="{{ route('publicPoetries.update',$data->id) }}" method="POST" enctype="multipart/form-data">
                    @method('PUT')
                    @csrf
                    <div class="row mt-3">
                        <div class="col-md-9">
                            <div class="form-outline">
                                <input type="test" id="title" name="title" required value="{{ old('title') ?? $data->title }}"
                                    class="form-control" />
                                <label class="form-label" for="title">لومړی بیت</label>
                            </div>
                        </div>
                      
                        <div class="col-md-9 mt-2">
                            <select id="cat_id" type="text"
                                class="form-control  @error('cat_id') is-invalid @enderror" required name="cat_id">
                                <option value="">کټګورۍ یی وټاکی</option>
                                @foreach ($categories as $row)
                                    <option value="{{ $row->id }}" @if($row->id==$data->cat_id) {{ "selected" }} @endif>{{ $row->name_en }}</option>
                                @endforeach
                            </select>
                            @error('cat_id')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                      

                        <div class="col-md-12 mt-3">
                            <div class="form-outline">
                                <textarea cols="10" rows="10" name="body" id="summernote" class="form-control">{{ old('body') ?? $data->body }}</textarea>
                            </div>
                        </div>
                        <div class="col-md-4 mt-2">
                            <button type="submit" class="btn btn-primary btn-rounded mb-4">Save</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </main>
@endsection


@section('pageJs')
    <script src="{{ asset('back-end/main.js') }}"></script>
    <script src="{{ asset('back-end/vendor/summernote/summernote-bs4.js') }}"></script>
    <script type="text/javascript">
        $(".app-menu").removeClass("active");
        $("#nav_poetsi").addClass("active");
        $("#poetsi").addClass("is-expanded");
        $("#poets_history").addClass("active");
        $(document).on('change', '#cat_id', function() {

            $.ajax({
                url: '{{ route('category.get') }}',
                type: 'GET',
                data: {
                    'cat_id': $(this).val(),
                },
                success: function(data) {

                    $("#scat_id").html(data);
                },
                error: function() {
                    swal("Warrning", "Error occured!", "error");
                },
            });
        });
        $(document).ready(function() {
            $('#summernote').summernote();
        });

    </script>


@endsection
