@extends('back-end.master.app')

@section('title', 'Edit Poetry')

@section('pageCSS')
    <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>Edit Poetry</h4>
        </div>
        <div class="card-body">
            @if ($errors->any())
                <div class="alert alert-danger">
                    <ul class="mb-0">
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif

            <form action="{{ route('poetries.poetry_update', $poetry->id) }}" method="POST">
                @csrf
                @method('PUT')
                <input type="hidden" name="poet_id" value="{{ $poetry->poet_id }}">

                <div class="row">
                    <div class="col-md-9">
                        <div class="form-group">
                            <label>لومړی بیت <span class="text-danger">*</span></label>
                            <input type="text" name="title" class="form-control" value="{{ old('title', $poetry->title) }}" required>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <label>لومړی الفابیټ <span class="text-danger">*</span></label>
                            <select name="alphabit" class="form-control" required>
                                <option value="">انتخاب</option>
                                @foreach($alphabits as $row)
                                    <option value="{{ $row->name }}" {{ (old('alphabit', $poetry->alphabit) == $row->name) ? 'selected' : '' }}>{{ $row->name }}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label>کټګورۍ <span class="text-danger">*</span></label>
                            <select name="cat_id" class="form-control" required>
                                <option value="">-- انتخاب --</option>
                                @foreach($categories as $cat)
                                    <option value="{{ $cat->id }}" {{ (old('cat_id', $poetry->cat_id) == $cat->id) ? 'selected' : '' }}>{{ $cat->title_ps }}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    @if($subCategories->count())
                    <div class="col-md-12">
                        <div class="form-group">
                            <label>فرعي کټګورۍ</label>
                            <select name="scat_id" class="form-control">
                                <option value="">-- اختیاري --</option>
                                @foreach($subCategories as $sub)
                                    <option value="{{ $sub->id }}" {{ (old('scat_id', $poetry->scat_id) == $sub->id) ? 'selected' : '' }}>{{ $sub->title_ps }}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    @endif
                    <div class="col-md-12">
                        <div class="form-group">
                            <label>شعر <span class="text-danger">*</span></label>
                            <textarea name="body" id="summernote" class="form-control">{{ old('body', $poetry->body) }}</textarea>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <button type="submit" class="btn btn-primary">Update</button>
                        <a href="{{ route('poets.show', $poetry->poet_id) }}" class="btn btn-secondary">Cancel</a>
                    </div>
                </div>
            </form>
        </div>
    </div>
</main>
@endsection

@section('pageJs')
    <script src="{{ asset('back-end/vendor/summernote/summernote-bs4.js') }}"></script>
    <script>
        $(document).ready(function() {
            $('#summernote').summernote({
                height: 300,
                direction: 'rtl'
            });
        });

        $(".app-menu").removeClass("active");
        $("#nav_poetsi").addClass("active");
        $("#poetsi").addClass("is-expanded");
        $("#poets_history").addClass("active");
    </script>
@endsection
